Skip to content

Commit

Permalink
FormatOps: inline leftParenStartsNewBlockOnRight
Browse files Browse the repository at this point in the history
It's used only once.
  • Loading branch information
kitbellew committed Sep 27, 2024
1 parent 994e7ed commit ca21bf4
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ class FormatOps(
case _: T.EOF => start
case _: T.Comma | _: T.Semicolon | _: T.RightArrow | _: T.Equals => null
case _ if start.hasBlankLine => start
case _
if !style.newlines.formatInfix &&
(isInfixOp(start.rightOwner) || isInfixOpOnLeft(start)) =>
if (start.hasBreak) start else null
case _: T.LeftParen if !leftParenStartsNewBlockOnRight(start) => null
case _ if !style.newlines.formatInfix && {
isInfixOp(start.rightOwner) ||
isInfixOp(prevNonComment(start).leftOwner)
} => if (start.hasBreak) start else null
case _: T.LeftParen if (start.rightOwner match {
case _: Member.ArgClause =>
!style.newlines.isBeforeOpenParenCallSite
case t => !isJustBeforeTree(start)(t)
}) => null
case _: T.RightBracket if start.left.is[T.RightBracket] => null
case _: T.LeftBracket => null
case _: T.Dot if start.rightOwner.is[Type.Select] => null
Expand Down Expand Up @@ -186,17 +190,6 @@ class FormatOps(
style: ScalafmtConfig,
): T = getSlbEndOnLeft(start).left

final def isInfixOpOnLeft(ft: FormatToken): Boolean =
isInfixOp(prevNonComment(ft).leftOwner)

final def leftParenStartsNewBlockOnRight(
ft: FormatToken,
)(implicit style: ScalafmtConfig): Boolean =
(ft.meta.rightOwner match {
case _: Member.ArgClause => style.newlines.isBeforeOpenParenCallSite
case t => isJustBeforeTree(ft)(t)
}) && !isInfixOpOnLeft(ft)

/** js.native is very special in Scala.js.
*
* Context: https://github.com/scalameta/scalafmt/issues/108
Expand Down

0 comments on commit ca21bf4

Please sign in to comment.