Skip to content

Issue #7064: Add influenceFormat property to SuppressWithPlainTextCommentFilter#11884

Closed
stoyanK7 wants to merge 2 commits into
checkstyle:masterfrom
stoyanK7:issue/7064-add-influenceFormat-prop-to-SuppressWithPlainTextCommentFilter
Closed

Issue #7064: Add influenceFormat property to SuppressWithPlainTextCommentFilter#11884
stoyanK7 wants to merge 2 commits into
checkstyle:masterfrom
stoyanK7:issue/7064-add-influenceFormat-prop-to-SuppressWithPlainTextCommentFilter

Conversation

@stoyanK7

Copy link
Copy Markdown
Collaborator

Resolves #7064

Changes

  • Adds influenceFormat property along with commentFormat
  • Adds 3 tests to cover new property
  • Updates all other tests with a lot more examples covering the new change
  • Updates all other tests' inline configurations to include the new property
  • Updates documentation about the new property(I will provide screenshots of the website once the problem below is discussed)
    • Examples of how this prop is used in javadoc and site are not added. I didn't add them yet because I think adding a reference to SuppressWithNearbyCommentFilter'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

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

Github, generate report

else {
commentFormat = filter.offCommentFormat;
}
final Pattern filterCommentFormat = getFilterCommentFormat(filter);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This method extraction is needed due to NCSS line count violation.

/** Off suppression type. */
OFF,
/** Default suppression type. */
DEFAULT,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I decided to go with DEFAULT. Not sure if this is the best choice, let me know what you think.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

NEARBY sounds good.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, please rename. Nearby or area seem better.

* </p>
* <ul>
* <li>
* Property {@code commentFormat} - Specify comment pattern to trigger filter to begin suppression.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

@stoyanK7 stoyanK7 Jul 10, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking naming this defaultCommentFormat since in the enum down below I chose DEFAULT, but this sounds misleading to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is better to avoid default. Nearby or area seem better to me.

@github-actions

Copy link
Copy Markdown
Contributor

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

@romani @strkkk @rnveach ping

* </p>
* <ul>
* <li>
* Property {@code commentFormat} - Specify comment pattern to trigger filter to begin suppression.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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"}.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add config + code examples for this property

@stoyanK7 stoyanK7 Jul 17, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, please rename. Nearby or area seem better.

else {
firstLine = lineNo + influence;
lastLine = lineNo;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use switch

*
* @param format influence format to parse
* @param influenceFormat raw influence format
* @param text text of the suppression

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please remove indentation for description here and above

if (suppressionType == SuppressionType.DEFAULT) {
isInScope = eventLine >= firstLine && eventLine <= lastLine;
}
return isInScope;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

may be just use ternary operator and make it

return suppressionType == SuppressionType.DEFAULT
  ? eventLine >= firstLine && eventLine <= lastLine
  : lineNo <= eventLine;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Checkstyle does not allow inline conditionals.

@strkkk strkkk self-assigned this Jul 16, 2022
@stoyanK7

Copy link
Copy Markdown
Collaborator Author

Github, generate site

@github-actions

Copy link
Copy Markdown
Contributor

@romani

romani commented Jul 17, 2022

Copy link
Copy Markdown
Member

as proof of implementation we need to restore code/comments of suppression at equalsverifier.

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

<!-- can't split long messages between lines -->

So we can avoid suppression by line number, that cause us a lot of pain.

@romani

romani commented Jul 17, 2022

Copy link
Copy Markdown
Member

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 ?

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

The more I look at this the more I become confident that we need for this functional new filter,

Do you mean a completely new filter or just change SuppressWithNearbyCommentCheck's parent to Checker?


Existing fields first fine for existing design, but not really for new fields.
Do you have the same filling ?

Kind of, it didn't require much tweaking to make it work in this case. Mostly copying behavior from SuppressWithNearbyCommentFilter.

  • SuppressWithNearbyCommentFilter uses internal class Tag
  • SuppressWithPlainTextCommentFilter uses internal class Suppression

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.


From issue. Please create PR to that project. You can use Snapshot version in their pom.

Should I still do it or shall we first discuss what to do with your proposal?


Can we we start to use this feature for google-checks.xml ? And may be other files

I think yes, absolutely. Suppressions can be done inline.

@romani

romani commented Jul 19, 2022

Copy link
Copy Markdown
Member

completely new filter.
Users do not care about filter name, they want easy to configure. Module with numerous properties blow mind of users.

Should I still do it or shall we first discuss what to do with your proposal?

Let's finish discussion on design.

Suppressions can be done inline.

Please do now, to prove that it is good.

Kind of, it didn't require much tweaking

Let's think of user experience, not our efforts.


@strkkk , what is your thoughts on this?

@stoyanK7

stoyanK7 commented Jul 19, 2022

Copy link
Copy Markdown
Collaborator Author

I completely agree with your statements here.

Added a second commit just to show that the new functionality works.

@romani

romani commented Jul 20, 2022

Copy link
Copy Markdown
Member

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

@stoyanK7

Copy link
Copy Markdown
Collaborator Author

On it. Raising the issue now.

@strkkk

strkkk commented Jul 21, 2022

Copy link
Copy Markdown
Member

@strkkk , what is your thoughts on this?

new filter seems fine.

@stoyanK7 I think this PR along with the issue can be closed as work will continue in new issues/PR

@stoyanK7 stoyanK7 closed this Jul 21, 2022
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.

SuppressWithPlainTextCommentFilter should has influenceFormat property

3 participants