Exclude test classes from CommentDefaultAccessModifier rule#3
Merged
lithium147 merged 2 commits intoMar 5, 2026
Merged
Conversation
Add violationSuppressXPath property to suppress CommentDefaultAccessModifier violations in test classes (matching pattern: Test*, IT*, *Test, *Tests, *TestCase, *IT, *ITCase). Co-Authored-By: lithium147@gmail.com <timlwalters@yahoo.co.uk>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
lithium147
deleted the
devin/1772670103-exclude-test-classes-comment-default-access
branch
March 5, 2026 01:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exclude test classes from CommentDefaultAccessModifier PMD rule
Summary
Adds a
violationSuppressXPathproperty to theCommentDefaultAccessModifierrule inpmd7-rules.xmlto suppress all violations inside test classes. This resolves the existing TODO comment ("ignore constructors of test classes") by excluding test classes entirely.The XPath matches classes using the same naming pattern already defined in the
ClassNamingConventionsrule:Test*,IT*,*Test,*Tests,*TestCase,*IT,*ITCase.The previous approach only ignored specific test-related annotations (e.g.
@Test,@BeforeEach). This change broadens the exclusion to cover everything inside a test class — including fields, constructors, and helper methods that lack those annotations.Review & Testing Checklist for Human
ClassDeclarationand@SimpleName, which are PMD 7 AST names (PMD 6 usedClassOrInterfaceDeclaration/@Image). Confirm these are valid for PMD 7.22.0.ancestor-or-self::ClassDeclarationmeans nested classes inside test classes are also excluded. Verify this is the intended behavior.^(Test|IT).*$|^[A-Z][a-zA-Z0-9]*Test(s|Case)?$|^[A-Z][a-zA-Z0-9]*IT(Case)?$).Notes