Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isolated projects compatibility #263

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class KtlintGradlePlugin : Plugin<Project> {
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") }
Comment on lines +37 to +38
Copy link
Contributor Author

@lwasyl lwasyl Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will now traverse directories and not projects. Previously if projects were set up with custom directories, the plugin would look for the .editorconfig file in the actual project directories. Now it traverses the file system directories from the project directory up to the root project directory.

So e.g. for projects set up to use custom directories (using project(":some-project").projectDir = file("custom/directory"))

: -> .
:foo -> ./projects/custom/directory/foo
:foo:bar -> ./projects/custom/directory/bar

then when applying the plugin in :foo:bar project:

  • previously we'd search for .editorconfig files in ./projects/custom/directory/foo, ./projects/(...)/bar and .
  • now, we'll search for .editorconfig files in ./projects/custom/directory/bar, ./projects/custom/directory, ./projects/custom, ./projects/ and .

(fwiw I think the new behavior is more intuitive and expected)

Copy link
Member

@mateuszkwiecinski mateuszkwiecinski Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this supposed to resemble what ktlint does when searching for applicable editorconfigs, so the new behavior can be even considered a fix 👍

.toList()

tasks.register("validateEditorConfigForKtlint", CheckEditorConfigTask::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Loading