From 88c49614ccc95e41eeb4af28c361064bcfa5b05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Tue, 11 Jun 2024 11:33:34 -0700 Subject: [PATCH] Inline `options.manageTrailingCommas` Summary: `isGoogleStyle` was introduced a while ago, before we had trailing commas support. Now that trailing support is around we don't need to call this `isGoogleStyle`. Instead of renaming it though, I decided to inline it. Reviewed By: cortinico Differential Revision: D58395568 fbshipit-source-id: 510044b5212a8d0d4ce2129f27b876e5cfedc887 --- .../ktfmt/format/KotlinInputAstVisitor.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt index 211feaba..85025e57 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt @@ -135,8 +135,6 @@ class KotlinInputAstVisitor( private val builder: OpsBuilder ) : KtTreeVisitorVoid() { - private val isGoogleStyle = options.manageTrailingCommas - /** Standard indentation for a block */ private val blockIndent: Indent.Const = Indent.Const.make(options.blockIndent, 1) @@ -257,7 +255,7 @@ class KotlinInputAstVisitor( visitEachCommaSeparated( typeArgumentList.arguments, typeArgumentList.trailingComma != null, - wrapInBlock = !isGoogleStyle, + wrapInBlock = !options.manageTrailingCommas, prefix = "<", postfix = ">", ) @@ -817,8 +815,8 @@ class KotlinInputAstVisitor( leadingBreak = !hasEmptyParens && hasTrailingComma breakAfterPrefix = false } else { - wrapInBlock = !isGoogleStyle - breakBeforePostfix = isGoogleStyle && !hasEmptyParens + wrapInBlock = !options.manageTrailingCommas + breakBeforePostfix = options.manageTrailingCommas && !hasEmptyParens leadingBreak = !hasEmptyParens breakAfterPrefix = !hasEmptyParens } @@ -1053,7 +1051,7 @@ class KotlinInputAstVisitor( prefix: String? = null, postfix: String? = null, breakAfterPrefix: Boolean = true, - breakBeforePostfix: Boolean = isGoogleStyle, + breakBeforePostfix: Boolean = options.manageTrailingCommas, ): BreakTag? { val breakAfterLastElement = hasTrailingComma || (postfix != null && breakBeforePostfix) val nameTag = if (breakAfterLastElement) null else genSym() @@ -2138,7 +2136,7 @@ class KotlinInputAstVisitor( hasTrailingComma = list.trailingComma != null, prefix = "<", postfix = ">", - wrapInBlock = !isGoogleStyle, + wrapInBlock = !options.manageTrailingCommas, ) } } @@ -2370,7 +2368,7 @@ class KotlinInputAstVisitor( expression.trailingComma != null, prefix = "[", postfix = "]", - wrapInBlock = !isGoogleStyle) + wrapInBlock = !options.manageTrailingCommas) } } @@ -2611,7 +2609,7 @@ class KotlinInputAstVisitor( builder.token(keyword) builder.space() builder.token("(") - if (isGoogleStyle) { + if (options.manageTrailingCommas) { builder.block(expressionBreakIndent) { builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO) visit(condition)