Skip to content

Commit 9c4e305

Browse files
committed
exclude deleted files from incremental checks (fixes #679)
1 parent cb6f708 commit 9c4e305

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ abstract class BaseKtLintCheckTask @Inject constructor(
201201
.create()
202202
.loadErrors(discoveredErrors.asFile.get())
203203
.map { it.lintedFile }
204+
.filter { it.exists() }
204205
.toSet()
205206
} else {
206207
emptySet()

plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt

+42
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,46 @@ class KtlintPluginTest : AbstractPluginTest() {
731731
build(CHECK_PARENT_TASK_NAME)
732732
}
733733
}
734+
735+
@DisplayName("Lint check should pass after file is deleted")
736+
@CommonTest
737+
fun checkAfterFileDelete(gradleVersion: GradleVersion) {
738+
project(gradleVersion) {
739+
val fileOne = "src/main/kotlin/FileOne.kt"
740+
createSourceFile(
741+
fileOne,
742+
"""
743+
val foo = "bar"
744+
745+
""".trimIndent()
746+
)
747+
748+
val fileTwo = "src/main/kotlin/FileTwo.kt"
749+
createSourceFile(
750+
fileTwo,
751+
"""
752+
val bar = "foo"
753+
754+
""".trimIndent()
755+
)
756+
757+
build(CHECK_PARENT_TASK_NAME) {
758+
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
759+
}
760+
761+
removeSourceFile(fileOne)
762+
val fileThree = "src/main/kotlin/FileThree.kt"
763+
createSourceFile( // Need to add or modify a source to repro file not found error.
764+
fileThree,
765+
"""
766+
val bar = "foo"
767+
768+
""".trimIndent()
769+
)
770+
771+
build(CHECK_PARENT_TASK_NAME, "--info") { // <-- Fails, file one is not found.
772+
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
773+
}
774+
}
775+
}
734776
}

0 commit comments

Comments
 (0)