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 |
TBD |
|
π’ | 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 |
TBD |
|
π’ | 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 |
|
π’ | Indentation |
TBD |
|
π’ | NewlineAtEndOfFile |
TBD |
|
π΄ | 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 |
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 |
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
π’ | EmptyForInitializerPad |
TBD |
|
π’ | EmptyForIteratorPad |
TBD |
|
π’ | EmptyLineSeparator |
TBD |
|
π’ | FileTabCharacter |
TBD |
|
π’ | GenericWhitespace |
TBD |
|
π’ | MethodParamPad |
TBD |
|
π΄ | NoLineWrap |
Requires line unwrapping decisions | |
π’ | NoWhitespaceAfter |
TBD |
|
π’ | NoWhitespaceBefore |
TBD |
|
π’ | NoWhitespaceBeforeCaseDefaultColon |
TBD |
|
π’ | OperatorWrap |
TBD |
|
π’ | ParenPad |
TBD |
|
π’ | SeparatorWrap |
TBD |
|
π’ | SingleSpaceSeparator |
TBD |
|
π’ | TypecastParenPad |
TBD |
|
π’ | WhitespaceAfter |
TBD |
|
π’ | WhitespaceAround |
TBD |