Skip to content

Commit

Permalink
DanglingParentheses: obtain tuple or call site
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 20, 2021
1 parent 1242310 commit fa6eb18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ case class DanglingParentheses(
private[config] val tupleSite: Option[Boolean] = None,
exclude: List[DanglingParentheses.Exclude] = Nil
) {
def getTupleSite = tupleSite.getOrElse(callSite)
@inline def tupleOrCallSite(isTuple: Boolean) =
if (isTuple) tupleSite.getOrElse(callSite) else callSite
}

object DanglingParentheses {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,7 @@ class Router(formatOps: FormatOps) {
mustDangleForTrailingCommas
val shouldDangle =
if (defnSite) !shouldNotDangleAtDefnSite(leftOwner, false)
else if (tupleSite) style.danglingParentheses.getTupleSite
else style.danglingParentheses.callSite
else style.danglingParentheses.tupleOrCallSite(tupleSite)
val wouldDangle = shouldDangle || {
val beforeClose = prev(closeFormatToken)
beforeClose.hasBreak && beforeClose.left.is[T.Comment]
Expand Down Expand Up @@ -1242,10 +1241,8 @@ class Router(formatOps: FormatOps) {
else splitOneArgOneLine(close, leftOwner) | newlineBeforeClose
} else if (
mustDangleForTrailingCommas ||
style.newlines.sourceIgnored && (
if (isTuple(leftOwner)) style.danglingParentheses.getTupleSite
else style.danglingParentheses.callSite
)
style.danglingParentheses.tupleOrCallSite(isTuple(leftOwner)) &&
style.newlines.sourceIgnored
)
newlineBeforeClose & binPackOnelinePolicy
else binPackOnelinePolicy
Expand Down Expand Up @@ -1962,13 +1959,9 @@ class Router(formatOps: FormatOps) {
cost: Int,
forceDangle: Boolean
)(implicit fileLine: FileLine) = {
val shouldDangle = forceDangle ||
style.danglingParentheses.callSite
val policy =
if (!shouldDangle) NoPolicy
else decideNewlinesOnlyBeforeClose(close)
val shouldDangle = forceDangle || style.danglingParentheses.callSite
Split(Newline, cost)
.withPolicy(policy)
.withPolicy(decideNewlinesOnlyBeforeClose(close), !shouldDangle)
.withIndent(style.indent.callSite, close, Before)
}
if (isSingleLineComment(right))
Expand Down Expand Up @@ -2514,10 +2507,8 @@ class Router(formatOps: FormatOps) {
ft.meta.leftOwner.parent.exists { lop =>
if (isDefnSite(lop)) !shouldNotDangleAtDefnSite(lop, false)
else
isCallSite(lop) && (
if (isTuple(lop)) style.danglingParentheses.getTupleSite
else style.danglingParentheses.callSite
)
isCallSite(lop) &&
style.danglingParentheses.tupleOrCallSite(isTuple(lop))
}

val expireFt = tokens.getLast(body)
Expand Down

0 comments on commit fa6eb18

Please sign in to comment.