diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala index 83eeb2663f..8559703017 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/AvoidInfix.scala @@ -93,20 +93,6 @@ class AvoidInfix(implicit ctx: RewriteCtx) extends RewriteSession { builder += TokenPatch.AddRight(lhsLast, ")", keepTok = true) } - // remove parens if enclosed - for { - parent <- tree.parent - if !parent.is[Term.ApplyInfix] && !parent.is[Term.Apply] - if ctx.style.rewrite.rules.contains(RedundantParens) - infixTokens = tree.tokens - head <- infixTokens.headOption if head.is[Token.LeftParen] - last <- infixTokens.lastOption if last.is[Token.RightParen] - if ctx.isMatching(head, last) - } yield { - builder += TokenPatch.Remove(head) - builder += TokenPatch.Remove(last) - } - ctx.addPatchSet(builder.result(): _*) case _ => diff --git a/scalafmt-tests/src/test/resources/rewrite/AvoidInfix.stat b/scalafmt-tests/src/test/resources/rewrite/AvoidInfix.stat index 588748ee9a..5bc2c84a68 100644 --- a/scalafmt-tests/src/test/resources/rewrite/AvoidInfix.stat +++ b/scalafmt-tests/src/test/resources/rewrite/AvoidInfix.stat @@ -410,3 +410,17 @@ rewrite.neverInfix.includeFilters = [ "[^*]+" ] foo baz (_) >>> foo.baz(_) +<<< enclosed in parens on separate lines, with RedundantParens +rewrite.rules = [AvoidInfix, RedundantParens] +=== +object a { + val foo = bar + ( + a baz b + ) +} +>>> +object a { + val foo = bar + a.baz(b) +}