GitHub - checkstyle/checkstyle-openrewrite-recipes · GitHub
Skip to content

checkstyle/checkstyle-openrewrite-recipes

Folders and files

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

Annotations

Status Check Recipe Coverage Notes
🟢 AnnotationLocation TBD
🟢 AnnotationOnSameLine TBD
🔴 AnnotationUseStyle Standardize annotation syntax
🟢 MissingDeprecated TBD
🟢 MissingOverride TBD
🟢 PackageAnnotation TBD
🔴 SuppressWarnings Remove inappropriate suppressions

Block Checks

Status Check Recipe Coverage Notes
🔴 AvoidNestedBlocks Requires code restructuring
🟢 EmptyBlock TBD
🟢 EmptyCatchBlock TBD
🟢 LeftCurly TBD
🟢 NeedBraces TBD
🟢 RightCurly TBD

Class Design

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

Coding

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

Headers

Status Check Recipe Coverage Notes
🟡 Header Header only java files are fixed.
🔴 MultiFileRegexpHeader Fix header content
🔴 RegexpHeader Fix header content

Imports

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

Javadoc Comments

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

Metrics

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

Miscellaneous

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

Modifiers

Status Check Recipe Coverage Notes
🟢 ClassMemberImpliedModifier TBD
🟢 InterfaceMemberImpliedModifier TBD
🟢 ModifierOrder TBD
🟢 RedundantModifier TBD

Naming Conventions

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

Regexp

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

Size Violations

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

Whitespace

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors