From cfebea928720fda5bc73a8f3a03b18c4c20d69ae Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 27 Mar 2024 06:57:55 -0700 Subject: [PATCH] FormatTokensRewrite: obtain rule from Replacement --- .../org/scalafmt/rewrite/FormatTokensRewrite.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala index dbf030a043..53a4c1c2a4 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/FormatTokensRewrite.scala @@ -134,7 +134,7 @@ class FormatTokensRewrite( private def getRewrittenTokens: Iterable[Replacement] = { implicit val session: Session = new Session(rules) val tokens = session.tokens - val leftDelimIndex = new mutable.ListBuffer[(Int, Option[Rule])]() + val leftDelimIndex = new mutable.ListBuffer[Int]() val formatOffStack = new mutable.ListBuffer[Boolean]() arr.foreach { implicit ft => ft.right match { @@ -149,16 +149,17 @@ class FormatTokensRewrite( case Some(c) => applyRule(c.rule) case _ => applyRules } - leftDelimIndex.prepend((ldelimIdx, ruleOpt)) + leftDelimIndex.prepend(ldelimIdx) if (ruleOpt.isEmpty) tokens.append(null) case _: T.RightBrace | _: T.RightParen | _: T.RightBracket => val formatOff = formatOffStack.remove(0) - val (ldelimIdx, ruleOpt) = leftDelimIndex.remove(0) + val ldelimIdx = leftDelimIndex.remove(0) if (formatOff && formatOffStack.nonEmpty) formatOffStack.update(0, true) - ruleOpt.foreach { rule => - val left = tokens(ldelimIdx) + val left = tokens(ldelimIdx) + if (left ne null) { + val rule = left.rule val replacement = if (ft.meta.formatOff) None else if (session.claimedRule.exists(_.rule ne rule)) None