From 03bdcee3adeaeff16270c9cd6cd6c292508e2ef9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 1 Oct 2021 13:28:47 +0200 Subject: [PATCH] Install ktlint plugin --- .editorconfig | 25 +++---------------------- .github/workflows/quality.yml | 8 ++++++-- .gitignore | 2 +- CONTRIBUTING.md | 5 ++--- build.gradle | 27 +++++++++++++++++++++++++++ changelog.d/3957.misc | 1 + 6 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 changelog.d/3957.misc diff --git a/.editorconfig b/.editorconfig index 0a49eadc0b..1966f91763 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,25 +9,6 @@ insert_final_newline=true # it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide) max_line_length=off -# Comma-separated list of rules to disable (Since 0.34.0) -# Note that rules in any ruleset other than the standard ruleset will need to be prefixed -# by the ruleset identifier. -disabled_rules=no-multi-spaces,colon-spacing,chain-wrapping,import-ordering,experimental:annotation - -# The following (so far identified) rules are kept: -# no-blank-line-before-rbrace -# final-newline -# no-consecutive-blank-lines -# comment-spacing -# filename -# comma-spacing -# paren-spacing -# op-spacing -# string-template -# no-unused-imports -# curly-spacing -# no-semi -# no-empty-class-body -# experimental:multiline-if-else -# experimental:no-empty-first-line-in-method-block -# no-wildcard-imports +# From https://github.com/pinterest/ktlint#custom-ktlint-specific-editorconfig-properties +# default IntelliJ IDEA style, same as alphabetical, but with "java", "javax", "kotlin" and alias imports in the end of the imports list +ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^ diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 0f11915258..8c56edfa3a 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -21,8 +21,12 @@ jobs: - uses: actions/checkout@v2 - name: Run klint run: | - curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.36.0/ktlint && chmod a+x ktlint - ./ktlint --android --experimental -v + ./gradlew ktlintCheck --continue + - name: Upload reports + uses: actions/upload-artifact@v2 + with: + name: ktlinting-report + path: vector/build/reports/ktlint/*.* # Lint for main module and all the other modules android-lint: diff --git a/.gitignore b/.gitignore index 935a3fc329..ff086d7723 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ /fastlane/private /fastlane/report.xml -ktlint +/library/build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e1d213e6b7..082e7e7252 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,14 +80,13 @@ Make sure the following commands execute without any error: #### ktlint
-curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.34.2/ktlint && chmod a+x ktlint
-./ktlint --android --experimental -v
+./gradlew ktlintCheck --continue
 
Note that you can run
-./ktlint --android --experimental -v -F
+./gradlew ktlintFormat
 
For ktlint to fix some detected errors for you (you still have to check and commit the fix of course) diff --git a/build.gradle b/build.gradle index 49c3e07ece..c3acc6bcf4 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,14 @@ buildscript { } } +// ktlint Plugin +plugins { + id "org.jlleitschuh.gradle.ktlint" version "10.1.0" +} + allprojects { + apply plugin: "org.jlleitschuh.gradle.ktlint" + repositories { // For olm library. This has to be declared first, to ensure that Olm library is not downloaded from another repo maven { @@ -75,6 +82,26 @@ allprojects { // You can override by passing `-PallWarningsAsErrors=false` in the command line kotlinOptions.allWarningsAsErrors = project.getProperties().getOrDefault("allWarningsAsErrors", "true").toBoolean() } + + // Fix "Java heap space" issue + tasks.withType(org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask).configureEach { + it.workerMaxHeapSize.set("2G") + } + + // See https://github.com/JLLeitschuh/ktlint-gradle#configuration + ktlint { + android = true + ignoreFailures = false + enableExperimentalRules = true + // display the corresponding rule + verbose = true + disabledRules = [ + "spacing-between-declarations-with-comments", + "no-multi-spaces", + "experimental:spacing-between-declarations-with-annotations", + "experimental:annotation" + ] + } } task clean(type: Delete) { diff --git a/changelog.d/3957.misc b/changelog.d/3957.misc new file mode 100644 index 0000000000..bc6e417a49 --- /dev/null +++ b/changelog.d/3957.misc @@ -0,0 +1 @@ +Use ktlint plugin. See [the documentation](https://github.com/vector-im/element-android/blob/develop/CONTRIBUTING.md#ktlint) for more detail. \ No newline at end of file