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
[java] CommentSize rule violation is not suppressed at method level #2996
Comments
@oowekyala Hi, oowekyala, I think this issue is very interesting and find you have added this to 7.0 milestone, could you please tell me the root cause or spot the potental buggy code file? THX. |
Rules normally report violations on an AST node that corresponds to the location of the violation, and that node is used to find an enclosing annotation, by inspecting its ancestors until the root of the tree. The problem is that comments are not nodes in the AST, and we also have no API to find a node close to a comment (although that exists in the designer currently). So this rule always uses the root node as a placeholder, eg here https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java#L105 This could be fixed in PMD 6 if the functionality to find a node from coordinates was backported from the designer into pmd-core. The relevant code is this function and its implementation: https://github.com/pmd/pmd-designer/blob/ee66c3678693deefc2582bebf0b0e8eb3259fa74/src/main/java/net/sourceforge/pmd/util/fxdesigner/util/codearea/PmdCoordinatesSystem.java#L92 I marked this for PMD 7 because maybe we can have a nicer solution then, eg by representing comments as actual nodes in the tree. There is a todo item in #3898 about that. Also moving the linked designer code into pmd-core would be easier in PMD 7 as there are already data types there to represent text positions, which in PMD 6 only exist in the designer codebase (this TextPos2d class). |
Affects PMD Version:
6.30.0
Description:
Violations of rule CommentSize are not suppressed by the annotations @SuppressWarnings("PMD.CommentSize") or @SuppressWarnings("PMD") when placed on the method definition.
Code Sample demonstrating the issue:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Referred from: #2995
The text was updated successfully, but these errors were encountered: