no matter what I try, I can't get the Android Stud...
# ktlint
d
no matter what I try, I can't get the Android Studio formatter to format files the same way ktlintFormat works
s
unfortunately these usually have to be fixed on a case by case basis. if you can file issues we can take a look
👍 1
p
Before creating new issues, please first check the issue list whether your issue was already filed before. For example, the next issue is scheduled for the next release: https://github.com/pinterest/ktlint/issues/1321
d
I will
Copy code
What ktlint rules are not fully supported by the Android Studio formatter and fail on our project?

Rule: File must end with a newline (\n)

<https://stackoverflow.com/a/28660298/3268303> 

Rule: Parameter should be on a separate line (unless all parameters can fit a single line)

<https://github.com/pinterest/ktlint/issues/206> `

Rule: Missing newline after "(" and Missing newline before ")"

<https://github.com/pinterest/ktlint/issues/1237#issuecomment-1103135680> 

Rule: Missing space after //

<https://github.com/pinterest/ktlint/issues/298> 

Rule: Imports must be ordered in lexicographic order without any empty lines in-between

<https://github.com/pinterest/ktlint/issues/527> 

Rule: Redundant curly braces

Rule: Unnecessary long whitespace
Those are the discrepancies I documented internally so far
p
Please keep in mind that KtLint is more strict than the default formatter of IntelliJ IDEA / Android Studio. There is much possible in Kotlin that harms readability and maintainability of code but which is allowed by Kotlin and by the IDEA. KtLint just makes the code (more) consistent. We try to rewrite code in such a way that it is not rejected/changed by the IDEA but it does not try to mimic the exact formatting of the IDEA.
d
oh yea - i am a fan of ktlint, but my boss was wanting me to get the two to match
most projects ive been on just rely on ktlint
i personally run it from the command line and commit from the command line so i dont really care if AS matches
s
yeah it will be difficult for us to make them match 100% of the time. in general it makes more sense to use AS or ktlint, but not both.
126 Views