Skip to content

Commit f27c1dd

Browse files
authored
fix isRootEditorConfig (#664)
1 parent 194db6e commit f27c1dd

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1111

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

1516
### Changed
1617

plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ private tailrec fun searchEditorConfigFiles(
7070
}
7171
}
7272

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

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

7878
toFile().useLines { lines ->
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.jlleitschuh.gradle.ktlint
2+
3+
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
5+
import org.junit.jupiter.api.io.TempDir
6+
import java.io.File
7+
8+
internal class PluginUtilTest {
9+
@TempDir
10+
lateinit var temporaryFolder: File
11+
12+
@Test
13+
fun `test isRootEditorConfig returns true`() {
14+
temporaryFolder.resolve("test-pos.txt").apply {
15+
createNewFile()
16+
writeText(
17+
"""
18+
root=true
19+
""".trimIndent()
20+
)
21+
Assertions.assertTrue(this.toPath().isRootEditorConfig()) {
22+
"correctly detects root"
23+
}
24+
delete()
25+
}
26+
}
27+
28+
@Test
29+
fun `test isRootEditorConfig returns false`() {
30+
temporaryFolder.resolve("test-neg.txt").apply {
31+
createNewFile()
32+
writeText(
33+
"""
34+
[*.kt]
35+
""".trimIndent()
36+
)
37+
Assertions.assertFalse(this.toPath().isRootEditorConfig()) {
38+
"correctly does not match non-root file"
39+
}
40+
delete()
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)