Skip to content

Latest commit

Β 

History

277 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

checkstyle-openrewrite-recipes

This OpenRewrite recipe automatically fixes Checkstyle violations in your Java project by analyzing the Checkstyle report and applying code transformations to resolve common issues.

Prerequisites

You need a Java project that already has the Checkstyle plugin configured and running.

Setup

First, add the OpenRewrite plugin and our autofix recipe dependency to your build configuration.

Example:

<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>

Configuration

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)

How to use it

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

OpenRewrite Recipe Coverage for Checkstyle Checks

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 Legend

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

Annotations

Status Check Coverage Notes
πŸ”΅ AnnotationLocation
πŸ”΅ AnnotationOnSameLine
πŸ”΄ AnnotationUseStyle Standardize annotation syntax
πŸ”΅ MissingDeprecated
πŸ”΅ MissingOverride
🟒 MissingOverrideOnRecordAccessor
🟒 OpenjdkAnnotationLocation
🟒 PackageAnnotation
πŸ”΄ SuppressWarnings Remove inappropriate suppressions
πŸ”΄ SuppressWarningsHolder Infrastructural module for SuppressWarningsFilter

Block Checks

Status Check Coverage Notes
πŸ”΄ AvoidNestedBlocks Requires code restructuring
🟒 EmptyBlock
🟒 EmptyCatchBlock
🟒 LeftCurly
🟒 NeedBraces
🟒 RightCurly

Class Design

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

Coding

Status Check Coverage Notes
πŸ”΅ ArrayTrailingComma
πŸ”΄ AvoidDoubleBraceInitialization Requires refactoring initialization logic
πŸ”΄ AvoidInlineConditionals Requires extracting to if-else statements
πŸ”΅ AvoidNoArgumentSuperConstructorCall
πŸ”΅ ConstructorsDeclarationGrouping
πŸ”΄ CovariantEquals Requires implementing proper equals(Object)
🟒 DeclarationOrder
🟒 DefaultComesLast
πŸ”΅ EmptyStatement
🟒 EqualsAvoidNull
πŸ”΄ EqualsHashCode Implement proper equals/hashCode pair
🟒 ExplicitInitialization
βšͺ ExpressionOverBlockLambda
πŸ”΄ FallThrough Add break statements or intentional comments
πŸ”΅ FinalLocalVariable
πŸ”΄ HiddenField Rename variables or use this. prefix
πŸ”΄ IllegalCatch Change catch block exception types
πŸ”΄ IllegalInstantiation Replace with factory methods
πŸ”΄ IllegalSymbol
πŸ”΄ 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
πŸ”΅ MissingSwitchDefault
πŸ”΄ ModifiedControlVariable Restructure loop logic
πŸ”΄ MultipleStringLiterals Extract to constants
🟒 MultipleVariableDeclarations
πŸ”΄ NestedForDepth Requires loop restructuring
πŸ”΄ NestedIfDepth Requires conditional restructuring
πŸ”΄ NestedTryDepth Requires exception handling restructuring
🟒 NoArrayTrailingComma
πŸ”΄ NoClone Remove clone() method
🟒 NoEnumTrailingComma
πŸ”΄ NoFinalizer Remove finalize() method
🟒 OneStatementPerLine
🟒 OverloadMethodsDeclarationOrder
🟒 PackageDeclaration
πŸ”΄ ParameterAssignment
πŸ”΄ PatternVariableAssignment
🟒 RequireThis
πŸ”΄ ReturnCount
🟒 SimplifyBooleanExpression
🟒 SimplifyBooleanReturn
🟒 StringLiteralEquality
πŸ”΄ SuperClone
🟒 SuperFinalize
🟒 TextBlockGoogleStyleFormatting
🟒 UnnecessaryTypeArgumentsWithRecordPattern
🟒 UnnecessaryNullCheckWithInstanceOf
πŸ”΅ UnnecessaryParentheses
🟒 UnnecessarySemicolonAfterOuterTypeDeclaration
🟒 UnnecessarySemicolonAfterTypeMemberDeclaration
🟒 UnnecessarySemicolonInEnumeration
🟒 UnnecessarySemicolonInTryWithResources
🟒 UnusedCatchParameterShouldBeUnnamed
🟒 UnusedLambdaParameterShouldBeUnnamed
πŸ”΅ UnusedLocalVariable
βšͺ UnusedPrivateField
🟒 UnusedTryResourceShouldBeUnnamed
πŸ”΅ UseEnhancedSwitch
πŸ”΄ VariableDeclarationUsageDistance
πŸ”΄ WhenShouldBeUsed

Headers

Status Check Coverage Notes
🟑 Header only java files are fixed.
πŸ”΄ MultiFileRegexpHeader Fix header content
πŸ”΄ RegexpHeader Fix header content

Imports

Status Check Coverage Notes
βšͺ AvoidModuleImport
πŸ”΅ AvoidStarImport
🟒 AvoidStaticImport
🟒 CustomImportOrder
πŸ”΄ IllegalImport Replace with allowed imports
πŸ”΄ ImportControl Restructure imports per rules
🟒 ImportOrder
βšͺ ModuleImportOrder
πŸ”΅ RedundantImport
βšͺ UnnecessaryFullyQualifiedType
πŸ”΅ UnusedImports

Javadoc Comments

Status Check Coverage Notes
🟒 AtclauseOrder
🟒 IllegalBlockTag
βšͺ InappropriateJavadocBlockTagsOnField
βšͺ InappropriateJavadocBlockTagsOnPackage
βšͺ InappropriateJavadocBlockTagsOnType
🟒 InvalidJavadocPosition
🟒 JavadocBlockTagLocation
🟒 JavadocContentLocation
βšͺ JavadocEndCommentDelimiter
🟒 JavadocLeadingAsteriskAlign
βšͺ JavadocLinkFirstOccurrence
βšͺ JavadocLinkWellKnownApi
πŸ”΄ JavadocMethod Add/fix method documentation
🟒 JavadocMissingLeadingAsterisk
🟒 JavadocMissingWhitespaceAfterAsterisk
βšͺ JavadocNoErrorInThrowsTag
πŸ”΄ JavadocPackage Create package-info.java
🟒 JavadocParagraph
βšͺ JavadocParamOrder
πŸ”΄ JavadocRegexp Context-dependent pattern matching
🟒 JavadocTagContinuationIndentation
βšͺ JavadocThrowsOrder
πŸ”΄ 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
βšͺ PreferCodeOrSnippetJavadocInlineTag
🟒 PreferLiteralJavadocInlineTag
🟒 RequireEmptyLineBeforeBlockTagGroup
🟒 SingleLineJavadoc
πŸ”΄ SummaryJavadoc Rewrite summary sentences
πŸ”΄ WriteTag Add/fix custom Javadoc tags

Metrics

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

Miscellaneous

Status Check Coverage Notes
🟒 ArrayTypeStyle
πŸ”΄ AvoidEscapedUnicodeCharacters Need to determine appropriate replacements
🟒 CommentsIndentation
βšͺ ModuleDirectiveOrder
🟒 MultilineCommentLeadingAsteriskPresence
πŸ”΄ DescendantToken Context-dependent token restrictions
🟒 FinalParameters
πŸ”΅ HexLiteralCase
🟒 Indentation
🟒 LineEnding
πŸ”΅ NewlineAtEndOfFile
πŸ”΄ NoCodeInFile Add code or remove file
πŸ”΅ NumericalPrefixesInfixesSuffixesCharacterCase
πŸ”΄ OrderedProperties Reorder properties
πŸ”΄ OuterTypeFilename Rename file or class
πŸ”΄ TodoComment Resolve TODO comments
🟒 TrailingComment
πŸ”΄ Translation Fix property file translations
🟒 UncommentedMain
πŸ”΄ UniqueProperties Remove duplicate properties
πŸ”΅ UpperEll

Modifiers

Status Check Coverage Notes
🟒 AnnotatedDeclarationVisibility
🟒 ClassMemberImpliedModifier
🟒 InterfaceMemberImpliedModifier
🟒 ModifierOrder
🟒 RedundantModifier

Naming Conventions

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

Regexp

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

Size Violations

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

Whitespace

Status Check Coverage Notes
🟒 ArrayBracketNoWhitespace
πŸ”΅ EmptyForInitializerPad
πŸ”΅ EmptyForIteratorPad
🟒 EmptyLineSeparator
🟒 FileTabCharacter
🟒 GenericWhitespace
🟒 MethodParamPad
πŸ”΄ NoLineWrap Requires line unwrapping decisions
πŸ”΅ NoWhitespaceAfter
🟒 NoWhitespaceBefore
🟒 NoWhitespaceBeforeCaseDefaultColon
🟒 OperatorWrap
🟒 ParenPad
🟒 SeparatorWrap
🟒 SingleSpaceSeparator
🟒 TypeBodyPadding
🟒 TypecastParenPad
🟒 WhitespaceAfter
🟒 WhitespaceAround
🟒 WhitespaceBeforeEmptyBody

About

No description, website, or topics provided.

Resources

Contributing

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages