-
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?
Conversation
|
@romani @rdiachenko This PR currently covers most of the cases (all cases for sarif report) but there are some failing edge cases for xml report. Issue: XML reports only mention the check ID, which creates ambiguous matching when the ID value matches another check's class name, such as: <module name="Checker">
<module name="TreeWalker">
<module name="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
<module name="com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck">
<property name="id" value="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
</module>
</module>
</module>No such issue with sarif since it mentions both the check name as well as the id. Can we make a similar thing for xml report in the main checkstyle repo otherwise there will be uncertainty with the logic always. |
|
@Anmol202005 please create an issue in the main checkstyle repo and include examples and expected output. Regarding: I think this is more theoretical than practical case. Users are in control of their configs, and I can't imagine the case when they want to set id pointing to a different module. This can be done by some odd refactoring or mistake. If the above case happens, what's the result of autofix execution? Will it fail or do nothing? We should just ignore such cases, because you have violation belonging to a different module id, which means if you try to execute recipe, nothing should change, right? |
|
If people wanted to shoot in their own leg by such config, ok , it is their problem. |
Yes nothing will change :) |
|
@romani this PR is ready to review. Should i create an issue for same in the main checkstyle repo ? |
|
Please create , but please use CLI to show a problem, to let us see all details. |
romani
left a comment
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.
we need some cleanup from "source" (xml attribute of checkstyle report) in naming to checkId or checkName or ...
as we have sarif report, so better to use better term that is not xml format special
src/main/java/org/checkstyle/autofix/parser/CheckstyleViolation.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/SarifReportParser.java
Outdated
Show resolved
Hide resolved
@romani issue created. This will make the flow straightforward here. |
romani
left a comment
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.
Few more updates required
|
|
||
| public CheckstyleViolation(int line, int column, String severity, | ||
| CheckstyleCheck source, String message, Path filePath) { | ||
| String source, String message, Path filePath) { |
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.
checkId
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.
Same for other places
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static CheckConfiguration findMatchingConfiguration(String source, |
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.
checkId
And for all new methods.
| .filter(configEntry -> matchesSource(configEntry.getKey(), source)) | ||
| .map(Map.Entry::getValue) | ||
| .findFirst() | ||
| .orElse(null); |
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.
could you return Optional and filter out absent values before trying to create recipe after calling findMatchingConfiguration
|
|
||
| package org.checkstyle.autofix; | ||
|
|
||
| public class CheckstyleConfigModule { |
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.
The name is misleading, this is not a config, but just a wrapper around check, which adds id attribute from config properties. This abstraction makes the whole logic more complex, since you eventually use CheckstyleCheck.
Could you try to simplify the logic by combining both classes into one CheckstyleCheck and CheckstyleConfigModule? In reality, id field inside CheckstyleCheck is actually a fully qualified check's name
|
@Anmol202005 , do you have time to finish this update? |
|
#127 (comment) after fixing this , update for suppression is easy activity. @Anmol202005 , fyi, fix for id support is close to merge state, release of CS will be at last Saturday on november, so you can expect fix to be ready for you very soon. |
|
@Anmol202005 , fix for IDs in XML is released https://checkstyle.org/releasenotes.html#Release_12.2.0 |
Fixes: #122