rulebook

Personal lint rules and code convention

View the Project on GitHub hendraanggrian/rulebook

Travis CI Codecov Maven Central Nexus Snapshot OpenJDK

Rulebook

Third-party rules for lint tools, meant to be used in conjunction with official ones. Most of the rules are opinionated personal code styles. 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

Download

repositories {
    mavenCentral()
}

dependencies {
    checkstyle "com.hendraanggrian.rulebook:rulebook-checkstyle:$version"
    ktlint "com.hendraanggrian.rulebook:rulebook-ktlint:$version"
}

Usage

Checkstyle

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"
}

KtLint

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

Spotless is not supported as because you can't add custom rules.

First time installation

Presuming the IDE is IntelliJ IDEA, consider applying the linter style to it.

Checkstyle

In File > Settings > Editor > Code Style > Java, import IntelliJ Java Google Style file. The whole process are better explained in Google Java Format.

KtLint

Explained in KtLint IntelliJ IDEA Configuration, using standard Kotlin coding conventions is enough: