-
Notifications
You must be signed in to change notification settings - Fork 186
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
Fixed ExplicitResultTypes for implicit members when memberKind and visibility configs are present #1627
Fixed ExplicitResultTypes for implicit members when memberKind and visibility configs are present #1627
Conversation
scalafix-rules/src/main/scala/scalafix/internal/rule/ExplicitResultTypes.scala
Outdated
Show resolved
Hide resolved
@@ -15,7 +15,7 @@ object ExplicitResultTypesBase { | |||
private val g = 1 | |||
private def h(a: Int) = "" | |||
private var i = 22 | |||
private implicit var j: Int = 1 | |||
private implicit var j = 1 |
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.
here the rule should not run, as per the config provided in the input file:
/*
rules = ExplicitResultTypes
ExplicitResultTypes.memberKind = [Val, Def, Var]
ExplicitResultTypes.memberVisibility = [Public, Protected]
*/
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.
Well done! Can you rebase against master to fix the conflict introduced by #1623 ? Thanks!
scalafix-rules/src/main/scala/scalafix/internal/rule/ExplicitResultTypes.scala
Outdated
Show resolved
Hide resolved
ab97dd2
to
574dbdf
Compare
def matchesMemberKindAndVisibility: Boolean = | ||
matchesMemberKind && matchesMemberVisibility | ||
|
||
def evaluateWhenNotImplicitOrFinalLiteralVal: Boolean = { |
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.
if you have a better name for this block let me know, I couldn't find a better one not based on the first isImplicitAndNotFinalLiteralVal
block
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 get the OrFinalLiteralVal
part here - isn't the return value of this function independant of whether it is a final val literal or not?
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 name doesn't reflect what the method does (or the content of the method) but reflects which branch of the logical expression of isRuleCandidate is executed, in relation with the first block in OR. This makes the logical expression more readable but the method itself less readable..it's a trade off and I think it's better if the logical expression is more readable, that's why we extracted the method in the first place
Running
|
scalafix/scalafix-tests/unit/src/test/scala/scalafix/tests/interfaces/ScalafixSuite.scala Lines 16 to 22 in c5633c6
|
!matchesSimpleDefinition() && | ||
matchesMemberKind() && | ||
matchesMemberVisibility() | ||
!matchesSimpleDefinition() |
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.
Not a review comment about this PR, but shouldn't this check be extracted and chained with AND just like matchesMemberKindAndVisibility
for both implicit and non-implicit decalaration, so that config.skipSimpleDefinitions
is honored everywhere? Maybe worth tracking this in a separate ticket for visbility if confirmed.
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.
will create a ticket for this
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.
Here is the ticket: #1628
def matchesMemberKindAndVisibility: Boolean = | ||
matchesMemberKind && matchesMemberVisibility | ||
|
||
def evaluateWhenNotImplicitOrFinalLiteralVal: Boolean = { |
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 get the OrFinalLiteralVal
part here - isn't the return value of this function independant of whether it is a final val literal or not?
scalafix-rules/src/main/scala/scalafix/internal/rule/ExplicitResultTypes.scala
Outdated
Show resolved
Hide resolved
@@ -173,13 +173,21 @@ final class ExplicitResultTypes( | |||
def hasParentWihTemplate: Boolean = | |||
defn.parent.exists(_.is[Template]) | |||
|
|||
isImplicit && !isFinalLiteralVal || { | |||
def isImplicitAndNotFinalLiteralVal: Boolean = | |||
isImplicit && !isFinalLiteralVal |
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.
Not a review comment about this PR, but that isFinalLiteralVal
is a bit mysterious to me - it was added in 162db39, but I can't easily see what scenario it covers.
6e362b2
to
8d12093
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.
Thanks & congrats for this first PR of the many to come!
8d12093
to
fd57526
Compare
Fixes #1216
Tests ran after changes:
unit2_13Target2_13/testOnly
: OKunit2_12Target2_12/testOnly
: OKunit2_11Target2_11/testOnly