How to setup scalafmt so it respects custom formatting of multiline method calls

249 Views Asked by At

I have a call that I would like to look like this:

newTimeRangeList(
  MonthRanges.Y2021.Jan, MonthRanges.Y2021.Feb, MonthRanges.Y2021.Mar, MonthRanges.Y2021.Apr,
  MonthRanges.Y2021.May, MonthRanges.Y2021.Jun, MonthRanges.Y2021.Jul, MonthRanges.Y2021.Aug,
  MonthRanges.Y2021.Sep, MonthRanges.Y2021.Oct, MonthRanges.Y2021.Nov, MonthRanges.Y2021.Dec
)

This is how I am trying to format it manually. I do not expect formatter to come up with exactly this formatting but I want it to stop moving arguments to next line if those are not exceeding the line length limit.

This is longer than a code folding threshold we try to keep (120 chars) but this is so long, that I don't want to have this with every argument on its own line. Right now this gets reformatted to

  newTimeRangeList(
    MonthRanges.Y2021.Jan,
    MonthRanges.Y2021.Feb,
    MonthRanges.Y2021.Mar,
    MonthRanges.Y2021.Apr,
    MonthRanges.Y2021.May,
    MonthRanges.Y2021.Jun,
    MonthRanges.Y2021.Jul,
    MonthRanges.Y2021.Aug,
    MonthRanges.Y2021.Sep,
    MonthRanges.Y2021.Oct,
    MonthRanges.Y2021.Nov,
    MonthRanges.Y2021.Dec
  )

My scalafmt:

version = 3.7.3
docstrings.style = Asterisk
runner.dialect = scala213source3
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, SortModifiers]
rewrite.redundantBraces.ifElseExpressions = false
rewrite.redundantBraces.generalExpressions = false
align = none
align.openParenDefnSite = false
align.openParenCallSite = false
align.tokens = []
optIn = {
  configStyleArguments = false
}
danglingParentheses.preset = false
danglingParentheses.callSite = true
rewrite.trailingCommas.style = keep
rewrite.trailingCommas.allowFolding = false
newlines.implicitParamListModifierForce = [after]
newlines.source=keep

Any advice on how where to look to get it working as described?

googled for a solution, experimented with various scalafmt params with no success

0

There are 0 best solutions below