Skip to content

hanggrian/rulebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

124 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI Codecov
Maven Central Java
Package Index Package Index Test Python

Rulebook

The Rulebook logo.

Third-party rules for JVM and Python 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 multiple languages.

Language Linter Styles
Java Checkstyle Sun Java Style or
Google Java Style Guide
Groovy CodeNarc Groovy Style Guide
Kotlin Ktlint Ktlint Official Style
C/C++ Cppcheck C++ Core Guidelines or
Google C++ Style Guide
Python Pylint Pylint Style or
Google Python Style Guide
JavaScript ESLint Crockford Code Conventions or
Google JavaScript Style Guide
TypeScript typescript-eslint Crockford Code Conventions or
Google TypeScript Style Guide

View all rules

Download

Maven

repositories {
    mavenCentral()
}

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

PyPI

pip install pylint regex rulebook-pylint

NPM

Coming soon.

Usage

Ktlint

  • Apply Ktlint Integration to Gradle project.

  • Using configuration ktlint, add this project as dependency.

    configurations {
        ktlint
    }
    
    dependencies {
        ktlint "com.hanggrian.rulebook:rulebook-ktlint:$libraryVersion"
    }
    
    // the rest of ktlint tasks' configuration

Checkstyle

  • Apply Checkstyle Gradle Plugin.

  • Using configuration checkstyle, add this project as dependency.

  • Point to local config file or put in /config/checkstyle/codenarc.xml.

    plugins {
        checkstyle
    }
    
    checkstyle {
        toolVersion "$checkstyleVersion"
        configFile "path/to/rulebook_checkstyle.xml"
    }
    
    dependencies {
        checkstyle "com.hanggrian.rulebook:rulebook-checkstyle:$libraryVersion"
    }

CodeNarc

  • Apply CodeNarc Gradle Plugin.

  • Using configuration codenarc, add this project as dependency.

  • Point to local config file or put in /config/codenarc/codenarc.xml.

    plugins {
        codenarc
    }
    
    codenarc {
        toolVersion "$codenarcVersion"
        configFile "path/to/rulebook_codenarc.xml"
    }
    
    dependencies {
        codenarc "com.hanggrian.rulebook:rulebook-codenarc:$libraryVersion"
    }

Pylint

  • Point config file to local pylintrc.

ESLint

  • Create .eslint.config.js.

    import rulebookEslint, { proxmoxJavaScriptStyleNamed } from 'rulebook-eslint';
    import rulebookTypescriptEslint, { microsoftTypeScriptStyleNamed } from 'rulebook-typescript-eslint';
    
    export default typescriptEslint.config(
        {
            files: ['**/*.{js,jsx}'],
            extends: [js.configs.recommended],
            plugins: {
                'rulebook': rulebookEslint,
            },
            rules: proxmoxJavaScriptStyleNamed('rulebook'),
        },
        {
            files: ['**/*.{ts,tsx}'],
            extends: [
                js.configs.recommended,
                ...typescriptEslint.configs.recommendedTypeChecked,
            ],
            plugins: {
                'rulebook': rulebookTypescriptEslint,
            },
            rules: microsoftTypeScriptStyleNamed('rulebook'),
        },
    );

IDE settings

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

  1. Ktlint Style

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

  • In File > Settings > Editor > Code Style > Kotlin, set from Kotlin style guide.
    • Append kotlin.code.style=official to root gradle.properties.
  1. Google Java Style

    Explained in Google Java Format: