modifier-order
What it does
Section titled “What it does”Reports the modifiers of a declaration (public, static, final, override, …) that are not in the order the style of the language wants: for Java the order of the Java Language Specification (public protected private abstract default static sealed non-sealed final transient volatile synchronized native strictfp), for Kotlin the order of the Kotlin coding conventions. Annotations and unknown keywords keep their place. The finding sits on the keyword that is out of place, or on the first modifier with the option report: list. The fix reorders the keywords.
Why it matters
Section titled “Why it matters”Modifiers in a fixed order are easier to scan: the access level is always first, so a reader and a search for public static find every declaration alike. The order carries no meaning for the compiler, so no behaviour changes.
To fix, reorder the modifiers; the fix does it.
Example
Section titled “Example”class A { static public final int A = 1; public static final int B = 1; @Deprecated final private int c = 1; private final @Deprecated int d = 1; synchronized public void f() {}}class A { public static final int A = 1; public static final int B = 1; @Deprecated private final int c = 1; private final @Deprecated int d = 1; public synchronized void f() {}}Configuration
Section titled “Configuration”lint: rules: modifier-order: level: warn # off (default), warn, error options: report: "keyword"| Option | Type | Default | Description |
|---|---|---|---|
report |
string | "keyword" |
Where a finding is reported: on the keyword that is out of place, or on the first token of the modifier list. Values: keyword, list |
Enabled by the presets: java/google, kotlin/ktlint.
Suppress one line with sudsy-disable-next-line modifier-order in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| checkstyle | ModifierOrder |
partial | Annotations are not checked against the modifiers. |
| ktlint | modifier-order |
partial | The shared rule over the #modifiers node; ktlint’s order, annotations stay in place |