This OpenRewrite recipe automatically fixes Checkstyle violations in your Java project by analyzing the Checkstyle report and applying code transformations to resolve common issues.
You need a Java project that already has the Checkstyle plugin configured and running.
First, add the OpenRewrite plugin and our autofix recipe dependency to your build configuration.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>${rewrite.maven.plugin}</version>
<configuration>
<activeRecipes>
<recipe>CheckstyleAutoFix</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle-openrewrite-recipes</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>Create a rewrite.yml file in your project root:
---
type: specs.openrewrite.org/v1beta/recipe
name: CheckstyleAutoFix
displayName: Checkstyle Auto Fix
description: Automatically fix Checkstyle violations
recipeList:
- org.checkstyle.autofix.CheckstyleAutoFix:
violationReportPath: "target/checkstyle/checkstyle-report.xml"
configurationPath: "config/checkstyle.xml"
propertiesPath: "config/checkstyle.properties"Parameters:
violationReportPath: Path to Checkstyle XML report (required)configurationPath: Path to Checkstyle configuration file (required)propertiesPath: Path to Checkstyle properties file (optional)
The autofix process works in two steps: first generate a Checkstyle report, then run the autofix recipe.
mvn checkstyle:check # Generate the violation report
mvn rewrite:run # Apply the fixes
This table tracks the auto-fix support status of OpenRewrite recipes for each Checkstyle check. Organized by Checkstyle categories, it helps contributors identify which checks are:
- Fully supported via auto-fix
- Partially supported
- Not feasible to auto-fix
| Status | Meaning |
|---|---|
| 🟢 | Full Coverage – Complete auto-fix capability for all violation scenarios |
| 🟡 | Partial Coverage – Auto-fix available for some violation scenarios |
| 🔴 | Won't Be Covered – Auto-fix not feasible or not planned |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | AnnotationLocation |
TBD |
|
| 🟢 | AnnotationOnSameLine |
TBD |
|
| 🔴 | AnnotationUseStyle |
Standardize annotation syntax | |
| 🟢 | MissingDeprecated |
TBD |
|
| 🟢 | MissingOverride |
TBD |
|
| 🟢 | PackageAnnotation |
TBD |
|
| 🔴 | SuppressWarnings |
Remove inappropriate suppressions |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | AvoidNestedBlocks |
Requires code restructuring | |
| 🟢 | EmptyBlock |
TBD |
|
| 🟢 | EmptyCatchBlock |
TBD |
|
| 🟢 | LeftCurly |
TBD |
|
| 🟢 | NeedBraces |
TBD |
|
| 🟢 | RightCurly |
TBD |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | DesignForExtension |
Requires design decisions (final/abstract) | |
| 🟢 | FinalClass |
FinalClass |
|
| 🟢 | HideUtilityClassConstructor |
TBD |
|
| 🟢 | InnerTypeLast |
TBD |
|
| 🔴 | InterfaceIsType |
Remove non-type interface members | |
| 🔴 | MutableException |
Make exception fields final | |
| 🔴 | OneTopLevelClass |
Split into separate files | |
| 🟢 | SealedShouldHavePermitsList |
TBD |
|
| 🔴 | ThrowsCount |
Reduce throws declarations | |
| 🔴 | VisibilityModifier |
Change visibility modifiers |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | ArrayTrailingComma |
TBD |
|
| 🔴 | AvoidDoubleBraceInitialization |
Requires refactoring initialization logic | |
| 🔴 | AvoidInlineConditionals |
Requires extracting to if-else statements | |
| 🟢 | AvoidNoArgumentSuperConstructorCall |
TBD |
|
| 🟢 | ConstructorsDeclarationGrouping |
TBD |
|
| 🔴 | CovariantEquals |
Requires implementing proper equals(Object) | |
| 🟢 | DeclarationOrder |
TBD |
|
| 🟢 | DefaultComesLast |
TBD |
|
| 🟢 | EmptyStatement |
EmptyStatement |
|
| 🟢 | EqualsAvoidNull |
TBD |
|
| 🔴 | EqualsHashCode |
Implement proper equals/hashCode pair | |
| 🟢 | ExplicitInitialization |
TBD |
|
| 🔴 | FallThrough |
Add break statements or intentional comments | |
| 🟢 | FinalLocalVariable |
FinalLocalVariable |
|
| 🔴 | HiddenField |
Rename variables or use this. prefix | |
| 🔴 | IllegalCatch |
Change catch block exception types | |
| 🔴 | IllegalInstantiation |
Replace with factory methods | |
| 🔴 | IllegalThrows |
Change throws declarations | |
| 🔴 | IllegalToken |
Replace illegal tokens | |
| 🔴 | IllegalTokenText |
Change token text | |
| 🔴 | IllegalType |
Replace with allowed types | |
| 🔴 | InnerAssignment |
Extract assignments to separate statements | |
| 🔴 | MagicNumber |
Extract to named constants | |
| 🔴 | MatchXpath |
Context-dependent XPath violations | |
| 🔴 | MissingCtor |
Add explicit constructor | |
| 🟢 | MissingNullCaseInSwitch |
TBD |
|
| 🟢 | MissingSwitchDefault |
TBD |
|
| 🔴 | ModifiedControlVariable |
Restructure loop logic | |
| 🔴 | MultipleStringLiterals |
Extract to constants | |
| 🟢 | MultipleVariableDeclarations |
TBD |
|
| 🔴 | NestedForDepth |
Requires loop restructuring | |
| 🔴 | NestedIfDepth |
Requires conditional restructuring | |
| 🔴 | NestedTryDepth |
Requires exception handling restructuring | |
| 🟢 | NoArrayTrailingComma |
TBD |
|
| 🔴 | NoClone |
Remove clone() method | |
| 🟢 | NoEnumTrailingComma |
TBD |
|
| 🔴 | NoFinalizer |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟡 | Header |
Header |
only java files are fixed. |
| 🔴 | MultiFileRegexpHeader |
Fix header content | |
| 🔴 | RegexpHeader |
Fix header content |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | AvoidStarImport |
TBD |
|
| 🟢 | AvoidStaticImport |
TBD |
|
| 🟢 | CustomImportOrder |
TBD |
|
| 🔴 | IllegalImport |
Replace with allowed imports | |
| 🔴 | ImportControl |
Restructure imports per rules | |
| 🟢 | ImportOrder |
TBD |
|
| 🟢 | RedundantImport |
RedundantImport |
|
| 🟢 | UnusedImports |
TBD |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | AtclauseOrder |
TBD |
|
| 🟢 | InvalidJavadocPosition |
TBD |
|
| 🟢 | JavadocBlockTagLocation |
TBD |
|
| 🟢 | JavadocContentLocation |
TBD |
|
| 🟢 | JavadocLeadingAsteriskAlign |
TBD |
|
| 🔴 | JavadocMethod |
Add/fix method documentation | |
| 🟢 | JavadocMissingLeadingAsterisk |
TBD |
|
| 🟢 | JavadocMissingWhitespaceAfterAsterisk |
TBD |
|
| 🔴 | JavadocPackage |
Create package-info.java | |
| 🟢 | JavadocParagraph |
TBD |
|
| 🟢 | JavadocStyle |
TBD |
|
| 🟢 | JavadocTagContinuationIndentation |
TBD |
|
| 🔴 | JavadocType |
Add/fix type documentation | |
| 🔴 | JavadocVariable |
Add variable documentation | |
| 🔴 | MissingJavadocMethod |
Add method documentation | |
| 🔴 | MissingJavadocPackage |
Add package documentation | |
| 🔴 | MissingJavadocType |
Add type documentation | |
| 🔴 | NonEmptyAtclauseDescription |
Add tag descriptions | |
| 🟢 | RequireEmptyLineBeforeBlockTagGroup |
TBD |
|
| 🟢 | SingleLineJavadoc |
TBD |
|
| 🔴 | SummaryJavadoc |
Rewrite summary sentences | |
| 🔴 | WriteTag |
Add/fix custom Javadoc tags |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | BooleanExpressionComplexity |
Requires breaking down complex expressions | |
| 🔴 | ClassDataAbstractionCoupling |
Requires architectural changes | |
| 🔴 | ClassFanOutComplexity |
Requires architectural refactoring | |
| 🔴 | CyclomaticComplexity |
Requires method decomposition | |
| 🔴 | JavaNCSS |
Requires code simplification | |
| 🔴 | NPathComplexity |
Requires method decomposition |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | ArrayTypeStyle |
TBD |
|
| 🔴 | AvoidEscapedUnicodeCharacters |
Need to determine appropriate replacements | |
| 🟢 | CommentsIndentation |
TBD |
|
| 🔴 | DescendantToken |
Context-dependent token restrictions | |
| 🟢 | FinalParameters |
TBD |
|
| 🟢 | HexLiteralCase |
HexLiteralCase |
|
| 🟢 | Indentation |
TBD |
|
| 🟢 | NewlineAtEndOfFile |
NewlineAtEndOfFile |
|
| 🔴 | NoCodeInFile |
Add code or remove file | |
| 🔴 | OrderedProperties |
Reorder properties | |
| 🔴 | OuterTypeFilename |
Rename file or class | |
| 🔴 | TodoComment |
Resolve TODO comments | |
| 🟢 | TrailingComment |
TBD |
|
| 🔴 | Translation |
Fix property file translations | |
| 🟢 | UncommentedMain |
TBD |
|
| 🔴 | UniqueProperties |
Remove duplicate properties | |
| 🟢 | UpperEll |
UpperEll |
|
| 🟢 | NumericalPrefixesInfixesSuffixesCharacterCase |
NumericalPrefixesInfixesSuffixesCharacterCase |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🟢 | ClassMemberImpliedModifier |
TBD |
|
| 🟢 | InterfaceMemberImpliedModifier |
TBD |
|
| 🟢 | ModifierOrder |
TBD |
|
| 🟢 | RedundantModifier |
TBD |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | AbbreviationAsWordInName |
Requires semantic understanding of abbreviations and context | |
| 🟡 | AbstractClassName |
TBD |
Partially covered by renaming abstract class names to match the configured pattern. |
| 🟢 | CatchParameterName |
TBD |
|
| 🟢 | ClassTypeParameterName |
TBD |
|
| 🟢 | ConstantName |
TBD |
|
| 🔴 | IllegalIdentifierName |
Rename identifiers | |
| 🟢 | InterfaceTypeParameterName |
TBD |
|
| 🟢 | LambdaParameterName |
TBD |
|
| 🟢 | LocalFinalVariableName |
TBD |
|
| 🟢 | LocalVariableName |
TBD |
|
| 🟢 | MemberName |
TBD |
|
| 🟢 | MethodName |
TBD |
|
| 🟢 | MethodTypeParameterName |
TBD |
|
| 🔴 | PackageName |
Rename package | |
| 🟢 | ParameterName |
TBD |
|
| 🟢 | PatternVariableName |
TBD |
|
| 🟢 | RecordComponentName |
TBD |
|
| 🟢 | RecordTypeParameterName |
TBD |
|
| 🟢 | StaticVariableName |
TBD |
|
| 🟢 | TypeName |
TBD |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | Regexp |
Context-dependent pattern matching | |
| 🔴 | RegexpMultiline |
Context-dependent pattern fixes | |
| 🔴 | RegexpOnFilename |
Rename files | |
| 🔴 | RegexpSingleline |
Context-dependent line fixes | |
| 🔴 | RegexpSinglelineJava |
Context-dependent Java line fixes |
| Status | Check | Recipe | Coverage Notes |
|---|---|---|---|
| 🔴 | AnonInnerLength |
Requires refactoring to named classes | |
| 🔴 | ExecutableStatementCount |
Requires method decomposition | |
| 🔴 | FileLength |
Requires file splitting | |
| 🔴 | LambdaBodyLength |
Extract lambda to method | |
| 🔴 | LineLength |
Requires line breaking decisions | |
| 🔴 | MethodCount |
Requires class decomposition | |
| 🔴 | MethodLength |
Requires method decomposition | |
| 🔴 | OuterTypeNumber |
Split types into separate files | |
| 🔴 | ParameterNumber |
Reduce parameter count | |
| 🔴 | RecordComponentNumber |
Reduce record components |
