-
Notifications
You must be signed in to change notification settings - Fork 182
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
RedundantSyntax removes unnecessary string interpolator #1602
RedundantSyntax removes unnecessary string interpolator #1602
Conversation
59ef8ea
to
c805905
Compare
acfed20
to
cc35111
Compare
"""foo | ||
|bar""" | ||
b = s"""foo $a bar""" | ||
b = s"""$a""" |
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 a
is a String
b = s"""$a""" | |
b = a |
but i guess it's not doable with a syntactic rule
scalafix-tests/output/src/main/scala/test/redundantSyntax/StringInterpolator.scala
Outdated
Show resolved
Hide resolved
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 for putting this together!
Interestingly, like any generic syntactic rule, this could live in scalafmt, but it seems that it was never requested...
A good use-case for this rule would be to fail (and not rewrite) after writing by accident println(s"variable: {variable})"
. Unfortunately, it's not possible to configure scalafixOnCompile
to --check
rather than rewrite (early feedback would be the best in that case). #1375 could be extended to support this I guess, so if the need comes we can do it at the framework level rather than the rule one (adding an adhoc lint
boolean would be cumbersome) anyway.
scalafix-tests/output/src/main/scala/test/redundantSyntax/StringInterpolator.scala
Outdated
Show resolved
Hide resolved
scalafix-tests/input/src/main/scala/test/redundantSyntax/StringInterpolator.scala
Show resolved
Hide resolved
finalObject: Boolean = true | ||
finalObject: Boolean = true, | ||
@Description("Remove unnecessary string interpolator") | ||
stringInterpolator: Boolean = true |
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 was wondering if we could make this more extensible:
stringInterpolator: Boolean = true | |
stringInterpolators: Seq[String] = Seq("s", "f", "raw") |
But considering raw
has a special case and all the custom interpolators I have used wouldn't be eligible for such rewrites, it's probably useless.
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 thought about that too... but i came to the same conclusion
cc35111
to
b2d7256
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.
LGTM 👍
Not merging right away to avoid updating the docs too much ahead of next release
Idea from gitter: