Skip to content
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

Parenthesize lambda parameters with type annotations #3182

Merged
merged 1 commit into from
Dec 2, 2019

Conversation

travisbrown
Copy link
Contributor

@travisbrown travisbrown commented Dec 2, 2019

Dotty warns on these and Scala 2 doesn't care, so it seems like we might as well change them now. I personally agree with Dotty and think they look better with the parentheses, anyway.

Dotty says it'll rewrite these with -rewrite but I couldn't get it to work so I just used a quick custom Scalafix rule:

import scalafix.v1.{Patch, SyntacticDocument, SyntacticRule}
import scala.meta.{Term, Token}

class TypedLambdaParamRewrite extends SyntacticRule("TypedLambdaParamRewrite") {
  override def fix(implicit doc: SyntacticDocument): Patch = Patch.fromIterable(
    doc.tree.collect {
      case Term.Function(List(param @ Term.Param(_, _, Some(_), None)), _) =>
        param.tokens.headOption match {
          case Some(Token.LeftParen()) => Patch.empty
          case _ => Patch.replaceTree(param, s"($param)")
        }
    }
  )
}

@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

Merging #3182 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3182   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files         376      376           
  Lines        7381     7381           
  Branches      195      201    +6     
=======================================
  Hits         6864     6864           
  Misses        517      517
Flag Coverage Δ
#scala_version_212 93.31% <100%> (-0.02%) ⬇️
#scala_version_213 90.59% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
core/src/main/scala/cats/data/IndexedStateT.scala 90% <ø> (ø) ⬆️
core/src/main/scala/cats/Eval.scala 98.83% <ø> (ø) ⬆️
core/src/main/scala/cats/data/Func.scala 96.42% <100%> (ø) ⬆️
core/src/main/scala/cats/Representable.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/Kleisli.scala 90.82% <100%> (ø) ⬆️
core/src/main/scala/cats/data/ContT.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/Composed.scala 96.87% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00ff6fe...9f0df6e. Read the comment docs.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

Copy link
Contributor

@kailuowang kailuowang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the scalafix code as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants