From dd56a9cafb683d8458a2f73e5db9a387029e3bbb Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Tue, 14 Aug 2018 00:58:02 +0300 Subject: [PATCH 1/3] Update supported tools to include ktlint --- docs/supported-tools.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/supported-tools.md b/docs/supported-tools.md index ae74f43..cba163b 100644 --- a/docs/supported-tools.md +++ b/docs/supported-tools.md @@ -10,9 +10,7 @@ Tool | Java | Android
(Java) | Kotlin | Android
(Kotlin) [`FindBugs`](http://findbugs.sourceforge.net/) | :white_check_mark: | :white_check_mark: | — | — [`Detekt`](https://github.com/arturbosch/detekt) | — | — | :white_check_mark: | :white_check_mark: [`Android Lint`](https://developer.android.com/studio/write/lint.html) | — | :white_check_mark:️ | — | :white_check_mark:️ -[`KtLint`\*](https://github.com/shyiko/ktlint) | — | — | ✖️ | ✖️ - -_\* Not supported [yet](https://github.com/novoda/gradle-static-analysis-plugin/issues?q=is%3Aopen+is%3Aissue+label%3A%22new+tool%22)_ +[`KtLint`](https://github.com/shyiko/ktlint) | — | — | :white_check_mark:️ | :white_check_mark:️ For additional informations and tips on how to obtain advanced behaviours with the plugin and its tools, please refer to the [advanced usage](advanced-usage.md) page. @@ -25,7 +23,7 @@ For additional informations and tips on how to obtain advanced behaviours with t * [PMD](tools/pmd.md) * [Findbugs](tools/findbugs.md) * [Android Lint](tools/android_lint.md) - * KtLint — _COMING SOON_ + * [KtLint](tools/ktlint.md) * [Example configurations](#example-configurations) --- @@ -42,7 +40,9 @@ staticAnalysis { checkstyle {} pmd {} findbugs {} + lintOptions {} detekt {} + ktlint {} } ``` From 4e38427c099e6c3b458188c7c1a6be455905dfef Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Tue, 14 Aug 2018 01:19:33 +0300 Subject: [PATCH 2/3] Create ktlint.md --- docs/tools/ktlint.md | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/tools/ktlint.md diff --git a/docs/tools/ktlint.md b/docs/tools/ktlint.md new file mode 100644 index 0000000..f9032b0 --- /dev/null +++ b/docs/tools/ktlint.md @@ -0,0 +1,58 @@ +# ktlint +[Ktlint](https://github.com/shyiko/ktlint) is a linter for Kotlin with a built-in formatter. It does not support Java. Adding +this tool only makes sense when you have Kotlin sources in your project. In fact, it will fail to run if you have 0 Kotlin +files. + +## Table of contents + * [IMPORTANT: setup Ktlint](#important-setup-ktlint) + * [Configure Ktlint](#configure-ktlint) +--- + +## IMPORTANT: setup Ktlint + +Unlike the other tools, the plugin **won't automatically add Ktlint** to your project. If you forget to do it, the plugin will +fail the build with an error. + +In order to integrate Ktlint easily we choose to use the [Ktlint Gradle plugin](https://github.com/JLLeitschuh/ktlint-gradle/). +This plugin has a very good understanding of Android source sets and build flavors. You can refer to the +[official documentation](https://github.com/JLLeitschuh/ktlint-gradle/#how-to-use) for further details. + +Note that you should _not_ add the `ktlint` closure to your `build.gradle`s, unlike what the official documentation says. The +`ktlint` closure in the `staticAnalysis` configuration gets applied to all Kotlin modules automatically. + +In most common cases, adding Ktlint to a project boils down to these simple steps: + + 1. Add this statement to your root `build.gradle` project (change the version according to your needs): + ```gradle + plugins { + id 'org.jlleitschuh.gradle.ktlint' version '5.0.0' + // ... + } + ``` + 2. Add this statement to each Kotlin project's `build.gradle`s: + ```gradle + plugins { + id 'org.jlleitschuh.gradle.ktlint' + // ... + } + ``` + +## Configure Ktlint + +Unlike other tools, Ktlint does not offer much configuration. By default, it applies +[Kotlin style guide](https://kotlinlang.org/docs/reference/coding-conventions.html) or +[Android Kotlin style guide](https://android.github.io/kotlin-guides/style.html). + +To use Android style guide: + +```gradle +ktlint { + android true +} +``` + +For other configuration options and adding custom rules, refer to the +[official guide](https://github.com/JLLeitschuh/ktlint-gradle/#configuration). + +**Note:** Please make sure __note__ to set `ignoreFailures = false` since failures and threshold detection is handled by +Static Analysis plugin From 924bf12b70c7c318b566cbf1d830e32128e5dd29 Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Tue, 14 Aug 2018 14:24:36 +0300 Subject: [PATCH 3/3] Clarify the note about ignoreFailures. --- docs/tools/ktlint.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tools/ktlint.md b/docs/tools/ktlint.md index f9032b0..f804859 100644 --- a/docs/tools/ktlint.md +++ b/docs/tools/ktlint.md @@ -54,5 +54,5 @@ ktlint { For other configuration options and adding custom rules, refer to the [official guide](https://github.com/JLLeitschuh/ktlint-gradle/#configuration). -**Note:** Please make sure __note__ to set `ignoreFailures = false` since failures and threshold detection is handled by -Static Analysis plugin +**Note:** Failures and threshold detection is handled by Static Analysis plugin. That is why `ignoreFailures = true` is set by +the plugin. Please do not manually override `ignoreFailures` property.