-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce Slf4jLoggerDeclaration
check
#783
Introduce Slf4jLoggerDeclaration
check
#783
Conversation
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
536811a
to
fc4d717
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
fc4d717
to
3c70f11
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
3c70f11
to
5947396
Compare
Kudos, SonarCloud Quality Gate passed! |
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
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.
Quick skim; hope this helps :)
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public Description matchClass(ClassTree tree, VisitorState state) { | ||
if (tree.getKind() == Kind.INTERFACE || !TEST_CLASS_WITH_LOGGER.matches(tree, state)) { |
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 don't think we need to skip interfaces: for those we can still suggest (but not auto-fix) the canonical field name.
(Separately from that we should drop redundant modifiers, but that should be a separate check, modeled after this Checkstyle rule.)
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 don't think we need to skip interfaces
The intention was to not apply modifiers to inteface variables but still suggest/fix field name.
: for those we can still suggest (but not auto-fix) the canonical field name.
Why only suggest and not auto-fix ?
(Separately from that we should drop redundant modifiers, but that should be a separate check, modeled after this Checkstyle rule.)
Should this check be part of this PR ?
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
@Override | ||
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { | ||
if (!GET_LOGGER_METHOD.matches(tree, state)) { |
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.
We're now creating separate fixes for the field declaration (modifiers + name) and for the referenced class. I wonder whether this means that we should have two separate checks. I can imagine that some users will appreciate the second, while finding the first too conservative.
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.
Pushed a change using TreeScanner (Conceptually still two checks usingvisitClass
& visitMethodInvocationTree
).
What do you think about making the separation into an EP flag ?
...-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
if (LOGGER.matches(member, state)) { | ||
VariableTree variable = (VariableTree) member; | ||
SuggestedFixes.addModifiers( | ||
member, state, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL) |
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.
Making the field final
or private
could make the code fail to compile. Likely this is still the right trade-off, but perhaps something worth calling out.
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.
Does it make sense to make the suggested modifiers EP flags instead ?
5947396
to
61626b7
Compare
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
Kudos, SonarCloud Quality Gate passed! |
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
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.
Some comments we discussed offline :).
...-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java
Outdated
Show resolved
Hide resolved
4142606
to
a54db09
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.
Sorry for the slow progress 🐢
...-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.java
Outdated
Show resolved
Hide resolved
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
1 similar comment
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
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.
Nice improvements!!
ebfe327
to
b7621f2
Compare
Quality Gate passedIssues Measures |
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed. |
#632
Suggested commit message: