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

Migrate to ktlint 0.47.1 or newer #2914

Closed
nikclayton opened this issue Nov 23, 2022 · 4 comments · Fixed by #3442
Closed

Migrate to ktlint 0.47.1 or newer #2914

nikclayton opened this issue Nov 23, 2022 · 4 comments · Fixed by #3442

Comments

@nikclayton
Copy link
Contributor

The org.jlleitschuh.gradle.ktlint plugin (ktlint-gradle) is using an old version of ktlint (0.43.2, per https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintExtension.kt#L38).

At the time of writing the most recent version of ktlint is 0.47.1.

The different ktlint versions have different rulesets, with newer versions recognising new issues.

This causes problems if you try and use other tools that incorporate ktlint. For example, editing Tusky code with the IntelliJ ktlint plugin (https://plugins.jetbrains.com/plugin/15057-ktlint-unofficial-) installed reports problems with the code that gradlew ktlintCheck does not find.

ktlint-gradle does not work with any version of ktlint > 0.45.x at the moment (JLLeitschuh/ktlint-gradle#589).

Other ktlint + gradle options exist (supporting 0.47.1), including:

I experimented with the first one with kotlinter-gradle.patch.txt (probably needs some work, I did the first thing that works, not necessarily the best thing).

With that, running gradlew lintKotlin generates an additional ~ 280 lint warnings, see lint.txt

That probably doesn't make sense as a PR, as it touches the entire codebase and would need to be regenerated with every other PR that gets merged.

I think the next steps are;

  1. Decide whether or not to fix this
  2. If "fix", decide which plugin to use. kotlinter-gradle solves this specific problem, Spotless and Autostyle can format more files (Markdown, SQL, XML, JSON, etc) but require more configuration.
  3. In one commit (a) modify the gradle files, (b) apply the style fixes, (c) update any CI commands, (d) update documentation
@connyduck
Copy link
Collaborator

Since it seems that the current Ktlint plugin isn't being updated we should migrate to kotlinter. Most complicated part is changing CI since that config currently is not in the repo (maybe we should fix that first? 🤔). I'd wait with all that until we have less open PRs, so until after Tusky 20 is out.

@connyduck
Copy link
Collaborator

The plugin has been updated https://github.com/JLLeitschuh/ktlint-gradle/releases/tag/v11.1.0

@nikclayton
Copy link
Contributor Author

Good to know. Migrating plugins is probably still worth considering, given JLLeitschuh/ktlint-gradle#569.

I tried the new version, by:

  1. Set ktlint = "11.1.0" in libs.versions
  2. Adding the following to app/build.gradle (in the android block).
ktlint {
    version = '0.48.1'
    android = true
}

As expected, hundreds of lint warnings.

Note: There are also a lot of confusing deprecation warnings. I went looking at those, and JLLeitschuh/ktlint-gradle#622 is the result.

To make merging changes easier on authors with currently open PRs I suspect the best way to do it is two distinct commits on develop.

First commit makes the version and ktlint { ... } change.

Second commit modifies the existing code to make it lint clean.

Authors of open PRs then have to do a 4 step process:

  1. Merge in the first develop commit that makes the version and android = true change
  2. Re-format and make lint-clean just the files that they have open in their PR, and commit
  3. Merge in the second develop commit that made everything else lint-clean.
  4. Push their PR

I think this will minimise the number of conflicts that authors of open PRs will see when they do the merge, and keeps the reviewable changes in the PR back to just the code that needs to be reviewed, without any extraneous formatting changes.

@wakingrufus
Copy link

given, JLLeitschuh/ktlint-gradle#622 try setting ktlint version to 0.47.1 for now.
also, regarding: JLLeitschuh/ktlint-gradle#569 I have volunteered to step up in maintaining this library, so expect some more frequent updates and support going forward. Of course, if you can find any issues, please continue to report them so I can take a look, and if you have an idea at the fix, I would love to help shepherd in other outside contributions as well. As an avid fediverse user, I'd like to also thank you for all your work on Tusky :)

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

Successfully merging a pull request may close this issue.

3 participants