Skip to content

Commit

Permalink
fix isRootEditorConfig (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
wakingrufus authored Apr 18, 2023
1 parent 194db6e commit f27c1dd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

- fix new ktlint errors that come from our new default version of ktlint [#651](https://github.com/JLLeitschuh/ktlint-gradle/pull/651)
- fix syntax bug in release logic for VERSION_LATEST_RELEASE.txt [#651](https://github.com/JLLeitschuh/ktlint-gradle/pull/651)
- fix isRootEditorConfig [#664](https://github.com/JLLeitschuh/ktlint-gradle/pull/664)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private tailrec fun searchEditorConfigFiles(
}
}

private val editorConfigRootRegex = "^root\\s?=\\s?true\\R".toRegex()
private val editorConfigRootRegex = "^root\\s?=\\s?true".toRegex()

private fun Path.isRootEditorConfig(): Boolean {
internal fun Path.isRootEditorConfig(): Boolean {
if (!Files.exists(this) || !Files.isReadable(this)) return false

toFile().useLines { lines ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jlleitschuh.gradle.ktlint

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File

internal class PluginUtilTest {
@TempDir
lateinit var temporaryFolder: File

@Test
fun `test isRootEditorConfig returns true`() {
temporaryFolder.resolve("test-pos.txt").apply {
createNewFile()
writeText(
"""
root=true
""".trimIndent()
)
Assertions.assertTrue(this.toPath().isRootEditorConfig()) {
"correctly detects root"
}
delete()
}
}

@Test
fun `test isRootEditorConfig returns false`() {
temporaryFolder.resolve("test-neg.txt").apply {
createNewFile()
writeText(
"""
[*.kt]
""".trimIndent()
)
Assertions.assertFalse(this.toPath().isRootEditorConfig()) {
"correctly does not match non-root file"
}
delete()
}
}
}

0 comments on commit f27c1dd

Please sign in to comment.