Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Update to ktlint 0.21.0 #747

Merged
merged 5 commits into from
Apr 17, 2018
Merged

Update to ktlint 0.21.0 #747

merged 5 commits into from
Apr 17, 2018

Conversation

aforcier
Copy link
Contributor

@aforcier aforcier commented Mar 12, 2018

Updates ktlint to 0.21.0 and fixes new style violations introduced.

Main changes:

  1. Functions that can't fit on a single line must have each of their parameters on a separate line, indented with normal (4 space) indentation:
fun newInstance(
    onClickListener: Listener,
    text1Hint: String,
    text2Hint: String,
    text3Hint: String
): ThreeEditTextDialog {
    ...
}

This one is also enforced in the AS formatter via changes to the shared IDEA config file.

  1. Operators need to appear before a wrapped line, not after:
prependToLog("error: " + event.error.type + "Some more text here: " +
        event.error.message)

This is, sadly, the opposite of our rule for Java (which is a checkstyle default), which forces the operators to appear at the beginning of the new line. There's some hope that this may be addressed in the future, but for now we'll have to live with the inconsistency.

cc @maxme

@aforcier aforcier added the Core label Mar 12, 2018
@aforcier
Copy link
Contributor Author

aforcier commented Mar 12, 2018

For a more substantial demo of the changes, see eabb35b, which applies the new rules to the woocommerce-store branch. (These changes have now been added to this branch.)

@shyiko
Copy link

shyiko commented Mar 13, 2018

Hey @aforcier.
Just in case you missed pinterest/ktlint#163:
+/- is wrapping is unlikely to change due to the following - pinterest/ktlint#163 (comment).
I know it's different from checkstyle's OperatorWrap default but there is little we can do (as unfortunate as it is).

@aforcier
Copy link
Contributor Author

Thanks @shyiko! Yes I read that, I was hopeful that the Android style guide might end up deciding to keep at least &&, || on the break-before-operator behavior, and make +/- exceptions since there's the unary operator problem. (In which case ktlint would probably be updated to reflect that, per your comment.) I probably should have used && in my example above since + probably won't change 😀

@aforcier
Copy link
Contributor Author

With #754 merged, rebased this branch and fixed new ktlint violations from code in that branch.

@aforcier aforcier force-pushed the feature/ktlint-0.19.0 branch from 1185f6a to d8db2fc Compare March 28, 2018 21:10
Multiline parameters should use normal indentation (+4)
rather than continuation indentation (+8) - this is also
enforced by ktlint.
@aforcier aforcier force-pushed the feature/ktlint-0.19.0 branch from d8db2fc to 73e08bd Compare April 16, 2018 21:06
@aforcier aforcier changed the title Update to ktlint 0.19.0 Update to ktlint 0.21.0 Apr 16, 2018
@maxme maxme self-assigned this Apr 17, 2018
@maxme
Copy link
Contributor

maxme commented Apr 17, 2018

  • ./gradlew ktlint: ✅
  • Sad 🐼 for the trailing +: ✅
  • Up to date with develop: ✅

@maxme
Copy link
Contributor

maxme commented Apr 17, 2018

:shipit:

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

Successfully merging this pull request may close these issues.

3 participants