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 #1264

Closed
robstoll opened this issue Oct 19, 2018 · 9 comments
Closed

false positive unused import #1264

robstoll opened this issue Oct 19, 2018 · 9 comments

Comments

@robstoll
Copy link
Contributor

Observed Behavior

import ch.tutteli.kbox.forEachRemaining as foreachRemaining //otherwise we use jdk8
fun foo(){
   listOf().iterator().foreachRemaining{}
}

Real use case including reporting:
https://sonarcloud.io/project/issues?id=robstoll_kbox&open=AWaMMX83Vfn4NtZOwYPB&resolved=false&sinceLeakPeriod=true&types=CODE_SMELL

The alias of the import is used in code. A wild guess: detekt is looking for forEachRemaining instead of the alias and does not find it; thus the false positive.

Your Environment

@arturbosch
Copy link
Member

arturbosch commented Oct 20, 2018

Thanks for reporting, yep aliases are not yet considered in the rule.

Edit: Well, are you sure you used detekt? I just see official sonarqube rules there?

@robstoll
Copy link
Contributor Author

robstoll commented Oct 20, 2018

Yes it is detekt 😉 Click on the issue on sonarcloud, you can see that it has the detekt label.

@arturbosch
Copy link
Member

arturbosch commented Oct 24, 2018

I'm still not sure if the report is really from detekt. If sonar-cload uses an old version maybe. But as you see in the PR I used your code and the false positive is not there :O

@robstoll
Copy link
Contributor Author

It's definitely detekt. I am runnng detekt myself and upload the issues. However, I am using 1.0.0.RC8 and maybe it is fixed by now. That's possible and would be great of course

@robstoll robstoll reopened this Oct 24, 2018
arturbosch added a commit that referenced this issue Oct 28, 2018
* Add test case for reported false positive - #1264

* Simplify test code
@arturbosch
Copy link
Member

Feel free to reopen this ticket if your problem still occurs in RC9.2 or newer.

@arturbosch arturbosch added this to the RC10 milestone Nov 2, 2018
@arturbosch
Copy link
Member

arturbosch commented Nov 2, 2018

Question: do you have to configure detekt in sonarcloud or is it available by default? Thinking about integrating sonarcloud into our CI ^^

@robstoll
Copy link
Contributor Author

robstoll commented Nov 3, 2018

It's available by default if you use the sonar-scanner. But, you have to run detekt on your own and tell sonar-scanner where the resulting checkstyle files are. See .travis.yml in the above mentioned project

@arturbosch
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Jun 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants