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 while formatting conditional #886

Closed
axemorgan opened this issue Sep 2, 2020 · 3 comments
Closed

False positive unused import while formatting conditional #886

axemorgan opened this issue Sep 2, 2020 · 3 comments
Labels

Comments

@axemorgan
Copy link

Expected Behavior

Formatting this code should not remove the import for CONSTANT.

import other.CONSTANT

fun main() {
	if (CONSTANT 
    	&& true
    ) {
        return
    }
}

Observed Behavior

Ktlint outputs the following (which no longer compiles due to error: unresolved reference: CONSTANT):

fun main() {
	if (CONSTANT &&
    	true
    ) {
        return
    }
}

Steps to Reproduce

I created a sample to reproduce it here. Format and then compile to reproduce the error.

Notes:
It seems like correcting the && wrapping is key here, because other formatting fixes don't seem to trigger this same behavior.
Also if CONSTANT is referenced elsewhere in the same file, it will not be removed during formatting.

Your Environment

ktlint 0.37.2

@romtsn
Copy link
Collaborator

romtsn commented Sep 2, 2020

Could you try the latest version (0.38.1) and also run with --verbose to get an idea which rule is it?

@romtsn romtsn added the bug label Sep 2, 2020
@axemorgan
Copy link
Author

I upgraded to 0.38.1 and it still happens. Verbose mode says this is the rule: Line must not begin with "&&" (chain-wrapping)

@paul-dingemans
Copy link
Collaborator

Problem with unused import was resolved in 0.38.1. The violation Line must not begin with "&&" (chain-wrapping) can simply be resolved by the user.

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

No branches or pull requests

3 participants