-
Notifications
You must be signed in to change notification settings - Fork 6
Issue #122: Support multiple instances of the same Checkstyle check #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // checkstyle-openrewrite-recipes: Automatically fix Checkstyle violations with OpenRewrite. | ||
| // Copyright (C) 2025 The Checkstyle OpenRewrite Recipes Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| /////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| package org.checkstyle.autofix; | ||
|
|
||
| public class CheckstyleConfigModule { | ||
| private final CheckstyleCheck check; | ||
| private final String id; | ||
|
|
||
| public CheckstyleConfigModule(CheckstyleCheck check, String id) { | ||
| this.check = check; | ||
| this.id = id; | ||
| } | ||
|
|
||
| public boolean matchesId(String input) { | ||
| return id != null && id.equals(input); | ||
| } | ||
|
|
||
| public boolean matchesCheck(String input) { | ||
| return CheckstyleCheck.fromSourceExact(input) | ||
| .map(checkFromInput -> checkFromInput == check) | ||
| .orElse(false); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,6 @@ | |
|
|
||
| import java.nio.file.Path; | ||
|
|
||
| import org.checkstyle.autofix.CheckstyleCheck; | ||
|
|
||
| public final class CheckstyleViolation { | ||
|
|
||
| private final int line; | ||
|
|
@@ -29,14 +27,14 @@ public final class CheckstyleViolation { | |
|
|
||
| private final String severity; | ||
|
|
||
| private final CheckstyleCheck source; | ||
| private final String source; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename "source" to "checkId" ? I know xml attribute is "source", very bad name, very confusing, and now we copied it new project. Better to have better name that is logical and explain what is this. |
||
|
|
||
| private final String message; | ||
|
|
||
| private final Path filePath; | ||
|
|
||
| public CheckstyleViolation(int line, int column, String severity, | ||
| CheckstyleCheck source, String message, Path filePath) { | ||
| String source, String message, Path filePath) { | ||
| this.line = line; | ||
| this.column = column; | ||
| this.severity = severity; | ||
|
|
@@ -46,7 +44,7 @@ public CheckstyleViolation(int line, int column, String severity, | |
| } | ||
|
|
||
| public CheckstyleViolation(int line, String severity, | ||
| CheckstyleCheck source, String message, Path filePath) { | ||
| String source, String message, Path filePath) { | ||
| this(line, -1, severity, source, message, filePath); | ||
| } | ||
|
|
||
|
|
@@ -58,7 +56,7 @@ public Integer getColumn() { | |
| return column; | ||
| } | ||
|
|
||
| public CheckstyleCheck getSource() { | ||
| public String getSource() { | ||
| return source; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,6 @@ | |
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.checkstyle.autofix.CheckstyleCheck; | ||
|
|
||
| import de.jcup.sarif_2_1_0.SarifSchema210ImportExportSupport; | ||
| import de.jcup.sarif_2_1_0.model.PhysicalLocation; | ||
| import de.jcup.sarif_2_1_0.model.Region; | ||
|
|
@@ -57,17 +55,14 @@ public List<CheckstyleViolation> parse(Path reportPath) { | |
| for (final Run run: report.getRuns()) { | ||
| if (run.getResults() != null) { | ||
| run.getResults().forEach(resultEntry -> { | ||
| CheckstyleCheck.fromSource(resultEntry.getRuleId()).ifPresent(check -> { | ||
| final CheckstyleViolation violation = createViolation(check, resultEntry); | ||
| result.add(violation); | ||
| }); | ||
| result.add(createViolation(resultEntry.getRuleId(), resultEntry)); | ||
| }); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private CheckstyleViolation createViolation(CheckstyleCheck check, Result result) { | ||
| private CheckstyleViolation createViolation(String check, Result result) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is first parameter checkId ? |
||
| final String severity = result.getLevel().name(); | ||
| final String message = result.getMessage().getText(); | ||
| final PhysicalLocation location = result.getLocations().get(0).getPhysicalLocation(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename parameter please.