ClassCanBeStatic: Exclude JUnit @Nested classes#3654
ClassCanBeStatic: Exclude JUnit @Nested classes#3654ljrmorgan wants to merge 2 commits intogoogle:masterfrom
@Nested classes#3654Conversation
|
Nice one. In our code base I find quite a number of these: @Nested
@SuppressWarnings("ClassCanBeStatic" /* @Nested classes cannot be static. */) |
|
Thanks, LGTM overall. We've been starting to consolidate more of the heuristics for situations where Error Prone shouldn't change modifiers etc. by using What do you think about using error-prone/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java Lines 1043 to 1044 in bb9ede9 |
From the [JUnit docs](https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested): > Only non-static nested classes (i.e. inner classes) can serve as `@Nested` test classes.
Replace the check for the `@Nested` annotation with a check for `@Keep`, and consider `@Nested` to be `@Keep`-annotated.
c13015f to
3a5bd67
Compare
|
@cushon thank you for taking a look at the PR, and for the suggestion! I think that makes sense - the JavaDoc for I've pushed that change as a separate commit, I'm happy to squash the two commits into one if you'd prefer, just let me know. Thanks! |
|
Hi @cushon, I wondered if you'd had a chance to take a look at the latest changes? Thanks! |
Exclude inner classes annotated with JUnit's `@Nested` annotation from the `ClassCanBeStatic` check. JUnit requires them to not be `static`. From the [JUnit docs](https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested): > Only non-static nested classes (i.e. inner classes) can serve as `@Nested` test classes. Fixes #956. Fixes #3654 FUTURE_COPYBARA_INTEGRATE_REVIEW=#3654 from ljrmorgan:junit_nested_test_classes_cannot_be_static 3a5bd67 PiperOrigin-RevId: 503544057
Exclude inner classes annotated with JUnit's
@Nestedannotation from theClassCanBeStaticcheck. JUnit requires them to not bestatic.From the JUnit docs:
Fixes #956.