-
Notifications
You must be signed in to change notification settings - Fork 688
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
SONARJAVA-5041 S5786 should raise an issue on JUnit5 annotated lifecycle methods with a public modifier #5004
base: master
Are you sure you want to change the base?
Conversation
4b6c339
to
b904577
Compare
…cle methods with a public modifier
b904577
to
f36240a
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good overall but it looks like we don't have examples of issues raised on classes by S5786 with the new logic. It probably would help if we could get some documentation on the modifier scope enums to understand their usage
@@ -517,6 +535,9 @@ | |||
522 | |||
], | |||
"org.eclipse.jetty:jetty-project:jetty-io/src/test/java/org/eclipse/jetty/io/SslEngineBehaviorTest.java": [ | |||
39, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 39 matches the class declaration. Are changes to the rules supposed to change our behavior on classes in addition to methods?
@@ -676,6 +712,9 @@ | |||
634 | |||
], | |||
"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/ErrorHandlerTest.java": [ | |||
54, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was fun to review 😅
.addTextEdit(JavaTextEdit.removeTree(modifier)) | ||
.build()) | ||
JavaQuickFix.newQuickFix("Remove \"%s\" modifier", modifier.keyword().text()) | ||
.addTextEdit(JavaTextEdit.removeTextSpan(AnalyzerMessage.textSpanBetween(modifier, true, QuickFixHelper.nextToken(modifier), false))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to change the way that we generate the quickfix?
|
||
raiseIssueOnMethods(junit5ClassMethods, ModifierScope.CLASS_METHOD); | ||
raiseIssueOnMethods(junit5InstanceMethods, ModifierScope.INSTANCE_METHOD); | ||
if (!junit5InstanceMethods.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract this for readability?
if (!junit5InstanceMethods.isEmpty()) { | |
boolean classHasJunit5InstanceMethods = !junit5InstanceMethods.isEmpty(); | |
if (classHasJunit5InstanceMethods) { |
if (!testMethods.isEmpty()) { | ||
raiseIssueOnNotCompliantModifiers(classTree.modifiers(), false); | ||
// Can we change the visibility of the class? | ||
if (!hasPublicStaticMethods && !hasPublicStaticFields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I like seeing doubling down on negatives here
public enum ModifierScope { | ||
CLASS, | ||
CLASS_METHOD, | ||
INSTANCE_METHOD | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be very helpful to document how these enums represent and how they can be used
SONARJAVA-5041