Skip to content

Commit

Permalink
Newlines: move poorMansTrailingCommasInConfigStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 26, 2024
1 parent df73462 commit 6521648
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 8 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,14 @@ object a {
}
```

### `newlines.configStyle.beforeComma`

If enabled, will break before comma (instead of after) when using config style.
However, if the `runner.dialect` supports trailing commas, using
[`rewrite.trailingCommas`](#trailing-commas) is recommended (which is why,
prior to v3.8.4, this parameter was called `poorMansTrailingCommasInConfigStyle`).
`

## Rewrite Rules

To enable a rewrite rule, add it to the config like this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ object Newlines {
bracketCallSite: Option[ConfigStyleElement] = None,
bracketDefnSite: Option[ConfigStyleElement] = None,
fallBack: ConfigStyleElement = ConfigStyleElement(),
@annotation.DeprecatedName(
"beforeComma",
"Scala supports trailing commas after 2.12.2. Use trailingCommas instead",
"2.5.0",
)
beforeComma: Boolean = false,
) {
def getParenCallSite: ConfigStyleElement = callSite.getOrElse(fallBack)
def getBracketCallSite: ConfigStyleElement = bracketCallSite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import metaconfig._
// scalafmt: { maxColumn = 100 }
@annotation.SectionRename("optIn.configStyleArguments", "newlines.configStyle.fallBack.prefer") // v3.8.2
@annotation.SectionRename("trailingCommas", "rewrite.trailingCommas.style") // v3.0.5
@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
Expand Down Expand Up @@ -111,12 +112,6 @@ case class ScalafmtConfig(
includeNoParensInSelectChains: Boolean = false,
assumeStandardLibraryStripMargin: Boolean = false,
danglingParentheses: DanglingParentheses = DanglingParentheses.default,
@annotation.DeprecatedName(
"poorMansTrailingCommasInConfigStyle",
"Scala supports trailing commas after 2.12.2. Use trailingCommas instead",
"2.5.0",
)
poorMansTrailingCommasInConfigStyle: Boolean = false,
verticalMultiline: VerticalMultiline = VerticalMultiline(),
onTestFailure: String = "",
encoding: Codec = "UTF-8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class FormatOps(
def splitOneArgOneLine(close: FT, owner: Tree)(implicit
style: ScalafmtConfig,
): Policy =
if (style.poorMansTrailingCommasInConfigStyle) Policy
if (style.newlines.configStyle.beforeComma) Policy
.beforeLeft(close, prefix = "B[,]")(splitOneArgPerLineBeforeComma(owner))
else Policy
.beforeLeft(close, prefix = "A[,]")(splitOneArgPerLineAfterComma(owner))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ class Router(formatOps: FormatOps) {
case _ => Policy.NoPolicy
})
val extraOneArgPerLineIndent =
if (multipleArgs && style.poorMansTrailingCommasInConfigStyle)
if (multipleArgs && style.newlines.configStyle.beforeComma)
Indent(2, afterOpen, After)
else Indent.Empty
val (implicitPenalty, implicitPolicy) =
Expand Down Expand Up @@ -1560,7 +1560,7 @@ class Router(formatOps: FormatOps) {
Seq(Split(NoSplit, 0))
// non-statement starting curly brace
case FT(_: T.Comma, _: T.LeftBrace, _)
if !style.poorMansTrailingCommasInConfigStyle &&
if !style.newlines.configStyle.beforeComma &&
isArgClauseSite(leftOwner) =>
val close = matchingRight(ft)
val binPackIsEnabled = style.binPack.callSiteFor(leftOwner) !=
Expand Down

0 comments on commit 6521648

Please sign in to comment.