-
Notifications
You must be signed in to change notification settings - Fork 10
Issue #335: Checks under neverSuppressedChecks group should give more… #381
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
Open
Brijeshthummar02
wants to merge
1
commit into
checkstyle:master
Choose a base branch
from
Brijeshthummar02:neversuppressedchecks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
9 changes: 9 additions & 0 deletions
9
...sionjavapatchfilter/neversuppressedchecks/CovariantEquals/checkID/context/case2/Test.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package TreeWalker.coding.CovariantEquals; | ||
|
|
||
| // patched line outside any type | ||
| public class Test { | ||
| public boolean equals(TreeWalker.coding.CovariantEquals.Test i) { // violation without filter | ||
| return false; | ||
| } | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
...chfilter/neversuppressedchecks/CovariantEquals/checkID/context/case2/defaultContext.patch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| diff --git a/Test.java b/Test.java | ||
| index 9af4e74..d6706f3 100644 | ||
| --- a/Test.java | ||
| +++ b/Test.java | ||
| @@ -1,5 +1,6 @@ | ||
| package TreeWalker.coding.CovariantEquals; | ||
| +// patched line outside any type | ||
| public class Test { | ||
| public boolean equals(TreeWalker.coding.CovariantEquals.Test i) { // violation without filter | ||
| return false; |
18 changes: 18 additions & 0 deletions
18
...lter/neversuppressedchecks/CovariantEquals/checkID/context/case2/defaultContextConfig.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0"?> | ||
| <!DOCTYPE module PUBLIC | ||
| "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" | ||
| "https://checkstyle.org/dtds/configuration_1_3.dtd"> | ||
| <module name="Checker"> | ||
| <module name="TreeWalker"> | ||
| <module name="CovariantEquals"> | ||
| <property name="id" value="covariantEquals"/> | ||
| </module> | ||
|
|
||
| <module name="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter"> | ||
| <property name="file" value="${tp}/defaultContext.patch" /> | ||
| <property name="strategy" value="context" /> | ||
| <property name="neverSuppressedChecks" value="covariantEquals" /> | ||
| </module> | ||
| </module> | ||
| </module> | ||
|
|
Empty file.
9 changes: 9 additions & 0 deletions
9
...javapatchfilter/neversuppressedchecks/CovariantEquals/checkID/patchedline/case2/Test.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package TreeWalker.coding.CovariantEquals; | ||
|
|
||
| // patched line outside any type | ||
| public class Test { | ||
| public boolean equals(TreeWalker.coding.CovariantEquals.Test i) { // violation without filter | ||
| return false; | ||
| } | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
...lter/neversuppressedchecks/CovariantEquals/checkID/patchedline/case2/defaultContext.patch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| diff --git a/Test.java b/Test.java | ||
| index 9af4e74..d6706f3 100644 | ||
| --- a/Test.java | ||
| +++ b/Test.java | ||
| @@ -1,5 +1,6 @@ | ||
| package TreeWalker.coding.CovariantEquals; | ||
| +// patched line outside any type | ||
| public class Test { | ||
| public boolean equals(TreeWalker.coding.CovariantEquals.Test i) { // violation without filter | ||
| return false; |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
this method will always return true, as in java all files are types of any sort.
in what test it return false ?
I think you need to differentiate if violation happened in input file methods (return false) and on method (return true, as it like on type).
but on the same type Check predicatably give violation on specific AST node, so we know by design of Check that it always give violaiton on methods
https://checkstyle.org/checks/coding/covariantequals.html#Example1-code .
prove by test in what cases we need such isChangedLineInsideEnclosingType, or remove it.
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.
Thanks for the review, this is a valid concern.
isChangedLineInsideEnclosingType(...)is not always true.For
CovariantEquals, violation is reported on method AST, but causality is type-level (missingequals(Object)in that class), so I attribute by enclosing type scope.It returns
falsewhen no patch line is inside the violation’s enclosing type, proven by:neversuppressedchecks/CovariantEquals/checkID/context/case2/defaultContextConfig.xmlneversuppressedchecks/CovariantEquals/checkID/patchedline/case2/defaultContextConfig.xmlneversuppressedchecks/CovariantEquals/checkShortName/context/case2/defaultContextConfig.xmlneversuppressedchecks/CovariantEquals/checkShortName/patchedline/case2/defaultContextConfig.xmlIn all above, patch is empty and expected output is empty.
Also, precision improved in:
neversuppressedchecks/CovariantEquals/checkID/patchedline/expected.txtneversuppressedchecks/CovariantEquals/checkShortName/patchedline/expected.txtNow only line 11 is reported (line 4 is suppressed), showing we no longer report unchanged-type violations.
If you prefer method-level attribution instead of type-level attribution for this check, I can update implementation and tests accordingly.
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.
I agree that we should explicitly demonstrate when
isChangedLineInsideEnclosingType(...)returnsfalse.I will reproduce this scenario locally and add a dedicated test case where a violation exists but no patch line falls inside the violation's enclosing type. This will help confirm whether the method is necessary or if the logic can be simplified.
I will update the PR once the test is added and verified.