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

Newlines: add forceBeforeAssign #3284

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,19 @@ class A {
}
```

### `newlines.forceBeforeAssign`

> Since v3.5.9

```scala mdoc:defaults
newlines.forceBeforeAssign
```

This parameter takes precedence over
[`newlines.forceBeforeMultilineAssign`](#newlinesforcebeforemultilineassign)
and uses the same values. The difference is, the rule forces a newline before a
matching assignment expression whether or not it can be formatted on a single line.

### `newlines.beforeTypeBounds`

> Since v3.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ case class Newlines(
@annotation.ExtraName("usingParamListModifierPrefer")
implicitParamListModifierPrefer: Option[BeforeAfter] = None,
alwaysBeforeElseAfterCurlyIf: Boolean = false,
forceBeforeAssign: ForceBeforeMultilineAssign =
ForceBeforeMultilineAssign.never,
private val forceBeforeMultilineAssign: Option[ForceBeforeMultilineAssign] =
None,
@annotation.DeprecatedName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,8 @@ class Router(formatOps: FormatOps) {
Seq(CtrlBodySplits.withIndent(Split(Space.orNL(ft.noBreak), 0), ft, body))
else if (isJsNative(body))
Seq(Split(Space, 0).withSingleLine(expire))
else if (style.newlines.forceBeforeAssign(ft.meta.leftOwner))
Seq(CtrlBodySplits.withIndent(Split(Newline, 0), ft, body))
else if (style.newlines.shouldForceBeforeMultilineAssign(ft.meta.leftOwner))
CtrlBodySplits.slbOnly(ft, body, spaceIndents) { x =>
CtrlBodySplits.withIndent(Split(Newline, x), ft, body)
Expand Down
8 changes: 8 additions & 0 deletions scalafmt-tests/src/test/resources/newlines/source_unfold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -6121,3 +6121,11 @@ class Foo() {
a + b
}.foo
}
<<< #3271
newlines.forceBeforeAssign = def
===
def sum(a: Int, b: Int): Int =
a + b
>>>
def sum(a: Int, b: Int): Int =
a + b