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

Fix unused import when import is duplicated #1129

Merged
merged 5 commits into from
Aug 5, 2021

Conversation

analog-alex
Copy link
Contributor

@analog-alex analog-alex commented Mar 30, 2021

Description

ktlint detects unused imports, such as:

import lib
import lib2 // <- ktlint unused import rule is violated

fun main() {
	lib.function();
}

However, when an import is duplicated -- and the duplicate import line is thus an unused import -- ktlint emits no rule violation.

Screen Shot 2021-03-30 at 2 17 05 PM

IntelliJ treats it as a duplicate import ☝️

E.g:

import lib
import lib // unused, but no violation

fun main() {
	lib.function();

This PR fixes that, emitting a rule violation when two imports have the same import path.

Checklist

  • tests are added

@analog-alex analog-alex changed the title Fix unsused import when import is duplicated Fix unused import when import is duplicated Mar 30, 2021
ktlint detects unused imports, such as:

```
import lib
import lib2 // <- ktlint unused import rule is violated

fun main() {
	lib.function();
}
```

However, when an import is duplicated -- and the duplicate import line is thus an unused import -- ktlint emits no rule violation.

E.g:

```
import lib
import lib // unused, but no violation

fun main() {
	lib.function();
```

This commit fixes that, emitting a rule violation when two imports have the same import path.
@shashachu
Copy link
Contributor

@analog-alex our dependency verification errors are fixed now. you should be able to revert the changes to verification-metadata.xml and rebase and your builds should pass.

@analog-alex
Copy link
Contributor Author

@analog-alex our dependency verification errors are fixed now. you should be able to revert the changes to verification-metadata.xml and rebase and your builds should pass.

Reverted!

@shashachu shashachu merged commit 3a43dbb into pinterest:master Aug 5, 2021
shashachu added a commit to shashachu/ktlint that referenced this pull request Aug 6, 2021
- Used imports state has to be reset per-file
shashachu added a commit to shashachu/ktlint that referenced this pull request Aug 6, 2021
- Used imports state has to be reset per-file
- Allow repeated imports to be auto-corrected
shashachu added a commit that referenced this pull request Aug 6, 2021
shashachu added a commit that referenced this pull request Aug 6, 2021
* Fix regressions introduced in #1129

- Used imports state has to be reset per-file
- Allow repeated imports to be auto-corrected

* fix lint

* Fix bad merge conflict

* more merge fixes
romtsn pushed a commit to paul-dingemans/ktlint that referenced this pull request Aug 8, 2021
* Fix unused import when import is duplicated

ktlint detects unused imports, such as:

```
import lib
import lib2 // <- ktlint unused import rule is violated

fun main() {
	lib.function();
}
```

However, when an import is duplicated -- and the duplicate import line is thus an unused import -- ktlint emits no rule violation.

E.g:

```
import lib
import lib // unused, but no violation

fun main() {
	lib.function();
```

This commit fixes that, emitting a rule violation when two imports have the same import path.

* Revert verification metadata

* fix lint

Co-authored-by: Yahor Berdnikau <[email protected]>
Co-authored-by: Sha Sha Chu <[email protected]>
romtsn pushed a commit to paul-dingemans/ktlint that referenced this pull request Aug 8, 2021
romtsn pushed a commit to paul-dingemans/ktlint that referenced this pull request Aug 8, 2021
* Fix regressions introduced in pinterest#1129

- Used imports state has to be reset per-file
- Allow repeated imports to be auto-corrected

* fix lint

* Fix bad merge conflict

* more merge fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants