Skip to content

Commit

Permalink
Ignore imports for assign in no-unused-imports rule (#2343) (#2382)
Browse files Browse the repository at this point in the history
Removing this import results in compilation error when shorthand "=" is used instead of function `assign(..)`.

Closes #2343
  • Loading branch information
paul-dingemans authored Nov 27, 2023
1 parent 9452621 commit bfaa201
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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()
}
}

0 comments on commit bfaa201

Please sign in to comment.