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

false positive from no-unused-imports when importing an inner declaration with wildcard #1393

Closed
RBusarow opened this issue Mar 3, 2022 · 1 comment · Fixed by #1402
Closed

Comments

@RBusarow
Copy link

RBusarow commented Mar 3, 2022

Given this file:

package com.example

import com.example.Outer.*

class Outer {
  class Inner
}

val foo = Inner()

command:

ktlint <path-to-file> --disabled_rules=no-wildcard-imports

Ktlint incorrectly says that import com.example.Outer.* is unnecessary. If the wildcard is replaced with the explicit import, Ktlint no longer complains.

Your Environment

  • Version of ktlint used: 0.43.2 and 0.44.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): cli
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Mar 5, 2022
@paul-dingemans
Copy link
Collaborator

Sorry, commit above is in no way related to this issue.

@paul-dingemans paul-dingemans added this to the 0.45.0 milestone Mar 9, 2022
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Mar 12, 2022
paul-dingemans added a commit that referenced this issue Mar 12, 2022
…emoval of required imports (#1402)

There is no reliable way to determined whether a wildcard import is actually used
in the file. The AST does not seem to contain information about the actuall class
that an identifier refers to. It is preferred to not remove unused imports than
that needed imports are removed.

Revert #1256
Closes #1277
Closes #1393
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
2 participants