Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatTokensRewrite: add createIfRequested() #3808

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading