diff --git a/docs/configuration.md b/docs/configuration.md index 02ecf092f1..b1decc3933 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -4753,6 +4753,7 @@ object Example2 { This group of parameters controls binpacking of an argument list if _all_ arguments are considered to be literals. +These parameters take precedence over [forcing of config style](#forcing-config-style). The following parameters affect this behaviour: @@ -4880,66 +4881,65 @@ object A { } ``` -### `binPack.defnSite` +### `binPack.xxxSite` -Controls binpacking around method/type definition sites (and was called -`unsafeDefnSite` up until v3.8.1). The following parameter values are supported +Controls binpacking around method/type definition sites (`binPack.defnSite`) or +method call sites (`binPack.callSite`) (both were called +`unsafeXxxSite` up until v3.8.1). The following parameter values are supported since v3.0.0: - `Never` disables the functionality (also takes `false`) - `Always` enables the functionality (also takes `true`) - `Oneline` ensures multiline arguments are not binpacked -When not disabled, this parameter has complex interactions with +When not disabled, these parameters have complex interactions with [`newline.source`](#newlinessource), -[config-style formatting](#newlines-config-style-formatting) and -[`danglingParentheses.defnSite`](#danglingparenthesesdefnsite). - -- `newlines.source=classic/keep` - - open break is preserved for `keep`, matches close break for `classic` - - when `config-style` is enabled: close break is preserved, - `danglingParentheses.defnSite` is ignored - - when `config-style` is disabled: `danglingParentheses.defnSite` - dictates close break -- `newlines.source=fold/unfold` - - open break matches close break for `fold`, dangles for `unfold` - - `danglingParentheses.defnSite` dictates close break - - `config-style` is ignored - -### `binPack.callSite` - -Controls binpacking around method call sites (and was called `unsafeCallSite` up -until v3.8.1). It takes the same values as [`binPack.defnSite`](#binpackdefnsite), -and similarly has cross-parameter interactions: - -- interaction with `config-style` parameters: - - when [config-style is forced](#forcing-config-style), it takes precedence - over binpacking - - for `newlines.source=classic`, behaviour depends on - [config-style](#newlinesconfigstylexxxsiteprefer): - - if enabled: used if [detected](#newlines-config-style-formatting), otherwise binpacked - - if disabled with both [`danglingParentheses.callSite`](#danglingparenthesescallsite) - enabled and closing parenthesis following a break: forces config-style, as described in - [scala.js](https://github.com/scala-js/scala-js/pull/4522#issuecomment-879168123) - - otherwise, uses binpacking - - for other values of [`newlines.source`](#newlinessource), - binpacking takes precedence -- interaction with [`danglingParentheses.callSite`](#danglingparenthesescallsite) - - `newlines.source=classic`: please see above - - `newlines.source=keep` - - open break is preserved - - when both [config-style](#newlinesconfigstylexxxsiteprefer) and - [`danglingParentheses.callSite`](#danglingparenthesescallsite) are disabled, - close break is "tucked" - - otherwise, close break matches open break - - `newlines.source=fold/unfold` - - when [`danglingParentheses.callSite`](#danglingparenthesescallsite) is enabled, - open break matches close break, and close is always dangling for `unfold`, - and only when [config-style is forced](#forcing-config-style) for `fold` - - otherwise, open is always dangling, - and close is dangling only when both - [`newlines.configStyleXxxSite.prefer=true`](#newlinesconfigstylexxxsiteprefer) - and [config-style is forced](#forcing-config-style) +[`newlines.configStyleXxxSite.prefer`](#newlinesconfigstylexxxsiteprefer) +(aka `cfgStyle` below) and +[`danglingParentheses.xxxSite`](#newlines-danglingparentheses) (aka `dangle`). +Keep in mind that when [config-style is forced](#forcing-config-style), +it takes precedence over options described below. + +- `newlines.source=classic` + - `cfgStyle=T`, `dangle=T`: + use cfg-style if both parens had breaks, otherwise binpack without breaks + - before v3.8.2, this formatting was used for `callSite` with `dangle=F` as well + - `cfgStyle=T`, `dangle=F`: + ([scala.js](https://github.com/scala-js/scala-js/pull/4522#issuecomment-879168123)) + use cfg-style if close paren had a break; otherwise, binpack without breaks + - `cfgStyle=F`, `dangle=T`: + binpack; if both parens had breaks, keep; otherwise, use no breaks + - before v3.8.2, this formatting was used for `defnSite` with + `cfgStyle=T` and any `dangle` + - `cfgStyle=F`, `dangle=F`: + binpack without breaks + - before v3.8.2, this formatting was used for `callSite` with + `cfgStyle=F` and any `dangle`, and for `defnSite` with + `cfgStyle=F` and `dangle=F` +- `newlines.source=keep` + - `cfgStyle=T`, `dangle=T`: + use cfg-style if open paren had a break; otherwise, binpack and preserve both breaks + - `cfgStyle=T`, `dangle=F`: + ([scala.js](https://github.com/scala-js/scala-js/pull/4522#issuecomment-879168123)) + use cfg-style if close paren had a break; otherwise, binpack without breaks + - `cfgStyle=F`, `dangle=T`: + binpack; if open paren had a break, force both breaks; otherwise, preserve both + - `cfgStyle=F`, `dangle=F`: + binpack; preserve both breaks +- `newlines.source=fold`: if single line is not possible: + - `cfgStyle=T`, `dangle=T`: + binpack with both breaks + - `cfgStyle=T`, `dangle=F`: + binpack with dangling open and tucked close + - `cfgStyle=F`, `dangle=T`: + binpack with tucked open and dangling close + - if [`binPack.indentCallSiteOnce`](#binpackindentcallsiteonce) is set, + we will not force dangling as it might lead to consecutive lines + with a closing parenthesis at the same indentation level + - `cfgStyle=F`, `dangle=F`: + binpack without breaks +- `newlines.source=unfold`: if single line is not possible: + - open dangles, close break matches `dangle`, `cfgStyle` is ignored > Please also see [callSite indentation parameters](#indent-for-binpackcallsite). diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/ConfigStyle.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/ConfigStyle.scala deleted file mode 100644 index 5d7dffcad5..0000000000 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/ConfigStyle.scala +++ /dev/null @@ -1,9 +0,0 @@ -package org.scalafmt.internal - -sealed abstract class ConfigStyle - -object ConfigStyle { - case object None extends ConfigStyle - case object Source extends ConfigStyle - case object Forced extends ConfigStyle -} diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index d002c7c459..40c8f9e4a2 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -861,13 +861,9 @@ class FormatOps( ft: FormatToken, breakBeforeClose: => Boolean, allowForce: Boolean = true, - )(implicit - style: ScalafmtConfig, - cfg: Newlines.ConfigStyleElement, - ): ConfigStyle = - if (allowForce && mustForceConfigStyle(ft)) ConfigStyle.Forced - else if (preserveConfigStyle(ft, breakBeforeClose)) ConfigStyle.Source - else ConfigStyle.None + )(implicit style: ScalafmtConfig, cfg: Newlines.ConfigStyleElement): Boolean = + allowForce && mustForceConfigStyle(ft) || + preserveConfigStyle(ft, breakBeforeClose) def mustForceConfigStyle(ft: FormatToken)(implicit cfg: Newlines.ConfigStyleElement, @@ -2644,30 +2640,98 @@ class FormatOps( ftBeforeClose: FormatToken, )(implicit style: ScalafmtConfig) = { val literalArgList = styleMap.opensLiteralArgumentList(ftAfterOpen) - val dangleForTrailingCommas = getMustDangleForTrailingCommas(ftBeforeClose) implicit val configStyleFlags = style.configStyleCallSite - val configStyle = - if (dangleForTrailingCommas) ConfigStyle.None - else - mustUseConfigStyle(ftAfterOpen, ftBeforeClose.hasBreak, !literalArgList) val shouldDangle = style.danglingParentheses .atCallSite(ftAfterOpen.meta.leftOwner) - val scalaJsStyle = style.newlines.source == Newlines.classic && - configStyle == ConfigStyle.None && !configStyleFlags.prefer && - !literalArgList && shouldDangle - BinpackCallsiteFlags( + getBinpackSiteFlags(ftAfterOpen, ftBeforeClose, literalArgList, shouldDangle) + } + + @inline + def getBinpackDefnsiteFlags( + ftAfterOpen: FormatToken, + ftBeforeClose: FormatToken, + )(implicit style: ScalafmtConfig): BinpackSiteFlags = { + implicit val configStyleFlags = style.configStyleDefnSite + getBinpackSiteFlags( + ftAfterOpen, + ftBeforeClose, + literalArgList = false, + shouldDangle = style.danglingParentheses + .atDefnSite(ftAfterOpen.meta.leftOwner), + ) + } + + def getBinpackSiteFlags( + ftAfterOpen: FormatToken, + ftBeforeClose: FormatToken, + literalArgList: Boolean, + shouldDangle: Boolean, + )(implicit + style: ScalafmtConfig, + configStyleFlags: Newlines.ConfigStyleElement, + ): BinpackSiteFlags = { + val configStylePrefer = configStyleFlags.prefer + val sourceIgnored = style.newlines.sourceIgnored + val configStyleSource = configStylePrefer && !sourceIgnored + val scalaJsStyle = configStyleSource && !shouldDangle + val closeBreak = ftBeforeClose.hasBreak + + def noNLPolicy(): Policy = { + val close = ftBeforeClose.right + if (scalaJsStyle) Policy(Policy.End.On(ftBeforeClose.right)) { + case d: Decision if d.formatToken.right eq close => d.noNewlines + } + else style.newlines.source match { + case Newlines.keep if closeBreak => decideNewlinesOnlyBeforeClose(close) + case Newlines.fold + if shouldDangle && !configStylePrefer && + !style.binPack.indentCallSiteOnce => + decideNewlinesOnlyBeforeCloseOnBreak(close) + case _ => NoPolicy + } + } + + def nlOpenClose(): (Boolean, NlClosedOnOpen) = + if (!literalArgList && mustForceConfigStyle(ftAfterOpen)) + (true, NlClosedOnOpen.Cfg) + else { + val openBreak = ftAfterOpen.hasBreak + val dangleForTrailingCommas = + getMustDangleForTrailingCommas(ftBeforeClose) + val nlOpenExcludingCfg = dangleForTrailingCommas || + (style.newlines.source match { + case Newlines.classic => openBreak && shouldDangle && closeBreak + case Newlines.keep => openBreak + case _ => false + }) || tokens.isRightCommentWithBreak(ftAfterOpen) + val nlBothIncludingCfg = !sourceIgnored && closeBreak && { + scalaJsStyle || nlOpenExcludingCfg || + preserveConfigStyle(ftAfterOpen, true) + } + // close on open NL; doesn't cover case with no break after open + val nlClose = nlBothIncludingCfg || dangleForTrailingCommas || + shouldDangle || style.newlines.keepBreak(closeBreak) + if (!nlClose) (nlOpenExcludingCfg && !scalaJsStyle, NlClosedOnOpen.No) + else { + val cfg = !literalArgList && configStyleSource + val dangle = if (cfg) NlClosedOnOpen.Cfg else NlClosedOnOpen.Yes + (nlBothIncludingCfg || nlOpenExcludingCfg, dangle) + } + } + + BinpackSiteFlags( literalArgList = literalArgList, - dangleForTrailingCommas = dangleForTrailingCommas, - configStyle = configStyle, + nlOpenClose = nlOpenClose, + noNLPolicy = noNLPolicy, shouldDangle = shouldDangle, - scalaJsStyle = scalaJsStyle, + scalaJsStyle = scalaJsStyle && !literalArgList, ) } @tailrec final def scalaJsOptClose( ftBeforeClose: FormatToken, - bpFlags: BinpackCallsiteFlags, + bpFlags: BinpackSiteFlags, )(implicit style: ScalafmtConfig): T = if (bpFlags.scalaJsStyle) { val ftAfterClose = tokens.nextNonCommentAfter(ftBeforeClose) @@ -2725,10 +2789,17 @@ object FormatOps { ) else Seq(Indent(Length.StateColumn, end, ExpiresOn.Before)) - case class BinpackCallsiteFlags( + private[internal] sealed trait NlClosedOnOpen + private[internal] object NlClosedOnOpen { + case object No extends NlClosedOnOpen + case object Yes extends NlClosedOnOpen + case object Cfg extends NlClosedOnOpen + } + + private[internal] case class BinpackSiteFlags( literalArgList: Boolean, - dangleForTrailingCommas: Boolean, - configStyle: ConfigStyle, + nlOpenClose: () => (Boolean, NlClosedOnOpen), + noNLPolicy: () => Policy, shouldDangle: Boolean, scalaJsStyle: Boolean, ) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index f478ac7158..4f93613b4b 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -874,8 +874,7 @@ class Router(formatOps: FormatOps) { implicit val configStyleFlags = if (defnSite) style.configStyleDefnSite else style.configStyleCallSite def closeBreak = mustDangleForTrailingCommas || beforeClose.hasBreak - val onlyConfigStyle = ConfigStyle.None != - mustUseConfigStyle(ft, closeBreak) + val onlyConfigStyle = mustUseConfigStyle(ft, closeBreak) val configStyleFlag = configStyleFlags.prefer val sourceIgnored = style.newlines.sourceIgnored @@ -1111,9 +1110,6 @@ class Router(formatOps: FormatOps) { val penalizeBrackets = bracketPenalty .map(p => PenalizeAllNewlines(close, p + 3)) val beforeClose = tokens.justBefore(close) - implicit val configStyleFlags = style.configStyleDefnSite - val onlyConfigStyle = getMustDangleForTrailingCommas(beforeClose) || - ConfigStyle.None != mustUseConfigStyle(ft, beforeClose.hasBreak) val argsHeadOpt = argumentStarts.get(ft.meta.idx) val isSingleArg = isSeqSingle(getArgs(leftOwner)) @@ -1125,13 +1121,15 @@ class Router(formatOps: FormatOps) { .map(splitOneArgPerLineAfterCommaOnBreak) } - val nlOnly = onlyConfigStyle || style.newlines.keepBreak(newlines) || - tokens.isRightCommentWithBreak(ft) - val mustDangle = onlyConfigStyle || - style.danglingParentheses.atDefnSite(leftOwner) && - (style.newlines.sourceIgnored || !configStyleFlags.prefer) - val slbOrNL = nlOnly || style.newlines.source == Newlines.unfold || - mustDangle + val flags = getBinpackDefnsiteFlags(ft, beforeClose) + val (nlOnly, nlCloseOnOpen) = flags.nlOpenClose() + val slbOrNL = nlOnly || + (style.newlines.source match { + case Newlines.unfold => true + case Newlines.fold => style.configStyleDefnSite.prefer + case _ => false + }) + def noSplitPolicy: Policy = if (slbOrNL) slbPolicy else { @@ -1148,7 +1146,7 @@ class Router(formatOps: FormatOps) { if (oneline && isSingleArg) NoPolicy else SingleLineBlock(x.tokens.last, noSyntaxNL = true) } - argPolicy & (opensPolicy | penalizeBrackets) + argPolicy & (opensPolicy | penalizeBrackets) & flags.noNLPolicy() } val rightIsComment = right.is[T.Comment] val noSplitModification = @@ -1156,7 +1154,13 @@ class Router(formatOps: FormatOps) { val nlMod = if (rightIsComment && nlOnly) getMod(ft) else Newline def getDanglePolicy(implicit fileLine: FileLine) = decideNewlinesOnlyBeforeClose(close) - val nlPolicy = if (mustDangle) getDanglePolicy else NoPolicy + val nlPolicy = nlCloseOnOpen match { + case NlClosedOnOpen.Cfg => getDanglePolicy | + splitOneArgOneLine(close, leftOwner) + case NlClosedOnOpen.Yes => getDanglePolicy + case NlClosedOnOpen.No => NoPolicy + } + def nlCost = bracketPenalty.getOrElse(1) Seq( @@ -1184,15 +1188,9 @@ class Router(formatOps: FormatOps) { if (isSingleArg) firstArg.flatMap(asInfixApp) else None val flags = getBinpackCallsiteFlags(ft, beforeClose)(style) - + val (nlOpen, nlCloseOnOpen) = flags.nlOpenClose() val singleLineOnly = style.binPack.literalsSingleLine && flags.literalArgList - - val scalaJsStyleNL = flags.scalaJsStyle && beforeClose.hasBreak - val nlOpen = flags.dangleForTrailingCommas || - flags.configStyle != ConfigStyle.None || - style.newlines.keepBreak(newlines) || scalaJsStyleNL || - tokens.isRightCommentWithBreak(ft) val nlOnly = nlOpen && !singleLineOnly def findComma(ft: FormatToken) = findFirstOnRight[T.Comma](ft, close) @@ -1225,8 +1223,11 @@ class Router(formatOps: FormatOps) { Split(Space(style.spaces.inParentheses), 0) val slbOrNL = nlOnly || singleLineOnly || needOnelinePolicy && nextCommaOneline.isEmpty || - // multiline binpack is at odds with unfold, at least force a break - style.newlines.source.eq(Newlines.unfold) + (style.newlines.source match { + case Newlines.unfold => true + case Newlines.fold => style.configStyleCallSite.prefer + case _ => false + }) val noSplit = if (nlOnly) Split.ignored @@ -1253,16 +1254,8 @@ class Router(formatOps: FormatOps) { ) getOpenParenAlignIndents(close) else Seq(indent) - def optClose = Some(scalaJsOptClose(beforeClose, flags)) - val opt = - if (oneline) nextCommaOneline.orElse(optClose) - else if (style.newlines.source.eq(Newlines.fold)) None - else findComma(ft).orElse(optClose) - val scajaJsPolicy = - if (flags.scalaJsStyle) Policy(Policy.End.On(close)) { - case d: Decision if d.formatToken.right eq close => d.noNewlines - } - else NoPolicy + def optClose = scalaJsOptClose(beforeClose, flags) + val opt = if (oneline) nextCommaOneline else findComma(ft) val noSplitPolicy = if (needOnelinePolicy) { @@ -1291,8 +1284,8 @@ class Router(formatOps: FormatOps) { } else NoPolicy unindentPolicy & indentOncePolicy } else NoPolicy - baseNoSplit.withOptimalTokenOpt(opt) - .withPolicy(noSplitPolicy & indentPolicy & scajaJsPolicy) + baseNoSplit.withOptimalToken(opt.getOrElse(optClose)) + .withPolicy(noSplitPolicy & indentPolicy & flags.noNLPolicy()) .withIndents(noSplitIndents) } @@ -1306,21 +1299,13 @@ class Router(formatOps: FormatOps) { def configStylePolicy(implicit fileLine: FileLine) = splitOneArgOneLine(close, leftOwner) | newlineBeforeClose - if (flags.configStyle != ConfigStyle.None) - if ( - (style.newlines.source == Newlines.keep && - flags.configStyle == ConfigStyle.Source) || - styleMap.forcedBinPack(leftOwner) - ) bothPolicies - else configStylePolicy - else if (scalaJsStyleNL) configStylePolicy - else if ( - flags.dangleForTrailingCommas || - flags.shouldDangle && - (style.newlines.sourceIgnored || !style.configStyleCallSite.prefer) - ) bothPolicies - else binPackOnelinePolicyOpt - .getOrElse(decideNewlinesOnlyBeforeCloseOnBreak(close)) + nlCloseOnOpen match { + case NlClosedOnOpen.No => binPackOnelinePolicyOpt + .getOrElse(decideNewlinesOnlyBeforeCloseOnBreak(close)) + case NlClosedOnOpen.Cfg if !styleMap.forcedBinPack(leftOwner) => + configStylePolicy + case _ => bothPolicies + } } val nlMod = if (nlOnly && noBreak() && right.is[T.Comment]) Space diff --git a/scalafmt-tests/src/test/resources/binPack/LiteralList.stat b/scalafmt-tests/src/test/resources/binPack/LiteralList.stat index ce3ddb942b..0fa299e03d 100644 --- a/scalafmt-tests/src/test/resources/binPack/LiteralList.stat +++ b/scalafmt-tests/src/test/resources/binPack/LiteralList.stat @@ -193,7 +193,8 @@ private val lengthByLeading: Array[Int] = Array( // 11110uuu 4, 4, 4, 4, 4, 4, 4, 4, // > 11110111 - -1, -1, -1, -1, -1, -1, -1, -1) + -1, -1, -1, -1, -1, -1, -1, -1 +) <<< native 2, !dangle danglingParentheses.preset = false === diff --git a/scalafmt-tests/src/test/resources/binPack/ParentConstructors.stat b/scalafmt-tests/src/test/resources/binPack/ParentConstructors.stat index 47b239f27c..68ac8fed86 100644 --- a/scalafmt-tests/src/test/resources/binPack/ParentConstructors.stat +++ b/scalafmt-tests/src/test/resources/binPack/ParentConstructors.stat @@ -63,7 +63,8 @@ object a { >>> object a { case class TopLevelExportInfo(moduleID: String, jsName: String)( - val pos: Position) extends ExportInfo + val pos: Position + ) extends ExportInfo } <<< #2633 keep with class, !dangle maxColumn = 70 diff --git a/scalafmt-tests/src/test/resources/binPack/TermNameList.stat b/scalafmt-tests/src/test/resources/binPack/TermNameList.stat index 753bc806c1..aff6fb285f 100644 --- a/scalafmt-tests/src/test/resources/binPack/TermNameList.stat +++ b/scalafmt-tests/src/test/resources/binPack/TermNameList.stat @@ -71,7 +71,8 @@ somethingVeryLong( baz( qux // c1 ) - }) + } +) <<< unsafeCallSite forced newline, cfg + !dangle maxColumn = 20 binPack.unsafeCallSite = true @@ -88,7 +89,8 @@ somethingVeryLong( baz( qux // c1 ) - }) + } +) <<< unsafeCallSite forced newline, !cfg + dangle maxColumn = 20 binPack.unsafeCallSite = true diff --git a/scalafmt-tests/src/test/resources/default/TypeArguments.stat b/scalafmt-tests/src/test/resources/default/TypeArguments.stat index e170c3cdae..09250eed89 100644 --- a/scalafmt-tests/src/test/resources/default/TypeArguments.stat +++ b/scalafmt-tests/src/test/resources/default/TypeArguments.stat @@ -436,9 +436,8 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: object a { def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder, K: KeyEncoder: KeyDecoder] = ??? - def props[ - M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() = - ??? + def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, + Event: PersistentEncoder: PersistentDecoder]() = ??? } <<< #2739 bracketDefnSite = oneline, !danglingParentheses maxColumn = 100 @@ -472,9 +471,8 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: object a { def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder, K: KeyEncoder: KeyDecoder] = ??? - def props[ - M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() = - ??? + def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, + Event: PersistentEncoder: PersistentDecoder]() = ??? } <<< #2739 bracketDefnSite = always, !danglingParentheses maxColumn = 100 diff --git a/scalafmt-tests/src/test/resources/newlines/source_classic.stat b/scalafmt-tests/src/test/resources/newlines/source_classic.stat index 822023457b..bd29020af9 100644 --- a/scalafmt-tests/src/test/resources/newlines/source_classic.stat +++ b/scalafmt-tests/src/test/resources/newlines/source_classic.stat @@ -2801,7 +2801,10 @@ object a { test("foo") { a.b(c, d) shouldBe E(Seq(F(1, "v1"), F(2, "v2")), - G(Some(Seq(h, i)), Some(Seq(j, k)), a.b, c.d, e.f.g, h.i.j)).foo + G(Some(Seq(h, i)), + Some(Seq(j, k)), a.b, c.d, + e.f.g, h.i.j) + ).foo } } <<< binpack call, oneline, with syntaxNL, single arg @@ -2870,7 +2873,8 @@ object a { object a { val foo = bar.map(x => x.copy( - baz = Option.when(false)(x.qux)) + baz = Option.when(false)(x.qux) + ) ) } <<< binPack with named parameter values, configStyleArguments + !danglingParentheses @@ -2889,7 +2893,8 @@ object a { object a { val foo = bar.map(x => x.copy( - baz = Option.when(false)(x.qux))) + baz = Option.when(false)(x.qux) + )) } <<< binPack with named parameter values, !configStyleArguments + danglingParentheses binPack.preset = true @@ -3042,8 +3047,10 @@ object a { Some(0), Some(1), foo = Some("bar")), Qux("", 1, "par1", "2018-01-01", "2018-12-31", "2018-01-01", "2018-02-01", None, None, 1000, Some(0), Some(1), foo = Some("bar")), - Qux("", 1, "par1", "2018-01-01", "2018-12-31", "2018-01-01", "2018-02-01", None, None, 1000, - Some(0), Some(1), foo = Some("bar")) + Qux( + "", 1, "par1", "2018-01-01", "2018-12-31", "2018-01-01", "2018-02-01", None, None, 1000, + Some(0), Some(1), foo = Some("bar") + ) ) ) ) @@ -3073,12 +3080,13 @@ object a { } >>> object a { - private val audience3 = - apiAudience(3, "b_name", Sams, Inid, "2", "created-by-user2", "updated-by-user2").copy( - updatedAt = nowDate.minusDays(15), - audienceSizeOnsite = Some(3333), - audienceSizeOffsite = Some(1) - ) + private val audience3 = apiAudience( + 3, "b_name", Sams, Inid, "2", "created-by-user2", "updated-by-user2" + ).copy( + updatedAt = nowDate.minusDays(15), + audienceSizeOnsite = Some(3333), + audienceSizeOffsite = Some(1) + ) private val audience3 = apiAudience(3, "b_name", Sams, Inid, "2", "created-by-user2", "updated-by-user2").copy( updatedAt = nowDate.minusDays(15), @@ -3115,10 +3123,10 @@ object a { } >>> object a { - protected def foo[U]( - bar: String, - baz: Seq[String] = Seq.empty - )(f: HttpResponse => U): U = qux + protected def foo[U](bar: String, + baz: Seq[String] = Seq.empty)( + f: HttpResponse => U + ): U = qux } <<< binPack indent expiresOn=Before when !dangle, configStyleArguments binPack.preset = true @@ -5040,8 +5048,11 @@ object a { } >>> object a { - def foo(bb: BB, cc: CC, dd: DD = DDD.ddd): Bar[ - Baz] = { + def foo( + bb: BB, + cc: CC, + dd: DD = DDD.ddd + ): Bar[Baz] = { // c qux } @@ -5080,8 +5091,9 @@ object a { } >>> object a { - def foo(dd: DD[AA[BB], CC] = - DDD.ddd): Bar[Baz] = { + def foo( + dd: DD[AA[BB], CC] = DDD.ddd + ): Bar[Baz] = { // c qux } @@ -7752,7 +7764,9 @@ object Main { >>> object Main { def foo1( - x1: X, x2: X, xs: X* + x1: X, + x2: X, + xs: X* ): Set[Int] def foo1(x1: X, x2: X, xs: X*): Set[Int] @@ -7761,12 +7775,18 @@ object Main { def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, danglingParentheses @@ -7797,17 +7817,12 @@ object Main { >>> object Main { val bar1 = foo1( - 10000, - 10001, - 10002 + 0 + 10000, 10001, 10002 + 0 ) val bar1 = foo1(10000, 10001, 10002 + 0) - val bar1 = foo1( - 10000, - 10001, - 10002 + 0 - ) + val bar1 = foo1(10000, + 10001, 10002 + 0) val bar1 = foo1(10000, 10001, 10002 + 0) val bar2 = foo2(0, 1, 2, 3, @@ -7846,23 +7861,19 @@ object Main { def foo1( x1: X, x2: X, xs: X* ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* - ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* - ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* - ): Set[Int] + def foo1(x1: X, x2: X, + xs: X*): Set[Int] + def foo1(x1: X, x2: X, + xs: X*): Set[Int] + def foo1(x1: X, x2: X, + xs: X*): Set[Int] def foo2( x1: X, x2: X, x3: X, x4: X, xs: X* ): Set[Int] - def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* - ): Set[Int] + def foo3(x1: X, x2: X, + x3: X, x4: X, xs: X*) + : Set[Int] } <<< binPack.callSite with configStyle, !danglingParentheses newlines.configStyleCallSite.prefer = true @@ -7898,8 +7909,11 @@ object Main { ) val bar1 = foo1(10000, 10001, 10002 + 0) - val bar1 = foo1(10000, - 10001, 10002 + 0) + val bar1 = foo1( + 10000, + 10001, + 10002 + 0 + ) val bar1 = foo1(10000, 10001, 10002 + 0) val bar2 = foo2( @@ -7947,21 +7961,32 @@ object Main { >>> object Main { def foo1( - x1: X, x2: X, xs: X* + x1: X, + x2: X, + xs: X* + ): Set[Int] + def foo1( + x1: X, + x2: X, + xs: X* ): Set[Int] - def foo1(x1: X, x2: X, - xs: X*): Set[Int] def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, !danglingParentheses diff --git a/scalafmt-tests/src/test/resources/newlines/source_fold.stat b/scalafmt-tests/src/test/resources/newlines/source_fold.stat index 993f8447c6..0344ce4f4e 100644 --- a/scalafmt-tests/src/test/resources/newlines/source_fold.stat +++ b/scalafmt-tests/src/test/resources/newlines/source_fold.stat @@ -2622,12 +2622,13 @@ object a { >>> object a { test("foo") { - a.b(c, d) shouldBe E( - Seq(F(1, "v1"), F(2, "v2")), - G(Some(Seq(h, i)), - Some(Seq(j, k)), a.b, c.d, - e.f.g, h.i.j) - ).foo + a.b(c, d) shouldBe + E(Seq(F(1, "v1"), F(2, "v2")), + G(Some(Seq(h, i)), + Some(Seq(j, k)), a.b, c.d, + e.f.g, h.i.j + ) + ).foo } } <<< binpack call, oneline @@ -2647,7 +2648,8 @@ object a { E(Seq(F(1, "v1"), F(2, "v2")), G(Some(Seq(h, i)), Some(Seq(j, k)), a.b, c.d, - e.f.g, h.i.j) + e.f.g, h.i.j + ) ).foo } } @@ -2716,8 +2718,9 @@ object a { >>> object a { val foo = bar.map(x => - x.copy(baz = Option - .when(false)(x.qux)) + x.copy( + baz = Option.when(false)(x.qux) + ) ) } <<< binPack with named parameter values, !danglingParentheses @@ -2796,9 +2799,8 @@ object a { } >>> object a { - foo(bar.baz(Seq(Qux( - "", 1, "par1", "2018-01-01", "2018-12-31", "2018-01-01", "2018-02-01", None, None, 1000, - Some(0), Some(1), foo = Some("bar") + foo(bar.baz(Seq(Qux("", 1, "par1", "2018-01-01", "2018-12-31", "2018-01-01", "2018-02-01", None, + None, 1000, Some(0), Some(1), foo = Some("bar") )))) } <<< binPack.literals, danglingParentheses, avoid fold @@ -2839,8 +2841,7 @@ object a { } >>> object a { - protected def foo[U]( - bar: String, + protected def foo[U](bar: String, baz: Seq[String] = Seq.empty )(f: HttpResponse => U): U = qux } @@ -4849,12 +4850,17 @@ object a { } >>> object a { - binder.bind("f", params) shouldBe Some(Left( - s"Cannot parse parameter f as DummyEnum, $wrongValue is not a member of Enum (dummy-value)" - )) + binder.bind("f", params) shouldBe Some( + Left( + s"Cannot parse parameter f as DummyEnum, $wrongValue is not a member of Enum (dummy-value)" + ) + ) - when(audienceService.publish(any[Tenant], any[Int])).thenReturn(Success[NonEmptyList[String], - ApiAudience](apiAudience.copy(status = AudienceStatus.Pending.name))) + when(audienceService.publish(any[Tenant], any[Int])).thenReturn( + Success[NonEmptyList[String], ApiAudience]( + apiAudience.copy(status = AudienceStatus.Pending.name) + ) + ) } <<< binPack.callSite = Oneline, nested with one arg, several options maxColumn = 100 @@ -4881,21 +4887,26 @@ object a { >>> object a { when( - service.list(ApiAudienceFilter(tenants = Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default) + service.list( + ApiAudienceFilter(tenants = Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default + ) ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when( - service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant)), Page(0, Page.maxPageLimit), - Order.default) + service.list( + ApiAudienceFilter(tenants), Contains(Seq(ATenant)), Page(0, Page.maxPageLimit), Order.default + ) ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + when( + service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), + Order.default + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default, PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - .thenReturn(None) + when( + service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), + Order.default, PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10)) + ).thenReturn(None) } <<< binPack.callSite = always, nested with one arg maxColumn = 100 @@ -4915,13 +4926,17 @@ object a { } >>> object a { - binder.bind("f", params) shouldBe Some(Left( + binder.bind("f", params) shouldBe Some( + Left( s"Cannot parse parameter f as DummyEnum, $wrongValue is not a member of Enum (dummy-value)" - )) + ) + ) - when(audienceService.publish(any[Tenant], any[Int])) - .thenReturn(Success[NonEmptyList[String], ApiAudience](apiAudience - .copy(status = AudienceStatus.Pending.name))) + when(audienceService.publish(any[Tenant], any[Int])).thenReturn( + Success[NonEmptyList[String], ApiAudience]( + apiAudience.copy(status = AudienceStatus.Pending.name) + ) + ) } <<< binPack.callSite = always, nested with one arg, several options maxColumn = 100 @@ -4947,20 +4962,27 @@ object a { } >>> object a { - when(service.list(ApiAudienceFilter(tenants = Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default)) - .thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + when( + service.list( + ApiAudienceFilter(tenants = Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default + ) + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant)), Page(0, Page.maxPageLimit), - Order.default)) - .thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + when( + service.list( + ApiAudienceFilter(tenants), Contains(Seq(ATenant)), Page(0, Page.maxPageLimit), Order.default + ) + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + when( + service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), + Order.default + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), - Order.default, PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) - .thenReturn(None) + when( + service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), + Order.default, PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10)) + ).thenReturn(None) } <<< #2821 default assembly / assemblyMergeStrategy := { @@ -6921,8 +6943,10 @@ object a { object a { assert( t21 == - (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21) + ( + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21 + ) ) } <<< SM 7.4.0: 44 @@ -7141,6 +7165,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7160,14 +7187,19 @@ object Main { } >>> object Main { - val bar1 = foo1(10000, - 10001, 10002 + 0) - val bar1 = foo1(10000, - 10001, 10002 + 0) - val bar1 = foo1(10000, - 10001, 10002 + 0) - val bar1 = foo1(10000, - 10001, 10002 + 0) + val bar0 = foo0(1, 2, 3 + 0) + val bar1 = foo1( + 10000, 10001, 10002 + 0 + ) + val bar1 = foo1( + 10000, 10001, 10002 + 0 + ) + val bar1 = foo1( + 10000, 10001, 10002 + 0 + ) + val bar1 = foo1( + 10000, 10001, 10002 + 0 + ) val bar2 = foo2( 0, 1, @@ -7225,12 +7257,18 @@ object Main { x1: X, x2: X, xs: X* ): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, danglingParentheses @@ -7241,6 +7279,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7260,17 +7301,21 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1(10000, - 10001, 10002 + 0) - val bar2 = foo2( - 0, 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10 + 0 + 10001, 10002 + 0 + ) + val bar2 = foo2(0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 10 + 0 ) } <<< binPack.defnSite with !configStyle, danglingParentheses @@ -7303,25 +7348,23 @@ object Main { } >>> object Main { - def foo1( - x1: X, x2: X, xs: X* + def foo1(x1: X, x2: X, + xs: X* ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* + def foo1(x1: X, x2: X, + xs: X* ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* + def foo1(x1: X, x2: X, + xs: X* ): Set[Int] - def foo1( - x1: X, x2: X, xs: X* + def foo1(x1: X, x2: X, + xs: X* ): Set[Int] - def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + def foo2(x1: X, x2: X, + x3: X, x4: X, xs: X* ): Set[Int] - def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + def foo3(x1: X, x2: X, + x3: X, x4: X, xs: X* ): Set[Int] } <<< binPack.callSite with configStyle, !danglingParentheses @@ -7332,6 +7375,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7351,6 +7397,7 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1( 10000, 10001, 10002 + 0) val bar1 = foo1( @@ -7403,21 +7450,31 @@ object Main { } >>> object Main { - def foo1(x1: X, x2: X, - xs: X*): Set[Int] - def foo1(x1: X, x2: X, - xs: X*): Set[Int] - def foo1(x1: X, x2: X, - xs: X*): Set[Int] - def foo1(x1: X, x2: X, - xs: X*): Set[Int] + def foo1( + x1: X, x2: X, xs: X*) + : Set[Int] + def foo1( + x1: X, x2: X, xs: X*) + : Set[Int] + def foo1( + x1: X, x2: X, xs: X*) + : Set[Int] + def foo1( + x1: X, x2: X, xs: X*) + : Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, !danglingParentheses @@ -7428,6 +7485,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7447,17 +7507,17 @@ object Main { } >>> object Main { - val bar1 = foo1( - 10000, 10001, 10002 + 0) - val bar1 = foo1( - 10000, 10001, 10002 + 0) - val bar1 = foo1( - 10000, 10001, 10002 + 0) - val bar1 = foo1( - 10000, 10001, 10002 + 0) - val bar2 = foo2( - 0, 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10 + 0) + val bar0 = foo0(1, 2, 3 + 0) + val bar1 = foo1(10000, + 10001, 10002 + 0) + val bar1 = foo1(10000, + 10001, 10002 + 0) + val bar1 = foo1(10000, + 10001, 10002 + 0) + val bar1 = foo1(10000, + 10001, 10002 + 0) + val bar2 = foo2(0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 10 + 0) } <<< binPack.defnSite with !configStyle, !danglingParentheses newlines.configStyleDefnSite.prefer = false diff --git a/scalafmt-tests/src/test/resources/newlines/source_keep.stat b/scalafmt-tests/src/test/resources/newlines/source_keep.stat index 678ac743ca..6d963a7859 100644 --- a/scalafmt-tests/src/test/resources/newlines/source_keep.stat +++ b/scalafmt-tests/src/test/resources/newlines/source_keep.stat @@ -2873,7 +2873,8 @@ object a { object a { val foo = bar.map(x => x.copy(baz = - Option.when(false)(x.qux)) + Option.when(false)(x.qux) + ) ) } <<< binPack with named parameter values, !danglingParentheses @@ -2892,7 +2893,8 @@ object a { object a { val foo = bar.map(x => x.copy(baz = - Option.when(false)(x.qux))) + Option.when(false)(x.qux) + )) } <<< literalsIncludeSimpleExpr with named parameter values, danglingParentheses binPack.literalsIncludeSimpleExpr = true @@ -3000,10 +3002,8 @@ object a { } >>> object a { - protected def foo[U]( - bar: String, - baz: Seq[String] = Seq.empty - )( + protected def foo[U](bar: String, + baz: Seq[String] = Seq.empty)( f: HttpResponse => U ): U = qux } @@ -5114,17 +5114,19 @@ object a { object a { when( service.list(ApiAudienceFilter(tenants = Contains(Seq(ATenant))), - Page(0, Page.maxPageLimit), Order.default) + Page(0, Page.maxPageLimit), Order.default + ) ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when( service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant)), - Page(0, Page.maxPageLimit), Order.default) + Page(0, Page.maxPageLimit), Order.default + ) ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), - Page(0, Page.maxPageLimit), Order.default).thenReturn( - PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + Page(0, Page.maxPageLimit), Order.default + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default, @@ -5168,7 +5170,8 @@ object a { when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default).thenReturn( - PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) + PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10)) + ) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default, @@ -5226,16 +5229,16 @@ object a { >>> object a { when(service.list(ApiAudienceFilter(tenants = Contains(Seq(ATenant))), - Page(0, Page.maxPageLimit), Order.default)).thenReturn(PageResult(Seq(audience, - audience.copy(id = 2)), PageInfo(50, 0, 10))) + Page(0, Page.maxPageLimit), Order.default + )).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant)), - Page(0, Page.maxPageLimit), Order.default)).thenReturn(PageResult(Seq(audience, - audience.copy(id = 2)), PageInfo(50, 0, 10))) + Page(0, Page.maxPageLimit), Order.default + )).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), - Page(0, Page.maxPageLimit), Order.default).thenReturn(PageResult(Seq(audience, - audience.copy(id = 2)), PageInfo(50, 0, 10))) + Page(0, Page.maxPageLimit), Order.default + ).thenReturn(PageResult(Seq(audience, audience.copy(id = 2)), PageInfo(50, 0, 10))) when(service.list(ApiAudienceFilter(tenants), Contains(Seq(ATenant))), Page(0, Page.maxPageLimit), Order.default, @@ -7575,15 +7578,19 @@ object Main { object Main { val bar1 = foo1( 10000, - 10001, 10002 + 0 + 10001, + 10002 + 0 ) val bar1 = foo1(10000, 10001, 10002 + 0) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1( 10000, - 10001, 10002 + 0) + 10001, + 10002 + 0 + ) val bar2 = foo2( 0, 1, @@ -7630,22 +7637,32 @@ object Main { object Main { def foo1( x1: X, - x2: X, xs: X* + x2: X, + xs: X* ): Set[Int] def foo1(x1: X, - x2: X, xs: X*): Set[Int] + x2: X, xs: X* + ): Set[Int] def foo1( x1: X, - x2: X, xs: X*): Set[Int] + x2: X, + xs: X* + ): Set[Int] def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, danglingParentheses @@ -7682,7 +7699,8 @@ object Main { val bar1 = foo1(10000, 10001, 10002 + 0) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7727,18 +7745,15 @@ object Main { x1: X, x2: X, xs: X* ): Set[Int] - def foo1( - x1: X, - x2: X, xs: X* - ): Set[Int] - def foo1( - x1: X, + def foo1(x1: X, x2: X, xs: X* ): Set[Int] def foo1( x1: X, x2: X, xs: X* ): Set[Int] + def foo1(x1: X, + x2: X, xs: X*): Set[Int] def foo2( x1: X, x2: X, x3: X, x4: X, xs: X* @@ -7777,14 +7792,17 @@ object Main { object Main { val bar1 = foo1( 10000, - 10001, 10002 + 0 + 10001, + 10002 + 0 ) - val bar1 = foo1(10000, - 10001, 10002 + 0) val bar1 = foo1(10000, 10001, 10002 + 0) val bar1 = foo1( 10000, + 10001, + 10002 + 0 + ) + val bar1 = foo1(10000, 10001, 10002 + 0) val bar2 = foo2( 0, @@ -7832,22 +7850,31 @@ object Main { object Main { def foo1( x1: X, - x2: X, xs: X* + x2: X, + xs: X* ): Set[Int] - def foo1(x1: X, - x2: X, xs: X*): Set[Int] def foo1( x1: X, + x2: X, + xs: X* + ): Set[Int] + def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo1(x1: X, x2: X, xs: X*): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, !danglingParentheses @@ -7879,11 +7906,13 @@ object Main { object Main { val bar1 = foo1( 10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1(10000, 10001, 10002 + 0) val bar1 = foo1(10000, - 10001, 10002 + 0) + 10001, 10002 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0) @@ -7924,9 +7953,11 @@ object Main { object Main { def foo1( x1: X, - x2: X, xs: X*): Set[Int] + x2: X, xs: X* + ): Set[Int] def foo1(x1: X, - x2: X, xs: X*): Set[Int] + x2: X, xs: X* + ): Set[Int] def foo1( x1: X, x2: X, xs: X*): Set[Int] @@ -7934,7 +7965,8 @@ object Main { x2: X, xs: X*): Set[Int] def foo2( x1: X, x2: X, x3: X, - x4: X, xs: X*): Set[Int] + x4: X, xs: X* + ): Set[Int] def foo3( x1: X, x2: X, x3: X, x4: X, xs: X*): Set[Int] diff --git a/scalafmt-tests/src/test/resources/newlines/source_unfold.stat b/scalafmt-tests/src/test/resources/newlines/source_unfold.stat index dba65eddd8..72e74f4bbd 100644 --- a/scalafmt-tests/src/test/resources/newlines/source_unfold.stat +++ b/scalafmt-tests/src/test/resources/newlines/source_unfold.stat @@ -7718,6 +7718,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7737,6 +7740,7 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1( 10000, 10001, 10002 + 0 ) @@ -7806,12 +7810,18 @@ object Main { x1: X, x2: X, xs: X* ): Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, danglingParentheses @@ -7822,6 +7832,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7841,6 +7854,7 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1( 10000, 10001, 10002 + 0 ) @@ -7917,6 +7931,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -7936,6 +7953,7 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1( 10000, 10001, 10002 + 0) val bar1 = foo1( @@ -8001,12 +8019,18 @@ object Main { x1: X, x2: X, xs: X*) : Set[Int] def foo2( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] def foo3( - x1: X, x2: X, x3: X, - x4: X, xs: X* + x1: X, + x2: X, + x3: X, + x4: X, + xs: X* ): Set[Int] } <<< binPack.callSite with !configStyle, !danglingParentheses @@ -8017,6 +8041,9 @@ maxColumn = 30 runner.optimizer.callSite { minSpan = 20, minCount = 5 } === object Main { + val bar0 = foo0( + 1, 2, 3 + 0 + ) val bar1 = foo1( 10000, 10001, 10002 + 0 @@ -8036,6 +8063,7 @@ object Main { } >>> object Main { + val bar0 = foo0(1, 2, 3 + 0) val bar1 = foo1( 10000, 10001, 10002 + 0) val bar1 = foo1( diff --git a/scalafmt-tests/src/test/resources/scalajs/Apply.stat b/scalafmt-tests/src/test/resources/scalajs/Apply.stat index 5be3dffde3..da1a87643c 100644 --- a/scalafmt-tests/src/test/resources/scalajs/Apply.stat +++ b/scalafmt-tests/src/test/resources/scalajs/Apply.stat @@ -359,9 +359,7 @@ object a { foo match { case Apply(appMeth, Apply(wrapRefArrayMeth, - StripCast( - arg @ ArrayValue(elemtpt, elems)) :: Nil - ) :: classTagEvidence :: Nil) + StripCast(arg @ ArrayValue(elemtpt, elems)) :: Nil) :: classTagEvidence :: Nil) if WrapArray.isClassTagBasedWrapArrayMethod(wrapRefArrayMeth.symbol) && appMeth.symbol == ArrayModule_genericApply => bar @@ -405,9 +403,7 @@ object a { object a { Apply(appMeth, Apply(wrapRefArrayMeth, - StripCast( - ArrayValue(elemtpt, elems)) :: Nil - ) :: classTagEvidence :: Nil) + StripCast(ArrayValue(elemtpt, elems)) :: Nil) :: classTagEvidence :: Nil) } <<< binpack=always, with infix maxColumn = 80 @@ -787,8 +783,9 @@ optDef.getOrElse { } >>> optDef.getOrElse { - abort(fooFoo && - barBar) + abort( + fooFoo && + barBar) abort( fooFoo && barBar, @@ -817,14 +814,16 @@ object a { } >>> object a { - Seq(foo + - bar) + Seq( + foo + + bar) Seq( foo + bar, foo + bar) - Seq(foo && + Seq( + foo && bar) Seq( foo && diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlways.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlways.stat index bc17ba0c63..52bc1800af 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlways.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlways.stat @@ -349,13 +349,16 @@ import foo.{ a, b, } class foo( - a: String, b: String, + a: String, + b: String, ) { def method( - a: String, b: String, + a: String, + b: String, ) = ??? method( - a, b, + a, + b, ) } <<< #2755 two, no comma, no fold, binpack, !cfgStyle @@ -386,7 +389,8 @@ class foo( a: String, b: String, ) = ??? method( - a, b, + a, + b, ) } <<< #3663 enclosed literal diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlwaysComments.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlwaysComments.stat index 0ec9df5d8d..bed97de0db 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlwaysComments.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasAlwaysComments.stat @@ -363,13 +363,16 @@ import foo.{ a, b, /* c1 */ /* c2 */ } class foo( - a: String, b: String, /* c1 */ /* c2 */ + a: String, + b: String, /* c1 */ /* c2 */ ) { def method( - a: String, b: String, /* c1 */ /* c2 */ + a: String, + b: String, /* c1 */ /* c2 */ ) = ??? method( - a, b, /* c1 */ /* c2 */ + a, + b, /* c1 */ /* c2 */ ) } <<< #2755 two, no comma, no fold, binPack, !cfgStyle @@ -391,10 +394,16 @@ class foo(a: String, b /* c1 */ /* c2 */ ) } >>> -Idempotency violated -=> Diff (- obtained, + expected) - method( -- a, -- b, /* c1 */ /* c2 */ -+ a, b, /* c1 */ /* c2 */ - ) +import foo.{ + a, b, /* c1 */ /* c2 */ +} +class foo( + a: String, b: String, /* c1 */ /* c2 */ +) { + def method( + a: String, b: String, /* c1 */ /* c2 */ + ) = ??? + method( + a, b, /* c1 */ /* c2 */ + ) +} diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultiple.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultiple.stat index 1a5498aa1d..fab4aef3d8 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultiple.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultiple.stat @@ -334,13 +334,16 @@ import foo.{ a, b, } class foo( - a: String, b: String, + a: String, + b: String, ) { def method( - a: String, b: String, + a: String, + b: String, ) = ??? method( - a, b, + a, + b, ) } <<< #2755 two, no comma, no fold, binpack, !cfgStyle diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultipleComments.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultipleComments.stat index c043c33911..e3e9bf9494 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultipleComments.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasMultipleComments.stat @@ -347,13 +347,16 @@ import foo.{ a, b, /* c1 */ /* c2 */ } class foo( - a: String, b: String, /* c1 */ /* c2 */ + a: String, + b: String, /* c1 */ /* c2 */ ) { def method( - a: String, b: String, /* c1 */ /* c2 */ + a: String, + b: String, /* c1 */ /* c2 */ ) = ??? method( - a, b, /* c1 */ /* c2 */ + a, + b, /* c1 */ /* c2 */ ) } <<< #2755 two, no comma, no fold, binPack, !cfgStyle @@ -375,10 +378,16 @@ class foo(a: String, b /* c1 */ /* c2 */ ) } >>> -Idempotency violated -=> Diff (- obtained, + expected) - method( -- a, -- b, /* c1 */ /* c2 */ -+ a, b, /* c1 */ /* c2 */ - ) +import foo.{ + a, b, /* c1 */ /* c2 */ +} +class foo( + a: String, b: String, /* c1 */ /* c2 */ +) { + def method( + a: String, b: String, /* c1 */ /* c2 */ + ) = ??? + method( + a, b, /* c1 */ /* c2 */ + ) +} diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat index 7967dd213e..0035f82dcc 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat @@ -60,7 +60,8 @@ def a(b: Int, ) >>> def a( - b: Int, c: Int, + b: Int, + c: Int, ) <<< keep, do not fold, binpack, !cfgStyle binPack.preset = true @@ -108,7 +109,9 @@ def a(b: Int, c: Int, /* comment */ ) >>> def a( - b: Int, c: Int, /* comment */ + b: Int, + c: Int, + /* comment */ ) <<< keep, do not fold, with comment after break, binpack, !cfgStyle maxColumn = 40 @@ -182,7 +185,8 @@ def a(b: Int, ) >>> def a( - b: Int, c: Int, + b: Int, + c: Int, ) <<< keep, do not fold, with spaces, binpack, !cfgStyle binPack.preset = true @@ -234,7 +238,9 @@ def a(b: Int, c: Int, /* comment */ ) >>> def a( - b: Int, c: Int, /* comment */ + b: Int, + c: Int, + /* comment */ ) <<< keep, do not fold, with spaces and comment after break, binpack, !cfgStyle spaces.inParentheses = true diff --git a/scalafmt-tests/src/test/resources/unit/Comment.stat b/scalafmt-tests/src/test/resources/unit/Comment.stat index d70734b465..4efbb0f079 100644 --- a/scalafmt-tests/src/test/resources/unit/Comment.stat +++ b/scalafmt-tests/src/test/resources/unit/Comment.stat @@ -913,7 +913,7 @@ object a: baz /* comment1 * comment2 * comment3 */ -<<< trailing-wrapped comments with fold, binpack(lots) and dangling +<<< trailing-wrapped comments with fold, binpack(lots) and dangling 1 maxColumn = 100 indent.callSite = 2 align.preset = none @@ -966,11 +966,13 @@ object a { user_id: String, dept_id: Option[Int], catg_grp_id: Option[Int], // for store only catg_id: Option[Int], subcatg_id: Option[Int], brand_id: Option[Int], order_date: String, item_id: Long - ) = SalesUserActivity(user_id, dept_id, catg_grp_id, catg_id, subcatg_id, brand_id, - Some(dummyBrand), 1f, 1f, item_id, tenant, inid, catalog, channel, - order_date.split("-")(0).toInt, order_date.split("-")(1).toInt, "v1", order_date) + ) = SalesUserActivity( + user_id, dept_id, catg_grp_id, catg_id, subcatg_id, brand_id, Some(dummyBrand), 1f, 1f, item_id, + tenant, inid, catalog, channel, order_date.split("-")(0).toInt, order_date.split("-")(1).toInt, + "v1", order_date + ) } -<<< trailing-wrapped comments with fold, binpack(lots) and dangling +<<< trailing-wrapped comments with fold, binpack(lots) and dangling 2 maxColumn = 100 indent.callSite = 2 align.preset = none @@ -996,8 +998,9 @@ object a { object a { private val impressionUniqueMetricsData = Seq( // out of range - ImpUnique("2018-01-02", 102, Some("444"), Some(1), Some(2), Some(1), None, None, 2018, 1, - ver) /* aggimp3 */ + ImpUnique( + "2018-01-02", 102, Some("444"), Some(1), Some(2), Some(1), None, None, 2018, 1, ver + ) /* aggimp3 */ ) } <<< trailing-wrapped comments with fold, binpack=oneline @@ -1020,7 +1023,8 @@ object a { object a { private val foo = Seq( // out of range - Bar("2018-01-02", 1, + Bar( + "2018-01-02", 1, ver) /* baz */ ) }