Skip to content
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

Update AbstractChecks to log DetailAST (part3) #5777

Closed
MEZk opened this issue May 6, 2018 · 10 comments
Closed

Update AbstractChecks to log DetailAST (part3) #5777

MEZk opened this issue May 6, 2018 · 10 comments
Labels
approved easy has bounty issue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issues miscellaneous
Milestone

Comments

@MEZk
Copy link
Contributor

MEZk commented May 6, 2018

Checkstyle has recently started to update old checks from logging on the line/column, to log on the AST node. This is needed to support https://checkstyle.org/config_filters.html#SuppressionXpathFilter which needs the AST of the violation to match it to the user supplied XPath.

As PR is started for each check, links from master ( Ex: https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/EmptyBlockCheck.java#L201 ) must be posted to show each log call found in the check. An additional note must be made of the number of logs actually modified. This will greatly help admins ensure the full check is now xpath compliant and nothing is missed.

All checks need to be reviewed to ensure:

  1. All their calls to log pass the AST and not the line/column
  2. Each log have a respective IT test to show that it supports xpath at https://github.com/checkstyle/checkstyle/tree/master/src/it/java/org/checkstyle/suppressionxpathfilter
  3. Documentation of https://checkstyle.org/config_filters.html#SuppressionXpathFilter_Description shows the check is now supported.
  4. Since this is modifying the functionality of a check, regression will be required for the PR. See https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#checkstyle-tester

1: We don't expect drastic change in current UTs when making the switch. If any items change the line/column drastically, please point them out to be clear to admins in the PR. Adding a column number when no was there before is ok and an expected change.
2: Must have a UT for each log in the check. If the check has 3 separate log calls, then it must have 3 separate UTs.
4: In report for each project, Number of unique base messages reported below and Number of unique path messages reported below should match otherwise it is saying there is an uneven amount of changes, either new violations or violations removed. We aren't expecting this type of change in these PRs unless you can account for it. One example where it would be acceptable is if duplicate violations on the same line were being dropped as we only report 1 violation per line/column/message/check.


@romani
Copy link
Member

romani commented May 8, 2018

Just use first or more related AST and report violation on it.
Message need be rechecked and could be updated to be reasonable. We will see what to do in each particular case.

There are about 135 usages of this method in our code:
image

Most of them just need to be converted from log(aAst.getLineNo,... to log(aAst,... .

The only Checks that should stay reporting by line number is FilesetChecks (non Treewalker's Checks):
image

@rnveach
Copy link
Member

rnveach commented May 17, 2018

How do we want to report handling a violation on a comment's specific line number?
Example: https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck.java#L102

There is no AST inside the comment for a specific line. The AST will point to the start of the comment and the TODO could be 3 lines after that. Do we still want to print a violation on the AST?


Also how do we want to handle checks that don't even use the AST? I made an issue before that they should be changed to FileSet checks, but that was denied.
Example: https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java#L280

@rnveach
Copy link
Member

rnveach commented May 17, 2018

28 checks fit into the easy category where we just do log(ast.getLineNo(), MSG_....

@romani
Copy link
Member

romani commented May 17, 2018

How do we want to report handling a violation on a comment's specific line number?

I do not know for now. It is better to postpone comment related Checks to most end of this project.

Do we still want to print a violation on the AST?

I would not doing this for now. Violation on AST will help extensions to do autofixes. Comment related violation is still unclear area. Let's postpone such Checks.

Also how do we want to handle checks that don't even use the AST? I

No AST no Xpath. They should continue to use any other way of suppression.

@rnveach
Copy link
Member

rnveach commented May 17, 2018

No AST no Xpath. They should continue to use any other way of suppression.

We can't reconsider changing to a FileSet? We broke configurations when we did the same for Filters.

@romani
Copy link
Member

romani commented May 17, 2018

I made an issue before that they should be changed to FileSet checks, but that was denied.

do you remember in what issue I rejected such proposal? We need to think about this one more time.
In most worse scenario we can take first token on this line and report violation by it.
damaging(braking compatibility) on users config is most unwanted scenario at least for now.

So we can update such Check to report violation on first AST in this line now ..... and in separate issue discuss reasons of Check to be under Treewalker.

@rnveach
Copy link
Member

rnveach commented May 17, 2018

do you remember in what issue I rejected such proposal?

#2116 . Different check then mentioned here, but still same issue.

@romani
Copy link
Member

romani commented May 17, 2018

conversion to FileSet is kind of reasonable but should be done with special attention and separately from Xpath project.

rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 4, 2018
rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 4, 2018
rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 4, 2018
rnveach added a commit to rnveach/checkstyle that referenced this issue Nov 10, 2018
@rnveach
Copy link
Member

rnveach commented Nov 10, 2018

PR #6199 is abandoned but anyone can take the code and finish it. Latest commit was rnveach@128bd56 .

What still needs to be done is we need a bunch of regression tests to show that xpath suppression works before we merge these changes. These tests will be located at https://github.com/checkstyle/checkstyle/tree/master/src/it/java/org/checkstyle/suppressionxpathfilter. This is similar to Issue #6207 but we need regression for the checks specifically modified in this issue.

This was referenced Mar 1, 2020
@rnveach
Copy link
Member

rnveach commented Mar 1, 2020

This issue is being closed as it was split into its children

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved easy has bounty issue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issues miscellaneous
Projects
No open projects
Development

No branches or pull requests

3 participants