diff --git a/CHANGELOG.md b/CHANGELOG.md index e0506f31..47fdc3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt index 7017db5f..6a7b19c8 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt @@ -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 -> diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtilTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtilTest.kt new file mode 100644 index 00000000..43ef281b --- /dev/null +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtilTest.kt @@ -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() + } + } +}