Skip to content

Commit

Permalink
Fix regression introduced in pinterest#1129
Browse files Browse the repository at this point in the history
- Used imports state has to be reset per-file
  • Loading branch information
shashachu committed Aug 6, 2021
1 parent 0bcfbfd commit 6db3932
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {
ref.add(Reference("*", false))
parentExpressions.clear()
imports.clear()
usedImportPaths.clear()
node.visit { vnode ->
val psi = vnode.psi
val type = vnode.elementType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,4 +729,34 @@ class NoUnusedImportsRuleTest {
)
).isEmpty()
}

@Test
fun `repeated invocations on the same rule instance should work`() {
val rule = NoUnusedImportsRule()
assertThat(
rule.lint(
"""
import foo.bar
fun main() {
bar()
}
""".trimIndent()
)
).isEmpty()

assertThat(
rule.lint(
"""
import foo.bar
import foo.baz
fun main() {
bar()
baz()
}
""".trimIndent()
)
).isEmpty()
}
}

0 comments on commit 6db3932

Please sign in to comment.