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

Non idempotent formatting #192

Closed
olafurpg opened this issue Apr 19, 2016 · 2 comments
Closed

Non idempotent formatting #192

olafurpg opened this issue Apr 19, 2016 · 2 comments
Labels
Milestone

Comments

@olafurpg
Copy link
Member

See

 -  def log(formatToken: FormatToken): String = s"""${log(formatToken.left)}
 -                                                 |${log(formatToken.between:_*)}
 -                                                 |${log(formatToken.right)}""".stripMargin
 +  def log(formatToken: FormatToken): String =
 +    s"""${log(formatToken.left)}
 +       |${log(
 +           formatToken.between: _*)}
 +       |${log(formatToken.right)}""".stripMargin

Reformatting again produces:

  def log(formatToken: FormatToken): String =
    s"""${log(formatToken.left)}
       |${log(formatToken.between: _*)}
       |${log(formatToken.right)}""".stripMargin

in commit olafurpg@779c1ee?diff=unified#diff-b276550f97eeb5bceb770dc3d64811ceL19

@olafurpg olafurpg added the bug label Apr 19, 2016
@olafurpg olafurpg added this to the 0.2.3 milestone Apr 19, 2016
@paulp
Copy link

paulp commented Apr 29, 2016

Here's a non-idempotent situation not involving an interpolated string.

class A {
  def traced(in: A => Unit, out: B => Unit): Fun[A, B] = ( f
    .   mapIn[A] { x => in(x) ; x }
    .  mapOut[B] { x => out(x) ; x }
  )
}

becomes

class A {
  def traced(in: A => Unit, out: B => Unit): Fun[A, B] = (f
    .mapIn[A] { x =>
      in(x); x
    }
    .mapOut[B] { x =>
      out(x); x
    })
}

which becomes

class A {
  def traced(in: A => Unit, out: B => Unit): Fun[A, B] =
    (f.mapIn[A] { x =>
        in(x); x
      }
      .mapOut[B] { x =>
        out(x); x
      })
}

Also, it was a lot better before anything happened to it.

And in the "watch out for the future" department, those leading dots are only necessary through 2.10. In 2.11 and beyond that can be written

  def traced(in: A => Unit, out: B => Unit): Fun[A, B] = ( f
      mapIn[A] { x => in(x) ; x }
     mapOut[B] { x => out(x) ; x }
  )

I think dotless syntax is far superior for readability but I doubt most people can handle it unless their formatter does all the handling of it, hint hint.

@olafurpg
Copy link
Member Author

Thanks for the example!

I think dotless syntax is far superior for readability but I doubt most people can handle it unless their formatter does all the handling of it, hint hint.

Some auto migration tool would be nice, indeed. I'm not sure about baking it with scalafmt, I think it better belongs to another tool like scala-tidy, similar to clang-tidy.

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

No branches or pull requests

2 participants