Skip to content

Commit

Permalink
PreferCurlyFors: don't rewrite semicolon only
Browse files Browse the repository at this point in the history
If we are not rewriting parentheses, we shouldn't remove semicolons as
they are required. Exclude the `if` guards, however, as they can come
without a newline or semicolon.
  • Loading branch information
kitbellew committed May 19, 2024
1 parent 408c8ed commit 8c3a622
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ private class PreferCurlyFors(implicit val ftoks: FormatTokens)
if !style.rewrite.preferCurlyFors.removeTrailingSemicolonsOnly ||
ftoks.hasBreakAfterRightBeforeNonComment(ft) =>
ft.meta.rightOwner match {
case _: Term.For | _: Term.ForYield => removeToken
case t @ (_: Term.For | _: Term.ForYield)
if ftoks.nextNonCommentAfter(ft).right.is[Token.KwIf] || {
val parenOrBrace = ftoks.nextNonComment(ftoks.getHead(t))
parenOrBrace.right.is[Token.LeftBrace] ||
session.claimedRule(parenOrBrace).exists(_.rule eq this)
} => removeToken
case _ => null
}

Expand Down

0 comments on commit 8c3a622

Please sign in to comment.