diff --git a/ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/KtlintGradlePlugin.kt b/ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/KtlintGradlePlugin.kt index cea9644..afb8107 100644 --- a/ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/KtlintGradlePlugin.kt +++ b/ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/KtlintGradlePlugin.kt @@ -34,8 +34,8 @@ public class KtlintGradlePlugin : Plugin { val ktlintConfiguration = createKtlintConfiguration(pluginExtension) val ruleSetConfiguration = createRuleSetConfiguration(ktlintConfiguration) val reportersConfiguration = createReportersConfiguration(ktlintConfiguration) - val recognisedEditorConfigs = generateSequence(project) { it.parent } - .map { it.layout.projectDirectory.file(".editorconfig").asFile } + val recognisedEditorConfigs = generateSequence(projectDir) { if (it == rootProject.projectDir) null else it.parentFile } + .map { it.resolve(".editorconfig") } .toList() tasks.register("validateEditorConfigForKtlint", CheckEditorConfigTask::class.java) { diff --git a/ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/KotlinProjectTest.kt b/ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/KotlinProjectTest.kt index bfaedf9..6ae0d59 100644 --- a/ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/KotlinProjectTest.kt +++ b/ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/KotlinProjectTest.kt @@ -459,6 +459,39 @@ internal class KotlinProjectTest : WithGradleTest.Kotlin() { } } + @Test + fun `plugin is compatible with isolated projects`() { + settingsFile().apply { + appendText("include ':foo:bar'") + } + buildFile().also { it.copyTo(testProjectDir.resolve("foo/bar/build.gradle")) } + kotlinSourceFile( + "CustomObject.kt", + """ + object CustomObject + + """.trimIndent(), + ) + + build("lintKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply { + assertThat(task(":lintKotlin")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + assertThat(output).contains("Configuration cache entry stored") + } + build("lintKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply { + assertThat(task(":lintKotlin")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + assertThat(output).contains("Configuration cache entry reused.") + } + + build("formatKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply { + assertThat(task(":formatKotlin")?.outcome).isEqualTo(TaskOutcome.SUCCESS) + assertThat(output).contains("Configuration cache entry stored") + } + build("formatKotlin", "-Dorg.gradle.unsafe.isolated-projects=true").apply { + assertThat(task(":formatKotlin")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + assertThat(output).contains("Configuration cache entry reused.") + } + } + @Test fun `plugin resolves dynamically loaded RuleSetProviders`() { settingsFile() @@ -520,7 +553,7 @@ internal class KotlinProjectTest : WithGradleTest.Kotlin() { } private fun settingsFile() = settingsFile.apply { - writeText("rootProject.name = 'ktlint-gradle-test-project'") + writeText("rootProject.name = 'ktlint-gradle-test-project'\n") } private fun editorConfig() = editorconfigFile.apply {