Skip to content

Commit

Permalink
VerticalMultiline: remove deprecated parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 25, 2022
1 parent 98deba7 commit 8b711b3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 56 deletions.
15 changes: 5 additions & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3188,19 +3188,14 @@ def other(a: String, b: String)(c: String, d: String) = a + b + c

### `verticalMultiline.excludeDanglingParens`

> This parameter has been deprecated, please use
> [danglingParentheses.exclude](#danglingparenthesesexclude). Keep in mind,
> though, that the new parameter is empty by default while the old one isn't, so
> to use empty exclude list, one must set the old
> `verticalMultiline.excludeDanglingParens=[]`.
```scala mdoc:defaults
verticalMultiline.excludeDanglingParens
```
This parameter has been removed in 3.4.0, please use
[danglingParentheses.exclude](#danglingparenthesesexclude). Keep in mind,
though, that the new parameter is empty by default while the old one
contained `[class, trait]`.

```scala mdoc:scalafmt
indent.defnSite = 2
verticalMultiline.excludeDanglingParens = [def]
danglingParentheses.exclude = [def]
verticalMultiline.atDefnSite = true
verticalMultiline.arityThreshold = 2
verticalMultiline.newlineAfterOpenParen = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ case class DanglingParentheses(
defnSite: Boolean,
ctrlSite: Boolean = true,
private[config] val tupleSite: Option[Boolean] = None,
exclude: List[DanglingParentheses.Exclude] = Nil
private val exclude: Option[List[DanglingParentheses.Exclude]] = None
) {
@inline def tupleOrCallSite(isTuple: Boolean) =
if (isTuple) tupleSite.getOrElse(callSite) else callSite

def getExclude(
isVerticalMultiline: Boolean
): Seq[DanglingParentheses.Exclude] =
exclude.getOrElse {
if (!isVerticalMultiline) Nil
else DanglingParentheses.Exclude.defaultVerticalMultiline
}

}

object DanglingParentheses {
Expand Down Expand Up @@ -44,9 +53,10 @@ object DanglingParentheses {
case object `def` extends Exclude
case object `given` extends Exclude

implicit val reader: ConfCodecEx[Exclude] =
ReaderUtil
.oneOf[Exclude](`class`, `trait`, `enum`, `extension`, `def`, `given`)
implicit val reader: ConfCodecEx[Exclude] = ReaderUtil
.oneOf[Exclude](`class`, `trait`, `enum`, `extension`, `def`, `given`)

val defaultVerticalMultiline = List(`class`, `trait`)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,7 @@ import metaconfig._
case class VerticalMultiline(
atDefnSite: Boolean = false,
arityThreshold: Int = 100,
@annotation.DeprecatedName(
"newlineBeforeImplicitKW",
"Use newlines.implicitParamListModifierForce=[before] instead",
"2.5.0"
)
newlineBeforeImplicitKW: Boolean = false,
@annotation.DeprecatedName(
"newlineAfterImplicitKW",
"Use newlines.implicitParamListModifierForce=[after] instead",
"2.5.0"
)
newlineAfterImplicitKW: Boolean = false,
newlineAfterOpenParen: Boolean = false,
@annotation.DeprecatedName(
"excludeDanglingParens",
"Use danglingParentheses.exclude instead",
"2.5.0"
)
excludeDanglingParens: List[DanglingParentheses.Exclude] = List(
DanglingParentheses.Exclude.`class`,
DanglingParentheses.Exclude.`trait`
)
newlineAfterOpenParen: Boolean = false
)

object VerticalMultiline {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,7 @@ class FormatOps(

val shouldAddNewline = {
if (right.is[soft.ImplicitOrUsing])
style.newlines.forceBeforeImplicitParamListModifier ||
style.verticalMultiline.newlineBeforeImplicitKW
style.newlines.forceBeforeImplicitParamListModifier
else
style.verticalMultiline.newlineAfterOpenParen && isDefinition
} || (mixedParams && prev(t).meta.leftOwner.is[CtorModifier])
Expand All @@ -1212,8 +1211,7 @@ class FormatOps(
.withIndent(indentParam, close2, ExpiresOn.Before)
)
case Decision(ftd @ FormatToken(soft.ImplicitOrUsing(), _, _), _)
if (style.newlines.forceAfterImplicitParamListModifier ||
style.verticalMultiline.newlineAfterImplicitKW) &&
if style.newlines.forceAfterImplicitParamListModifier &&
!tokens.isRightCommentThenBreak(ftd) =>
Seq(Split(Newline, 0))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,7 @@ object TreeOps {
)(implicit style: ScalafmtConfig): Boolean =
!style.danglingParentheses.defnSite || {
val excludeList =
if (isVerticalMultiline && style.danglingParentheses.exclude.isEmpty)
style.verticalMultiline.excludeDanglingParens
else
style.danglingParentheses.exclude
style.danglingParentheses.getExclude(isVerticalMultiline)
excludeList.nonEmpty && {
val exclude = tree match {
case _: Ctor.Primary | _: Defn.Class =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Test {

}
<<< #2044
verticalMultiline.excludeDanglingParens = []
danglingParentheses.exclude = []
===
object a {
final class Dummy[F[+_, +_]: BIOMonad: BIOPrimitives: Clock2](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Abc(
<<< #1539 2: config style, dangling
optIn.configStyleArguments = true
danglingParentheses.preset = true
verticalMultiline.excludeDanglingParens = []
danglingParentheses.exclude = []
===
class Abc(
x: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
verticalMultiline = {
atDefnSite = true
excludeDanglingParens = [class, trait, def]
}

verticalMultiline.atDefnSite = true
danglingParentheses.exclude = [class, trait, def]
<<< not modify single line
optIn.configStyleArguments = false
===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ indent.defnSite = 2
verticalMultiline = {
atDefnSite = true
arityThreshold = 2 // Used here to force reformatting.
excludeDanglingParens = []
newlineAfterOpenParen = true
newlineBeforeImplicitKW = false // make sure this is respected
newlineAfterImplicitKW = true
}
danglingParentheses.exclude = []
newlines.implicitParamListModifierForce=[after]
<<< It should force a newline after open paren.
def other(a: String, b: String)(c: String) = a + b + c
>>>
Expand All @@ -18,7 +17,7 @@ def other(
c: String
) = a + b + c

<<< It should still respect newlineBeforeImplicitKW
<<< It should still respect newlines.implicitParamListModifierForce=[after]
def other[T](a: String, b: String)(implicit c: Parse[T]) = a + b + c
>>>
def other[T](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ indent.defnSite = 2
verticalMultiline = {
atDefnSite = true
arityThreshold = 2
excludeDanglingParens = []
}
danglingParentheses.exclude = []
<<< Verify that it respects dangling parens options
sealed trait Foobar
case class Foo(x: String) extends Foobar
Expand Down

0 comments on commit 8b711b3

Please sign in to comment.