Skip to content

Commit 6cb41d1

Browse files
committed
Re-format
1 parent 1ca92b2 commit 6cb41d1

22 files changed

Lines changed: 828 additions & 465 deletions

core/src/main/java/com/facebook/ktfmt/cli/Main.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class Main(
7373
result.addAll(
7474
File(arg).walkTopDown().filter {
7575
it.isFile && (it.extension == "kt" || it.extension == "kts")
76-
})
76+
}
77+
)
7778
}
7879
return result
7980
}

core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ data class ParsedArgs(
134134
stdinName =
135135
parseKeyValueArg("--stdin-name", arg)
136136
?: return ParseResult.Error(
137-
"Found option '${arg}', expected '${"--stdin-name"}=<value>'")
137+
"Found option '${arg}', expected '${"--stdin-name"}=<value>'"
138+
)
138139
arg.startsWith("--") -> return ParseResult.Error("Unexpected option: $arg")
139140
arg.startsWith("@") -> return ParseResult.Error("Unexpected option: $arg")
140141
else -> fileNames.add(arg)
@@ -147,7 +148,8 @@ data class ParsedArgs(
147148
val filesExceptStdin = fileNames - "-"
148149
return ParseResult.Error(
149150
"Cannot read from stdin and files in same run. Found stdin specifier '-'" +
150-
" and files ${filesExceptStdin.joinToString(", ")} ")
151+
" and files ${filesExceptStdin.joinToString(", ")} "
152+
)
151153
}
152154
} else if (stdinName != null) {
153155
return ParseResult.Error("--stdin-name can only be specified when reading from stdin")
@@ -162,7 +164,8 @@ data class ParsedArgs(
162164
stdinName,
163165
editorConfig,
164166
quiet,
165-
))
167+
)
168+
)
166169
}
167170

168171
private fun parseKeyValueArg(key: String, arg: String): String? {

core/src/main/java/com/facebook/ktfmt/format/Formatter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ object Formatter {
132132
val tokenRangeSet =
133133
kotlinInput.characterRangesToTokenRanges(ImmutableList.of(Range.closedOpen(0, code.length)))
134134
return WhitespaceTombstones.replaceTombstoneWithTrailingWhitespace(
135-
JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet)))
135+
JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet))
136+
)
136137
}
137138

138139
private fun createAstVisitor(options: FormattingOptions, builder: OpsBuilder): PsiElementVisitor {

core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
8484
characterRangeToTokenRange(
8585
characterRange.lowerEndpoint(),
8686
characterRange.upperEndpoint() - characterRange.lowerEndpoint(),
87-
))
87+
)
88+
)
8889
}
8990
return tokenRangeSet
9091
}
@@ -106,7 +107,8 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
106107
"error: invalid length %d, offset + length (%d) is outside the file",
107108
length,
108109
requiredLength,
109-
))
110+
)
111+
)
110112
}
111113
val expandedLength =
112114
when {

core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,10 @@ class KotlinInputAstVisitor(
664664
(receiverExpression as? KtQualifiedExpression)?.selectorExpression
665665
?: receiverExpression
666666
val current = checkNotNull(part.selectorExpression)
667-
if (lastIndexToOpen == 0 &&
668-
shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
667+
if (
668+
lastIndexToOpen == 0 &&
669+
shouldGroupPartWithPrevious(parts, part, index, previous, current)
670+
) {
669671
// this and the previous items should be grouped for better style
670672
// we add another group to open in index 0
671673
groupingInfos[0].groupOpenCount++
@@ -709,21 +711,27 @@ class KotlinInputAstVisitor(
709711
return true
710712
}
711713
// this and the previous part are a package name, type name, or property
712-
if (previous is KtSimpleNameExpression &&
713-
current is KtSimpleNameExpression &&
714-
part is KtDotQualifiedExpression) {
714+
if (
715+
previous is KtSimpleNameExpression &&
716+
current is KtSimpleNameExpression &&
717+
part is KtDotQualifiedExpression
718+
) {
715719
return true
716720
}
717721
// this is `Foo` in `com.facebook.Foo`, so everything before it is a package name
718-
if (current.text.first().isUpperCase() &&
719-
current is KtSimpleNameExpression &&
720-
part is KtDotQualifiedExpression) {
722+
if (
723+
current.text.first().isUpperCase() &&
724+
current is KtSimpleNameExpression &&
725+
part is KtDotQualifiedExpression
726+
) {
721727
return true
722728
}
723729
// this is the `foo()` in `com.facebook.Foo.foo()` or in `Foo.foo()`
724-
if (current is KtCallExpression &&
725-
(previous !is KtCallExpression) &&
726-
previous.text?.firstOrNull()?.isUpperCase() == true) {
730+
if (
731+
current is KtCallExpression &&
732+
(previous !is KtCallExpression) &&
733+
previous.text?.firstOrNull()?.isUpperCase() == true
734+
) {
727735
return true
728736
}
729737
// this is an invocation and the last item, and the previous it not, i.e. `a.b.c()`
@@ -926,10 +934,12 @@ class KotlinInputAstVisitor(
926934
val shouldForceMultiline =
927935
options.preserveLambdaBreaks && hasSourceNewlineInLambdaBody(lambdaExpression)
928936

929-
if (!shouldForceMultiline &&
930-
expressionStatements.size == 1 &&
931-
expressionStatements.first() !is KtReturnExpression &&
932-
!bodyExpression.startsWithComment()) {
937+
if (
938+
!shouldForceMultiline &&
939+
expressionStatements.size == 1 &&
940+
expressionStatements.first() !is KtReturnExpression &&
941+
!bodyExpression.startsWithComment()
942+
) {
933943
visitStatement(expressionStatements[0])
934944
} else {
935945
visitStatements(expressionStatements)
@@ -1304,8 +1314,10 @@ class KotlinInputAstVisitor(
13041314
val operator = expression.operationReference.text
13051315

13061316
visit(baseExpression)
1307-
if (baseExpression is KtPostfixExpression &&
1308-
baseExpression.operationReference.text.last() == operator.first()) {
1317+
if (
1318+
baseExpression is KtPostfixExpression &&
1319+
baseExpression.operationReference.text.last() == operator.first()
1320+
) {
13091321
builder.space()
13101322
}
13111323
builder.token(operator)
@@ -1319,8 +1331,10 @@ class KotlinInputAstVisitor(
13191331
val operator = expression.operationReference.text
13201332

13211333
builder.token(operator)
1322-
if (baseExpression is KtPrefixExpression &&
1323-
operator.last() == baseExpression.operationReference.text.first()) {
1334+
if (
1335+
baseExpression is KtPrefixExpression &&
1336+
operator.last() == baseExpression.operationReference.text.first()
1337+
) {
13241338
builder.space()
13251339
}
13261340
visit(baseExpression)
@@ -1576,9 +1590,11 @@ class KotlinInputAstVisitor(
15761590
carry = carry.selectorExpression
15771591
}
15781592
if (carry is KtCallExpression) {
1579-
if (carry.valueArgumentList?.leftParenthesis == null &&
1580-
carry.lambdaArguments.isNotEmpty() &&
1581-
carry.typeArgumentList?.arguments.isNullOrEmpty()) {
1593+
if (
1594+
carry.valueArgumentList?.leftParenthesis == null &&
1595+
carry.lambdaArguments.isNotEmpty() &&
1596+
carry.typeArgumentList?.arguments.isNullOrEmpty()
1597+
) {
15821598
carry = carry.lambdaArguments[0].getArgumentExpression()
15831599
} else {
15841600
return false
@@ -2507,9 +2523,11 @@ class KotlinInputAstVisitor(
25072523
visit(expression.leftHandSide)
25082524
if (!openGroupBeforeLeft) builder.open(ZERO)
25092525
val parent = expression.parent
2510-
if (parent is KtValueArgument ||
2511-
parent is KtParenthesizedExpression ||
2512-
parent is KtContainerNode) {
2526+
if (
2527+
parent is KtValueArgument ||
2528+
parent is KtParenthesizedExpression ||
2529+
parent is KtContainerNode
2530+
) {
25132531
builder.breakOp(Doc.FillMode.UNIFIED, " ", expressionBreakIndent)
25142532
} else {
25152533
builder.space()
@@ -2672,7 +2690,8 @@ class KotlinInputAstVisitor(
26722690
child is PsiComment -> continue
26732691
child is KtScript && importListEmpty -> OpsBuilder.BlankLineWanted.PRESERVE
26742692
else -> OpsBuilder.BlankLineWanted.YES
2675-
})
2693+
}
2694+
)
26762695

26772696
visit(child)
26782697
isFirst = false
@@ -2695,8 +2714,9 @@ class KotlinInputAstVisitor(
26952714
builder.blankLineWanted(OpsBuilder.BlankLineWanted.PRESERVE)
26962715
} else if (lastChildIsContextReceiver) {
26972716
builder.blankLineWanted(OpsBuilder.BlankLineWanted.NO)
2698-
} else if (child !is PsiComment &&
2699-
(childGetsBlankLineBefore || lastChildHadBlankLineBefore)) {
2717+
} else if (
2718+
child !is PsiComment && (childGetsBlankLineBefore || lastChildHadBlankLineBefore)
2719+
) {
27002720
builder.blankLineWanted(OpsBuilder.BlankLineWanted.YES)
27012721
}
27022722
visit(child)

core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ class MultilineStringFormatter(val continuationIndentSize: Int) {
150150
expression.getParentOfType<KtStringTemplateExpression>(strict = false) !=
151151
null,
152152
commentsBetweenStringAndTrimCall = comments,
153-
))
153+
)
154+
)
154155
}
155156
}
156-
})
157+
}
158+
)
157159
return strings.toList()
158160
}
159161
}

core/src/main/java/com/facebook/ktfmt/format/ParseError.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiElement
2121

2222
class ParseError(val errorDescription: String, val lineColumn: LineColumn) :
2323
IllegalArgumentException(
24-
"${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription") {
24+
"${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription"
25+
) {
2526

2627
constructor(
2728
errorDescription: String,

core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ object RedundantElementManager {
6868
redundantImportDetector.takeReferenceExpression(expression)
6969
super.visitReferenceExpression(expression)
7070
}
71-
})
71+
}
72+
)
7273

7374
val elementsToRemove =
7475
redundantSemicolonDetector.getRedundantSemicolonElements() +
@@ -105,7 +106,8 @@ object RedundantElementManager {
105106
trailingCommaSuggestor.takeElement(element)
106107
super.visitElement(element)
107108
}
108-
})
109+
}
110+
)
109111

110112
val suggestionElements = trailingCommaSuggestor.getTrailingCommaSuggestions()
111113
if (suggestionElements.isEmpty()) return code

core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ internal class RedundantSemicolonDetector {
6969

7070
val prevConcreteSibling = element.getPrevSiblingIgnoringWhitespaceAndComments()
7171
if (parent is KtClassBody) {
72-
if (prevConcreteSibling is KtObjectDeclaration &&
73-
prevConcreteSibling.isCompanion() &&
74-
prevConcreteSibling.nameIdentifier == null &&
75-
!isLastConcreteChild(element)) {
72+
if (
73+
prevConcreteSibling is KtObjectDeclaration &&
74+
prevConcreteSibling.isCompanion() &&
75+
prevConcreteSibling.nameIdentifier == null &&
76+
!isLastConcreteChild(element)
77+
) {
7678
// Example: `class Foo { companion object ; init { } }`
7779
return false
7880
}
@@ -83,9 +85,11 @@ internal class RedundantSemicolonDetector {
8385
}
8486

8587
val prevLeaf = element.prevLeaf(false)
86-
if ((prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
87-
prevLeaf is KtContainerNodeForControlStructureBody &&
88-
prevLeaf.text.isEmpty()) {
88+
if (
89+
(prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
90+
prevLeaf is KtContainerNodeForControlStructureBody &&
91+
prevLeaf.text.isEmpty()
92+
) {
8993
return false
9094
}
9195

core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class KDocCommentsHelper(private val lineSeparator: String, private val maxLineL
5454
convertMarkup = false
5555
nestedListIndent = 4
5656
optimal = false // Use greedy line breaking for predictability.
57-
})
57+
}
58+
)
5859

5960
override fun rewrite(tok: Tok, maxWidth: Int, column0: Int): String {
6061
if (!tok.isComment) {

0 commit comments

Comments
 (0)