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

Scalafmt is not idempotent #3090

Closed
github-julien-pie opened this issue Jan 31, 2022 · 0 comments · Fixed by #3095
Closed

Scalafmt is not idempotent #3090

github-julien-pie opened this issue Jan 31, 2022 · 0 comments · Fixed by #3095

Comments

@github-julien-pie
Copy link

Hey there 👋

First of all, thanks for your work, scalafmt is great tool ❤️

I've just discovered a case where scalafmt is not idempotent:

  • Version: 3.4.0
  • Integration: CLI
  • Configuration:
version = 3.4.0

runner.dialect = scala213
preset = defaultWithAlign
maxColumn = 100
importSelectors = singleLine
assumeStandardLibraryStripMargin = true
rewrite.rules = [RedundantBraces, RedundantParens]
rewrite.redundantBraces.stringInterpolation = true
project.git = true
optIn.breaksInsideChains = true
lineEndings = preserve
trailingCommas = preserve
newlines.implicitParamListModifierPrefer = before

Steps

Given code like this:

class Test {
  val test = foo.bar.baz
    .map(thisvariablenameisreallylong =>
      fr"""UPDATE mytable
          |SET
          | column = $thisvariablenameisreallylong
          |WHERE column2 = ${foo.bar}""".stripMargin.update.run
    ).getOrElse {
      ().pure[ConnectionIO]
    }
}

When I run scalafmt like this:

scalafmt --debug ./Test.scala

Problem

Scalafmt formats code like this:

class Test {
  val test = foo.bar.baz
    .map(thisvariablenameisreallylong => fr"""UPDATE mytable
                                             |SET
                                             | column = $thisvariablenameisreallylong
                                             |WHERE column2 = ${foo.bar}""".stripMargin.update.run).getOrElse {
      ().pure[ConnectionIO]
    }
}

But when I run scalafmt once again:

scalafmt --debug ./Test.scala

Scalafmt formats code like this:

class Test {
  val test = foo.bar.baz
    .map(thisvariablenameisreallylong =>
      fr"""UPDATE mytable
          |SET
          | column = $thisvariablenameisreallylong
          |WHERE column2 = ${foo.bar}""".stripMargin.update.run
    ).getOrElse {
      ().pure[ConnectionIO]
    }
}

Expectation

Scalafmt should be idempotent. Meaning it could be applied multiple times without changing the result beyond the initial application.

Workaround

I can deactivate the scalafmt using https://scalameta.org/scalafmt/docs/configuration.html#-format-off

Note

I just noticed this issue #339. Maybe there's a fix for my particular case?

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