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>org.checkstyle.autofix</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 |
No checks analyzed yet
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
🟢 | FinalClass |
TBD |
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
🟢 | FinalLocalVariable |
TBD |
|
🔴 | MagicNumber |
it requires contextual understanding to replace literals with meaningful named constants | |
🟢 | UnusedLocalVariable |
TBD |
|
🟢 | UnnecessaryParentheses |
TBD |
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
🟡 | Header |
Header |
only java files are fixed. |
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
🟢 | RedundantImport |
RedundantImport |
No checks analyzed yet
No checks analyzed yet
Status | Check | Recipe | Coverage Notes |
---|---|---|---|
🟢 | UpperEll |
UpperEll |
No checks analyzed yet
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. |
No checks analyzed yet
No checks analyzed yet
No checks analyzed yet