-
Notifications
You must be signed in to change notification settings - Fork 746
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
ClassCanBeStatic: Exclude JUnit @Nested
classes
#3654
ClassCanBeStatic: Exclude JUnit @Nested
classes
#3654
Conversation
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 error-prone/annotations/src/main/java/com/google/errorprone/annotations/Keep.java Lines 30 to 31 in bb9ede9
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
@Nested
annotation from theClassCanBeStatic
check. JUnit requires them to not bestatic
.From the JUnit docs:
Fixes #956.