Issue #7064: Add influenceFormat property to SuppressWithPlainTextCommentFilter#11884
Issue #7064: Add influenceFormat property to SuppressWithPlainTextCommentFilter#11884stoyanK7 wants to merge 2 commits intocheckstyle:masterfrom stoyanK7:issue/7064-add-influenceFormat-prop-to-SuppressWithPlainTextCommentFilter
Conversation
|
Github, generate report |
| else { | ||
| commentFormat = filter.offCommentFormat; | ||
| } | ||
| final Pattern filterCommentFormat = getFilterCommentFormat(filter); |
There was a problem hiding this comment.
This method extraction is needed due to NCSS line count violation.
| /** Off suppression type. */ | ||
| OFF, | ||
| /** Default suppression type. */ | ||
| DEFAULT, |
There was a problem hiding this comment.
I decided to go with DEFAULT. Not sure if this is the best choice, let me know what you think.
There was a problem hiding this comment.
NEARBY sounds good.
There was a problem hiding this comment.
yes, please rename. Nearby or area seem better.
| * </p> | ||
| * <ul> | ||
| * <li> | ||
| * Property {@code commentFormat} - Specify comment pattern to trigger filter to begin suppression. |
There was a problem hiding this comment.
The description of this property is the same as the next one. I think we can maybe mention it is tied to influenceFormat or something like that?
There was a problem hiding this comment.
it is better to make it different, otherwise it seems like a copy-paste and not clear for user
| private static final String DEFAULT_INFLUENCE_FORMAT = "0"; | ||
|
|
||
| /** Specify comment pattern to trigger filter to begin suppression. */ | ||
| private Pattern commentFormat = Pattern.compile(DEFAULT_COMMENT_FORMAT); |
There was a problem hiding this comment.
I was thinking naming this defaultCommentFormat since in the enum down below I chose DEFAULT, but this sounds misleading to me.
There was a problem hiding this comment.
I think it is better to avoid default. Nearby or area seem better to me.
| * </p> | ||
| * <ul> | ||
| * <li> | ||
| * Property {@code commentFormat} - Specify comment pattern to trigger filter to begin suppression. |
There was a problem hiding this comment.
it is better to make it different, otherwise it seems like a copy-paste and not clear for user
| * Property {@code influenceFormat} - Specify negative/zero/positive value that | ||
| * defines the number of lines preceding/at/following the suppression comment. | ||
| * Type is {@code java.lang.String}. | ||
| * Default value is {@code "0"}. |
There was a problem hiding this comment.
please add config + code examples for this property
There was a problem hiding this comment.
Done! All the points that have thumbs up are done and committed. Only on 2 I have left comment that are not done yet.
| private static final String DEFAULT_INFLUENCE_FORMAT = "0"; | ||
|
|
||
| /** Specify comment pattern to trigger filter to begin suppression. */ | ||
| private Pattern commentFormat = Pattern.compile(DEFAULT_COMMENT_FORMAT); |
There was a problem hiding this comment.
I think it is better to avoid default. Nearby or area seem better to me.
| suppression = new Suppression(offCommentMatcher.group(0), | ||
| lineNo + 1, offCommentMatcher.start(), SuppressionType.OFF, this); | ||
| } | ||
| if (commentMatcher.find()) { |
There was a problem hiding this comment.
commentMatcher and onCommentMatcher look confusing, please rename it. Also, from code it looks like there can be a case when suppression from one comment is overwritten by other. Is there some test case for it?
There was a problem hiding this comment.
No, no test case for that yet. I think I should tweak it so that there is no overwrite. Do you think this should be the expected behavior?
| /** Off suppression type. */ | ||
| OFF, | ||
| /** Default suppression type. */ | ||
| DEFAULT, |
There was a problem hiding this comment.
yes, please rename. Nearby or area seem better.
| else { | ||
| firstLine = lineNo + influence; | ||
| lastLine = lineNo; | ||
| } |
There was a problem hiding this comment.
what about
firstLine = Math.min(lineNo, lineNo + influence);
lastLine = Math.max(lineNo, lineNo + influence);
| */ | ||
| private Pattern getFilterCommentFormat(SuppressWithPlainTextCommentFilter filter) { | ||
| final Pattern filterCommentFormat; | ||
| if (suppressionType == SuppressionType.ON) { |
| * | ||
| * @param format influence format to parse | ||
| * @param influenceFormat raw influence format | ||
| * @param text text of the suppression |
There was a problem hiding this comment.
please remove indentation for description here and above
| if (suppressionType == SuppressionType.DEFAULT) { | ||
| isInScope = eventLine >= firstLine && eventLine <= lastLine; | ||
| } | ||
| return isInScope; |
There was a problem hiding this comment.
may be just use ternary operator and make it
return suppressionType == SuppressionType.DEFAULT
? eventLine >= firstLine && eventLine <= lastLine
: lineNo <= eventLine;
There was a problem hiding this comment.
Checkstyle does not allow inline conditionals.
|
Github, generate site |
From issue. Please create PR to that project. You can use Snapshot version in their pom. Can we we start to use this feature for google-checks.xml ? And may be other files checkstyle/config/suppressions.xml Line 8 in 04cc6c5 So we can avoid suppression by line number, that cause us a lot of pain. |
|
The more I look at this the more I become confident that we need for this functional new filter, as current filter is about suppression from-to comment. Existing fields first fine for existing design, but not really for new fields. But we are talking about "around" comment. Do you have the same filling ? |
Do you mean a completely new filter or just change SuppressWithNearbyCommentCheck's parent to
Kind of, it didn't require much tweaking to make it work in this case. Mostly copying behavior from
but both have similar purpose. I get what you mean though, same thought crossed my mind - it feels like this check is doing too much now.
Should I still do it or shall we first discuss what to do with your proposal?
I think yes, absolutely. Suppressions can be done inline. |
|
completely new filter.
Let's finish discussion on design.
Please do now, to prove that it is good.
Let's think of user experience, not our efforts. @strkkk , what is your thoughts on this? |
|
I completely agree with your statements here. Added a second commit just to show that the new functionality works. |
|
@stoyanK7 , if you and me think that new Filter will be more logical and has better design, lets create new issue to describe new Filter and convert this PR to use new filter, I pretty sure we will reuse bunch of code(in some form) from other filters , so it will not be very time consuming. |
|
On it. Raising the issue now. |
Resolves #7064
Changes
influenceFormatproperty along withcommentFormatSuppressWithNearbyCommentFilter's examples might be better. In the end it's the same prop doing the exact same thing. No need to repeat it. Let me know what you think.Diff Regression config: https://gist.githubusercontent.com/stoyanK7/0d95fd3ec8caa5cae9eb597ac8c78b8d/raw/c60fcc04f28f853f530efeceb598e6b5173d4855/config.xml