Skip to content

Commit

Permalink
RedundantBraces: keep some around PartialFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 1, 2024
1 parent f34185d commit 1e89fb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,17 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
owner match {
case t: Term.FunctionTerm if t.tokens.last.is[Token.RightBrace] =>
if (!okToRemoveFunctionInApplyOrInit(t)) null else removeToken
case t: Term.PartialFunction if t.parent.exists { p =>
SingleArgInBraces.orBlock(p).exists(_._2 eq t) &&
t.pos.start != p.pos.start
} => removeToken
case t: Term.PartialFunction => t.parent match {
case Some(SingleArgInBraces.OrBlock(lft, `t`, _))
if lft.left ne ft.right =>
val ok = ftoks.findTokenWith(lft, ftoks.prev) { xft =>
if (!xft.left.is[Token.LeftBrace]) Some(false)
else if (session.isRemovedOnLeft(xft, ok = true)) None
else Some(true)
}.contains(true)
if (ok) removeToken else null
case _ => null
}
case t: Term.Block => t.parent match {
case Some(f: Term.FunctionTerm)
if okToReplaceFunctionInSingleArgApply(f) => removeToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,11 @@ val toIterator: Any => Iterator[_] = if (lenient) {
unsupportedCollectionType(tag.runtimeClass)
}
>>>
test does not parse: [dialect scala213] illegal start of simple expression
val toIterator: Any => Iterator[_] =
if (lenient)
case i: scala.collection.Iterable[_] => i.iterator
^
case l: java.util.List[_] => l.iterator().asScala
case a: Array[_] => a.iterator
case o => unsupportedCollectionType(o.getClass)
====== full result: ======
val toIterator: Any => Iterator[_] =
if (lenient)
val toIterator: Any => Iterator[_] = if (lenient) {
case i: scala.collection.Iterable[_] => i.iterator
case l: java.util.List[_] => l.iterator().asScala
case a: Array[_] => a.iterator
case o => unsupportedCollectionType(o.getClass)
else
unsupportedCollectionType(tag.runtimeClass)
}
else
unsupportedCollectionType(tag.runtimeClass)

0 comments on commit 1e89fb7

Please sign in to comment.