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

KtLint gives wrong autoCorrect flag to custom rule. #154

Closed
MyDogTom opened this issue Feb 14, 2018 · 8 comments
Closed

KtLint gives wrong autoCorrect flag to custom rule. #154

MyDogTom opened this issue Feb 14, 2018 · 8 comments

Comments

@MyDogTom
Copy link
Contributor

Overview
My custom rule always receives autoCorrect = false, regardless that I'm calling emit with canBeAutocorrected = true.

Description
My custom rule is a copy of IndentationRule, but with enabled autocorrection. It means that both rules detect same error in same place. IndentationRule emits error with canBeAutocorrected = false, my CustomIndentationRule emits error with canBeAutocorrected = true

How to reproduce.
I have repository which show case the problem. https://github.com/MyDogTom/ktlint-custom-rules/tree/fix-format (branch fix-format)
It has intentional indent violation.
Auto correction works only when I remove autoCorrect check. See this commit

For sure, it somehow conflicts with standard IndentionRule, but it shouldn't. Unfortunately, I couldn't quickly figure out where is problem.

@MyDogTom
Copy link
Contributor Author

As experiment, I removed IndentionRule from StandardRuleSetProvider. Behavior stayed the same. Autocorrection happens only when I remove if (autoCorrect) from CustomIndentationRule. At least bug it's not related to the fact that one rule is a copy of another. I still cannot find why that happens. Any help is really welcome :)

@shyiko
Copy link
Collaborator

shyiko commented Feb 14, 2018

$ ktlint --version
0.15.0

$ cat A.kt 
fun main(
    args: String) {
println("")
}

$ ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -v
/tmp/A.kt:2:17: Parenthesis should be on new line (custom:class-and-function-header-format)

$ ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -F
<no output>

$ ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -v
<no output>

Looks like everything is OK (at least in [email protected]).
Can you provide an example with a different behavior?

@MyDogTom
Copy link
Contributor Author

Sure.

fun main(args: String) {
   println("")
}

ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -v

A.kt:2:1: Unexpected indentation (3) (it should be 4) (indent)
A.kt:2:1: Unexpected indentation (3) (it should be 4) (custom:indent)

ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -F

A.kt:2:1: Unexpected indentation (3) (it should be 4)

ktlint -R com.github.MyDogTom:ktlint-custom-rules:master-SNAPSHOT A.kt -v

A.kt:2:1: Unexpected indentation (3) (it should be 4) (indent)
A.kt:2:1: Unexpected indentation (3) (it should be 4) (custom:indent)

@shyiko
Copy link
Collaborator

shyiko commented Feb 15, 2018

Fix available in 0.15.1 (Maven Central sync might take up to 25 minutes). 🎈

@shyiko shyiko closed this as completed Feb 15, 2018
@MyDogTom
Copy link
Contributor Author

Thank you for quick fix. I've checked new version via brew and it works! Unfortunately, new version is still not available via Maven/JCenter.

@shyiko
Copy link
Collaborator

shyiko commented Feb 15, 2018

@MyDogTom thank you for letting me know. https://issues.sonatype.org/browse/OSSRH-37894 submitted.

@shyiko
Copy link
Collaborator

shyiko commented Feb 15, 2018

@MyDogTom it looks like Maven Central sync finally took place

@MyDogTom
Copy link
Contributor Author

Thank you!

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

No branches or pull requests

2 participants