This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Update docs for ktlint integration #124
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
__note__
in the middle is a leftover of something else, and to double check: I would expectignoreFailures
to be set totrue
because we don't want ktlint to break the build itselfThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update. We already automatically set it to true. Here I was trying to say that they shouldn't set it to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually,
note
should benot
here.But I will reword this. It is too many negates. Also because of
ignoreFailures
.ktlint
could've chosen a positive prop here.