Skip to content

Commit

Permalink
FormatOps: use exemptScope = not{,Within}Assign
Browse files Browse the repository at this point in the history
Also, remove assignmentOnly field and use notAssign scope.
Follow-on to #4681.
  • Loading branch information
kitbellew committed Dec 27, 2024
1 parent f506a29 commit bcc33e4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ case class IndentOperator(
includeRegex: String = ".*",
@annotation.ExtraName("exclude")
excludeRegex: String = "^(&&|\\|\\|)$",
assignmentOnly: Boolean = false,
) {
private val includeRegexp = includeRegex.r.pattern
private val excludeRegexp = excludeRegex.r.pattern
Expand Down Expand Up @@ -102,4 +101,12 @@ object IndentOperator {
notWithinAssign,
)
}

val boolToAssign: PartialFunction[Conf, Conf] = { case Conf.Bool(value) =>
if (value) Conf.Obj(
"exemptScope" -> Conf.Str("notAssign"),
"excludeRegex" -> Conf.Str(".*"),
)
else Conf.Obj.empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import metaconfig._
@annotation.SectionRename("poorMansTrailingCommasInConfigStyle", "newlines.configStyle.beforeComma") // v3.8.4
@annotation.SectionRename("optIn.forceBlankLineBeforeDocstring", "docstrings.forceBlankLineBefore") // v3.4.0
@annotation.SectionRename("indentOperator", "indent.infix") // v3.8.4
@annotation.SectionRename("verticalAlignMultilineOperators", "indent.infix.assignmentOnly") // v3.8.4
@annotation.SectionRename("verticalAlignMultilineOperators", "indent.infix", IndentOperator.boolToAssign) // v3.8.4
@annotation.SectionRename("indentYieldKeyword", "indent.yieldKeyword") // v3.8.4
@annotation.SectionRename("rewriteTokens", "rewrite.tokens") // v3.8.4
@annotation.SectionRename("importSelectors", "binPack.importSelectors") // v3.8.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,16 @@ class FormatOps(
case IndentOperator.Exempt.oldTopLevel => isOldTopLevel(getChild)
case IndentOperator.Exempt.aloneEnclosed => isAloneEnclosed(getChild)
case IndentOperator.Exempt.aloneArgOrBody => isAloneArgOrBody(getChild)
case _ => true
case IndentOperator.Exempt.notAssign => isAfterAssignmentOp(false)
case IndentOperator.Exempt.notWithinAssign => !app.isAssignment &&
// fullInfix itself is never an assignment
fullInfix.parent.exists {
case _: Member.Infix => false
case p: Member.ArgClause => !p.parent.is[Member.Infix]
case _ => true
}
}
if (cfg.assignmentOnly) isAfterAssignmentOp(false)
else if (beforeLhs) assignBodyExpire.isEmpty
if (beforeLhs) assignBodyExpire.isEmpty
else app.is[Pat] || allowNoIndent && cfg.noindent(app.op.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ object a {
}
<<< #4681 notAssign
maxColumn = 16
verticalAlignMultilineOperators = false
indent.infix {
exemptScope = notAssign
excludeRegex = ".*"
Expand Down Expand Up @@ -147,6 +148,7 @@ object a {
}
<<< #4681 notWithinAssign
maxColumn = 16
verticalAlignMultilineOperators = false
indent.infix {
exemptScope = notWithinAssign
excludeRegex = ".*"
Expand Down Expand Up @@ -185,15 +187,15 @@ object a {
foo1 =
aaaabbbb
foo1 += aaaa -
bbbb
bbbb
foo1 +=
aaaabbbb
foo1 == aaaa -
bbbb
foo1 ==
aaaabbbb
foo1 := aaaa -
bbbb
bbbb
foo1 :=
aaaabbbb
foo1 >= aaaa -
Expand Down

0 comments on commit bcc33e4

Please sign in to comment.