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

false-positive Unused Import with importing sealed class subclass with master version(b6ddf65) #845

Closed
takahirom opened this issue Aug 21, 2020 · 0 comments · Fixed by #889
Labels
Milestone

Comments

@takahirom
Copy link

The bug you're experiencing might have already be reported!
Please search in the issues before creating one.

Expected Behavior

Not detecting Unused Import

Observed Behavior

It is better to fix this code, but if you delete the import according to lint, a build error will occur.

                import com.foo.psi.Sealed
                import com.foo.psi.Sealed.SubClass

                fun main() {
                    listOf<Sealed>()
                    Sealed.SubClass()
                    SubClass()
                }

We can check this by adding this test.

https://github.com/pinterest/ktlint/blob/master/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt#L9

    @Test
    fun `only redundant sealed sub class imports should be removed`() {
        assertThat(
            NoUnusedImportsRule().lint(
                """
                import com.foo.psi.Sealed
                import com.foo.psi.Sealed.SubClass

                fun main() {
                    listOf<Sealed>()
                    Sealed.SubClass()
                    SubClass()
                }
                """.trimIndent()
            )
        ).isEmpty()
    }
}

Steps to Reproduce

Adding test

Your Environment

Probably happens regardless of environment

  • Version of ktlint used: master version
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): b6ddf65
  • Version of Gradle used (if applicable): 6.6
  • Operating System and version: Mac OSX
  • Link to your project (if it's a public repository):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants