Skip to content
New issue

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

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

Already on GitHub? # to your account

Unused import is not reported #405

Closed
Ilya-Gh opened this issue Apr 26, 2019 · 1 comment · Fixed by #535
Closed

Unused import is not reported #405

Ilya-Gh opened this issue Apr 26, 2019 · 1 comment · Fixed by #535
Labels
Milestone

Comments

@Ilya-Gh
Copy link
Contributor

Ilya-Gh commented Apr 26, 2019

Unused import a of static function is not reported if the function is used referenced with its parent class.

Android Studio/IDea does report the import as unnecessary using KotlinUnusedImportInspection:

image

The following test added to NoUnusedImportsRuleTest currently fails:

@Test
fun testParentPackImport() {
    assertThat(
        NoUnusedImportsRule().lint(
            """
            import A.b

            fun main() {
                A.b
            }
            """.trimIndent()
        )
    ).isEqualTo(
        listOf(
            LintError(1, 1, "no-unused-imports", "Unused import")
        )
    )
}

The error:

java.lang.AssertionError: 
Expecting:
 <[]>
to be equal to:
 <[LintError(line=1, col=1, ruleId=no-unused-imports, detail=Unused import)]>
but was not.
	at com.pinterest.ktlint.ruleset.standard.NoUnusedImportsRuleTest.testParentPackImport(NoUnusedImportsRuleTest.kt:208)
@shashachu shashachu added this to the 0.33.1 milestone May 31, 2019
shashachu added a commit to shashachu/ktlint that referenced this issue Jul 17, 2019
shashachu added a commit that referenced this issue Jul 17, 2019
…437)" (#532)

* Revert "Report used import when parent reference is already present (#437)"

This reverts commit 238b774.

Fixes #437, re-introduces #405

* fix build
@shashachu shashachu reopened this Jul 17, 2019
@shashachu
Copy link
Contributor

Re-opening because I reverted the fix, as it caused a couple regressions with false-positives.

sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this issue Jul 18, 2019
…interest#437)" (pinterest#532)

* Revert "Report used import when parent reference is already present (pinterest#437)"

This reverts commit 238b774.

Fixes pinterest#437, re-introduces pinterest#405

* fix build
orchestr7 pushed a commit to saveourtool/diktat that referenced this issue Jun 29, 2020
…437)" (#532)

* Revert "Report used import when parent reference is already present (#437)"

This reverts commit 238b774b86cdf6c96dbb8a84d250e7c4a20ac7e7.

Fixes pinterest/ktlint#437, re-introduces pinterest/ktlint#405

* fix build
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants