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

Ignore imports for assign in no-unused-imports rule #2382

Merged
merged 1 commit into from
Nov 27, 2023
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 @@ -298,8 +298,8 @@ public class NoUnusedImportsRule : StandardRule("no-unused-imports") {
"get", "set",
// invoke
"invoke",
// augmented assignments
"plusAssign", "minusAssign", "timesAssign", "divAssign", "modAssign",
// (augmented) assignment
"assign", "plusAssign", "minusAssign", "timesAssign", "divAssign", "modAssign",
// (in)equality
"equals",
// comparison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,29 @@ class NoUnusedImportsRuleTest {
""".trimIndent()
noUnusedImportsRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2343 - Do not mark assign as unused import`() {
val code =
"""
package com.github.erdi.ktlint.bug

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.assign
import javax.inject.Inject

class ExamplePlugin @Inject constructor() : Plugin<Project> {
override fun apply(project: Project) {
project.let {
it.javaexec {
mainClass = "com.github.erdi.ktlint.bug.ExampleMainClass"
}
}
}
}
""".trimIndent()
noUnusedImportsRuleAssertThat(code)
.hasNoLintViolations()
}
}