Overview
What is Rulebook?
Library extension
A set of additional rules for static code analysis tools
Multiple languages
Originally written for Kotlin, it now supports Java, Groovy and Python
Features
Follows guidelines
Works together with standard rules from the linters and respects common coding convention
Shared configuration
Available in standard and Google Style Guide variants with adjusted defaults.
Compatibility table¶
Legend
The rule is fully implemented
Functionality already exists in other rules
The rule is already supported by the linter
Not supported due to technical limitations
Empty — not applicable to this language
| Rule | Java | Groovy | Kotlin | Python |
|---|---|---|---|---|
| Block tag punctuation51 | ||||
| Built-in types39 | ||||
| Confusing predicate35 | ||||
| Null equality44 | ||||
| Redundant qualifier27 | ||||
| TODO comment29 | ||||
| Trailing comma in call45 | ||||
| Trailing comma in collection55 | ||||
| Trailing comma in declaration45 | ||||
| Unused import7 | ||||
| Wildcard import21 | ||||
| format_text_clip Clipping group | Java | Groovy | Kotlin | Python |
| Empty braces clip15 | ||||
| Empty brackets clip3 | ||||
| Empty parentheses clip3 | ||||
| Empty tags clip3 | ||||
| Short block comment clip34 | ||||
| data_object Declaring group | Java | Groovy | Kotlin | Python |
| Abstract class definition1 | ||||
| Contract function definition38 | ||||
| Exception inheritance53 | ||||
| Number suffix for double24 | ||||
| Number suffix for float24 | ||||
| Number suffix for integer24 | ||||
| Number suffix for long24 | ||||
| String quotes17 | ||||
| Unnecessary parentheses in lambda52 | ||||
| Utility class definition4 | ||||
| draft Formatting group | Java | Groovy | Kotlin | Python |
| File size43 | ||||
| Final newline13 | ||||
| Indent style13 | ||||
| Line length16 | ||||
| label Naming group | Java | Groovy | Kotlin | Python |
| Class name abbreviation30 | ||||
| Class name48 | ||||
| Constant property name48 | ||||
| File name42 | ||||
| Identifier name48 | ||||
| Illegal class name suffix30 | ||||
| Illegal variable name2 | ||||
| Package name48 | ||||
| Property name interop41 | ||||
| Required generics name54 | ||||
| swap_vert Ordering group | Java | Groovy | Kotlin | Python |
| Block tag order9 | ||||
| Built-in function position47 | ||||
| Import order20 | ||||
| Inner class position32 | ||||
| Member order32 | ||||
| Overload function position40 | ||||
| Static import position47 | ||||
| format_letter_spacing_2 Spacing group | Java | Groovy | Kotlin | Python |
| Block comment spaces50 | ||||
| Block tag indentation18 | ||||
| Case separator33 | ||||
| Comment space11 | ||||
| Member separator23 | ||||
| Missing blank line before block tags37 | ||||
| code_blocks Stating group | Java | Groovy | Kotlin | Python |
| Illegal catch53 | ||||
| Illegal throw53 | ||||
| Missing braces10 | ||||
| Nested if-else25 | ||||
| Redundant default26 | ||||
| Redundant else26 | ||||
| Unnecessary switch28 | ||||
| format_letter_spacing_standard Trimming group | Java | Groovy | Kotlin | Python |
| Block comment trim6 | ||||
| Braces trim14 | ||||
| Brackets trim8 | ||||
| Comment trim6 | ||||
| Duplicate blank line23 | ||||
| Duplicate blank line in block comment6 | ||||
| Duplicate blank line in comment6 | ||||
| Duplicate space36 | ||||
| Parentheses trim8 | ||||
| Tags trim8 | ||||
| Unnecessary blank line after colon14 | ||||
| Unnecessary blank line before package22 | ||||
| format_text_wrap Wrapping group | Java | Groovy | Kotlin | Python |
| Assignment wrap19 | ||||
| Chain call wrap46 | ||||
| Elvis wrap5 | ||||
| Infix call wrap12 | ||||
| Lambda wrap19 | ||||
| Operator wrap12 | ||||
| Parameter wrap31 | ||||
| Statement wrap49 |
Download¶
Integrate the linter tools
-
Java
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.
-
Groovy
CodeNarc is similar to popular static analysis tools such as PMD or Checkstyle.
-
Kotlin
An anti-bikeshedding Kotlin linter with built-in formatter.
-
Python
It's not just a linter that annoys you!
FAQ¶
Why is it necessary?¶
When working on a project with multiple programming languages, we often forget to apply the same coding style and leave the validation to a linter tool. However, the default behavior of these linters are not always consistent. Consider the example below:
| Java | Groovy | Kotlin | Python |
|---|---|---|---|
| Java does not allow trailing commas except in array initializers. | Groovy allows trailing commas in call sites, but CodeNarc does not natively support it. | Trailing commas can be placed in call and declaration sites in Kotlin, the rule is provided by Ktlint. | Python allows trailing commas but Pylint considers it optional in PEP. Note that the comment spacing rule is different in Python. |
|
|
How stable is it?¶
The rules are mostly work in progress and have not been tested against a large codebase. Disable the rules individually if they behave unexpectedly.
What's next for Rulebook?¶
Although there is no timeline for the roadmap, more languages are planned:
- Java
- Groovy
- Kotlin
- Python
- JavaScript
- TypeScript