Skip to content

Commit

Permalink
FormatTokensRewrite: add createIfRequested()
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 3, 2024
1 parent bc1675f commit a3cdf2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ object FormatTokensRewrite {
private[rewrite] trait RuleFactory {
def enabled(implicit style: ScalafmtConfig): Boolean
def create(implicit ftoks: FormatTokens): Rule
final def createIfRequested(implicit
ftoks: FormatTokens,
style: ScalafmtConfig
): Option[Rule] =
if (getFactories.contains(this) && enabled) Some(create) else None
}

private def getFactories(implicit style: ScalafmtConfig): Seq[RuleFactory] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
): RedundantBracesSettings =
style.rewrite.redundantBraces

private def redundantParensFunc(implicit
style: ScalafmtConfig
): Option[Rule] =
if (!style.rewrite.rules.contains(RedundantParens)) None
else Some(RedundantParens.create)

private def processInterpolation(implicit ft: FormatToken): Boolean = {
def isIdentifierAtStart(value: String) =
value.headOption.exists(x => Character.isLetterOrDigit(x) || x == '_')
Expand Down Expand Up @@ -450,8 +444,8 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
case x: Token.LeftParen =>
ftoks.matchingOpt(x) match {
case Some(y) if y ne stat.tokens.last =>
redundantParensFunc.exists { parensRule =>
parensRule.onToken(ftoks(x, -1), session, style).exists {
RedundantParens.createIfRequested.exists {
_.onToken(ftoks(x, -1), session, style).exists {
_.how eq ReplacementType.Remove
}
}
Expand Down

0 comments on commit a3cdf2e

Please sign in to comment.