Personal lint rules and code convention
Additional third-party rules for lint tools, meant to be used in conjunction with official ones. Most of the rules are opinionated personal code style mandate. However, some already exists in other linters, providing the same experience across languages.
Language | Linter | Main Rules |
---|---|---|
Java | Checkstyle | Google Java Style Guide via Checkstyle Google Checks |
Kotlin | KtLint | Kotlin coding conventions via KtLint standard rules |
repositories {
mavenCentral()
}
dependencies {
checkstyle "com.hendraanggrian.rulebook:rulebook-checkstyle:$version"
ktlint "com.hendraanggrian.rulebook:rulebook-ktlint:$version"
}
Apply Checkstyle Gradle Plugin.
Using configuration checkstyle
, add this project as dependency. Then
use rulebook_checks.xml
provided in sample-checkstyle or
within rulebook-checkstyle jar.
plugins {
checkstyle
}
checkstyle {
toolVersion "$checkstyleVersion"
configFile "path/to/rulebook_checks.xml"
// the rest of checkstyle plugin configurations
}
dependencies {
checkstyle "com.puppycrawl.tools:checkstyle:$checkstyleVersion"
checkstyle "com.hendraanggrian.rulebook:rulebook-checkstyle:libraryVersion"
}
Apply KtLint Integration
to Gradle project. Using configuration ktlint
, add this project as dependency.
configurations {
ktlint
}
dependencies {
ktlint "com.pinterest:ktlint:$ktlintVersion"
ktlint "com.hendraanggrian.rulebook:rulebook-ktlint:libraryVersion"
}
// the rest of ktlint tasks' configuration
Do not use KtLint with Spotless, as there is yet no way to add custom rules.
Presuming the IDE is IntelliJ IDEA, consider applying the linter style to it.
In File > Settings > Editor > Code Style > Java
,
import IntelliJ Java Google Style file.
The whole process are better explained in Google Java Format.
Explained in KtLint IntelliJ IDEA Configuration, using standard Kotlin coding conventions is enough:
File > Settings > Editor > Code Style > Kotlin
, set
from Kotlin style guide
.
kotlin.code.style=official
to root gradle.properties
.