Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalafmt: keep empty lines in a List

I want to keep a single empty line in the List definition using the scalafmt formatter:

List(
  "some-random-string1"
    .trim
    .stripMargin,

  "some-random-string2"
    .intern
    .dropRight(3),

  "some-random-string3"
    .takeRight(4)
    .substring(10)
)

The formatter removes the empty lines and breaks the readability of such code. My .scalafmt.conf configuration:

version = "3.7.3"
runner.dialect = scala3
align.preset = most
newlines.source = keep

I want to find a way to configure the formatter to keep the empty lines.

like image 451
Anton Filimonov Avatar asked Feb 02 '26 21:02

Anton Filimonov


1 Answers

If this is a one-time occurrence in your code, you might want to use // format: off and // format: on around the relevant code to ask scalafmt to preserve its current formatting (documentation):

// format: off
List(
  "some-random-string1"
    .trim
    .stripMargin,

  "some-random-string2"
    .intern
    .dropRight(3),

  "some-random-string3"
    .takeRight(4)
    .substring(10)
)
// format: on
like image 64
stefanobaghino Avatar answered Feb 05 '26 14:02

stefanobaghino