diff --git a/CHANGELOG.md b/CHANGELOG.md index b9990482..f7e03da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - update latest version text file manually [#674](https://github.com/JLLeitschuh/ktlint-gradle/pull/674) - decrease plugin build workers to 4 to prevent thrashing [#675](https://github.com/JLLeitschuh/ktlint-gradle/pull/675) +- exclude deleted files from incremental checks [#681](https://github.com/JLLeitschuh/ktlint-gradle/pull/681) ## [11.4.0] - 2023-06-06 diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt index 971b275b..7871cf78 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt @@ -201,6 +201,7 @@ abstract class BaseKtLintCheckTask @Inject constructor( .create() .loadErrors(discoveredErrors.asFile.get()) .map { it.lintedFile } + .filter { it.exists() } .toSet() } else { emptySet() diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt index 76432d74..1ff5f3ff 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt @@ -731,4 +731,46 @@ class KtlintPluginTest : AbstractPluginTest() { build(CHECK_PARENT_TASK_NAME) } } + + @DisplayName("Lint check should pass after file is deleted") + @CommonTest + fun checkAfterFileDelete(gradleVersion: GradleVersion) { + project(gradleVersion) { + val fileOne = "src/main/kotlin/FileOne.kt" + createSourceFile( + fileOne, + """ + val foo = "bar" + + """.trimIndent() + ) + + val fileTwo = "src/main/kotlin/FileTwo.kt" + createSourceFile( + fileTwo, + """ + val bar = "foo" + + """.trimIndent() + ) + + build(CHECK_PARENT_TASK_NAME) { + assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } + + removeSourceFile(fileOne) + val fileThree = "src/main/kotlin/FileThree.kt" + createSourceFile( // Need to add or modify a source to repro file not found error. + fileThree, + """ + val bar = "foo" + + """.trimIndent() + ) + + build(CHECK_PARENT_TASK_NAME, "--info") { // <-- Fails, file one is not found. + assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + } + } + } }