Repository: jeremymailen/kotlinter-gradle (kotlin)

Issue:
Lint task sometimes does not re-run when editorconfig changes
Although we are supposed to consider the editorconfig file contents a build input and re-run lint tasks when it changes, somehow this isn't happening sometimes. It often leads users to perceive that one of their editorconfig settings is not working.
Reference #324 and #321

Pull request:
Fixes #327

h/t @mateuszkwiecinski for figuring this one out.

After a build failure, logic before did not check for changed editorconfig files since that scenario is not "incremental".
Instead we always return changed editorconfig files.

Update tests accordingly.

Patch:
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
index 2322bafb..74c6d3bb 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
@@ -28,11 +28,8 @@ abstract class ConfigurableKtLintTask(
         from(projectLayout.findApplicableEditorConfigFiles().toList())
     }
 
-    protected fun getChangedEditorconfigFiles(inputChanges: InputChanges) = if (inputChanges.isIncremental) {
+    protected fun getChangedEditorconfigFiles(inputChanges: InputChanges) =
         inputChanges.getFileChanges(editorconfigFiles).map(FileChange::getFile)
-    } else {
-        emptyList()
-    }
 }
 
 internal inline fun <reified T> ObjectFactory.property(default: T? = null): Property<T> = property(T::class.java).apply {


Test patch:
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
index 2b19e0d6..cec116bd 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
@@ -131,7 +131,7 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
     }
 
     @Test
-    fun `editorconfig changes are taken into account on lint task re-runs`() {
+    fun `editorconfig changes are taken into account when adds lint issues`() {
         setup(KotlinterConfig.DEFAULT)
         projectRoot.resolve(".editorconfig") {
             writeText(
@@ -173,7 +173,36 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
     }
 
     @Test
-    fun `editorconfig changes are ignored for format task re-runs`() {
+    fun `editorconfig changes are taken into account when removes lint issues`() {
+        setup(KotlinterConfig.DEFAULT)
+        projectRoot.resolve(".editorconfig") {
+            writeText(editorConfig)
+        }
+        projectRoot.resolve("src/main/kotlin/FileName.kt") {
+            writeText(kotlinClass("DifferentClassName"))
+        }
+        buildAndFail("lintKotlin").apply {
+            assertEquals(TaskOutcome.FAILED, task(":lintKotlinMain")?.outcome)
+            assertTrue(output.contains("[standard:filename] File 'FileName.kt' contains a single top level declaration"))
+        }
+
+        projectRoot.resolve(".editorconfig") {
+            writeText(
+                // language=editorconfig
+                """
+                    [*.{kt,kts}]
+                    ktlint_standard_filename = disabled
+                """.trimIndent(),
+            )
+        }
+        build("lintKotlin", "--info").apply {
+            assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome)
+            assertTrue(output.contains("resetting KtLint caches"))
+        }
+    }
+
+    @Test
+    fun `editorconfig changes are taken for format task re-runs`() {
         setup(KotlinterConfig.DEFAULT)
         projectRoot.resolve(".editorconfig") {
             writeText(editorConfig)
@@ -200,13 +229,12 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
         }
         build("formatKotlin", "--info").apply {
             assertEquals(TaskOutcome.SUCCESS, task(":formatKotlinMain")?.outcome)
-            assertTrue(output.contains("Format could not fix"))
-            assertFalse(output.contains("resetting KtLint caches"))
+            assertFalse(output.contains("Format could not fix"))
         }
     }
 
     @Test
-    fun `editorconfig changes are ignored for format task re-runs when failBuildWhenCannotAutoFormat enabled`() {
+    fun `editorconfig changes are taken for format task re-runs when failBuildWhenCannotAutoFormat configured`() {
         setup(KotlinterConfig.FAIL_BUILD_WHEN_CANNOT_AUTO_FORMAT)
         projectRoot.resolve(".editorconfig") {
             writeText(editorConfig)
@@ -231,10 +259,8 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
                 """.trimIndent(),
             )
         }
-        buildAndFail("formatKotlin", "--info").apply {
-            assertEquals(TaskOutcome.FAILED, task(":formatKotlinMain")?.outcome)
-            assertTrue(output.contains("Format could not fix"))
-            assertFalse(output.contains("resetting KtLint caches"))
+        build("formatKotlin", "--info").apply {
+            assertEquals(TaskOutcome.SUCCESS, task(":formatKotlinMain")?.outcome)
         }
     }
 }