Skip to content

Conversation

@Anmol202005
Copy link
Collaborator

Fixes: #122

@Anmol202005 Anmol202005 marked this pull request as draft October 28, 2025 23:09
@Anmol202005 Anmol202005 marked this pull request as ready for review October 29, 2025 13:25
@Anmol202005 Anmol202005 marked this pull request as draft October 29, 2025 13:26
@Anmol202005
Copy link
Collaborator Author

@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.
for the above case the sarif report provides the source as:
com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck#com.puppycrawl.tools.checkstyle.checks.UpperEllCheck

Can we make a similar thing for xml report in the main checkstyle repo otherwise there will be uncertainty with the logic always.

@rdiachenko
Copy link
Member

@Anmol202005 please create an issue in the main checkstyle repo and include examples and expected output.

Regarding:

    <module name="com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck">
      <property name="id" value="com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"/>
    </module>

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?

@romani
Copy link
Member

romani commented Oct 30, 2025

If people wanted to shoot in their own leg by such config, ok , it is their problem.
There are a lot of places where you can do stupid stuff in our config, we will not support it.

@Anmol202005
Copy link
Collaborator Author

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?

Yes nothing will change :)

@Anmol202005 Anmol202005 marked this pull request as ready for review October 30, 2025 19:36
@Anmol202005
Copy link
Collaborator Author

@romani this PR is ready to review.
but IMO we should update the violation report to mention both check as well as the id as source (If it doesn't break anything else). It will make the logic much straight forward here.

Should i create an issue for same in the main checkstyle repo ?

@romani
Copy link
Member

romani commented Oct 31, 2025

Please create , but please use CLI to show a problem, to let us see all details.

Copy link
Member

@romani romani left a 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

@Anmol202005
Copy link
Collaborator Author

Anmol202005 commented Nov 13, 2025

Please create , but please use CLI to show a problem, to let us see all details.

checkstyle/checkstyle#18088

@romani issue created. This will make the flow straightforward here.

Copy link
Member

@romani romani left a 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkId

Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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 {
Copy link
Member

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

@romani
Copy link
Member

romani commented Nov 20, 2025

@Anmol202005 , do you have time to finish this update?
You can presume that issue in main repo is already resolved.
If any extra update required, we always follow up in new PR.

@romani
Copy link
Member

romani commented Nov 23, 2025

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

@romani
Copy link
Member

romani commented Nov 30, 2025

@Anmol202005 , fix for IDs in XML is released https://checkstyle.org/releasenotes.html#Release_12.2.0
please bump cs version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple instances of the same Checkstyle check with different IDs

3 participants