Issue #122: Support multiple instances of the same Checkstyle check#123
Issue #122: Support multiple instances of the same Checkstyle check#123rdiachenko merged 1 commit intocheckstyle:mainfrom
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.
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. |
|
|
||
| public CheckstyleViolation(int line, int column, String severity, | ||
| CheckstyleCheck source, String message, Path filePath) { | ||
| String source, String message, Path filePath) { |
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static CheckConfiguration findMatchingConfiguration(String source, |
There was a problem hiding this comment.
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.
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.
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 |
|
@romani @rdiachenko sorry for delay. I have simplified the flow :) |
195227e to
7260209
Compare
There was a problem hiding this comment.
This is a line ending normalization - the file content is identical (same checksum), but Git's metadata needed to be refreshed to match our .gitattributes rules, which caused every line to show as changed even though the actual content is unchanged. I've tried various workarounds (Git config changes, checkout options), but re-committing the file is the only reliable solution to fix the index mismatch.
There was a problem hiding this comment.
Question is more on what you did to run into problems with this file.
Why it was not a problem before?
There was a problem hiding this comment.
I just try avoid situation when next contributors with flip this file back.
There was a problem hiding this comment.
well the reason is git attributes,
i needed to create git attributes because of a new check in the check config that flags window file ending.
checkstyle/checkstyle#18069
There was a problem hiding this comment.
ok so there is a misunderstanding, Just to clarify no actual line endings were changed in the .cmd file. It was already using CRLF before, and it still uses CRLF now.
The diff you’re seeing is a side effect of adding .gitattributes to explicitly enforce eol=crlf for .cmd files. Git re-normalized the file against the new rule, which caused it to show every line as “modified” in the diff even though the bytes on disk are identical.
tomato@fedora:~/projects/checkstyle-openrewrite-recipes$ file mvnw.cmd
mvnw.cmd: ASCII text, with CRLF line terminators
tomato@fedora:~/projects/checkstyle-openrewrite-recipes$ git show HEAD~1:mvnw.cmd | file -
/dev/stdin: ASCII text, with CRLF line terminators
tomato@fedora:~/projects/checkstyle-openrewrite-recipes$ git show HEAD~2:mvnw.cmd | file -
/dev/stdin: ASCII text, with CRLF line terminatorsThere was a problem hiding this comment.
@Anmol202005 , please add new line at the end of .gitattributes
3f04884 to
80bdccb
Compare
src/main/java/org/checkstyle/autofix/CheckstyleCheckInstance.java
Outdated
Show resolved
Hide resolved
|
@romani done, pls review. |
|
@romani I’ve reverted https://github.com/checkstyle/checkstyle-openrewrite-recipes/pull/125/changes#diff-537e6a2fcf2f52dddfb99709a5ae95e22e1d9d2386ee4f21961e3827035cebf2 |
|
Please update suppression to make pitest happy. |
done. |
romani
left a comment
There was a problem hiding this comment.
I am ok to meet.
One item to be considered for future PR
| final List<CheckstyleViolation> violations = reportParser | ||
| .parse(Path.of(getViolationReportPath())); | ||
| final Map<CheckstyleCheck, | ||
| final Map<CheckstyleCheckInstance, |
There was a problem hiding this comment.
In next PR we need to improve names of this two records.
There was a problem hiding this comment.
Agree, we should give it a better name. Having Instance in the class name is ambiguous in Java
Fixes: #122