Skip to content

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

Download the library

Get the artifacts from official package managers.

Maven CentralPyPI

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.
void foo(
    int a,
    int b
) {
    bar(
        a,
        b
    )
}
def foo(
    int a,
    int b
) {
    bar(
        a,
        b // no!
    )
}
fun foo(
    a: Int,
    b: Int // no!
) =
    bar(
        a,
        b // no!
    )
def foo(
    a: int,
    b: int  # no!
):
    bar(
        a,
        b  # no!
    )

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.

<!--module name="CommentSpaces"/-->
<!--rule class="com.hanggrian.rulebook.codenarc.CommentSpacesRule"/-->
ktlint_rulebook_comment-spaces = disabled
# rulebook_pylint.comment_spaces,

What's next for Rulebook?

Although there is no timeline for the roadmap, more languages are planned:

  • Java
  • Groovy
  • Kotlin
  • Python
  • JavaScript
  • TypeScript

  1. Abstract class require abstract method 

  2. Avoid primitive names 

  3. Concise brackets, parentheses and tags 

  4. Hide utility class instance 

  5. Move trailing elvis to the next line 

  6. No blank lines at initial, final and consecutive comments 

  7. Remove unused imports 

  8. Trim multiline brackets, parentheses and tags 

  9. Android: Block tags  

  10. Android: Braces  

  11. Android: Horizontal whitespace  

  12. Android: Where to break  

  13. EditorConfig: What's an EditorConfig file look like?  

  14. Google: Nonempty blocks  

  15. Google: Empty blocks  

  16. Google: Column limit: 100  

  17. Google: Use single quotes  

  18. Google: Block tags  

  19. Google: Where to break  

  20. Google: Ordering and spacing  

  21. Google: Import statements  

  22. Google: Source file structure  

  23. Google: Vertical whitespace  

  24. Groovy: Number type suffixes  

  25. JetBrains: Invert if statement  

  26. JetBrains: Redundant else keyword  

  27. JetBrains: Redundant qualifier name  

  28. JetBrains: Minimum switch branches  

  29. JetBrains: TODO comments  

  30. Kotlin: Choose good names  

  31. Kotlin: Class headers  

  32. Kotlin: Class layout  

  33. Kotlin: Control flow statements  

  34. Kotlin: Documentation comments  

  35. Kotlin: Filter by predicate  

  36. Kotlin: Horizontal whitespace  

  37. Kotlin: KDoc syntax  

  38. Kotlin: Kotlin contracts  

  39. Kotlin: Mapped types  

  40. Kotlin: Overload layout  

  41. Kotlin: Calling Kotlin from Java  

  42. Kotlin: Source file names  

  43. Kotlin: Source file organization  

  44. Kotlin: Structural equality  

  45. Kotlin: Trailing commas  

  46. Kotlin: Wrap chained calls  

  47. OpenJDK: Java Style Guidelines feedback  

  48. Oracle: Naming conventions  

  49. Oracle: Simple statements  

  50. Oracle: Javadoc reference  

  51. Oracle: Javadoc tool  

  52. Oracle: Lambda expressions  

  53. Oracle: How to throw exceptions  

  54. Oracle: Generic types  

  55. Python: When to use trailing commas