scalameta / scalafmt

Code formatter for Scala
http://scalameta.org/scalafmt
Apache License 2.0
1.44k stars 276 forks source link

Align regression for sbt files (`:=` in a Seq) #1288

Closed ArturGajowy closed 6 years ago

ArturGajowy commented 6 years ago

Steps

Given code like this:

  lazy val bnfcSettings = {
    inConfig(BNFCConfig)(
      Defaults.configSettings ++ Seq(
        javaSource     := (javaSource in Compile).value,
        scalaSource    := (javaSource in Compile).value,
        bnfcNamespace  := "coop.rchain.rholang.syntax",
        bnfcGrammarDir := baseDirectory.value / "src" / "main" / "bnfc",
        bnfcOutputDir  := (javaSource in Compile).value,
        bnfcDocDir     := baseDirectory.value / "doc" / "bnfc",
        clean          := cleanDir(bnfcOutputDir.value / nsToPath(bnfcNamespace.value)),
        generate       := {
          val fullCP = (fullClasspath in BNFCConfig).value
          bnfcFiles(bnfcGrammarDir.value).foreach { (f: File) =>
            bnfcGenerateSources(fullCP, f, bnfcOutputDir.value, bnfcNamespace.value)
          }
        },
        cleanDocs      := cleanDir(bnfcDocDir.value),
        generateDocs   := bnfcFiles(bnfcGrammarDir.value).foreach { (f: File) =>
          bnfcGenerateLaTeX(f, bnfcDocDir.value)
        }
      )
    )
  }

When I run scalafmt like this:

sbt scalafmtSbt

Problem

Scalafmt formats code like this:

  lazy val bnfcSettings = {
    inConfig(BNFCConfig)(
      Defaults.configSettings ++ Seq(
        javaSource := (javaSource in Compile).value,
        scalaSource := (javaSource in Compile).value,
        bnfcNamespace := "coop.rchain.rholang.syntax",
        bnfcGrammarDir := baseDirectory.value / "src" / "main" / "bnfc",
        bnfcOutputDir := (javaSource in Compile).value,
        bnfcDocDir := baseDirectory.value / "doc" / "bnfc",
        clean := cleanDir(bnfcOutputDir.value / nsToPath(bnfcNamespace.value)),
        generate := {
          val fullCP = (fullClasspath in BNFCConfig).value
          bnfcFiles(bnfcGrammarDir.value).foreach { (f: File) =>
            bnfcGenerateSources(fullCP, f, bnfcOutputDir.value, bnfcNamespace.value)
          }
        },
        cleanDocs := cleanDir(bnfcDocDir.value),
        generateDocs := bnfcFiles(bnfcGrammarDir.value).foreach { (f: File) =>
          bnfcGenerateLaTeX(f, bnfcDocDir.value)
        }
      )
    )
  }

Expectation

I would like the formatted output to look like the "given" code above.

Workaround

I tried extracting the Seq on a separate variable, same results. Format:off is my only hope.

Notes

See also https://github.com/rchain/rchain/pull/1549/files

ArturGajowy commented 6 years ago

As in #1289 - TBH I'm not sure if that's a regression - those files haven't been formatted for a while. My expectations about how that should be formatted are as above though :)

olafurpg commented 6 years ago

Thanks for reporting! Related https://github.com/scalameta/scalafmt/issues/1289#issuecomment-424231110

Please reopen if you would like to take a stab at this. Further improvements to vertical alignment is not on the roadmap unless somebody volunteers to work on it.