A fast, native linter and formatter for Java in a single binary. Written in Rust. No JVM required.
Replace google-java-format, Checkstyle, and PMD with one tool and one config file.
- Formatter: output identical to google-java-format, verified against large open-source codebases.
- Linter: the most-used syntax-level Checkstyle and PMD rules, with automatic fixes.
- One binary, one config: starts in milliseconds and works with Maven, Gradle, or no build tool.
- Machine-readable output: JSON diagnostics with exact locations and fixes, for editors, CI, and coding agents.
Each part is scored against an existing tool, over a corpus of open-source Java:
| Part | Reference | Score |
|---|---|---|
| Parser | javac |
Share of files accepted or rejected the same way |
| Formatter | google-java-format | Share of files with identical output |
| Linter | Checkstyle, PMD | Share of diagnostics matching by rule and line |
The linter has a second score, coverage: of the diagnostics that Checkstyle's own sun_checks and google_checks configurations and PMD's quickstart ruleset report, the share that comes from checks WeaveJig has a rule for. Agreement says how good the rules are; coverage says how many there are.
And a third, takeover, for the codebases of the corpus that are checked with Checkstyle or PMD themselves: weavejig migrate converts the project's own configuration, and the score is the share of its files for which WeaveJig then reports exactly what the other tool reports with the original. This is the goal measured directly: one tool in the place of another, on a real project, with the project's own rules.
- Build the scoring harness first: one command that prints these scores.
- Keep a held-out set of codebases that is never used during development.
- Reimplement from documentation and observed behaviour. Do not translate the reference tools' source (Checkstyle is LGPL).
- Type-aware analysis (Error Prone, NullAway)
- Kotlin and other JVM languages
- Building or dependency management
Early development. Everything below runs, but nothing is at parity yet: do not rely on it for real code.
| Part | What exists |
|---|---|
| Parser | Hand-written, lossless, error-tolerant, written for the Java 21 grammar. Agrees with javac on 6,636 of 6,640 dev-corpus files and on 2,548 of 2,549 held-out files. The 4 dev disagreements are JUnit tests that use unnamed variables (_), which are Java 22: javac 21 rejects them. |
| Formatter | Formats whole files in google-java-format style, Javadoc included. 99.2% of dev-corpus files (6,583 of 6,636) come out identical to google-java-format 2.0.0, and 98.4% of held-out files (2,508 of 2,549). By codebase, the dev corpus matches between 96.8% (jsoup) and 100% (gson). As google-java-format does, long string literals are split at word boundaries, long trailing // comments continue on lines under their start, modifiers are put in JLS order, unused imports and tokens that do nothing are removed, text blocks are re-indented, and lists that the source writes as tables keep their rows. Not done: a tail of rarer wrapping and comment-placement cases differs, most of it around // comments inside expressions, and so does Javadoc that is malformed or laid out unusually: 16 of the 114 smoke-corpus files that google-java-format accepts, all of them probes written for the lint rules, come out differently. |
| Linter | 311 rules, 18 with fixes; 48 run by default and the rest are opt-in. 118 mirror Checkstyle checks, 19 of them its checks of Javadoc comments: with default options their diagnostics match Checkstyle on 272,176 of 272,189 in the dev corpus and on 85,020 of 85,084 in the held-out corpus. 198 mirror PMD rules, 5 of them also a Checkstyle check, matching on 328,312 of 328,451 and 87,390 of 87,707. Rules take options, a rule can run several times with different ones, and diagnostics can be suppressed in the source or by file. Coverage: setting aside layout checks, which the formatter replaces, the rules account for all of what Checkstyle's sun_checks reports on both corpora, and for 99.6% of what google_checks reports on the dev corpus (99.3% on the held-out corpus); setting aside rules that need types, for 97.6% of what PMD's quickstart reports (97.1%). Takeover: for each of the three dev codebases that has a Checkstyle configuration of its own (commons-lang, junit-framework and zxing), and for commons-lang's PMD ruleset, WeaveJig with the migrated configuration reports on every file what the reference reports with the original. Not done: a handful of Checkstyle checks those configurations and google_checks use (FinalLocalVariable, ImportControl, VariableDeclarationUsageDistance, the header checks), a few PMD rules in quickstart (GuardLogStatement, UnusedReturnValue, PreserveStackTrace, UseCollectionIsEmpty), and anything that needs types. |
| CLI | check, format, rules, migrate; text and JSON output; weavejig.toml, with rule selection, rule options, per-file ignores and suppressions. migrate writes a weavejig.toml from a Checkstyle configuration, with its suppressions file, or from a PMD ruleset, and lists what it could not carry over. |
| Scoring | cargo xtask score for the parser (javac), formatter (google-java-format) and linter (Checkstyle and PMD), rule by rule, with coverage against Checkstyle's bundled configurations and takeover of the corpus's own. The formatter's score is broken down by codebase and by kind of difference. |
The formatter never changes anything but whitespace, import order, the wrapping of comments, the splitting of long string literals, the indentation of text blocks, the order of modifier keywords, which imports there are and whether a few tokens that do nothing are there: it checks its own output against the input, and refuses to write a file if any token would differ or any comment would gain or lose text. A string literal may only become, or be merged from, literals joined by + whose text, put together, is the same. A text block may only be re-indented, or have its closing delimiter moved to a line of its own behind a \: the string the compiler reads from it must be the same. Modifier keywords may only trade places with keywords not separated from them by an annotation. An import may only go if nothing in the output uses its simple name, or if it imports from java.lang or the file's own package; any other wildcard import always stays. The tokens that may go are the ; of an empty statement in a block or of an empty declaration, the () of an annotation without values, and the parentheses around a single lambda parameter that has no type.
cargo install --path crates/weavejigweavejig check # lint the current directory
weavejig check --fix src/ # apply fixes
weavejig check --output-format json # diagnostics for tools
weavejig check --select all # every rule, not only the default ones
weavejig format # format in place
weavejig format --check # exit 1 if anything would change
weavejig format - < Foo.java # format standard input
weavejig rules # list the lint rules
weavejig migrate checkstyle.xml # print a weavejig.toml that does what a Checkstyle configuration doesDirectories are searched for .java files, skipping anything in .gitignore.
Exit status: 0 nothing to report, 1 problems found or files need formatting, 2 WeaveJig could not do what was asked.
WeaveJig reads the nearest weavejig.toml in the current directory or above it. Every key is optional.
# Paths never checked or formatted, relative to this file.
exclude = ["**/generated/**"]
[format]
style = "google" # or "aosp"
[lint]
select = ["upper-ell", "need-braces"] # default: the rules that are on by default
extend-select = ["magic-number"] # these as well
ignore = ["avoid-star-import"] # but never these
# Rules to skip where a glob matches, relative to this file.
[lint.per-file-ignores]
"**/src/test/**" = ["magic-number", "method-name"]
# Options of a rule.
[lint.rules.magic-number]
ignore-numbers = [-1, 0, 1, 2, 100]
[lint.rules.line-length]
max = 120
# A rule runs once more for each further table of its own.
[[lint.rules.regexp-singleline]]
format = '\s+$'
message = "Line has trailing spaces."
[[lint.rules.regexp-singleline]]
format = 'System\.out\.println'
# Rules to skip where a regular expression is found in the file's path.
[[lint.suppressions]]
files = '[/\\]generated[/\\]'
rules = ["all"]select = ["all"] runs every rule. weavejig rules lists the rules, marking the opt-in ones; weavejig rules --output-format json adds each rule's options with their types and defaults. Options that are patterns are regular expressions as Rust's regex crate reads them, which is the common syntax without look-around and backreferences.
weavejig migrate config/checkstyle.xml --output weavejig.toml
weavejig migrate checkstyle.xml pmd-ruleset.xml # both, into one configuration- Each Checkstyle module that names a check with a rule becomes a selected rule, and its properties the rule's options. A check that is configured several times becomes a rule that runs several times.
- A
SuppressionFilter's file is read, and its entries become[[lint.suppressions]].@SuppressWarningsandCHECKSTYLE:OFFcomments work without being asked for. - Checks about layout (indentation, whitespace, where braces go) are left out: the formatter settles those.
- A PMD ruleset's references to rules, or to whole categories with exclusions, select the rules that mirror them, and the properties of a rule become its options. Patterns are anchored, since PMD matches whole names. A rule that also mirrors a Checkstyle check keeps PMD's defaults: they are written out where they differ. Rules under the names they had before PMD 7 are found too.
- Where Checkstyle and PMD draw a line differently, as
EmptyBlockandEmptyControlStatementdo, each has a rule of its own, and the PMD one is named after PMD's:empty-control-statement. - Where PMD has a rule that WeaveJig only has a near relative of (
UnnecessaryImport,ModifierOrder), the relative is selected and a note says so. - What has no counterpart is listed on standard error, one note each: checks without a rule, PMD rules that need the types of the whole program, properties without an option, patterns that use look-around, suppressions by line. Nothing is dropped silently.
The result selects exactly the rules the configuration asked for, so it is also where to see what WeaveJig would not check that the other tool did.
long a = 1l; // weavejig-ignore: upper-ell
// weavejig-ignore: upper-ell, magic-number
long b = 250l;
@SuppressWarnings("weavejig:magic-number")
int port() {
return 8080;
}- A comment that starts with
weavejig-ignorecovers its line if it comes after code; on a line of its own, the next line. Without rule ids it covers every rule. // weavejig-ignore-file: rule-idcovers the whole file.@SuppressWarnings("weavejig:rule-id")covers the declaration it is on;"weavejig"and"all"cover every rule.
Code that already suppresses Checkstyle or PMD needs no changes. For the rules that mirror their checks, WeaveJig honours @SuppressWarnings("checkstyle:magicnumber") and // CHECKSTYLE:OFF up to // CHECKSTYLE:ON, and @SuppressWarnings("PMD.RuleName"), @SuppressWarnings("PMD") and // NOPMD.
weavejig check --output-format json prints one object:
{
"version": 1,
"diagnostics": [
{
"file": "src/Foo.java",
"rule": "upper-ell",
"severity": "warning",
"message": "long literal should use an upper-case `L` suffix",
"range": {
"start": { "line": 6, "column": 33, "offset": 102 },
"end": { "line": 6, "column": 36, "offset": 105 }
},
"fix": {
"description": "use an upper-case `L`",
"edits": [
{
"range": {
"start": { "line": 6, "column": 35, "offset": 104 },
"end": { "line": 6, "column": 36, "offset": 105 }
},
"replacement": "L"
}
]
}
}
],
"summary": { "files_checked": 1, "files_with_diagnostics": 1, "diagnostics": 1, "fixable": 1, "fixed": 0 }
}Lines and columns are 1-based; columns count Unicode code points. offset is a 0-based byte offset into the UTF-8 file. Ranges are half-open. fix is null when a diagnostic has no automatic fix; a fix's edits never overlap and must be applied together. Syntax errors are reported as rule syntax-error with severity error.
A rule mirrors a Checkstyle check unless marked as PMD's, and with default options reports what that check reports with its own. The rules about Javadoc read a comment as Checkstyle does: where it documents a declaration at all, and, like Checkstyle, they report nothing for a comment whose HTML does not add up (a </p> that closes nothing, List<K, V> outside {@code}). Three rules differ on purpose. line-length allows 100 columns, the formatter's width, where Checkstyle allows 80. final-class and redundant-modifier leave out a few cases where Checkstyle asks for a change that would not compile or would change what the code means.
| Rule | Mirrors | Default | Fix | Options |
|---|---|---|---|---|
abbreviation-as-word-in-name |
AbbreviationAsWordInName | allowed-abbreviation-length, allowed-abbreviations, ignore-final, ignore-static, ignore-static-final, ignore-overridden-methods |
||
abstract-class-without-abstract-method |
PMD AbstractClassWithoutAbstractMethod | |||
abstract-class-without-any-method |
PMD AbstractClassWithoutAnyMethod | |||
add-empty-string |
PMD AddEmptyString | |||
anon-inner-length |
AnonInnerLength | max |
||
append-character-with-char |
PMD AppendCharacterWithChar | |||
array-is-stored-directly |
PMD ArrayIsStoredDirectly | |||
array-type-style |
ArrayTypeStyle | yes | yes | |
assignment-in-operand |
PMD AssignmentInOperand | allow-if, allow-for, allow-while, allow-do-while, allow-switch, allow-increment-decrement |
||
at-least-one-constructor |
PMD AtLeastOneConstructor | ignored-annotations |
||
atclause-order |
AtclauseOrder | tag-order, target |
||
avoid-accessibility-alteration |
PMD AvoidAccessibilityAlteration | |||
avoid-array-loops |
PMD AvoidArrayLoops | |||
avoid-branching-statement-as-last-in-loop |
PMD AvoidBranchingStatementAsLastInLoop | check-break-loop-types, check-continue-loop-types, check-return-loop-types |
||
avoid-calling-finalize |
PMD AvoidCallingFinalize | |||
avoid-catching-generic-exception |
PMD AvoidCatchingGenericException | types-that-should-not-be-caught |
||
avoid-decimal-literals-in-big-decimal-constructor |
PMD AvoidDecimalLiteralsInBigDecimalConstructor | |||
avoid-deeply-nested-if-stmts |
PMD AvoidDeeplyNestedIfStmts | problem-depth |
||
avoid-dollar-signs |
PMD AvoidDollarSigns | |||
avoid-duplicate-literals |
PMD AvoidDuplicateLiterals | max-duplicate-literals, minimum-length, skip-annotations, exception-list |
||
avoid-escaped-unicode-characters |
AvoidEscapedUnicodeCharacters | allow-escapes-for-control-characters, allow-by-tail-comment, allow-if-all-characters-escaped, allow-non-printable-escapes |
||
avoid-field-name-matching-method-name |
PMD AvoidFieldNameMatchingMethodName | |||
avoid-field-name-matching-type-name |
PMD AvoidFieldNameMatchingTypeName | |||
avoid-file-stream |
PMD AvoidFileStream | |||
avoid-inline-conditionals |
AvoidInlineConditionals | |||
avoid-instanceof-checks-in-catch-clause |
PMD AvoidInstanceofChecksInCatchClause | |||
avoid-instantiating-objects-in-loops |
PMD AvoidInstantiatingObjectsInLoops | |||
avoid-literals-in-if-condition |
PMD AvoidLiteralsInIfCondition | ignore-magic-numbers, ignore-expressions |
||
avoid-message-digest-field |
PMD AvoidMessageDigestField | |||
avoid-multiple-unary-operators |
PMD AvoidMultipleUnaryOperators | |||
avoid-nested-blocks |
AvoidNestedBlocks | yes | allow-in-switch-case |
|
avoid-print-stack-trace |
PMD AvoidPrintStackTrace | |||
avoid-reassigning-loop-variables |
PMD AvoidReassigningLoopVariables | foreach-reassign, for-reassign |
||
avoid-reassigning-parameters |
PMD AvoidReassigningParameters | |||
avoid-rethrowing-exception |
PMD AvoidRethrowingException | |||
avoid-star-import |
AvoidStarImport, PMD OnDemandImport | yes | allow-static-imports-from, allow-type-imports-from |
|
avoid-static-import |
AvoidStaticImport | excludes |
||
avoid-string-buffer-field |
PMD AvoidStringBufferField | |||
avoid-synchronized-at-method-level |
PMD AvoidSynchronizedAtMethodLevel | |||
avoid-synchronized-statement |
PMD AvoidSynchronizedStatement | |||
avoid-thread-group |
PMD AvoidThreadGroup | |||
avoid-throwing-new-instance-of-same-exception |
PMD AvoidThrowingNewInstanceOfSameException | |||
avoid-throwing-null-pointer-exception |
PMD AvoidThrowingNullPointerException | |||
avoid-throwing-raw-exception-types |
PMD AvoidThrowingRawExceptionTypes | |||
avoid-using-hard-coded-ip |
PMD AvoidUsingHardCodedIP | check-address-types |
||
avoid-using-native-code |
PMD AvoidUsingNativeCode | |||
avoid-using-octal-values |
PMD AvoidUsingOctalValues | strict |
||
avoid-using-volatile |
PMD AvoidUsingVolatile | |||
big-integer-instantiation |
PMD BigIntegerInstantiation | |||
boolean-expression-complexity |
BooleanExpressionComplexity | max, tokens |
||
boolean-get-method-name |
PMD BooleanGetMethodName | check-parameterized-methods, include-wrapped-type |
||
broken-null-check |
PMD BrokenNullCheck | |||
call-super-in-constructor |
PMD CallSuperInConstructor | |||
catch-parameter-name |
CatchParameterName | format |
||
class-cast-exception-with-to-array |
PMD ClassCastExceptionWithToArray | |||
class-data-abstraction-coupling |
ClassDataAbstractionCoupling | max, excluded-classes, excluded-packages, exclude-classes-regexps |
||
class-fan-out-complexity |
ClassFanOutComplexity | max, excluded-classes, excluded-packages, exclude-classes-regexps |
||
class-naming-conventions |
PMD ClassNamingConventions | class-pattern, abstract-class-pattern, interface-pattern, enum-pattern, annotation-pattern, utility-class-pattern, test-class-pattern |
||
class-type-parameter-name |
ClassTypeParameterName | format |
||
class-with-only-private-constructors-should-be-final |
PMD ClassWithOnlyPrivateConstructorsShouldBeFinal | |||
clone-method-must-be-public |
PMD CloneMethodMustBePublic | |||
clone-method-must-implement-cloneable |
PMD CloneMethodMustImplementCloneable | |||
clone-method-return-type-must-match-class-name |
PMD CloneMethodReturnTypeMustMatchClassName | |||
cognitive-complexity |
PMD CognitiveComplexity | report-level |
||
collapsible-if-statements |
PMD CollapsibleIfStatements | |||
comment-default-access-modifier |
PMD CommentDefaultAccessModifier | regex, check-top-level-types, ignored-annotations |
||
comment-size |
PMD CommentSize | max-lines, max-line-length |
||
confusing-ternary |
PMD ConfusingTernary | ignore-else-if, null-check-branch |
||
consecutive-appends-should-reuse |
PMD ConsecutiveAppendsShouldReuse | |||
consecutive-literal-appends |
PMD ConsecutiveLiteralAppends | threshold |
||
constant-name |
ConstantName | format, apply-to-public, apply-to-protected, apply-to-package, apply-to-private |
||
constants-in-interface |
PMD ConstantsInInterface | ignore-if-has-methods |
||
constructors-declaration-grouping |
ConstructorsDeclarationGrouping | |||
covariant-equals |
CovariantEquals | yes | ||
cyclomatic-complexity |
CyclomaticComplexity | max, switch-block-as-single-decision-point, tokens |
||
cyclomatic-complexity-pmd |
PMD CyclomaticComplexity | class-report-level, method-report-level, cyclo-options |
||
dangling-javadoc |
PMD DanglingJavadoc | |||
declaration-order |
DeclarationOrder | ignore-constructors, ignore-modifiers |
||
default-comes-last |
DefaultComesLast, PMD DefaultLabelNotLastInSwitch | yes | ||
design-for-extension |
DesignForExtension | ignored-annotations, required-javadoc-phrase |
||
detached-test-case |
PMD DetachedTestCase | |||
do-not-call-garbage-collection-explicitly |
PMD DoNotCallGarbageCollectionExplicitly | |||
do-not-extend-java-lang-error |
PMD DoNotExtendJavaLangError | |||
do-not-extend-java-lang-throwable |
PMD DoNotExtendJavaLangThrowable | |||
do-not-throw-exception-in-finally |
PMD DoNotThrowExceptionInFinally | |||
double-brace-initialization |
PMD DoubleBraceInitialization | |||
empty-block |
EmptyBlock | yes | option |
|
empty-catch-block |
EmptyCatchBlock, PMD EmptyCatchBlock | yes | exception-variable-name, comment-format |
|
empty-control-statement |
PMD EmptyControlStatement | allow-commented-blocks |
||
empty-finalizer |
PMD EmptyFinalizer | |||
empty-method-in-abstract-class-should-be-abstract |
PMD EmptyMethodInAbstractClassShouldBeAbstract | |||
empty-statement |
EmptyStatement | yes | yes | |
equals-avoid-null |
EqualsAvoidNull | yes | ignore-equals-ignore-case |
|
equals-hash-code |
EqualsHashCode | yes | ||
equals-null |
PMD EqualsNull | |||
excessive-imports |
PMD ExcessiveImports | minimum |
||
excessive-parameter-list |
PMD ExcessiveParameterList | minimum |
||
excessive-public-count |
PMD ExcessivePublicCount | minimum |
||
executable-statement-count |
ExecutableStatementCount | max, tokens |
||
explicit-initialization |
ExplicitInitialization | yes | yes | only-object-references |
fall-through |
FallThrough, PMD ImplicitSwitchFallThrough | yes | relief-pattern, check-last-case-group |
|
field-declarations-should-be-at-start-of-class |
PMD FieldDeclarationsShouldBeAtStartOfClass | ignore-anonymous-class-declarations, ignore-interface-declarations, ignore-enum-declarations |
||
field-naming-conventions |
PMD FieldNamingConventions | public-constant-pattern, constant-pattern, enum-constant-pattern, final-field-pattern, static-field-pattern, default-field-pattern, exclusions |
||
file-length |
FileLength | max |
||
file-tab-character |
FileTabCharacter | each-line |
||
final-class |
FinalClass | yes | ||
final-field-could-be-static |
PMD FinalFieldCouldBeStatic | |||
final-parameter-in-abstract-method |
PMD FinalParameterInAbstractMethod | |||
final-parameters |
FinalParameters | yes | ignore-primitive-types |
|
finalize-does-not-call-super-finalize |
PMD FinalizeDoesNotCallSuperFinalize | |||
finalize-only-calls-super-finalize |
PMD FinalizeOnlyCallsSuperFinalize | |||
finalize-overloaded |
PMD FinalizeOverloaded | |||
finalize-should-be-protected |
PMD FinalizeShouldBeProtected | |||
for-loop-can-be-foreach |
PMD ForLoopCanBeForeach | |||
for-loop-variable-count |
PMD ForLoopVariableCount | maximum-variables |
||
formal-parameter-naming-conventions |
PMD FormalParameterNamingConventions | method-parameter-pattern, final-method-parameter-pattern, lambda-parameter-pattern, explicit-lambda-parameter-pattern |
||
google-method-name |
GoogleMethodName | |||
google-non-constant-field-name |
GoogleNonConstantFieldName | |||
hard-coded-crypto-key |
PMD HardCodedCryptoKey | |||
hidden-field |
HiddenField | ignore-constructor-parameter, ignore-setter, setter-can-return-its-class, ignore-abstract-methods, ignore-format |
||
hide-utility-class-constructor |
HideUtilityClassConstructor | yes | ||
idempotent-operations |
PMD IdempotentOperations | |||
identical-catch-branches |
PMD IdenticalCatchBranches | |||
illegal-import |
IllegalImport | yes | packages, classes |
|
illegal-instantiation |
IllegalInstantiation | classes |
||
illegal-token-text |
IllegalTokenText | tokens, format, ignore-case, message |
||
illegal-type |
IllegalType | illegal-class-names, ignored-method-names, member-modifiers, validate-abstract-class-names, illegal-abstract-class-name-format, legal-abstract-class-names |
||
inefficient-empty-string-check |
PMD InefficientEmptyStringCheck | |||
inefficient-string-buffering |
PMD InefficientStringBuffering | |||
inner-assignment |
InnerAssignment | yes | ||
insecure-crypto-iv |
PMD InsecureCryptoIv | |||
instantiable-utility-class |
PMD InstantiableUtilityClass | |||
instantiation-to-get-class |
PMD InstantiationToGetClass | |||
insufficient-string-buffer-declaration |
PMD InsufficientStringBufferDeclaration | |||
interface-is-type |
InterfaceIsType | allow-marker-interfaces |
||
interface-type-parameter-name |
InterfaceTypeParameterName | format |
||
invalid-javadoc-position |
InvalidJavadocPosition | yes | ||
java-ncss |
JavaNCSS | method-maximum, class-maximum, record-maximum, file-maximum |
||
javadoc-content-location |
JavadocContentLocation | location |
||
javadoc-leading-asterisk-align |
JavadocLeadingAsteriskAlign | |||
javadoc-method |
JavadocMethod | access-modifiers, allowed-annotations, allow-missing-param-tags, allow-missing-return-tag, allow-inline-return, validate-throws |
||
javadoc-missing-leading-asterisk |
JavadocMissingLeadingAsterisk | yes | ||
javadoc-missing-whitespace-after-asterisk |
JavadocMissingWhitespaceAfterAsterisk | yes | ||
javadoc-package |
JavadocPackage | allow-legacy |
||
javadoc-paragraph |
JavadocParagraph | yes | allow-newline-paragraph |
|
javadoc-tag-continuation-indentation |
JavadocTagContinuationIndentation | offset |
||
javadoc-type |
JavadocType | scope, exclude-scope, author-format, version-format, allow-missing-param-tags, allow-unknown-tags, allowed-annotations |
||
javadoc-variable |
JavadocVariable | access-modifiers, ignore-name-pattern |
||
jumbled-incrementer |
PMD JumbledIncrementer | |||
junit-jupiter-test-no-private-modifier |
PMD JUnitJupiterTestNoPrivateModifier | |||
junit-jupiter-test-should-be-package-private |
PMD JUnitJupiterTestShouldBePackagePrivate | |||
junit-suites-should-use-suite-annotation |
PMD JUnit4SuitesShouldUseSuiteAnnotation | |||
junit-use-expected |
PMD JUnitUseExpected | |||
labeled-statement |
PMD LabeledStatement | allow-loops |
||
lambda-body-length |
LambdaBodyLength | max |
||
lambda-parameter-name |
LambdaParameterName | yes | format |
|
line-length |
LineLength | max, ignore-pattern, tab-width |
||
linguistic-naming |
PMD LinguisticNaming | ignored-annotations, check-boolean-method, check-getters, check-setters, check-prefixed-transform-methods, check-transform-methods, boolean-method-prefixes, transform-method-names, check-fields, check-variables, boolean-field-prefixes |
||
literals-first-in-comparisons |
PMD LiteralsFirstInComparisons | |||
local-final-variable-name |
LocalFinalVariableName | yes | format |
|
local-variable-could-be-final |
PMD LocalVariableCouldBeFinal | ignore-for-each-decl |
||
local-variable-name |
LocalVariableName | yes | format |
|
local-variable-naming-conventions |
PMD LocalVariableNamingConventions | local-var-pattern, final-var-pattern, catch-parameter-pattern |
||
logic-inversion |
PMD LogicInversion | |||
long-variable |
PMD LongVariable | minimum |
||
loose-coupling |
PMD LooseCoupling | allowed-types |
||
magic-number |
MagicNumber | ignore-numbers, ignore-hash-code-method, ignore-annotation, ignore-field-declaration, ignore-annotation-element-defaults |
||
member-name |
MemberName | yes | format, apply-to-public, apply-to-protected, apply-to-package, apply-to-private |
|
method-argument-could-be-final |
PMD MethodArgumentCouldBeFinal | |||
method-count |
MethodCount | max-total, max-private, max-package, max-protected, max-public |
||
method-length |
MethodLength | max, count-empty |
||
method-name |
MethodName | format, allow-class-name, apply-to-public, apply-to-protected, apply-to-package, apply-to-private |
||
method-naming-conventions |
PMD MethodNamingConventions | method-pattern, static-pattern, native-pattern, test-case-pattern, junit-test-pattern, jupiter-test-pattern |
||
method-returns-internal-array |
PMD MethodReturnsInternalArray | |||
method-type-parameter-name |
MethodTypeParameterName | format |
||
method-with-same-name-as-enclosing-class |
PMD MethodWithSameNameAsEnclosingClass | |||
misplaced-null-check |
PMD MisplacedNullCheck | |||
missing-deprecated |
MissingDeprecated | yes | ||
missing-javadoc-method |
MissingJavadocMethod | scope, exclude-scope, min-line-count, allowed-annotations, allow-missing-property-javadoc, ignore-method-names-regex |
||
missing-javadoc-type |
MissingJavadocType | scope, exclude-scope, skip-annotations |
||
missing-override |
MissingOverride | yes | ||
missing-static-method-in-non-instantiatable-class |
PMD MissingStaticMethodInNonInstantiatableClass | annotations |
||
missing-switch-default |
MissingSwitchDefault | yes | ||
modifier-order |
ModifierOrder | yes | yes | |
multiline-comment-leading-asterisk-presence |
MultilineCommentLeadingAsteriskPresence | |||
multiple-variable-declarations |
MultipleVariableDeclarations | yes | ||
mutable-static-state |
PMD MutableStaticState | |||
ncss-count |
PMD NcssCount | method-report-level, class-report-level, ncss-options |
||
need-braces |
NeedBraces, PMD ControlStatementBraces | yes | yes | |
nested-for-depth |
NestedForDepth | max |
||
nested-if-depth |
NestedIfDepth | max |
||
nested-try-depth |
NestedTryDepth | max |
||
newline-at-end-of-file |
NewlineAtEndOfFile | yes | yes | |
no-clone |
NoClone | |||
no-finalizer |
NoFinalizer | yes | ||
no-package |
PMD NoPackage | |||
non-empty-atclause-description |
NonEmptyAtclauseDescription | |||
non-exhaustive-switch |
PMD NonExhaustiveSwitch | |||
non-static-initializer |
PMD NonStaticInitializer | |||
non-thread-safe-singleton |
PMD NonThreadSafeSingleton | check-non-static-fields |
||
npath-complexity |
NPathComplexity | max |
||
npath-complexity-pmd |
PMD NPathComplexity | report-level |
||
null-assignment |
PMD NullAssignment | |||
one-declaration-per-line |
PMD OneDeclarationPerLine | strict-mode |
||
one-statement-per-line |
OneStatementPerLine | yes | ||
one-top-level-class |
OneTopLevelClass | yes | ||
only-one-return |
PMD OnlyOneReturn | ignored-method-names, allow-guard-ifs |
||
optimizable-to-array-call |
PMD OptimizableToArrayCall | |||
outer-type-filename |
OuterTypeFilename | yes | ||
outer-type-number |
OuterTypeNumber | max |
||
overload-methods-declaration-order |
OverloadMethodsDeclarationOrder | |||
override-both-equals-and-hashcode |
PMD OverrideBothEqualsAndHashcode | |||
overriding-thread-run |
PMD OverridingThreadRun | |||
package-declaration |
PackageDeclaration | match-directory-structure |
||
package-name |
PackageName | yes | format |
|
parameter-name |
ParameterName | yes | format |
|
parameter-number |
ParameterNumber | max, ignore-overridden-methods |
||
pattern-variable-name |
PatternVariableName | yes | format |
|
primitive-wrapper-instantiation |
PMD PrimitiveWrapperInstantiation | |||
proper-clone-implementation |
PMD ProperCloneImplementation | |||
protected-member-in-final-class |
PMD ProtectedMemberInFinalClass | |||
public-member-in-non-public-type |
PMD PublicMemberInNonPublicType | |||
record-component-name |
RecordComponentName | yes | format |
|
record-component-number |
RecordComponentNumber | max, access-modifiers |
||
record-type-parameter-name |
RecordTypeParameterName | format |
||
redundant-field-initializer |
PMD RedundantFieldInitializer | yes | ||
redundant-import |
RedundantImport | yes | yes | |
redundant-modifier |
RedundantModifier | yes | yes | |
regexp-singleline |
RegexpSingleline | yes | format, message, ignore-case, maximum, minimum, ignore-comments |
|
regexp-singleline-java |
RegexpSinglelineJava | yes | format, message, ignore-case, maximum, minimum, ignore-comments |
|
replace-hashtable-with-map |
PMD ReplaceHashtableWithMap | |||
replace-java-util-calendar |
PMD ReplaceJavaUtilCalendar | |||
replace-java-util-date |
PMD ReplaceJavaUtilDate | |||
replace-java-util-vector |
PMD ReplaceJavaUtilVector | |||
require-empty-line-before-block-tag-group |
RequireEmptyLineBeforeBlockTagGroup | yes | ||
return-count |
ReturnCount | max, max-for-void, format, tokens |
||
return-empty-collection-rather-than-null |
PMD ReturnEmptyCollectionRatherThanNull | |||
return-from-finally-block |
PMD ReturnFromFinallyBlock | |||
short-class-name |
PMD ShortClassName | minimum |
||
short-method-name |
PMD ShortMethodName | minimum |
||
short-variable |
PMD ShortVariable | minimum |
||
signature-declare-throws-exception |
PMD SignatureDeclareThrowsException | ignore-junit-completely |
||
simple-date-format-needs-locale |
PMD SimpleDateFormatNeedsLocale | |||
simplified-ternary |
PMD SimplifiedTernary | |||
simplify-boolean-expression |
SimplifyBooleanExpression | yes | ||
simplify-boolean-return |
SimplifyBooleanReturn | yes | ||
simplify-boolean-returns |
PMD SimplifyBooleanReturns | |||
simplify-conditional |
PMD SimplifyConditional | |||
single-line-javadoc |
SingleLineJavadoc | ignored-tags, ignore-inline-tags |
||
single-method-singleton |
PMD SingleMethodSingleton | |||
singleton-class-returning-new-instance |
PMD SingletonClassReturningNewInstance | |||
static-variable-name |
StaticVariableName | yes | format, apply-to-public, apply-to-protected, apply-to-package, apply-to-private |
|
string-instantiation |
PMD StringInstantiation | |||
string-literal-equality |
StringLiteralEquality | yes | ||
string-to-string |
PMD StringToString | |||
summary-javadoc |
SummaryJavadoc | forbidden-summary-fragments, period |
||
super-clone |
SuperClone | yes | ||
super-finalize |
SuperFinalize | yes | ||
suspicious-equals-method-name |
PMD SuspiciousEqualsMethodName | |||
suspicious-hashcode-method-name |
PMD SuspiciousHashcodeMethodName | |||
suspicious-octal-escape |
PMD SuspiciousOctalEscape | |||
switch-density |
PMD SwitchDensity | minimum |
||
system-println |
PMD SystemPrintln | |||
test-class-without-test-cases |
PMD TestClassWithoutTestCases | test-class-pattern |
||
throws-count |
ThrowsCount | max, ignore-private-methods |
||
todo-comment |
TodoComment | format |
||
too-few-branches-for-switch |
PMD TooFewBranchesForSwitch | minimum-number-case-for-a-switch |
||
too-many-fields |
PMD TooManyFields | maxfields |
||
too-many-methods |
PMD TooManyMethods | maxmethods |
||
too-many-static-imports |
PMD TooManyStaticImports | maximum-static-imports |
||
type-name |
TypeName | yes | format, apply-to-public, apply-to-protected, apply-to-package, apply-to-private |
|
type-name-mismatch |
PMD TypeNameMismatch | |||
type-parameter-naming-conventions |
PMD TypeParameterNamingConventions | type-parameter-name-pattern |
||
uncommented-empty-constructor |
PMD UncommentedEmptyConstructor | |||
uncommented-empty-method-body |
PMD UncommentedEmptyMethodBody | |||
unconditional-if-statement |
PMD UnconditionalIfStatement | |||
unit-test-contains-too-many-asserts |
PMD UnitTestContainsTooManyAsserts | maximum-asserts, extra-assert-method-names |
||
unit-test-should-include-assert |
PMD UnitTestShouldIncludeAssert | extra-assert-method-names |
||
unit-test-should-use-test-annotation |
PMD UnitTestShouldUseTestAnnotation | test-class-pattern |
||
unnecessary-annotation-value-element |
PMD UnnecessaryAnnotationValueElement | |||
unnecessary-block |
PMD UnnecessaryBlock | |||
unnecessary-boolean-assertion |
PMD UnnecessaryBooleanAssertion | |||
unnecessary-constructor |
PMD UnnecessaryConstructor | ignored-annotations |
||
unnecessary-modifier |
PMD UnnecessaryModifier | |||
unnecessary-parentheses |
UnnecessaryParentheses | yes | ||
unnecessary-return |
PMD UnnecessaryReturn | |||
unnecessary-semicolon |
PMD UnnecessarySemicolon | |||
unused-formal-parameter |
PMD UnusedFormalParameter | check-all |
||
unused-imports |
UnusedImports | yes | yes | process-javadoc |
unused-local-variable |
PMD UnusedLocalVariable | |||
unused-private-field |
PMD UnusedPrivateField | ignored-field-names, report-for-annotations |
||
unused-private-method |
PMD UnusedPrivateMethod | ignored-annotations |
||
upper-ell |
UpperEll | yes | yes | |
use-arrays-as-list |
PMD UseArraysAsList | |||
use-concurrent-hash-map |
PMD UseConcurrentHashMap | |||
use-equals-to-compare-strings |
PMD UseEqualsToCompareStrings | |||
use-index-of-char |
PMD UseIndexOfChar | |||
use-proper-class-loader |
PMD UseProperClassLoader | |||
use-short-array-initializer |
PMD UseShortArrayInitializer | |||
use-standard-charsets |
PMD UseStandardCharsets | |||
use-string-buffer-for-string-appends |
PMD UseStringBufferForStringAppends | |||
use-string-buffer-length |
PMD UseStringBufferLength | |||
use-underscores-in-numeric-literals |
PMD UseUnderscoresInNumericLiterals | acceptable-decimal-length |
||
use-varargs |
PMD UseVarargs | |||
useless-parentheses |
PMD UselessParentheses | ignore-clarifying, ignore-balancing |
||
useless-qualified-this |
PMD UselessQualifiedThis | |||
useless-string-value-of |
PMD UselessStringValueOf | |||
variable-can-be-inlined |
PMD VariableCanBeInlined | |||
visibility-modifier |
VisibilityModifier | package-allowed, protected-allowed, public-member-pattern, allow-public-final-fields, ignore-annotations |
||
while-loop-with-literal-boolean |
PMD WhileLoopWithLiteralBoolean | |||
wrong-test-annotation |
PMD WrongTestAnnotation |
Requires Rust 1.88 or newer. Scoring also needs JDK 21 or newer.
cargo test --workspace
cargo xtask score| Path | What |
|---|---|
crates/weavejig-syntax |
Lexer, parser and lossless syntax tree |
crates/weavejig-formatter |
Syntax tree → layout document → text |
crates/weavejig-linter |
Lint rules and fixes, one module per rule |
crates/weavejig |
The command-line binary, and as a library what it is made of: configuration, migrate |
xtask |
The scoring harness |
scoring.toml |
Pinned reference tools (google-java-format, Checkstyle, PMD) and corpus |
reference/ |
The javac parse helper the harness runs |
corpus/smoke/ |
A small in-repository corpus |
corpus/smoke/lint/ |
Hand-written probes that trip every lint rule: checks/ and javadoc/ for Checkstyle's, pmd/ for PMD's |
cargo xtask score prints the scores from Measuring progress. With no arguments it uses the smoke corpus in this repository, and measures whatever it has the references for; the parser score needs only a JDK.
cargo xtask fetch references # google-java-format, Checkstyle and PMD
cargo xtask fetch corpus --set dev # the development codebases
cargo xtask score --set dev --show 20 # scores, and the first 20 disagreements per partThe formatter is scored twice. The second row, scrambled, formats each file after its whitespace has been rewritten into another style (other indentation, other line wrapping, braces on their own line), keeping every token and comment. Much of the corpus is already in google-java-format style, so the first row alone would mostly test leaving formatted code alone. To see the scrambled input for a disagreement:
cargo xtask scramble path/to/File.javaUnder the totals, the formatter's score is broken down twice: by codebase, and by the kind of difference in each file that does not match. Both are counts, so they are printed for the held-out set as well.
| Kind | The outputs differ in |
|---|---|
| line wrapping | where lines break, or how they are indented |
| Javadoc | Javadoc comments only |
| text blocks | the whitespace inside text blocks only |
| Javadoc and text blocks | both of those, and nothing else |
| blank lines | empty lines only |
| tokens or comment text | the tokens themselves: a string split elsewhere, an import kept or removed, a // comment wrapped differently |
Each disagreement that --show lists names its kind and the first line that differs.
Reference tool versions and corpus commits are pinned in scoring.toml; downloads go to .weavejig/ and are checked against the pinned SHA-256. The harness looks for a JDK in WEAVEJIG_JAVA_HOME, JAVA_HOME, then PATH.
The held-out set is for measuring only. cargo xtask score --set held-out prints totals and never lists individual disagreements: do not inspect its files to fix a score.
The linter is scored rule by rule, and the table of rules is printed under the totals. To work on one rule:
cargo xtask score --set dev --part linter --rule magic-number --show 50- Checkstyle and PMD are each run with exactly the checks WeaveJig mirrors, with default options (
xtask/src/lint_score.rslists the few properties set to match a WeaveJig default). Their output is kept in.weavejig/cache/and reused while the checks and the files stay the same;--no-cacheruns them again. - A diagnostic matches Checkstyle's if it starts on the same line. PMD often reports the same finding a line or two away, on the statement under an
ifwhere Checkstyle names theif, so a diagnostic matches PMD's if it covers the line PMD reports. - The
Coveragerows run Checkstyle's bundledsun_checksandgoogle_checks, and PMD'squickstart, and count how many of their diagnostics come from checks with a rule. PMD rules that need the types of the whole program are counted apart, since WeaveJig does not analyse types. Under them,--showlists the checks without a rule, most frequent first: what to add next. - The
Takeoverrows are for the codebases that name acheckstyle-configor apmd-rulesetinscoring.toml. The reference is run with that configuration from the codebase's directory, as its build runs it, less the checks and properties that the reference version no longer has, which the row lists. WeaveJig is run with whatweavejig migratemakes of the same file. A file counts if both report the same rules on the same lines, which for a project that passes its own checks mostly means nothing at all; the row also gives the diagnostics that match, and names the configuration's checks that have no rule. - The references' output is cached check by check, so a new rule costs one check over the corpus.
Rules are written from the reference tools' documentation and from what they are seen to do, not from their source.
- Add a module in
crates/weavejig-linter/src/rules/with a unit struct implementingRuleand astatic META, built withRuleMeta::new(id, summary)and then.checkstyle(..)or.pmd(..),.fixable(),.opt_in()and.options(..)as they apply. A rule mirrors both tools only where they agree; where they draw the line differently, each gets a rule, and the PMD one, opt-in, is named after PMD's rule in kebab case.crate::asthas helpers for reading the tree,crate::javadoctakes a Javadoc comment apart, andcrate::scopefinds how a name is declared; the rule'sContexthas the file's text, path and lines, its Javadoc comments, and the rule's options. - List it in
ALLinrules/mod.rs, which is sorted by id. - Add code that trips the rule, and code that nearly does, to a probe in
corpus/smoke/lint/. Where the documentation leaves a case open, running the reference tool on a probe settles it. - Run
cargo xtask score --part linterandcargo xtask score --set dev --part linter --rule <id>, and compare with the reference until they agree. - Record what the probes now report (see
corpus/smoke/lint/README.md), add the rule to the table above, and add cases tocrates/weavejig-linter/tests/rules.rs, or to thetests/pmd_*.rsfile of its family, for its fix and options. For a fix, apply it to a copy of a dev codebase and run both tools on the result: they should agree on what is left, and the reference should still be able to read every comment. - If a Checkstyle property does not become the option of the same name in kebab case, or takes Checkstyle's token names, say so in the tables at the top of
crates/weavejig/src/migrate.rs; for PMD properties, inPMD_ALIASESthere. A PMD rule that cannot be written without types goes inPMD_TYPE_RULESincrates/weavejig-linter/src/lib.rs, so that coverage andmigratecan say so.
Formatting rules live in crates/weavejig-formatter/src/format.rs; a node kind without a rule is laid out on one line by the spacing table in spacing.rs. Javadoc is reflowed in javadoc.rs and text blocks are re-indented in textblock.rs, both while printing, when the column they land on is known. Long string literals are split after layout, in strings.rs.
Where the documentation of google-java-format does not say what it does, find out by running it on a small probe, and keep the probe as a reference fixture. Fixtures in crates/weavejig-formatter/tests/fixtures/ record current output so that changes show up in review; see the README there.