Adam Mackler
Adam Mackler

Reputation: 2080

Make scalafmt keep infix expression on one line and break line before match case pattern and body

Inside a match expression Scalafmt is giving me:

case Some(thing) => s ++
    myMethodName(Some(my.other.method(argument)))

What I want is this:

case Some(thing) =>
    s ++ myMethodName(Some(my.other.method(argument)))

Or, if the line is too long then this:

case Some(thing) =>
    s ++ myMethodName(
      Some(my.other.method(argument))
    )

The closest I can get is the following, by increasing maxColumn value:

case Some(thing) => s ++ myMethodName(Some(my.other.method(argument)))

The ++ operator and its arguments are a single expression, so should be on the same line, and if it's too long to fit on the same line as the match pattern then the break should come after the => arrow that separates the match pattern from the expression.

I have attempted to achieve this using configuration parameters, though I admit I have a very weak understanding of what all their settings mean, and how they interact with each other:

newlines {
  source=fold
  beforeMultiline=fold
  afterInfix=some
  forceBeforeMultilineAssign=any
}

set to various values, but still Scalafmt really wants to put the match pattern and first argument to the operator on the same line as each other. How can I get the newline to come after the => arrow?

Upvotes: 2

Views: 351

Answers (0)

Related Questions