Skip to content

Commit

Permalink
IndentOperator: add not{,Within}Assign scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 27, 2024
1 parent 0bf8999 commit ad359a6
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 8 deletions.
9 changes: 4 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ to be exempted from the default indentation rule:
[scala-js coding style](https://github.com/scala-js/scala-js/blob/main/CODINGSTYLE.md#long-expressions-with-binary-operators).
- `all`: all infix operators
- this value replaced deprecated `indentOperator.topLevelOnly=false`
- `notAssign` (since v3.8.4): any non-assignment operator
- this value expanded upon deprecated `verticalAlignMultilineOperators`
which now simply maps to `{ exemptScope = notAssign, excludeRegex = ".*" }`
- `notWithinAssign` (since v3.8.4): any infix not part of a larger assignment expression

```scala mdoc:scalafmt
indent.infix.exemptScope = oldTopLevel
Expand Down Expand Up @@ -1026,11 +1030,6 @@ renamed from `indentOperator.include`.
indent.infix.includeRegex
```

#### `indent.infix.assignmentOnly`

Indents only after an assignment operator. Prior to v3.8.4, was called
`verticalAlignMultilineOperators`.

#### `indent.infix.preset`

- `default`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ object IndentOperator {
case object oldTopLevel extends Exempt
case object aloneEnclosed extends Exempt
case object aloneArgOrBody extends Exempt
case object notAssign extends Exempt
case object notWithinAssign extends Exempt

implicit val reader: ConfCodecEx[Exempt] = ReaderUtil
.oneOf[Exempt](all, oldTopLevel, aloneEnclosed, aloneArgOrBody)
implicit val reader: ConfCodecEx[Exempt] = ReaderUtil.oneOf[Exempt](
all,
oldTopLevel,
aloneEnclosed,
aloneArgOrBody,
notAssign,
notWithinAssign,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ class FormatOps(
case IndentOperator.Exempt.oldTopLevel => isOldTopLevel(getChild)
case IndentOperator.Exempt.aloneEnclosed => isAloneEnclosed(getChild)
case IndentOperator.Exempt.aloneArgOrBody => isAloneArgOrBody(getChild)
case _ => true
}
if (cfg.assignmentOnly) isAfterAssignmentOp(false)
else if (beforeLhs) assignBodyExpire.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,167 @@ object Foo3 {
a +
b
}
<<< #4681 verticalAlignMultilineOperators
maxColumn = 16
===
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
>>>
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
<<< #4681 notAssign
maxColumn = 16
indent.infix {
exemptScope = notAssign
excludeRegex = ".*"
}
===
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
>>>
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
<<< #4681 notWithinAssign
maxColumn = 16
indent.infix {
exemptScope = notWithinAssign
excludeRegex = ".*"
}
===
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
>>>
object a {
val foo1 = a +
b
foo1 = aaaa -
bbbb
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
bbbb
foo1 >=
aaaabbbb
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1241608, "total explored")
assertEquals(explored, 1241926, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit ad359a6

Please sign in to comment.