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 |
|---|---|
| π’ | Implemented β Recipes have been created for these checks |
| π‘ | Partial Coverage β Recipes exist but only cover specific violation scenarios |
| π΅ | Planned β Feasible to implement, but no recipe exists yet |
| π΄ | Not Supported β Cannot be implemented or not feasible to auto-fix |
| βͺ | Pending Review β Automatically detected requires human review to determine feasibility |
| Status | Check | Coverage Notes |
|---|---|---|
| π’ | AnnotationLocation |
|
| π’ | AnnotationOnSameLine |
|
| π΄ | AnnotationUseStyle |
Standardize annotation syntax |
| π’ | MissingDeprecated |
|
| π’ | MissingOverride |
|
| π΅ | MissingOverrideOnRecordAccessor |
|
| π΅ | OpenjdkAnnotationLocation |
|
| π΅ | PackageAnnotation |
|
| π΄ | SuppressWarnings |
Remove inappropriate suppressions |
| π΄ | SuppressWarningsHolder |
Infrastructural module for SuppressWarningsFilter |
| Status | Check | Coverage Notes |
|---|---|---|
| π΄ | AvoidNestedBlocks |
Requires code restructuring |
| π΅ | EmptyBlock |
|
| π΅ | EmptyCatchBlock |
|
| βͺ | GoogleRightCurly |
|
| π΅ | LeftCurly |
|
| π΅ | NeedBraces |
|
| π΅ | RightCurly |
| Status | Check | Coverage Notes |
|---|---|---|
| π΄ | DesignForExtension |
Requires design decisions (final/abstract) |
| π’ | FinalClass |
|
| π΅ | HideUtilityClassConstructor |
|
| π΅ | InnerTypeLast |
|
| π΄ | InterfaceIsType |
Remove non-type interface members |
| π΄ | MutableException |
Make exception fields final |
| π΄ | OneTopLevelClass |
Split into separate files |
| π΅ | SealedShouldHavePermitsList |
|
| π΄ | ThrowsCount |
Reduce throws declarations |
| π΄ | VisibilityModifier |
Change visibility modifiers |
| Status | Check | Coverage Notes |
|---|---|---|
| π‘ | Header |
only java files are fixed. |
| π΄ | MultiFileRegexpHeader |
Fix header content |
| π΄ | RegexpHeader |
Fix header content |
| Status | Check | Coverage Notes |
|---|---|---|
| βͺ | AvoidModuleImport |
|
| π’ | AvoidStarImport |
|
| π΅ | AvoidStaticImport |
|
| π΅ | CustomImportOrder |
|
| π΄ | IllegalImport |
Replace with allowed imports |
| π΄ | ImportControl |
Restructure imports per rules |
| π΅ | ImportOrder |
|
| βͺ | ModuleImportOrder |
|
| π’ | RedundantImport |
|
| βͺ | UnnecessaryFullyQualifiedType |
|
| π’ | UnusedImports |
| Status | Check | 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 | Coverage Notes |
|---|---|---|
| π΅ | ArrayTypeStyle |
|
| π΄ | AvoidEscapedUnicodeCharacters |
Need to determine appropriate replacements |
| βͺ | ClassHeaderWrapOpenjdk |
|
| π΅ | CommentsIndentation |
|
| βͺ | ModuleDirectiveOrder |
|
| π΅ | MultilineCommentLeadingAsteriskPresence |
|
| π΄ | DescendantToken |
Context-dependent token restrictions |
| π΅ | FinalParameters |
|
| π’ | HexLiteralCase |
|
| π΅ | Indentation |
|
| π΅ | LineEnding |
|
| π’ | NewlineAtEndOfFile |
|
| π΄ | NoCodeInFile |
Add code or remove file |
| π’ | NumericalPrefixesInfixesSuffixesCharacterCase |
|
| βͺ | OpenjdkMethodThrowsAlignment |
|
| π΄ | OrderedProperties |
Reorder properties |
| π΄ | OuterTypeFilename |
Rename file or class |
| π΄ | TodoComment |
Resolve TODO comments |
| π΅ | TrailingComment |
|
| π΄ | Translation |
Fix property file translations |
| π΅ | UncommentedMain |
|
| π΄ | UniqueProperties |
Remove duplicate properties |
| π’ | UpperEll |
| Status | Check | Coverage Notes |
|---|---|---|
| π΅ | AnnotatedDeclarationVisibility |
|
| π΅ | ClassMemberImpliedModifier |
|
| π΅ | InterfaceMemberImpliedModifier |
|
| π΅ | ModifierOrder |
|
| π΅ | RedundantModifier |
|
| βͺ | RedundantModifierCompactSource |
| Status | Check | Coverage Notes |
|---|---|---|
| π΄ | AbbreviationAsWordInName |
Requires semantic understanding of abbreviations and context |
| π‘ | AbstractClassName |
Partially covered by renaming abstract class names to match the configured pattern. |
| π΅ | CatchParameterName |
|
| π΅ | ClassTypeParameterName |
|
| π΅ | ConstantName |
|
| π΄ | GoogleMethodName |
Requires manual renaming |
| π΄ | GoogleNonConstantFieldName |
|
| π΄ | IllegalIdentifierName |
Rename identifiers |
| π΅ | InterfaceTypeParameterName |
|
| π΅ | LambdaParameterName |
|
| π΅ | LocalFinalVariableName |
|
| π΅ | LocalVariableName |
|
| π΅ | MemberName |
|
| π΅ | MethodName |
|
| π΅ | MethodTypeParameterName |
|
| π΄ | PackageName |
Rename package |
| π΅ | ParameterName |
|
| π΅ | PatternVariableName |
|
| π΅ | RecordComponentName |
|
| π΅ | RecordTypeParameterName |
|
| π΅ | StaticVariableName |
|
| π΅ | TypeName |
| Status | Check | 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 | 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 | Coverage Notes |
|---|---|---|
| π΅ | ArrayBracketNoWhitespace |
|
| π’ | EmptyForInitializerPad |
|
| π’ | EmptyForIteratorPad |
|
| π΅ | EmptyLineSeparator |
|
| βͺ | EmptyLineWrappingInBlock |
|
| π΅ | FileTabCharacter |
|
| π΅ | GenericWhitespace |
|
| π΅ | MethodParamPad |
|
| π΄ | NoLineWrap |
Requires line unwrapping decisions |
| π’ | NoWhitespaceAfter |
|
| π΅ | NoWhitespaceBefore |
|
| π΅ | NoWhitespaceBeforeCaseDefaultColon |
|
| βͺ | OpenjdkMethodParameterAlignment |
|
| π΅ | OperatorWrap |
|
| π΅ | ParenPad |
|
| π΅ | SeparatorWrap |
|
| π΅ | SingleSpaceSeparator |
|
| π΅ | TypeBodyPadding |
|
| π΅ | TypecastParenPad |
|
| π΅ | WhitespaceAfter |
|
| π΅ | WhitespaceAround |
|
| π΅ | WhitespaceBeforeEmptyBody |