Skip to content

Conversation

@rickie
Copy link
Contributor

@rickie rickie commented Dec 12, 2023

This PR is based on a suggestion by @romani in: #14129. The idea is to add Error Prone Support to Checkstyle in this PR and after that discuss which checks we want to enable.

I added Error Prone Support as part of the already existing Maven profile that runs Error Prone. The reason for this is that Error Prone Support is an extension and "just adds some checks". Configuration wise, this is the simplest. The only difference the user could notice is that the documentation URL from the Error Prone Support checks are slightly different. See an example below.

Error from an Error Prone check from Google:

Error: /home/runner/work/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocNodeImpl.java:[183,51] [ArrayHashCode] hashcode method on array does not hash array contents
(see https://errorprone.info/bugpattern/ArrayHashCode)

Error from an Error Prone check from Error Prone Support:

Error: /home/runner/work/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java:[257,88] [CollectorMutability] Avoid Collectors.to{List,Map,Set} in favor of collectors that emphasize (im)mutability
(see https://error-prone.picnic.tech/bugpatterns/CollectorMutability)

Checkstyle is configured to only consider checks that have SeverityLevel.ERROR, see here. In Error Prone Support there are 3 checks with error severity. So adding the tool itself requires changes only in the pom.xml.
Now we can simply increase the severity of Error Prone Support checks as follows:

-Xplugin:ErrorProne -Xep:CollectorMutability:ERROR

In the follow up issue (#14137) we can discuss which checks we want to enable. I'm definitely open to creating PRs for that!

@rickie rickie force-pushed the rossendrijver/add_eps branch 2 times, most recently from c75f336 to 3186038 Compare December 12, 2023 20:55
@romani
Copy link
Member

romani commented Dec 13, 2023

Example of error level rule https://error-prone.picnic.tech/bugpatterns/FluxFlatMapUsage/

Please share where -Xplugin:ErrorProne -Xep:CollectorMutability:ERROR will be placed to change default value of severity for this rule/pattern.

Please use in commit message prefix Issue #14137: ....... we keep wide explanations linked to commit to easily restore later on.

As already noticed we use hacky groovy script to put on leash reporting of errorprone. As you very knowledgeable in this tool, do you know better way to get report from tool? We just need print to contributor not all messages but messages that requires to fix.

Is there ability to exclude pattern/rule from execution at all? Or change severity to IGNORE/OFF.
As far as I remember we focused on fixing ERROR only as we did not able to find way to on/off rules or certain violation. To enable all and iteratively and slowly clean up backlog.

Our suppression model: https://github.com/checkstyle/checkstyle/blob/master/config/error-prone-suppressions/compile-phase-suppressions.xml

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Ok to merge.
Next PRs will be more interesting.

@romani
Copy link
Member

romani commented Dec 13, 2023

@Vyom-Yadav , please read this as you were involved in error prone activation in our project

@rnveach
Copy link
Contributor

rnveach commented Dec 13, 2023

@rickie
Copy link
Contributor Author

rickie commented Dec 13, 2023

Thanks for all the questions, let me know if something is unclear or I'm missing something.

Please share where -Xplugin:ErrorProne -Xep:CollectorMutability:ERROR will be placed to change default value of severity for this rule/pattern.

After the -Xplugin:ErrorProne we have to add exta configuration (here) if we want to. Now that I'm writing down, I we need to have a place in the pom.xml where we define this property as we will use it in two places, namely in the error-prone-compile and error-prone-test-compile profiles. Do we define a property and use it in both profiles?

W.r.t. how we can best configure the checks, I'd like to propose to use a similar approach to what we have here, which allows us to specifically disable and increase the severity of checks.

As already noticed we use hacky groovy script to put on leash reporting of errorprone. As you very knowledgeable in this tool, do you know better way to get report from tool? We just need print to contributor not all messages but messages that requires to fix.

Currently there is nothing yet that gives us the reports easily. There is a GitHub issue related to this: google/error-prone#3766, that's all...

Is there ability to exclude pattern/rule from execution at all? Or change severity to IGNORE/OFF.

We can use the command-line flags to enable and disable checks, see the docs here.
So we simply disable rules by adding -Xep:NameOfTheCheck:OFF, or use one of their convenience flags like -XepDisableAllWarnings.

As far as I remember we focused on fixing ERROR only as we did not able to find way to on/off rules or certain violation. To enable all and iteratively and slowly clean up backlog.

I tried searching fo a discussion related to this in the old Error Prone activation PR but I couldn't find any. We can iteratively enable all of the rules, I don't see blockers (yet?). If you know what was blocking you from doing this, let me know, I'm curious!

Our suppression model: master/config/error-prone-suppressions/compile-phase-suppressions.xml

Thanks for sharing. Is there a specific reason for not using @SuppressWarnings("ArrayHashCode" /* Explanation why we suppress this check. */) for the suppression?

Oh: I think I found the reason in the old Error Prone PR: #12063 (comment), am I correct?

checkstyle/checkstyle/actions/runs/7187166866/job/19574155042?pr=14136
Log file jumped from 100 kb to 2.5 megs in this PR.

Good point, I noticed a few of our checks are creating quite some output. What we can do is already disable some of the rules like StaticImport, LexicographicalAnnotationListing, and JUnitMethodDeclaration. I suggest we disable them in follow up PRs.

@rickie rickie force-pushed the rossendrijver/add_eps branch from 3186038 to acca2e2 Compare December 13, 2023 07:50
@rickie rickie changed the title dependency: Introduce Error Prone Support Issue #14137: Introduce Error Prone Support Dec 13, 2023
@rickie
Copy link
Contributor Author

rickie commented Dec 14, 2023

Rebased.

FYI: The build is failing because the linked issue is not approved.

@rickie rickie force-pushed the rossendrijver/add_eps branch from acca2e2 to 45b7790 Compare December 14, 2023 06:28
@romani
Copy link
Member

romani commented Dec 17, 2023

Do we define a property and use it in both profiles?

Yes. We can define properties in pom xml, we already have bunch.

propose to use a similar approach to what we have here,

Works for us too.

So we simply disable rules by adding -Xep:NameOfTheCheck:OFF

Yes, this is good for us, as we have rule that if we enforce some rule we do it as build failure, no leaks are allowed.

I don't see blockers (yet?). If you know what was blocking you from doing this, let me know, I'm curious!

No blockers, but we would need your help to make it, we are sinking in PRs, maintainers are overloaded.

Is there a specific reason for not using @SuppressWarnings("ArrayHashCode"

We keep culture of "no pollution in main code for tools". So we keep main code clean and all hacks and unfortunate cases outside, let let readers do not be bothered by extra details. If we put all to code it will have a lot of annotations :). But sometimes we need to suppression on specific line, not whole method.

I suggest we disable them in follow up PRs.

Yes, please. I updated issue with opinion on what should apply and what we should disable.

@romani
Copy link
Member

romani commented Dec 17, 2023

@Vyom-Yadav , fyi

@rickie
Copy link
Contributor Author

rickie commented Dec 18, 2023

Yes. We can define properties in pom xml, we already have bunch.

Nice sounds good, will do that as part of the follow up PRs :).

we would need your help to make it

Sounds good, I'll try to keep it doable and not overload with PRs. After this one is merged I'll open the first one(s).

We keep culture of "no pollution in main code for tools".

Interesting, cool approach! Thanks for explaining.

Yes, please. I updated issue with opinion on what should apply and what we should disable.

Yes perfect. Will start creating them after we merge this PR. Oh and if it goes too fast or too slow after we merge this one, just let me know and we will work it out :).

@rickie rickie force-pushed the rossendrijver/add_eps branch from 45b7790 to e244cf3 Compare December 20, 2023 13:24
@rickie
Copy link
Contributor Author

rickie commented Dec 20, 2023

Rebased and resolved conflict.

Copy link
Contributor

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

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

@rickie thanks a lot for taking this up!

@nrmancuso nrmancuso merged commit a28694c into checkstyle:master Dec 21, 2023
@Vyom-Yadav
Copy link
Member

Sorry, Late to the party, but this is really cool, thanks a lot, @rickie for taking charge here.

Checkstyle is configured to only consider checks that have SeverityLevel.ERROR

Just curious, do you, in your org, consider the warnings as well? Are there any good checks that give out warnings but are good to have as errors? That way we can further improve the quality.

@romani
Copy link
Member

romani commented Jan 3, 2024

We usually apply/enforce all rules, if we do not see some rule doing any good, of it is against our style or .., we just disable it at all.
There should be no violations of any severity.

@rickie
Copy link
Contributor Author

rickie commented Jan 5, 2024

Sorry, Late to the party, but this is really cool, thanks a lot, @rickie for taking charge here.

No problem, I really like doing this @Vyom-Yadav.

Just curious, do you, in your org, consider the warnings as well? Are there any good checks that give out warnings but are good to have as errors? That way we can further improve the quality.

Yes we do! I think we have quite the same approach & goals as Checkstyle. Namely, try to enable as much static analysis as possible. For our Error Prone usage, it means that we use the following command-line flags: -XepAllDisabledChecksAsWarnings and -XepAllSuggestionsAsWarnings (fun fact: the last flag we contributed ourselves to Error Prone). These flags combined enable all checks that Error Prone provides, see the full list of checks here: https://errorprone.info/bugpatterns. After enabling all of them with these flags, we selectively disable a few of the checks.

If you want to see an example, here is our configuration from Error Prone Support: https://github.com/PicnicSupermarket/error-prone-support/blob/master/pom.xml#L1701-L1757.

This is roughly similar to what we have in our internal setup at Picnic.

I'd say after we went through the checks of Error Prone Support as defined in #14137, we can take a look at the checks from Error Prone that are listed under "WARNING" and "INFO" https://errorprone.info/bugpatterns. WDYT?

@romani
Copy link
Member

romani commented Jan 5, 2024

Yes, please, let's try to activate all. It helps a lot to maintenance of project by small team.

@Vyom-Yadav
Copy link
Member

Good suggestion. As we have default ERROR in our script, we can enable all, look at the logs to find some value checks from the warning which we can later change to ERROR severity level.

@rickie rickie deleted the rossendrijver/add_eps branch January 8, 2024 20:19
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.

5 participants