-
Notifications
You must be signed in to change notification settings - Fork 507
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
Unnecessary import error for used imports with * at the end #1277
Comments
you're disabling the wrong rule, it should actually be |
@romtsn no, I`m disabling correct rule. |
Ah, alright, then it's indeed a bug |
@illuzor Please copy paste the code samples and output in the issue instead of an image. Also you should provide the expected code. |
With file
and
ktlint does not fail for me as expected. However when I remove the disabled_rules from the |
@paul-dingemans done |
@romtsn This problem has been introduced by fixing #1256. I am stuck with trying to resolve this issue without reverting #1256. The basic problem is that due to #1256 the import in code below is removed as no reference is found to package
So when visiting the CALL_EXPRESSION |
@romtsn I had the same problem, then I created an example to reproduce it and I was going to report it, but I found this issue reporting the same problem. Here is the example I created, I hope it is useful somehow |
@paul-dingemans Any progress on this? This bug removes in-use star imports when I use the formatter through kotlinter. |
Sorry no progress. Waiting for response of @romtsn |
I'd need to look into that, but from the top of my head we probably can't extract this info easily. the proper way would be to depend on the compiler analysis, but that requires quite some setup |
My suggestion would be to revert the change that introduced this regression, and work from there. This way projects like kotlinter can continue to track the latest ktlint. |
Any updates on this issue yet? We're unable to upgrade to the latest version of ktlint due to this issue because Android Studio by default enforces wildcard-imports after a certain threshold of imports from the same package has been reached. |
@Mehly You can turn that off in IntelliJ settings: But I do agree, we're still on 0.41.0 since this is the last version that does work for us just fine |
@Mehly you can also disable it through .editorconfig |
I just ran into this issue also, but it looks like if I disable that line with I'm not sure why wildcards are working in other files and it's just this one. But if I remove that disable line the import will be deleted. |
@InTheCloudDan can you please try to minimize your example and just paste it here? Also, it would be better to use an EOL comment to prevent removal of the import on that specific line. Now you have disabled it for the remainder of the file. |
…lead to removal of required imports 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 pinterest#1256 Closes pinterest#1277
Solution of #1256 has been reverted as it leads to compilation failures when required wildcard important are removed. Downside is that some unused wilcard imports may not be detected. But that is not considered as harmfull. |
…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
Expected Behavior
No error
Observed Behavior
Error
Steps to Reproduce
Disable no-wildcard-imports rule and create a file with wildcard import
Your Environment
.editorconfig:
Code:
Output:
Fails only if run by the plugin task gradlew ktlintCheck.
Does not fail if run ktlint from command line
Sample project: ktlint_error.zip
The text was updated successfully, but these errors were encountered: