Skip to content

Commit 7b1ffd0

Browse files
committed
Re-format
1 parent 343def4 commit 7b1ffd0

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
@@ -133,7 +133,8 @@ object Formatter {
133133
val tokenRangeSet =
134134
kotlinInput.characterRangesToTokenRanges(ImmutableList.of(Range.closedOpen(0, code.length)))
135135
return WhitespaceTombstones.replaceTombstoneWithTrailingWhitespace(
136-
JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet)))
136+
JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet))
137+
)
137138
}
138139

139140
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
@@ -665,8 +665,10 @@ class KotlinInputAstVisitor(
665665
(receiverExpression as? KtQualifiedExpression)?.selectorExpression
666666
?: receiverExpression
667667
val current = checkNotNull(part.selectorExpression)
668-
if (lastIndexToOpen == 0 &&
669-
shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
668+
if (
669+
lastIndexToOpen == 0 &&
670+
shouldGroupPartWithPrevious(parts, part, index, previous, current)
671+
) {
670672
// this and the previous items should be grouped for better style
671673
// we add another group to open in index 0
672674
groupingInfos[0].groupOpenCount++
@@ -710,21 +712,27 @@ class KotlinInputAstVisitor(
710712
return true
711713
}
712714
// this and the previous part are a package name, type name, or property
713-
if (previous is KtSimpleNameExpression &&
714-
current is KtSimpleNameExpression &&
715-
part is KtDotQualifiedExpression) {
715+
if (
716+
previous is KtSimpleNameExpression &&
717+
current is KtSimpleNameExpression &&
718+
part is KtDotQualifiedExpression
719+
) {
716720
return true
717721
}
718722
// this is `Foo` in `com.facebook.Foo`, so everything before it is a package name
719-
if (current.text.first().isUpperCase() &&
720-
current is KtSimpleNameExpression &&
721-
part is KtDotQualifiedExpression) {
723+
if (
724+
current.text.first().isUpperCase() &&
725+
current is KtSimpleNameExpression &&
726+
part is KtDotQualifiedExpression
727+
) {
722728
return true
723729
}
724730
// this is the `foo()` in `com.facebook.Foo.foo()` or in `Foo.foo()`
725-
if (current is KtCallExpression &&
726-
(previous !is KtCallExpression) &&
727-
previous.text?.firstOrNull()?.isUpperCase() == true) {
731+
if (
732+
current is KtCallExpression &&
733+
(previous !is KtCallExpression) &&
734+
previous.text?.firstOrNull()?.isUpperCase() == true
735+
) {
728736
return true
729737
}
730738
// this is an invocation and the last item, and the previous it not, i.e. `a.b.c()`
@@ -927,10 +935,12 @@ class KotlinInputAstVisitor(
927935
val shouldForceMultiline =
928936
options.preserveLambdaBreaks && hasSourceNewlineInLambdaBody(lambdaExpression)
929937

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

13071317
visit(baseExpression)
1308-
if (baseExpression is KtPostfixExpression &&
1309-
baseExpression.operationReference.text.last() == operator.first()) {
1318+
if (
1319+
baseExpression is KtPostfixExpression &&
1320+
baseExpression.operationReference.text.last() == operator.first()
1321+
) {
13101322
builder.space()
13111323
}
13121324
builder.token(operator)
@@ -1320,8 +1332,10 @@ class KotlinInputAstVisitor(
13201332
val operator = expression.operationReference.text
13211333

13221334
builder.token(operator)
1323-
if (baseExpression is KtPrefixExpression &&
1324-
operator.last() == baseExpression.operationReference.text.first()) {
1335+
if (
1336+
baseExpression is KtPrefixExpression &&
1337+
operator.last() == baseExpression.operationReference.text.first()
1338+
) {
13251339
builder.space()
13261340
}
13271341
visit(baseExpression)
@@ -1577,9 +1591,11 @@ class KotlinInputAstVisitor(
15771591
carry = carry.selectorExpression
15781592
}
15791593
if (carry is KtCallExpression) {
1580-
if (carry.valueArgumentList?.leftParenthesis == null &&
1581-
carry.lambdaArguments.isNotEmpty() &&
1582-
carry.typeArgumentList?.arguments.isNullOrEmpty()) {
1594+
if (
1595+
carry.valueArgumentList?.leftParenthesis == null &&
1596+
carry.lambdaArguments.isNotEmpty() &&
1597+
carry.typeArgumentList?.arguments.isNullOrEmpty()
1598+
) {
15831599
carry = carry.lambdaArguments[0].getArgumentExpression()
15841600
} else {
15851601
return false
@@ -2510,9 +2526,11 @@ class KotlinInputAstVisitor(
25102526
visit(expression.leftHandSide)
25112527
if (!openGroupBeforeLeft) builder.open(ZERO)
25122528
val parent = expression.parent
2513-
if (parent is KtValueArgument ||
2514-
parent is KtParenthesizedExpression ||
2515-
parent is KtContainerNode) {
2529+
if (
2530+
parent is KtValueArgument ||
2531+
parent is KtParenthesizedExpression ||
2532+
parent is KtContainerNode
2533+
) {
25162534
builder.breakOp(Doc.FillMode.UNIFIED, " ", expressionBreakIndent)
25172535
} else {
25182536
builder.space()
@@ -2675,7 +2693,8 @@ class KotlinInputAstVisitor(
26752693
child is PsiComment -> continue
26762694
child is KtScript && importListEmpty -> OpsBuilder.BlankLineWanted.PRESERVE
26772695
else -> OpsBuilder.BlankLineWanted.YES
2678-
})
2696+
}
2697+
)
26792698

26802699
visit(child)
26812700
isFirst = false
@@ -2698,8 +2717,9 @@ class KotlinInputAstVisitor(
26982717
builder.blankLineWanted(OpsBuilder.BlankLineWanted.PRESERVE)
26992718
} else if (lastChildIsContextReceiver) {
27002719
builder.blankLineWanted(OpsBuilder.BlankLineWanted.NO)
2701-
} else if (child !is PsiComment &&
2702-
(childGetsBlankLineBefore || lastChildHadBlankLineBefore)) {
2720+
} else if (
2721+
child !is PsiComment && (childGetsBlankLineBefore || lastChildHadBlankLineBefore)
2722+
) {
27032723
builder.blankLineWanted(OpsBuilder.BlankLineWanted.YES)
27042724
}
27052725
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
@@ -152,10 +152,12 @@ class MultilineStringFormatter(val continuationIndentSize: Int) {
152152
expression.getParentOfType<KtStringTemplateExpression>(strict = false) !=
153153
null,
154154
commentsBetweenStringAndTrimCall = comments,
155-
))
155+
)
156+
)
156157
}
157158
}
158-
})
159+
}
160+
)
159161
return strings.toList()
160162
}
161163
}

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
@@ -69,7 +69,8 @@ object RedundantElementManager {
6969
redundantImportDetector.takeReferenceExpression(expression)
7070
super.visitReferenceExpression(expression)
7171
}
72-
})
72+
}
73+
)
7374

7475
val elementsToRemove =
7576
redundantSemicolonDetector.getRedundantSemicolonElements() +
@@ -106,7 +107,8 @@ object RedundantElementManager {
106107
trailingCommaSuggestor.takeElement(element)
107108
super.visitElement(element)
108109
}
109-
})
110+
}
111+
)
110112

111113
val suggestionElements = trailingCommaSuggestor.getTrailingCommaSuggestions()
112114
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)