Skip to content

checkstyle/checkstyle-openrewrite-recipes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

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

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

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

No packages published

Contributors 3

  •  
  •  
  •  

Languages