From 3ac5477ae920ad02a0c947fd6f452f7f711c8b33 Mon Sep 17 00:00:00 2001
From: Zac Sweers
Date: Sat, 13 Jun 2026 09:44:10 -0400
Subject: [PATCH 1/5] Run missing formatting
---
.../main/java/com/facebook/ktfmt/cli/Main.kt | 3 +-
.../java/com/facebook/ktfmt/cli/ParsedArgs.kt | 9 +-
.../com/facebook/ktfmt/format/Formatter.kt | 3 +-
.../com/facebook/ktfmt/format/KotlinInput.kt | 6 +-
.../ktfmt/format/KotlinInputAstVisitor.kt | 76 +-
.../ktfmt/format/MultilineStringFormatter.kt | 6 +-
.../com/facebook/ktfmt/format/ParseError.kt | 3 +-
.../ktfmt/format/RedundantElementManager.kt | 6 +-
.../format/RedundantSemicolonDetector.kt | 18 +-
.../facebook/ktfmt/kdoc/KDocCommentsHelper.kt | 3 +-
.../ktfmt/kdoc/KDocFormattingOptions.kt | 3 +-
.../java/com/facebook/ktfmt/kdoc/Paragraph.kt | 42 +-
.../ktfmt/kdoc/ParagraphListBuilder.kt | 149 ++--
.../java/com/facebook/ktfmt/kdoc/Table.kt | 22 +-
.../ktfmt/cli/EditorConfigResolverTest.kt | 48 +-
.../com/facebook/ktfmt/cli/ParsedArgsTest.kt | 9 +-
.../facebook/ktfmt/format/FormatterTest.kt | 735 ++++++------------
.../format/GoogleStyleFormatterKtTest.kt | 3 +-
.../format/MultilineStringFormatterTest.kt | 124 ++-
.../ktfmt/format/WhitespaceTombstonesTest.kt | 6 +-
.../com/facebook/ktfmt/kdoc/DokkaVerifier.kt | 7 +-
.../com/facebook/ktfmt/testutil/KtfmtTruth.kt | 12 +-
22 files changed, 465 insertions(+), 828 deletions(-)
diff --git a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
index f026772b..8f86798b 100644
--- a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
+++ b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
@@ -73,8 +73,7 @@ class Main(
result.addAll(
File(arg).walkTopDown().filter {
it.isFile && (it.extension == "kt" || it.extension == "kts")
- }
- )
+ })
}
return result
}
diff --git a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
index 949dd57a..bd0e524a 100644
--- a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
+++ b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
@@ -134,8 +134,7 @@ data class ParsedArgs(
stdinName =
parseKeyValueArg("--stdin-name", arg)
?: return ParseResult.Error(
- "Found option '${arg}', expected '${"--stdin-name"}='"
- )
+ "Found option '${arg}', expected '${"--stdin-name"}='")
arg.startsWith("--") -> return ParseResult.Error("Unexpected option: $arg")
arg.startsWith("@") -> return ParseResult.Error("Unexpected option: $arg")
else -> fileNames.add(arg)
@@ -148,8 +147,7 @@ data class ParsedArgs(
val filesExceptStdin = fileNames - "-"
return ParseResult.Error(
"Cannot read from stdin and files in same run. Found stdin specifier '-'" +
- " and files ${filesExceptStdin.joinToString(", ")} "
- )
+ " and files ${filesExceptStdin.joinToString(", ")} ")
}
} else if (stdinName != null) {
return ParseResult.Error("--stdin-name can only be specified when reading from stdin")
@@ -164,8 +162,7 @@ data class ParsedArgs(
stdinName,
editorConfig,
quiet,
- )
- )
+ ))
}
private fun parseKeyValueArg(key: String, arg: String): String? {
diff --git a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
index 24864b5a..11f140f2 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
@@ -133,8 +133,7 @@ object Formatter {
val tokenRangeSet =
kotlinInput.characterRangesToTokenRanges(ImmutableList.of(Range.closedOpen(0, code.length)))
return WhitespaceTombstones.replaceTombstoneWithTrailingWhitespace(
- JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet))
- )
+ JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet)))
}
private fun createAstVisitor(options: FormattingOptions, builder: OpsBuilder): PsiElementVisitor {
diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
index b559ef1a..49565b70 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
@@ -84,8 +84,7 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
characterRangeToTokenRange(
characterRange.lowerEndpoint(),
characterRange.upperEndpoint() - characterRange.lowerEndpoint(),
- )
- )
+ ))
}
return tokenRangeSet
}
@@ -107,8 +106,7 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
"error: invalid length %d, offset + length (%d) is outside the file",
length,
requiredLength,
- )
- )
+ ))
}
val expandedLength =
when {
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 ed52de53..c6e1d32e 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
@@ -665,10 +665,8 @@ class KotlinInputAstVisitor(
(receiverExpression as? KtQualifiedExpression)?.selectorExpression
?: receiverExpression
val current = checkNotNull(part.selectorExpression)
- if (
- lastIndexToOpen == 0 &&
- shouldGroupPartWithPrevious(parts, part, index, previous, current)
- ) {
+ if (lastIndexToOpen == 0 &&
+ shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
// this and the previous items should be grouped for better style
// we add another group to open in index 0
groupingInfos[0].groupOpenCount++
@@ -712,27 +710,21 @@ class KotlinInputAstVisitor(
return true
}
// this and the previous part are a package name, type name, or property
- if (
- previous is KtSimpleNameExpression &&
- current is KtSimpleNameExpression &&
- part is KtDotQualifiedExpression
- ) {
+ if (previous is KtSimpleNameExpression &&
+ current is KtSimpleNameExpression &&
+ part is KtDotQualifiedExpression) {
return true
}
// this is `Foo` in `com.facebook.Foo`, so everything before it is a package name
- if (
- current.text.first().isUpperCase() &&
- current is KtSimpleNameExpression &&
- part is KtDotQualifiedExpression
- ) {
+ if (current.text.first().isUpperCase() &&
+ current is KtSimpleNameExpression &&
+ part is KtDotQualifiedExpression) {
return true
}
// this is the `foo()` in `com.facebook.Foo.foo()` or in `Foo.foo()`
- if (
- current is KtCallExpression &&
- (previous !is KtCallExpression) &&
- previous.text?.firstOrNull()?.isUpperCase() == true
- ) {
+ if (current is KtCallExpression &&
+ (previous !is KtCallExpression) &&
+ previous.text?.firstOrNull()?.isUpperCase() == true) {
return true
}
// this is an invocation and the last item, and the previous it not, i.e. `a.b.c()`
@@ -935,12 +927,10 @@ class KotlinInputAstVisitor(
val shouldForceMultiline =
options.preserveLambdaBreaks && hasSourceNewlineInLambdaBody(lambdaExpression)
- if (
- !shouldForceMultiline &&
- expressionStatements.size == 1 &&
- expressionStatements.first() !is KtReturnExpression &&
- !bodyExpression.startsWithComment()
- ) {
+ if (!shouldForceMultiline &&
+ expressionStatements.size == 1 &&
+ expressionStatements.first() !is KtReturnExpression &&
+ !bodyExpression.startsWithComment()) {
visitStatement(expressionStatements[0])
} else {
visitStatements(expressionStatements)
@@ -1315,10 +1305,8 @@ class KotlinInputAstVisitor(
val operator = expression.operationReference.text
visit(baseExpression)
- if (
- baseExpression is KtPostfixExpression &&
- baseExpression.operationReference.text.last() == operator.first()
- ) {
+ if (baseExpression is KtPostfixExpression &&
+ baseExpression.operationReference.text.last() == operator.first()) {
builder.space()
}
builder.token(operator)
@@ -1332,10 +1320,8 @@ class KotlinInputAstVisitor(
val operator = expression.operationReference.text
builder.token(operator)
- if (
- baseExpression is KtPrefixExpression &&
- operator.last() == baseExpression.operationReference.text.first()
- ) {
+ if (baseExpression is KtPrefixExpression &&
+ operator.last() == baseExpression.operationReference.text.first()) {
builder.space()
}
visit(baseExpression)
@@ -1591,11 +1577,9 @@ class KotlinInputAstVisitor(
carry = carry.selectorExpression
}
if (carry is KtCallExpression) {
- if (
- carry.valueArgumentList?.leftParenthesis == null &&
- carry.lambdaArguments.isNotEmpty() &&
- carry.typeArgumentList?.arguments.isNullOrEmpty()
- ) {
+ if (carry.valueArgumentList?.leftParenthesis == null &&
+ carry.lambdaArguments.isNotEmpty() &&
+ carry.typeArgumentList?.arguments.isNullOrEmpty()) {
carry = carry.lambdaArguments[0].getArgumentExpression()
} else {
return false
@@ -2526,11 +2510,9 @@ class KotlinInputAstVisitor(
visit(expression.leftHandSide)
if (!openGroupBeforeLeft) builder.open(ZERO)
val parent = expression.parent
- if (
- parent is KtValueArgument ||
- parent is KtParenthesizedExpression ||
- parent is KtContainerNode
- ) {
+ if (parent is KtValueArgument ||
+ parent is KtParenthesizedExpression ||
+ parent is KtContainerNode) {
builder.breakOp(Doc.FillMode.UNIFIED, " ", expressionBreakIndent)
} else {
builder.space()
@@ -2693,8 +2675,7 @@ class KotlinInputAstVisitor(
child is PsiComment -> continue
child is KtScript && importListEmpty -> OpsBuilder.BlankLineWanted.PRESERVE
else -> OpsBuilder.BlankLineWanted.YES
- }
- )
+ })
visit(child)
isFirst = false
@@ -2717,9 +2698,8 @@ class KotlinInputAstVisitor(
builder.blankLineWanted(OpsBuilder.BlankLineWanted.PRESERVE)
} else if (lastChildIsContextReceiver) {
builder.blankLineWanted(OpsBuilder.BlankLineWanted.NO)
- } else if (
- child !is PsiComment && (childGetsBlankLineBefore || lastChildHadBlankLineBefore)
- ) {
+ } else if (child !is PsiComment &&
+ (childGetsBlankLineBefore || lastChildHadBlankLineBefore)) {
builder.blankLineWanted(OpsBuilder.BlankLineWanted.YES)
}
visit(child)
diff --git a/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt b/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
index b9079b1b..653c8f02 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
@@ -152,12 +152,10 @@ class MultilineStringFormatter(val continuationIndentSize: Int) {
expression.getParentOfType(strict = false) !=
null,
commentsBetweenStringAndTrimCall = comments,
- )
- )
+ ))
}
}
- }
- )
+ })
return strings.toList()
}
}
diff --git a/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt b/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
index daaba540..6c19b524 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
@@ -21,8 +21,7 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiElement
class ParseError(val errorDescription: String, val lineColumn: LineColumn) :
IllegalArgumentException(
- "${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription"
- ) {
+ "${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription") {
constructor(
errorDescription: String,
diff --git a/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt b/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
index d05863d8..3930a8c9 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
@@ -69,8 +69,7 @@ object RedundantElementManager {
redundantImportDetector.takeReferenceExpression(expression)
super.visitReferenceExpression(expression)
}
- }
- )
+ })
val elementsToRemove =
redundantSemicolonDetector.getRedundantSemicolonElements() +
@@ -107,8 +106,7 @@ object RedundantElementManager {
trailingCommaSuggestor.takeElement(element)
super.visitElement(element)
}
- }
- )
+ })
val suggestionElements = trailingCommaSuggestor.getTrailingCommaSuggestions()
if (suggestionElements.isEmpty()) return code
diff --git a/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt b/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
index d4c54cee..76a2d058 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
@@ -69,12 +69,10 @@ internal class RedundantSemicolonDetector {
val prevConcreteSibling = element.getPrevSiblingIgnoringWhitespaceAndComments()
if (parent is KtClassBody) {
- if (
- prevConcreteSibling is KtObjectDeclaration &&
- prevConcreteSibling.isCompanion() &&
- prevConcreteSibling.nameIdentifier == null &&
- !isLastConcreteChild(element)
- ) {
+ if (prevConcreteSibling is KtObjectDeclaration &&
+ prevConcreteSibling.isCompanion() &&
+ prevConcreteSibling.nameIdentifier == null &&
+ !isLastConcreteChild(element)) {
// Example: `class Foo { companion object ; init { } }`
return false
}
@@ -85,11 +83,9 @@ internal class RedundantSemicolonDetector {
}
val prevLeaf = element.prevLeaf(false)
- if (
- (prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
- prevLeaf is KtContainerNodeForControlStructureBody &&
- prevLeaf.text.isEmpty()
- ) {
+ if ((prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
+ prevLeaf is KtContainerNodeForControlStructureBody &&
+ prevLeaf.text.isEmpty()) {
return false
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
index e04bd118..313efb52 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
@@ -54,8 +54,7 @@ class KDocCommentsHelper(private val lineSeparator: String, private val maxLineL
convertMarkup = false
nestedListIndent = 4
optimal = false // Use greedy line breaking for predictability.
- }
- )
+ })
override fun rewrite(tok: Tok, maxWidth: Int, column0: Int): String {
if (!tok.isComment) {
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
index 2784d1d0..91034910 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
@@ -69,8 +69,7 @@ class KDocFormattingOptions(
if (value < 3) {
error(
"Nested list indent must be at least 3; if list items are only indented 2 spaces they " +
- "will not be rendered as list items"
- )
+ "will not be rendered as list items")
}
field = value
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
index 2a0337ad..6ca1b8dc 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
@@ -249,12 +249,10 @@ class Paragraph(private val task: FormattingTask) {
sb.append(']')
i = end + 1
continue
- } else if (
- s.startsWith("@link", i, true)
- // @linkplain is similar to @link, but kdoc does *not* render a [symbol]
- // into a {@linkplain} in HTML, so converting these would change the output.
- && !s.startsWith("@linkplain", i, true)
- ) {
+ } else if (s.startsWith("@link", i, true)
+ // @linkplain is similar to @link, but kdoc does *not* render a [symbol]
+ // into a {@linkplain} in HTML, so converting these would change the output.
+ && !s.startsWith("@linkplain", i, true)) {
// {@link} or {@linkplain}
sb.append('[')
var curr = i + 5
@@ -346,13 +344,11 @@ class Paragraph(private val task: FormattingTask) {
}
private fun reflow(words: List, lineWidth: Int, hangingIndentSize: Int): List {
- if (
- options.alternate ||
- !options.optimal ||
- (hanging && hangingIndentSize > 0) ||
- // An unbreakable long word may make other lines shorter and won't look good
- words.any { it.length > lineWidth }
- ) {
+ if (options.alternate ||
+ !options.optimal ||
+ (hanging && hangingIndentSize > 0) ||
+ // An unbreakable long word may make other lines shorter and won't look good
+ words.any { it.length > lineWidth }) {
// Switch to greedy if explicitly turned on, and for hanging indent
// paragraphs, since the current implementation doesn't have support
// for a different maximum length on the first line from the rest
@@ -390,10 +386,8 @@ class Paragraph(private val task: FormattingTask) {
val newLines = reflowOptimal(lineWidth - hangingIndentSize, words.subList(0, lastWord))
if (newLines.size < lines.size) {
val newLongestLine = newLines.maxOf(maxLine)
- if (
- newLongestLine > longestLine &&
- newLines.subList(0, newLines.size - 1).any { it.length > longestLine }
- ) {
+ if (newLongestLine > longestLine &&
+ newLines.subList(0, newLines.size - 1).any { it.length > longestLine }) {
return newLines +
reflowGreedy(
lineWidth - hangingIndentSize,
@@ -422,14 +416,12 @@ class Paragraph(private val task: FormattingTask) {
// Can we start a new line with this without interpreting it in a special
// way?
- if (
- word.startsWith("#") ||
- word.startsWith("```") ||
- word.isDirectiveMarker() ||
- word.startsWith("@") || // interpreted as a tag
- word.isTodo() ||
- word.startsWith(">")
- ) {
+ if (word.startsWith("#") ||
+ word.startsWith("```") ||
+ word.isDirectiveMarker() ||
+ word.startsWith("@") || // interpreted as a tag
+ word.isTodo() ||
+ word.startsWith(">")) {
return false
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
index 24f10075..2e3f34fe 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
@@ -163,9 +163,8 @@ class ParagraphListBuilder(
while (j < lines.size) {
val l = lines[j]
val lineWithIndentation = lineContent(l)
- if (
- lineWithIndentation.contains("```") && lineWithIndentation.trimStart().startsWith("```")
- ) {
+ if (lineWithIndentation.contains("```") &&
+ lineWithIndentation.trimStart().startsWith("```")) {
// Don't convert tags if we already have nested ``` content; that will lead to
// trouble
allowCustomize = false
@@ -248,50 +247,42 @@ class ParagraphListBuilder(
return paragraph
}
- if (
- lineWithIndentation.startsWith(" ") && // markdown preformatted text
- (i == 1 || lineContent(lines[i - 2]).isBlank()) && // we've already ++'ed i above
- // Make sure it's not just deeply indented inside a different block
- (paragraph.prev == null ||
- lineWithIndentation.length - lineWithoutIndentation.length >=
- checkNotNull(paragraph.prev).originalIndent + 4)
- ) {
+ if (lineWithIndentation.startsWith(" ") && // markdown preformatted text
+ (i == 1 || lineContent(lines[i - 2]).isBlank()) && // we've already ++'ed i above
+ // Make sure it's not just deeply indented inside a different block
+ (paragraph.prev == null ||
+ lineWithIndentation.length - lineWithoutIndentation.length >=
+ checkNotNull(paragraph.prev).originalIndent + 4)) {
i = addPreformatted(i - 1, includeEnd = false, expectClose = false) { !it.startsWith(" ") }
- } else if (
- lineWithoutIndentation.startsWith("-") &&
- lineWithoutIndentation.containsOnly('-', '|', ' ')
- ) {
+ } else if (lineWithoutIndentation.startsWith("-") &&
+ lineWithoutIndentation.containsOnly('-', '|', ' ')) {
val paragraph = newParagraph(i - 1)
appendText(lineWithoutIndentation)
newParagraph(i).block = true
// Dividers must be surrounded by blank lines
- if (
- lineWithIndentation.isLine() &&
- (i < 2 || lineContent(lines[i - 2]).isBlank()) &&
- (i > lines.size - 1 || lineContent(lines[i]).isBlank())
- ) {
+ if (lineWithIndentation.isLine() &&
+ (i < 2 || lineContent(lines[i - 2]).isBlank()) &&
+ (i > lines.size - 1 || lineContent(lines[i]).isBlank())) {
paragraph.separator = true
}
- } else if (
- lineWithoutIndentation.startsWith("=") && lineWithoutIndentation.containsOnly('=', ' ')
- ) {
+ } else if (lineWithoutIndentation.startsWith("=") &&
+ lineWithoutIndentation.containsOnly('=', ' ')) {
// Header
// ======
newParagraph(i - 1).block = true
appendText(lineWithoutIndentation)
newParagraph(i).block = true
- } else if (
- lineWithoutIndentation.startsWith("#")
- // "## X" is a header, "##X" is not
- && lineWithoutIndentation.firstOrNull { it != '#' }?.equals(' ') == true
- ) { // not isHeader() because is handled separately
+ } else if (lineWithoutIndentation.startsWith("#")
+ // "## X" is a header, "##X" is not
+ &&
+ lineWithoutIndentation.firstOrNull { it != '#' }?.equals(' ') ==
+ true) { // not isHeader() because is handled separately
// ## Header
newParagraph(i - 1).block = true
appendText(lineWithoutIndentation)
newParagraph(i).block = true
- } else if (
- lineWithoutIndentation.startsWith("*") && lineWithoutIndentation.containsOnly('*', ' ')
- ) {
+ } else if (lineWithoutIndentation.startsWith("*") &&
+ lineWithoutIndentation.containsOnly('*', ' ')) {
// Horizontal rule:
// *******
// * * *
@@ -365,13 +356,11 @@ class ParagraphListBuilder(
val qTrimmed = qLineContent.trim()
// Check termination conditions
- if (
- qTrimmed.isBlank() ||
- qTrimmed.isKDocTag() ||
- qTrimmed.isTodo() ||
- qTrimmed.isDirectiveMarker() ||
- qTrimmed.isHeader()
- ) {
+ if (qTrimmed.isBlank() ||
+ qTrimmed.isKDocTag() ||
+ qTrimmed.isTodo() ||
+ qTrimmed.isDirectiveMarker() ||
+ qTrimmed.isHeader()) {
break
}
@@ -419,9 +408,8 @@ class ParagraphListBuilder(
}
newParagraph(i)
- } else if (
- lineWithoutIndentation.equals("", true) || lineWithoutIndentation.equals("", true)
- ) {
+ } else if (lineWithoutIndentation.equals("
", true))
- ) {
+ if (lineWithoutIndentation.equals(" with a blank line
paragraph.separate = true
@@ -594,17 +574,13 @@ class ParagraphListBuilder(
newParagraph(i).block = true
}
continue
- } else if (
- lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true)
- ) {
- if (
- lineWithoutIndentation.startsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true)) {
+ if (lineWithoutIndentation.startsWith("", true) || text.startsWith("", true))
- ) {
+ return if (options.convertMarkup &&
+ (text.startsWith("", true) || text.startsWith("
", true))) {
paragraph.separate = true
text.substring(text.indexOf('>') + 1).trim()
} else {
@@ -647,10 +622,8 @@ class ParagraphListBuilder(
}
private fun convertSuffix(trimmedPrefix: String): String {
- return if (
- options.convertMarkup &&
- (trimmedPrefix.endsWith("", true) || (trimmedPrefix.endsWith("
", true)))
- ) {
+ return if (options.convertMarkup &&
+ (trimmedPrefix.endsWith("()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `list of superclasses over multiple lines`() =
@@ -2306,8 +2257,7 @@ class FormatterTest {
"""
|@AnnWithArrayValue(1, 2, 3) class C
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `method modifiers`() =
@@ -2315,8 +2265,7 @@ class FormatterTest {
"""
|override internal fun f() {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `class modifiers`() =
@@ -2330,8 +2279,7 @@ class FormatterTest {
|
|open class Foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `kdoc comments`() {
@@ -2384,8 +2332,7 @@ class FormatterTest {
| */
|fun foo() {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `formatting kdoc doesn't add p HTML tags`() =
@@ -2400,8 +2347,7 @@ class FormatterTest {
| * On the other hand, we respect existing tags, and don't remove them.
| */
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `formatting kdoc preserves lists`() =
@@ -2415,8 +2361,7 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `formatting kdoc lists with line wraps breaks and merges correctly`() {
@@ -2459,8 +2404,7 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `formatting kdoc preserves numbered`() =
@@ -2474,8 +2418,7 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `formatting kdoc with markdown errors`() =
@@ -2484,8 +2427,7 @@ class FormatterTest {
|/** \[ */
|fun markdownError() = Unit
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `return statement with value`() =
@@ -2495,8 +2437,7 @@ class FormatterTest {
| return 4
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `return statement without value`() =
@@ -2507,8 +2448,7 @@ class FormatterTest {
| return
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `return expression without value`() =
@@ -2518,8 +2458,7 @@ class FormatterTest {
| print(b ?: return)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `if statement without else`() =
@@ -2531,8 +2470,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `if statement with else`() =
@@ -2546,8 +2484,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `if expression with else`() =
@@ -2563,8 +2500,7 @@ class FormatterTest {
| return if (b) 1 else 2
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `if expression with break before else`() =
@@ -2620,8 +2556,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `if expression with multiline condition`() =
@@ -2683,8 +2618,7 @@ class FormatterTest {
"""
|val x = 2
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `a few variations of constructors`() =
@@ -2779,8 +2713,7 @@ class FormatterTest {
| val offspring2: List
|) {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `a constructor with keyword and many arguments over breaking to next line`() =
@@ -2795,8 +2728,7 @@ class FormatterTest {
| val foo: String
|) {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `a constructor with many arguments over multiple lines`() =
@@ -2828,8 +2760,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `a secondary constructor with many arguments over multiple lines`() =
@@ -2907,8 +2838,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle calling super constructor in secondary constructor`() =
@@ -2918,8 +2848,7 @@ class FormatterTest {
| internal constructor(number: Int) : super(number) {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle super statement with with type argument`() =
@@ -2931,8 +2860,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle super statement with with label argument`() =
@@ -2949,8 +2877,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `primary constructor without parameters with a KDoc`() =
@@ -2960,8 +2887,7 @@ class FormatterTest {
|/** A comment */
|constructor() {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle objects`() =
@@ -2969,8 +2895,7 @@ class FormatterTest {
"""
|object Foo(n: Int) {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle object expression`() =
@@ -2980,8 +2905,7 @@ class FormatterTest {
| return object : Adapter() {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle object expression in parenthesis`() =
@@ -2991,8 +2915,7 @@ class FormatterTest {
| return (object : Adapter() {})
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle array indexing operator`() =
@@ -3003,8 +2926,7 @@ class FormatterTest {
| b[3, 4]
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `keep array indexing grouped with expression is possible`() =
@@ -3208,8 +3130,7 @@ class FormatterTest {
| .also { _somePropertyWithBackingOne = it }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `array access in middle of chain and end of it behaves similarly`() =
@@ -3249,8 +3170,7 @@ class FormatterTest {
|var x: (@Anno (Int?)) = null
|var x: (@Anno() (Int)?) = null
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `nullable function type`() =
@@ -3258,8 +3178,7 @@ class FormatterTest {
"""
|var listener: ((Boolean) -> Unit)? = null
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `redundant parenthesis in function types`() =
@@ -3269,8 +3188,7 @@ class FormatterTest {
|
|var listener: ((Boolean) -> Unit) = foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle string literals`() =
@@ -3282,8 +3200,7 @@ class FormatterTest {
| println("Hello! ${'$'}{"wor" + "ld"}")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle multiline string literals`() =
@@ -3300,8 +3217,7 @@ class FormatterTest {
| world!${TQ})
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `Trailing whitespaces are preserved in multiline strings`() {
@@ -3339,8 +3255,7 @@ class FormatterTest {
|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|$TQ
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `multiline trimMargin special handling`() {
@@ -3433,8 +3348,7 @@ class FormatterTest {
| .trimIndent()
| )
|"""
- .trimMargin()
- )
+ .trimMargin())
.withOptions(META_FORMAT)
.isEqualTo(
"""
@@ -3461,8 +3375,7 @@ class FormatterTest {
| .trimIndent()
| )
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -3474,8 +3387,7 @@ class FormatterTest {
| |is this the end of the line?$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3484,8 +3396,7 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
assertThatFormatting(
"""
@@ -3494,8 +3405,7 @@ class FormatterTest {
| is this the end of the line?$TQ
| .trimIndent()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3504,8 +3414,7 @@ class FormatterTest {
| $TQ
| .trimIndent()
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -3520,8 +3429,7 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3531,8 +3439,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `properly handles trimMargin that has margin in the first line`() =
@@ -3544,8 +3451,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3555,8 +3461,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handles multiline trim with template expressions inside of it`() {
@@ -3580,8 +3485,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -3602,8 +3506,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -3618,8 +3521,7 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3630,8 +3532,7 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -3645,8 +3546,7 @@ class FormatterTest {
| // This comment should be preserved
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `comments between multiline string and trimIndent are preserved`() =
@@ -3659,8 +3559,7 @@ class FormatterTest {
| // This comment should be preserved
| .trimIndent()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `multiple comments between multiline string and trimMargin are preserved`() =
@@ -3674,8 +3573,7 @@ class FormatterTest {
| // Second comment
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `comment between multiline string and trimMargin is not deleted in string concatenation`() {
@@ -3727,8 +3625,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
assertThatFormatting(
"""
@@ -3750,8 +3647,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin1 =
@@ -3772,8 +3668,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -3788,8 +3683,7 @@ class FormatterTest {
|
| $TQ.trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|val margin =
@@ -3800,8 +3694,7 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `Trailing spaces in a comment are not preserved`() {
@@ -3841,8 +3734,7 @@ class FormatterTest {
|
|class Foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle for loops`() =
@@ -3854,8 +3746,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle for loops with long dot chains`() =
@@ -3934,8 +3825,7 @@ class FormatterTest {
| .methodCall()
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle where formatting, fits into single line`() =
@@ -3945,8 +3835,7 @@ class FormatterTest {
|
|fun foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle where formatting, full expression breaks into single line`() =
@@ -4169,8 +4058,7 @@ class FormatterTest {
| })
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `Qualified type`() =
@@ -4182,8 +4070,7 @@ class FormatterTest {
| var x: List.Iterator
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle destructuring declaration in for loop`() =
@@ -4193,8 +4080,7 @@ class FormatterTest {
| for ((x, y: Int) in a) {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle function references`() =
@@ -4238,8 +4124,7 @@ class FormatterTest {
|
|class `more spaces`
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle annotations with arguments`() =
@@ -4255,8 +4140,7 @@ class FormatterTest {
| //
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `no newlines after annotations if entire expr fits in one line`() =
@@ -4352,8 +4236,7 @@ class FormatterTest {
"""
|val callback: (@Anno List<@JvmSuppressWildcards String>) -> Unit = foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on type parameters`() =
@@ -4363,8 +4246,7 @@ class FormatterTest {
| inline fun <@Anno reified @Anno X, @Anno reified @Anno Y> bar() {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on type constraints`() =
@@ -4374,8 +4256,7 @@ class FormatterTest {
| fun bar() where U : @Anno Kip, U : @Anno Qux {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on type arguments`() =
@@ -4383,8 +4264,7 @@ class FormatterTest {
"""
|fun foo(x: Foo) {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on destructuring declaration elements`() =
@@ -4392,8 +4272,7 @@ class FormatterTest {
"""
|val x = { (@Anno x, @Anno y) -> x }
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on exceptions`() =
@@ -4407,8 +4286,7 @@ class FormatterTest {
| } catch (@Suppress("GeneralException") e: Exception) {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on return statements`() =
@@ -4419,8 +4297,7 @@ class FormatterTest {
| return map.asMap()
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `Unary prefix expressions`() =
@@ -4452,8 +4329,7 @@ class FormatterTest {
| !--a
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `Unary postfix expressions`() =
@@ -4470,8 +4346,7 @@ class FormatterTest {
| a!! !!
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle wildcard generics`() =
@@ -4482,8 +4357,7 @@ class FormatterTest {
| val p: Pair<*, *>
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle intersection generics`() =
@@ -4494,8 +4368,7 @@ class FormatterTest {
| val p = Ctor
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle covariant and contravariant type arguments`() =
@@ -4503,8 +4376,7 @@ class FormatterTest {
"""
|val p: Pair
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle covariant and contravariant type parameters`() =
@@ -4512,8 +4384,7 @@ class FormatterTest {
"""
|class Foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle bounds for type parameters`() =
@@ -4521,8 +4392,7 @@ class FormatterTest {
"""
|class Foo, out S : Any?>
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle compound generic bounds on classes`() =
@@ -4530,8 +4400,7 @@ class FormatterTest {
"""
|class Foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle compound generic bounds on functions`() =
@@ -4539,8 +4408,7 @@ class FormatterTest {
"""
|fun foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle compound generic bounds on properties`() =
@@ -4551,8 +4419,7 @@ class FormatterTest {
| return 2 * sum()
| }
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle compound generic bounds on class with delegate`() =
@@ -4561,8 +4428,7 @@ class FormatterTest {
|class Foo() : Bar by bar
| where T : Qux
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `explicit type on property getter`() =
@@ -4573,8 +4439,7 @@ class FormatterTest {
| get(): Int = 1
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `explicit backing field`() =
@@ -4588,8 +4453,7 @@ class FormatterTest {
| field: MutableList = mutableListOf()
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `explicit backing field without type`() =
@@ -4600,8 +4464,7 @@ class FormatterTest {
| field = 0
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `explicit backing field with private set accessor`() =
@@ -4613,8 +4476,7 @@ class FormatterTest {
| private set
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle method calls with lambda arg only`() =
@@ -4624,8 +4486,7 @@ class FormatterTest {
| val a = g { 1 + 1 }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle method calls value args and a lambda arg`() =
@@ -4635,8 +4496,7 @@ class FormatterTest {
| val a = g(1, 2) { 1 + 1 }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle top level constants`() =
@@ -4661,8 +4521,7 @@ class FormatterTest {
| val b = { x: Int, y: Int -> x + y }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `avoid newline before lambda argument if it is named`() =
@@ -4679,8 +4538,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle labeled this pointer`() =
@@ -4692,8 +4550,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle extension and operator functions`() =
@@ -4701,8 +4558,7 @@ class FormatterTest {
"""
|operator fun Point.component1() = x
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle extension methods with very long names`() =
@@ -4728,8 +4584,7 @@ class FormatterTest {
|val Int.isPrime: Boolean
| get() = runMillerRabinPrimality(this)
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `generic extension property`() =
@@ -4737,8 +4592,7 @@ class FormatterTest {
"""
|val List.twiceSize = 2 * size()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle file annotations`() {
@@ -4754,8 +4608,7 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -4769,8 +4622,7 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -4786,8 +4638,7 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -4802,8 +4653,7 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -4816,8 +4666,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle interface delegation`() =
@@ -4825,8 +4674,7 @@ class FormatterTest {
"""
|class MyList(impl: List) : Collection by impl
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle property delegation`() =
@@ -4834,8 +4682,7 @@ class FormatterTest {
"""
|val a by lazy { 1 + 1 }
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle property delegation with type and breaks`() =
@@ -4877,8 +4724,7 @@ class FormatterTest {
| var httpClient: OkHttpClient
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle parameters with annoations with parameters`() =
@@ -4890,8 +4736,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle lambda types`() =
@@ -4905,8 +4750,7 @@ class FormatterTest {
|
|val listener4: Int.(Int, Boolean) -> Unit
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle unicode in string literals`() =
@@ -4914,8 +4758,7 @@ class FormatterTest {
"""
|val a = "\uD83D\uDC4D"
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle casting`() =
@@ -4928,8 +4771,7 @@ class FormatterTest {
| doIt(o as? Int)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle casting with breaks`() =
@@ -4989,8 +4831,7 @@ class FormatterTest {
| //
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle try, catch and finally`() =
@@ -5006,8 +4847,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle infix methods`() =
@@ -5017,8 +4857,7 @@ class FormatterTest {
| (0 until 100).size
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle while loops`() =
@@ -5030,8 +4869,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle do while loops`() =
@@ -5045,8 +4883,7 @@ class FormatterTest {
| do while (1 < 2)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle break and continue`() =
@@ -5063,8 +4900,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle all kinds of labels and jumps`() =
@@ -5087,8 +4923,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `don't crash on top level statements with semicolons`() {
@@ -5380,8 +5215,7 @@ class FormatterTest {
| a { println("a") }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle multi statement lambdas`() =
@@ -5394,8 +5228,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle multi line one statement lambda`() =
@@ -5423,8 +5256,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `properly break fully qualified nested user types`() =
@@ -5472,8 +5304,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle multi line lambdas with explicit args`() =
@@ -5499,8 +5330,7 @@ class FormatterTest {
| g { (a, b): List, (c, d): List -> a }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle parenthesis in lambda calls for now`() =
@@ -5510,8 +5340,7 @@ class FormatterTest {
| a() { println("a") }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle chaining of calls with lambdas`() =
@@ -5528,8 +5357,7 @@ class FormatterTest {
| .sum
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle break of lambda args per line with indentation`() =
@@ -5674,8 +5502,7 @@ class FormatterTest {
| println(t)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle suspended types`() =
@@ -5689,8 +5516,7 @@ class FormatterTest {
|
|inline fun bar(noinline block: (suspend () -> R)?): (suspend () -> R)?
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle simple enum classes`() =
@@ -5702,8 +5528,7 @@ class FormatterTest {
| FILE_NOT_FOUND,
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle enum class with functions`() =
@@ -5719,8 +5544,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle enum with annotations`() =
@@ -5731,8 +5555,7 @@ class FormatterTest {
| @False @WhatIsTruth FALSE,
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle enum constructor calls`() =
@@ -5743,8 +5566,7 @@ class FormatterTest {
| FALSE("false", false),
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle enum entries with body`() =
@@ -5757,8 +5579,7 @@ class FormatterTest {
| FISH(false) {},
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle empty enum`() =
@@ -5766,8 +5587,7 @@ class FormatterTest {
"""
|enum class YTho {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `expect enum class`() =
@@ -5775,8 +5595,7 @@ class FormatterTest {
"""
|expect enum class ExpectedEnum
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `enum without trailing comma`() =
@@ -5786,8 +5605,7 @@ class FormatterTest {
| ONE
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `enum comma and semicolon`() {
@@ -5797,16 +5615,14 @@ class FormatterTest {
| ONE,;
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|enum class Highlander {
| ONE,
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -5817,14 +5633,12 @@ class FormatterTest {
| ;
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|enum class Empty {}
|"""
- .trimMargin()
- )
+ .trimMargin())
assertThatFormatting(
"""
@@ -5834,14 +5648,12 @@ class FormatterTest {
| ;
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|enum class Empty {}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -5856,8 +5668,7 @@ class FormatterTest {
| fun f() {}
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `semicolon is removed from empty enum`() {
@@ -5930,8 +5741,7 @@ class FormatterTest {
| foo3(options = *args)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle typealias`() =
@@ -5957,8 +5767,7 @@ class FormatterTest {
|
|val dyn: dynamic = 1
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle class expression with generics`() =
@@ -5968,8 +5777,7 @@ class FormatterTest {
| println(Array::class.java)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `ParseError contains correct line and column numbers`() {
@@ -6024,8 +5832,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations on function types`() =
@@ -6049,8 +5856,7 @@ class FormatterTest {
| (x) -> Unit)
|) {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle annotations with use-site targets`() =
@@ -6062,8 +5868,7 @@ class FormatterTest {
| @set:Magic(name = "Jane") var field: String
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle annotations mixed with keywords since we cannot reorder them for now`() =
@@ -6075,8 +5880,7 @@ class FormatterTest {
|
|@Magic(1) public final class Foo
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle annotations more`() =
@@ -6153,8 +5957,7 @@ class FormatterTest {
| add(10)
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotated class declarations`() =
@@ -6169,8 +5972,7 @@ class FormatterTest {
|@Anno("param")
|class F
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle type arguments in annotations`() =
@@ -6178,8 +5980,7 @@ class FormatterTest {
"""
|@TypeParceler() class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle one line KDoc`() =
@@ -6188,8 +5989,7 @@ class FormatterTest {
|/** Hi, I am a one line kdoc */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with Link`() =
@@ -6198,8 +5998,7 @@ class FormatterTest {
|/** This links to [AnotherClass] */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with paragraphs`() =
@@ -6212,8 +6011,7 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with blocks`() =
@@ -6227,8 +6025,7 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with code examples`() =
@@ -6252,8 +6049,7 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with tagged code examples`() =
@@ -6268,8 +6064,7 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle stray code markers in lines and produce stable output`() {
@@ -6336,8 +6131,7 @@ class FormatterTest {
|/** Doc line with a reference to [AnotherClass] in the middle of a sentence */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with links one after another`() =
@@ -6346,8 +6140,7 @@ class FormatterTest {
|/** Here are some links [AnotherClass] [AnotherClass2] */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `don't add spaces after links in Kdoc`() =
@@ -6356,8 +6149,7 @@ class FormatterTest {
|/** Here are some links [AnotherClass][AnotherClass2]hello */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `don't remove spaces after links in Kdoc`() =
@@ -6366,8 +6158,7 @@ class FormatterTest {
|/** Please see [onNext] (which has more details) */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `link anchor in KDoc are preserved`() =
@@ -6376,8 +6167,7 @@ class FormatterTest {
|/** [link anchor](the URL for the link anchor goes here) */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `don't add spaces between links in KDoc (because they're actually references)`() =
@@ -6389,8 +6179,7 @@ class FormatterTest {
|/** The final produced value may have [size][ByteString.size] < [bufferSize]. */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `collapse spaces after links in KDoc`() {
@@ -6450,8 +6239,7 @@ class FormatterTest {
|/** There are many [FooObject]s. */
|class MyClass {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle KDoc with multiple separated param tags, breaking and merging lines and missing asterisk`() {
@@ -6552,8 +6340,7 @@ class FormatterTest {
|
|/* this is the first comment */
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `preserve LF, CRLF and CR line endings`() {
@@ -7013,8 +6800,7 @@ class FormatterTest {
|const val SOME_CONST = foo.a
|val SOME_STR = bar.a
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|import com.example.bar
@@ -7023,8 +6809,7 @@ class FormatterTest {
|const val SOME_CONST = foo.a
|val SOME_STR = bar.a
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -7034,14 +6819,12 @@ class FormatterTest {
|
|fun f() {}
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|fun f() {}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `at most one newline between any adjacent top-level elements`() =
@@ -7070,8 +6853,7 @@ class FormatterTest {
|
|val x = Bar()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|import com.Bar
@@ -7089,8 +6871,7 @@ class FormatterTest {
|
|val x = Bar()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `at least one newline between any adjacent top-level elements, unless it's a property`() =
@@ -7105,8 +6886,7 @@ class FormatterTest {
|val x = Foo()
|val x = Bar()
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|import com.Bar
@@ -7123,8 +6903,7 @@ class FormatterTest {
|val x = Foo()
|val x = Bar()
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `handle array of annotations with field prefix`() {
@@ -7190,8 +6969,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
// Regression test against https://github.com/facebook/ktfmt/issues/557
@@ -7227,8 +7005,7 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `lambda with optional arrow`() =
@@ -7241,8 +7018,7 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `lambda missing optional arrow`() =
@@ -7255,8 +7031,7 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `lambda with only comments`() {
@@ -7277,8 +7052,7 @@ class FormatterTest {
|}
|private val g: () -> Unit = { /* no-op */ }
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -7327,8 +7101,7 @@ class FormatterTest {
|
|private val d: () -> Unit = { TODO("implement me") }
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `lambda block with comments and statements mix`() =
@@ -7354,8 +7127,7 @@ class FormatterTest {
|
|private val e: (String, Int) -> Unit = { _, i -> foo(i) /* do nothing ... */ }
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `lambda block with comments and with statements have same formatting treatment`() =
@@ -7385,8 +7157,7 @@ class FormatterTest {
| TODO("implement me")
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `last parameter with comment and with statements have same formatting treatment`() {
@@ -7409,8 +7180,7 @@ class FormatterTest {
|private val c = firstCall().prop.call(param) { /* no-op */ }
|private val C = firstCall().prop.call(param) { TODO("implement me") }
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -8389,8 +8159,7 @@ class FormatterTest {
| @Anno1 /* comment */ @Anno2 f(1) as Int
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `annotations for expressions 2`() {
@@ -8780,8 +8549,7 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `trailing comment after function top-level`() {
@@ -8794,8 +8562,7 @@ class FormatterTest {
|
|// End of file
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -8804,8 +8571,7 @@ class FormatterTest {
|
|// End of file
|"""
- .trimMargin()
- )
+ .trimMargin())
assertFormatted(
"""
@@ -8823,8 +8589,7 @@ class FormatterTest {
| return
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -8893,8 +8658,7 @@ class FormatterTest {
| fun foo(): Unit
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
.isEqualTo(
"""
|enum class Foo {
@@ -8903,8 +8667,7 @@ class FormatterTest {
| fun foo(): Unit
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
}
@Test
@@ -9198,8 +8961,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(code)
}
@@ -9223,8 +8985,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(code)
}
@@ -9254,8 +9015,7 @@ class FormatterTest {
preserveLambdaBreaks = false,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(expected)
}
@@ -9281,8 +9041,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(code)
}
@@ -9308,8 +9067,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(code)
}
@@ -9338,8 +9096,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(expected)
}
@@ -9361,8 +9118,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(code)
}
@@ -9396,8 +9152,7 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- )
- )
+ ))
.isEqualTo(expected)
}
diff --git a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
index 1afd4a32..262f5236 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
@@ -1335,8 +1335,7 @@ class GoogleStyleFormatterKtTest {
| doItTwice()
|}
|"""
- .trimMargin()
- )
+ .trimMargin())
@Test
fun `comma separated lists, no automatic trailing break after lambda params`() =
diff --git a/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
index 7943a923..0e7d30d9 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
@@ -32,29 +32,28 @@ class MultilineStringFormatterTest {
" |line2",
" $TQ",
" .trimMargin()",
- )
- ) {
- assertThat(usesTrimMargin).isTrue()
- assertThat(indentationSuffix).isEqualTo("|")
- assertThat(isDollarString).isFalse()
- assertThat(indentCount).isEqualTo(0)
- assertThat(lines).hasSize(5)
- assertThat(lines)
- .containsExactly(
- TQ,
- " |line1",
- " |line2",
- " $TQ",
- " .trimMargin()",
- )
- .inOrder()
- assertThat(lineStart).isEqualTo(0)
- assertThat(lineEnd).isEqualTo(4)
- assertThat(lastStringLineIndex).isEqualTo(3)
- assertThat(openStringOffset).isEqualTo(0)
- assertThat(trimMethodCallOffset).isEqualTo(42)
- assertThat(isNestedMultiline).isFalse()
- }
+ )) {
+ assertThat(usesTrimMargin).isTrue()
+ assertThat(indentationSuffix).isEqualTo("|")
+ assertThat(isDollarString).isFalse()
+ assertThat(indentCount).isEqualTo(0)
+ assertThat(lines).hasSize(5)
+ assertThat(lines)
+ .containsExactly(
+ TQ,
+ " |line1",
+ " |line2",
+ " $TQ",
+ " .trimMargin()",
+ )
+ .inOrder()
+ assertThat(lineStart).isEqualTo(0)
+ assertThat(lineEnd).isEqualTo(4)
+ assertThat(lastStringLineIndex).isEqualTo(3)
+ assertThat(openStringOffset).isEqualTo(0)
+ assertThat(trimMethodCallOffset).isEqualTo(42)
+ assertThat(isNestedMultiline).isFalse()
+ }
with(
multilineTrimmedStringFromLines(
@@ -63,28 +62,27 @@ class MultilineStringFormatterTest {
" line1 |",
" |line2",
" $TQ.trimIndent()",
- )
- ) {
- assertThat(usesTrimMargin).isFalse()
- assertThat(indentationSuffix).isEqualTo("")
- assertThat(isDollarString).isTrue()
- assertThat(indentCount).isEqualTo(2)
- assertThat(lines).hasSize(4)
- assertThat(lines)
- .containsExactly(
- " $$$TQ",
- " line1 |",
- " |line2",
- " $TQ.trimIndent()",
- )
- .inOrder()
- assertThat(lineStart).isEqualTo(1)
- assertThat(lineEnd).isEqualTo(4)
- assertThat(lastStringLineIndex).isEqualTo(3)
- assertThat(openStringOffset).isEqualTo(10)
- assertThat(trimMethodCallOffset).isEqualTo(46)
- assertThat(isNestedMultiline).isFalse()
- }
+ )) {
+ assertThat(usesTrimMargin).isFalse()
+ assertThat(indentationSuffix).isEqualTo("")
+ assertThat(isDollarString).isTrue()
+ assertThat(indentCount).isEqualTo(2)
+ assertThat(lines).hasSize(4)
+ assertThat(lines)
+ .containsExactly(
+ " $$$TQ",
+ " line1 |",
+ " |line2",
+ " $TQ.trimIndent()",
+ )
+ .inOrder()
+ assertThat(lineStart).isEqualTo(1)
+ assertThat(lineEnd).isEqualTo(4)
+ assertThat(lastStringLineIndex).isEqualTo(3)
+ assertThat(openStringOffset).isEqualTo(10)
+ assertThat(trimMethodCallOffset).isEqualTo(46)
+ assertThat(isNestedMultiline).isFalse()
+ }
}
@Test
@@ -112,8 +110,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isFalse()
// dollar string without dollar template expression
@@ -124,8 +121,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isFalse()
// simple string with template expression
@@ -136,8 +132,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isTrue()
// dollar string with template expression
@@ -148,8 +143,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isTrue()
// simple string with multiline template expression
@@ -163,8 +157,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isTrue()
// dollar string with multiline template expression
@@ -178,8 +171,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression()
- )
+ .hasTemplateExpression())
.isTrue()
}
@@ -193,8 +185,7 @@ class MultilineStringFormatterTest {
" |line3",
" $TQ.trimMargin()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
"line1",
"line2",
@@ -210,8 +201,7 @@ class MultilineStringFormatterTest {
" line3",
" |$TQ.trimMargin()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
" line1",
" line2",
@@ -232,8 +222,7 @@ class MultilineStringFormatterTest {
"",
" $TQ.trimIndent()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
"line1",
" line2",
@@ -252,8 +241,7 @@ class MultilineStringFormatterTest {
" $TQ",
" .trimIndent()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
"line1",
" line2",
@@ -273,8 +261,7 @@ class MultilineStringFormatterTest {
" $TQ",
" .trimMargin()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
"content",
"line1",
@@ -289,8 +276,7 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .getStringContent()
- )
+ .getStringContent())
.containsExactly(
"content",
"line1",
diff --git a/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt b/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
index d2b423e7..79ce6ce8 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
@@ -39,11 +39,9 @@ class WhitespaceTombstonesTest {
.isEqualTo(" sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh")
assertThat(WhitespaceTombstones.replaceTrailingWhitespaceWithTombstone(" sdfl \n skdjfh "))
.isEqualTo(
- " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}"
- )
+ " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}")
assertThat(WhitespaceTombstones.replaceTrailingWhitespaceWithTombstone(" sdfl \n\n skdjfh "))
.isEqualTo(
- " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}"
- )
+ " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}")
}
}
diff --git a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt b/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
index 5b19cf55..76fe54d2 100644
--- a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
+++ b/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
@@ -92,10 +92,9 @@ class DokkaVerifier(private val tempFolder: File) {
";" // instead of File.pathSeparator as would have been reasonable (e.g. : on Unix)
val path =
listOf(analysis, base, compiler, intellij, coroutines, html, freemarker).joinToString(
- pathSeparator
- ) {
- it.path
- }
+ pathSeparator) {
+ it.path
+ }
args.add(path)
args.add("-sourceSet")
args.add("-src $src") // (nested parameter within -sourceSet)
diff --git a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt b/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
index 60a585aa..299630df 100644
--- a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
+++ b/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
@@ -57,16 +57,14 @@ fun assertFormatted(
if (deduceMaxWidth) {
if (!isFirstLineAMaxWidthMarker) {
throw RuntimeException(
- "When deduceMaxWidth is true the first line needs to be all dashes only (i.e. ---)"
- )
+ "When deduceMaxWidth is true the first line needs to be all dashes only (i.e. ---)")
}
deducedCode = code.substring(code.indexOf('\n') + 1)
maxWidth = first.length
} else {
if (isFirstLineAMaxWidthMarker) {
throw RuntimeException(
- "deduceMaxWidth is false, please remove the first dashes only line from the code (i.e. ---)"
- )
+ "deduceMaxWidth is false, please remove the first dashes only line from the code (i.e. ---)")
}
}
assertThatFormatting(deducedCode)
@@ -106,8 +104,7 @@ class FormattedCodeSubject(metadata: FailureMetadata, private val code: String)
expectedFormatting
.lines()
.map { if (it.endsWith(" ")) "[$it]" else it }
- .joinToString("\n")
- )
+ .joinToString("\n"))
}
val actualFormatting: String
try {
@@ -123,8 +120,7 @@ class FormattedCodeSubject(metadata: FailureMetadata, private val code: String)
println("#".repeat(20))
println(
"Need more information about the break operations? " +
- "Run test with assertion with \"FormattingOptions(debuggingPrintOpsAfterFormatting = true)\""
- )
+ "Run test with assertion with \"FormattingOptions(debuggingPrintOpsAfterFormatting = true)\"")
}
} catch (e: Error) {
reportError(code)
From 343def43d9f0e3fd14207c093a36ac6001e2f54c Mon Sep 17 00:00:00 2001
From: Zac Sweers
Date: Sat, 13 Jun 2026 15:33:34 -0400
Subject: [PATCH 2/5] Switch to simple in-repo format
---
build.gradle.kts | 78 +++++++++++++++++++++++++++++-
core/build.gradle.kts | 12 -----
gradle/libs.versions.toml | 2 -
ktfmt_idea_plugin/build.gradle.kts | 7 ---
online_formatter/build.gradle.kts | 7 ---
5 files changed, 77 insertions(+), 29 deletions(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index d9555cdc..758b53d2 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -14,12 +14,19 @@
* limitations under the License.
*/
+import org.gradle.api.attributes.Bundling
+import org.gradle.api.attributes.Category
+import org.gradle.api.attributes.LibraryElements
+import org.gradle.api.attributes.Usage
+import org.gradle.api.attributes.java.TargetJvmEnvironment
+import org.gradle.api.file.FileCollection
+import org.gradle.process.CommandLineArgumentProvider
+
plugins {
alias(libs.plugins.dokka) apply false
alias(libs.plugins.dokka.javadoc) apply false
alias(libs.plugins.intelliJPlatform) apply false
alias(libs.plugins.kotlin) apply false
- alias(libs.plugins.ktfmt) apply false
alias(libs.plugins.nexusPublish)
alias(libs.plugins.shadowJar) apply false
}
@@ -28,6 +35,75 @@ version = providers.gradleProperty("ktfmt.version").get()
tasks.wrapper { distributionType = Wrapper.DistributionType.ALL }
+repositories {
+ mavenCentral()
+}
+
+val ktfmtCliDependencies = configurations.dependencyScope("ktfmtCliDependencies")
+val ktfmtCliClasspath =
+ configurations.resolvable("ktfmtCliClasspath") {
+ extendsFrom(ktfmtCliDependencies.get())
+ attributes {
+ attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
+ attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
+ attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
+ attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
+ attribute(
+ TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
+ objects.named(TargetJvmEnvironment.STANDARD_JVM),
+ )
+ }
+ }
+
+dependencies { add(ktfmtCliDependencies.name, project(":ktfmt")) }
+
+val ktfmtFiles =
+ fileTree(rootDir) {
+ include("**/*.kt")
+ include("**/*.kts")
+ exclude("**/build/**")
+ }
+
+class KtfmtArgumentsProvider(
+ @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) val files: FileCollection,
+ @get:Input val check: Boolean,
+) : CommandLineArgumentProvider {
+ override fun asArguments(): Iterable = buildList {
+ add("--quiet")
+ if (check) {
+ add("--dry-run")
+ add("--set-exit-if-changed")
+ }
+ addAll(files.files.sorted().map { it.path })
+ }
+}
+
+fun JavaExec.configureKtfmtRun(files: FileCollection, check: Boolean) {
+ group = if (check) "verification" else "formatting"
+ classpath = ktfmtCliClasspath.get()
+ mainClass.set("com.facebook.ktfmt.cli.Main")
+ argumentProviders.add(KtfmtArgumentsProvider(files, check))
+ onlyIf { files.files.isNotEmpty() }
+}
+
+val ktfmtCheck =
+ tasks.register("ktfmtCheck") {
+ group = "verification"
+ description = "Run Ktfmt formatter validation"
+ configureKtfmtRun(ktfmtFiles, check = true)
+ }
+
+val ktfmtFormat =
+ tasks.register("ktfmtFormat") {
+ group = "formatting"
+ description = "Run Ktfmt formatter"
+ configureKtfmtRun(ktfmtFiles, check = false)
+ }
+
+subprojects {
+ tasks.named { it == "check" }.configureEach { dependsOn(rootProject.tasks.named("ktfmtCheck")) }
+}
+
nexusPublishing {
repositories {
sonatype {
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 32bd429c..ed762350 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -15,7 +15,6 @@
*/
import com.facebook.ktfmt.GenerateKtfmtFileTask
-import com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
@@ -23,7 +22,6 @@ plugins {
kotlin("jvm")
alias(libs.plugins.dokka)
alias(libs.plugins.dokka.javadoc)
- alias(libs.plugins.ktfmt)
alias(libs.plugins.shadowJar)
id("maven-publish")
id("signing")
@@ -111,16 +109,6 @@ kotlin {
}
}
-ktfmt {
- trailingCommaManagementStrategy.set(
- com.ncorti.ktfmt.gradle.TrailingCommaManagementStrategy.ONLY_ADD
- )
-}
-
-tasks.named("compileKotlin") { setMustRunAfter(emptyList()) }
-
-tasks.withType().configureEach { setMustRunAfter(listOf(tasks.named("jar"))) }
-
group = "com.facebook"
version = rootProject.version
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index f0052dbc..ada8fbd0 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -14,7 +14,6 @@ org-ec4j-core = "1.2.0"
# plugins
gradlePlugin-dokka = "2.2.0"
gradlePlugin-intelliJPlatform = "2.6.0"
-gradlePlugin-ktfmt = "0.26.0"
gradlePlugin-nexusPublish = "2.0.0"
gradlePlugin-shadowJar = "9.0.2"
@@ -39,6 +38,5 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "gradlePlugin-dokka" }
dokka-javadoc = { id = "org.jetbrains.dokka-javadoc", version.ref = "gradlePlugin-dokka" }
intelliJPlatform = { id = "org.jetbrains.intellij.platform", version.ref = "gradlePlugin-intelliJPlatform" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
-ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "gradlePlugin-ktfmt" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "gradlePlugin-nexusPublish" }
shadowJar = { id = "com.gradleup.shadow", version.ref = "gradlePlugin-shadowJar" }
diff --git a/ktfmt_idea_plugin/build.gradle.kts b/ktfmt_idea_plugin/build.gradle.kts
index c51e41e2..cf7b954a 100644
--- a/ktfmt_idea_plugin/build.gradle.kts
+++ b/ktfmt_idea_plugin/build.gradle.kts
@@ -19,7 +19,6 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType.IntellijIdeaC
plugins {
java
alias(libs.plugins.kotlin)
- alias(libs.plugins.ktfmt)
alias(libs.plugins.intelliJPlatform)
}
@@ -51,12 +50,6 @@ dependencies {
implementation(project(":ktfmt"))
}
-ktfmt {
- trailingCommaManagementStrategy.set(
- com.ncorti.ktfmt.gradle.TrailingCommaManagementStrategy.ONLY_ADD
- )
-}
-
intellijPlatform {
projectName.set("ktfmt_idea_plugin")
diff --git a/online_formatter/build.gradle.kts b/online_formatter/build.gradle.kts
index e22538a3..4eacc6de 100644
--- a/online_formatter/build.gradle.kts
+++ b/online_formatter/build.gradle.kts
@@ -16,7 +16,6 @@
plugins {
kotlin("jvm")
- alias(libs.plugins.ktfmt)
}
repositories {
@@ -39,12 +38,6 @@ kotlin {
jvmToolchain(javaVersion.toInt())
}
-ktfmt {
- trailingCommaManagementStrategy.set(
- com.ncorti.ktfmt.gradle.TrailingCommaManagementStrategy.ONLY_ADD
- )
-}
-
tasks {
test { useJUnit() }
From 7b1ffd0a62571c8302520fecd60ef670516a35cd Mon Sep 17 00:00:00 2001
From: Zac Sweers
Date: Sat, 13 Jun 2026 15:33:42 -0400
Subject: [PATCH 3/5] Re-format
---
.../main/java/com/facebook/ktfmt/cli/Main.kt | 3 +-
.../java/com/facebook/ktfmt/cli/ParsedArgs.kt | 9 +-
.../com/facebook/ktfmt/format/Formatter.kt | 3 +-
.../com/facebook/ktfmt/format/KotlinInput.kt | 6 +-
.../ktfmt/format/KotlinInputAstVisitor.kt | 76 +-
.../ktfmt/format/MultilineStringFormatter.kt | 6 +-
.../com/facebook/ktfmt/format/ParseError.kt | 3 +-
.../ktfmt/format/RedundantElementManager.kt | 6 +-
.../format/RedundantSemicolonDetector.kt | 18 +-
.../facebook/ktfmt/kdoc/KDocCommentsHelper.kt | 3 +-
.../ktfmt/kdoc/KDocFormattingOptions.kt | 3 +-
.../java/com/facebook/ktfmt/kdoc/Paragraph.kt | 42 +-
.../ktfmt/kdoc/ParagraphListBuilder.kt | 149 ++--
.../java/com/facebook/ktfmt/kdoc/Table.kt | 22 +-
.../ktfmt/cli/EditorConfigResolverTest.kt | 48 +-
.../com/facebook/ktfmt/cli/ParsedArgsTest.kt | 9 +-
.../facebook/ktfmt/format/FormatterTest.kt | 735 ++++++++++++------
.../format/GoogleStyleFormatterKtTest.kt | 3 +-
.../format/MultilineStringFormatterTest.kt | 124 +--
.../ktfmt/format/WhitespaceTombstonesTest.kt | 6 +-
.../com/facebook/ktfmt/kdoc/DokkaVerifier.kt | 7 +-
.../com/facebook/ktfmt/testutil/KtfmtTruth.kt | 12 +-
22 files changed, 828 insertions(+), 465 deletions(-)
diff --git a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
index 8f86798b..f026772b 100644
--- a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
+++ b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt
@@ -73,7 +73,8 @@ class Main(
result.addAll(
File(arg).walkTopDown().filter {
it.isFile && (it.extension == "kt" || it.extension == "kts")
- })
+ }
+ )
}
return result
}
diff --git a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
index bd0e524a..949dd57a 100644
--- a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
+++ b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
@@ -134,7 +134,8 @@ data class ParsedArgs(
stdinName =
parseKeyValueArg("--stdin-name", arg)
?: return ParseResult.Error(
- "Found option '${arg}', expected '${"--stdin-name"}='")
+ "Found option '${arg}', expected '${"--stdin-name"}='"
+ )
arg.startsWith("--") -> return ParseResult.Error("Unexpected option: $arg")
arg.startsWith("@") -> return ParseResult.Error("Unexpected option: $arg")
else -> fileNames.add(arg)
@@ -147,7 +148,8 @@ data class ParsedArgs(
val filesExceptStdin = fileNames - "-"
return ParseResult.Error(
"Cannot read from stdin and files in same run. Found stdin specifier '-'" +
- " and files ${filesExceptStdin.joinToString(", ")} ")
+ " and files ${filesExceptStdin.joinToString(", ")} "
+ )
}
} else if (stdinName != null) {
return ParseResult.Error("--stdin-name can only be specified when reading from stdin")
@@ -162,7 +164,8 @@ data class ParsedArgs(
stdinName,
editorConfig,
quiet,
- ))
+ )
+ )
}
private fun parseKeyValueArg(key: String, arg: String): String? {
diff --git a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
index 11f140f2..24864b5a 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
@@ -133,7 +133,8 @@ object Formatter {
val tokenRangeSet =
kotlinInput.characterRangesToTokenRanges(ImmutableList.of(Range.closedOpen(0, code.length)))
return WhitespaceTombstones.replaceTombstoneWithTrailingWhitespace(
- JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet)))
+ JavaOutput.applyReplacements(code, javaOutput.getFormatReplacements(tokenRangeSet))
+ )
}
private fun createAstVisitor(options: FormattingOptions, builder: OpsBuilder): PsiElementVisitor {
diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
index 49565b70..b559ef1a 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
@@ -84,7 +84,8 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
characterRangeToTokenRange(
characterRange.lowerEndpoint(),
characterRange.upperEndpoint() - characterRange.lowerEndpoint(),
- ))
+ )
+ )
}
return tokenRangeSet
}
@@ -106,7 +107,8 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
"error: invalid length %d, offset + length (%d) is outside the file",
length,
requiredLength,
- ))
+ )
+ )
}
val expandedLength =
when {
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 c6e1d32e..ed52de53 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt
@@ -665,8 +665,10 @@ class KotlinInputAstVisitor(
(receiverExpression as? KtQualifiedExpression)?.selectorExpression
?: receiverExpression
val current = checkNotNull(part.selectorExpression)
- if (lastIndexToOpen == 0 &&
- shouldGroupPartWithPrevious(parts, part, index, previous, current)) {
+ if (
+ lastIndexToOpen == 0 &&
+ shouldGroupPartWithPrevious(parts, part, index, previous, current)
+ ) {
// this and the previous items should be grouped for better style
// we add another group to open in index 0
groupingInfos[0].groupOpenCount++
@@ -710,21 +712,27 @@ class KotlinInputAstVisitor(
return true
}
// this and the previous part are a package name, type name, or property
- if (previous is KtSimpleNameExpression &&
- current is KtSimpleNameExpression &&
- part is KtDotQualifiedExpression) {
+ if (
+ previous is KtSimpleNameExpression &&
+ current is KtSimpleNameExpression &&
+ part is KtDotQualifiedExpression
+ ) {
return true
}
// this is `Foo` in `com.facebook.Foo`, so everything before it is a package name
- if (current.text.first().isUpperCase() &&
- current is KtSimpleNameExpression &&
- part is KtDotQualifiedExpression) {
+ if (
+ current.text.first().isUpperCase() &&
+ current is KtSimpleNameExpression &&
+ part is KtDotQualifiedExpression
+ ) {
return true
}
// this is the `foo()` in `com.facebook.Foo.foo()` or in `Foo.foo()`
- if (current is KtCallExpression &&
- (previous !is KtCallExpression) &&
- previous.text?.firstOrNull()?.isUpperCase() == true) {
+ if (
+ current is KtCallExpression &&
+ (previous !is KtCallExpression) &&
+ previous.text?.firstOrNull()?.isUpperCase() == true
+ ) {
return true
}
// this is an invocation and the last item, and the previous it not, i.e. `a.b.c()`
@@ -927,10 +935,12 @@ class KotlinInputAstVisitor(
val shouldForceMultiline =
options.preserveLambdaBreaks && hasSourceNewlineInLambdaBody(lambdaExpression)
- if (!shouldForceMultiline &&
- expressionStatements.size == 1 &&
- expressionStatements.first() !is KtReturnExpression &&
- !bodyExpression.startsWithComment()) {
+ if (
+ !shouldForceMultiline &&
+ expressionStatements.size == 1 &&
+ expressionStatements.first() !is KtReturnExpression &&
+ !bodyExpression.startsWithComment()
+ ) {
visitStatement(expressionStatements[0])
} else {
visitStatements(expressionStatements)
@@ -1305,8 +1315,10 @@ class KotlinInputAstVisitor(
val operator = expression.operationReference.text
visit(baseExpression)
- if (baseExpression is KtPostfixExpression &&
- baseExpression.operationReference.text.last() == operator.first()) {
+ if (
+ baseExpression is KtPostfixExpression &&
+ baseExpression.operationReference.text.last() == operator.first()
+ ) {
builder.space()
}
builder.token(operator)
@@ -1320,8 +1332,10 @@ class KotlinInputAstVisitor(
val operator = expression.operationReference.text
builder.token(operator)
- if (baseExpression is KtPrefixExpression &&
- operator.last() == baseExpression.operationReference.text.first()) {
+ if (
+ baseExpression is KtPrefixExpression &&
+ operator.last() == baseExpression.operationReference.text.first()
+ ) {
builder.space()
}
visit(baseExpression)
@@ -1577,9 +1591,11 @@ class KotlinInputAstVisitor(
carry = carry.selectorExpression
}
if (carry is KtCallExpression) {
- if (carry.valueArgumentList?.leftParenthesis == null &&
- carry.lambdaArguments.isNotEmpty() &&
- carry.typeArgumentList?.arguments.isNullOrEmpty()) {
+ if (
+ carry.valueArgumentList?.leftParenthesis == null &&
+ carry.lambdaArguments.isNotEmpty() &&
+ carry.typeArgumentList?.arguments.isNullOrEmpty()
+ ) {
carry = carry.lambdaArguments[0].getArgumentExpression()
} else {
return false
@@ -2510,9 +2526,11 @@ class KotlinInputAstVisitor(
visit(expression.leftHandSide)
if (!openGroupBeforeLeft) builder.open(ZERO)
val parent = expression.parent
- if (parent is KtValueArgument ||
- parent is KtParenthesizedExpression ||
- parent is KtContainerNode) {
+ if (
+ parent is KtValueArgument ||
+ parent is KtParenthesizedExpression ||
+ parent is KtContainerNode
+ ) {
builder.breakOp(Doc.FillMode.UNIFIED, " ", expressionBreakIndent)
} else {
builder.space()
@@ -2675,7 +2693,8 @@ class KotlinInputAstVisitor(
child is PsiComment -> continue
child is KtScript && importListEmpty -> OpsBuilder.BlankLineWanted.PRESERVE
else -> OpsBuilder.BlankLineWanted.YES
- })
+ }
+ )
visit(child)
isFirst = false
@@ -2698,8 +2717,9 @@ class KotlinInputAstVisitor(
builder.blankLineWanted(OpsBuilder.BlankLineWanted.PRESERVE)
} else if (lastChildIsContextReceiver) {
builder.blankLineWanted(OpsBuilder.BlankLineWanted.NO)
- } else if (child !is PsiComment &&
- (childGetsBlankLineBefore || lastChildHadBlankLineBefore)) {
+ } else if (
+ child !is PsiComment && (childGetsBlankLineBefore || lastChildHadBlankLineBefore)
+ ) {
builder.blankLineWanted(OpsBuilder.BlankLineWanted.YES)
}
visit(child)
diff --git a/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt b/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
index 653c8f02..b9079b1b 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/MultilineStringFormatter.kt
@@ -152,10 +152,12 @@ class MultilineStringFormatter(val continuationIndentSize: Int) {
expression.getParentOfType(strict = false) !=
null,
commentsBetweenStringAndTrimCall = comments,
- ))
+ )
+ )
}
}
- })
+ }
+ )
return strings.toList()
}
}
diff --git a/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt b/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
index 6c19b524..daaba540 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.com.intellij.psi.PsiElement
class ParseError(val errorDescription: String, val lineColumn: LineColumn) :
IllegalArgumentException(
- "${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription") {
+ "${lineColumn.line + 1}:${lineColumn.column + 1}: error: $errorDescription"
+ ) {
constructor(
errorDescription: String,
diff --git a/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt b/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
index 3930a8c9..d05863d8 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/RedundantElementManager.kt
@@ -69,7 +69,8 @@ object RedundantElementManager {
redundantImportDetector.takeReferenceExpression(expression)
super.visitReferenceExpression(expression)
}
- })
+ }
+ )
val elementsToRemove =
redundantSemicolonDetector.getRedundantSemicolonElements() +
@@ -106,7 +107,8 @@ object RedundantElementManager {
trailingCommaSuggestor.takeElement(element)
super.visitElement(element)
}
- })
+ }
+ )
val suggestionElements = trailingCommaSuggestor.getTrailingCommaSuggestions()
if (suggestionElements.isEmpty()) return code
diff --git a/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt b/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
index 76a2d058..d4c54cee 100644
--- a/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
+++ b/core/src/main/java/com/facebook/ktfmt/format/RedundantSemicolonDetector.kt
@@ -69,10 +69,12 @@ internal class RedundantSemicolonDetector {
val prevConcreteSibling = element.getPrevSiblingIgnoringWhitespaceAndComments()
if (parent is KtClassBody) {
- if (prevConcreteSibling is KtObjectDeclaration &&
- prevConcreteSibling.isCompanion() &&
- prevConcreteSibling.nameIdentifier == null &&
- !isLastConcreteChild(element)) {
+ if (
+ prevConcreteSibling is KtObjectDeclaration &&
+ prevConcreteSibling.isCompanion() &&
+ prevConcreteSibling.nameIdentifier == null &&
+ !isLastConcreteChild(element)
+ ) {
// Example: `class Foo { companion object ; init { } }`
return false
}
@@ -83,9 +85,11 @@ internal class RedundantSemicolonDetector {
}
val prevLeaf = element.prevLeaf(false)
- if ((prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
- prevLeaf is KtContainerNodeForControlStructureBody &&
- prevLeaf.text.isEmpty()) {
+ if (
+ (prevConcreteSibling is KtIfExpression || prevConcreteSibling is KtWhileExpression) &&
+ prevLeaf is KtContainerNodeForControlStructureBody &&
+ prevLeaf.text.isEmpty()
+ ) {
return false
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
index 313efb52..e04bd118 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocCommentsHelper.kt
@@ -54,7 +54,8 @@ class KDocCommentsHelper(private val lineSeparator: String, private val maxLineL
convertMarkup = false
nestedListIndent = 4
optimal = false // Use greedy line breaking for predictability.
- })
+ }
+ )
override fun rewrite(tok: Tok, maxWidth: Int, column0: Int): String {
if (!tok.isComment) {
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
index 91034910..2784d1d0 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormattingOptions.kt
@@ -69,7 +69,8 @@ class KDocFormattingOptions(
if (value < 3) {
error(
"Nested list indent must be at least 3; if list items are only indented 2 spaces they " +
- "will not be rendered as list items")
+ "will not be rendered as list items"
+ )
}
field = value
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
index 6ca1b8dc..2a0337ad 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/Paragraph.kt
@@ -249,10 +249,12 @@ class Paragraph(private val task: FormattingTask) {
sb.append(']')
i = end + 1
continue
- } else if (s.startsWith("@link", i, true)
- // @linkplain is similar to @link, but kdoc does *not* render a [symbol]
- // into a {@linkplain} in HTML, so converting these would change the output.
- && !s.startsWith("@linkplain", i, true)) {
+ } else if (
+ s.startsWith("@link", i, true)
+ // @linkplain is similar to @link, but kdoc does *not* render a [symbol]
+ // into a {@linkplain} in HTML, so converting these would change the output.
+ && !s.startsWith("@linkplain", i, true)
+ ) {
// {@link} or {@linkplain}
sb.append('[')
var curr = i + 5
@@ -344,11 +346,13 @@ class Paragraph(private val task: FormattingTask) {
}
private fun reflow(words: List, lineWidth: Int, hangingIndentSize: Int): List {
- if (options.alternate ||
- !options.optimal ||
- (hanging && hangingIndentSize > 0) ||
- // An unbreakable long word may make other lines shorter and won't look good
- words.any { it.length > lineWidth }) {
+ if (
+ options.alternate ||
+ !options.optimal ||
+ (hanging && hangingIndentSize > 0) ||
+ // An unbreakable long word may make other lines shorter and won't look good
+ words.any { it.length > lineWidth }
+ ) {
// Switch to greedy if explicitly turned on, and for hanging indent
// paragraphs, since the current implementation doesn't have support
// for a different maximum length on the first line from the rest
@@ -386,8 +390,10 @@ class Paragraph(private val task: FormattingTask) {
val newLines = reflowOptimal(lineWidth - hangingIndentSize, words.subList(0, lastWord))
if (newLines.size < lines.size) {
val newLongestLine = newLines.maxOf(maxLine)
- if (newLongestLine > longestLine &&
- newLines.subList(0, newLines.size - 1).any { it.length > longestLine }) {
+ if (
+ newLongestLine > longestLine &&
+ newLines.subList(0, newLines.size - 1).any { it.length > longestLine }
+ ) {
return newLines +
reflowGreedy(
lineWidth - hangingIndentSize,
@@ -416,12 +422,14 @@ class Paragraph(private val task: FormattingTask) {
// Can we start a new line with this without interpreting it in a special
// way?
- if (word.startsWith("#") ||
- word.startsWith("```") ||
- word.isDirectiveMarker() ||
- word.startsWith("@") || // interpreted as a tag
- word.isTodo() ||
- word.startsWith(">")) {
+ if (
+ word.startsWith("#") ||
+ word.startsWith("```") ||
+ word.isDirectiveMarker() ||
+ word.startsWith("@") || // interpreted as a tag
+ word.isTodo() ||
+ word.startsWith(">")
+ ) {
return false
}
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
index 2e3f34fe..24f10075 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/ParagraphListBuilder.kt
@@ -163,8 +163,9 @@ class ParagraphListBuilder(
while (j < lines.size) {
val l = lines[j]
val lineWithIndentation = lineContent(l)
- if (lineWithIndentation.contains("```") &&
- lineWithIndentation.trimStart().startsWith("```")) {
+ if (
+ lineWithIndentation.contains("```") && lineWithIndentation.trimStart().startsWith("```")
+ ) {
// Don't convert tags if we already have nested ``` content; that will lead to
// trouble
allowCustomize = false
@@ -247,42 +248,50 @@ class ParagraphListBuilder(
return paragraph
}
- if (lineWithIndentation.startsWith(" ") && // markdown preformatted text
- (i == 1 || lineContent(lines[i - 2]).isBlank()) && // we've already ++'ed i above
- // Make sure it's not just deeply indented inside a different block
- (paragraph.prev == null ||
- lineWithIndentation.length - lineWithoutIndentation.length >=
- checkNotNull(paragraph.prev).originalIndent + 4)) {
+ if (
+ lineWithIndentation.startsWith(" ") && // markdown preformatted text
+ (i == 1 || lineContent(lines[i - 2]).isBlank()) && // we've already ++'ed i above
+ // Make sure it's not just deeply indented inside a different block
+ (paragraph.prev == null ||
+ lineWithIndentation.length - lineWithoutIndentation.length >=
+ checkNotNull(paragraph.prev).originalIndent + 4)
+ ) {
i = addPreformatted(i - 1, includeEnd = false, expectClose = false) { !it.startsWith(" ") }
- } else if (lineWithoutIndentation.startsWith("-") &&
- lineWithoutIndentation.containsOnly('-', '|', ' ')) {
+ } else if (
+ lineWithoutIndentation.startsWith("-") &&
+ lineWithoutIndentation.containsOnly('-', '|', ' ')
+ ) {
val paragraph = newParagraph(i - 1)
appendText(lineWithoutIndentation)
newParagraph(i).block = true
// Dividers must be surrounded by blank lines
- if (lineWithIndentation.isLine() &&
- (i < 2 || lineContent(lines[i - 2]).isBlank()) &&
- (i > lines.size - 1 || lineContent(lines[i]).isBlank())) {
+ if (
+ lineWithIndentation.isLine() &&
+ (i < 2 || lineContent(lines[i - 2]).isBlank()) &&
+ (i > lines.size - 1 || lineContent(lines[i]).isBlank())
+ ) {
paragraph.separator = true
}
- } else if (lineWithoutIndentation.startsWith("=") &&
- lineWithoutIndentation.containsOnly('=', ' ')) {
+ } else if (
+ lineWithoutIndentation.startsWith("=") && lineWithoutIndentation.containsOnly('=', ' ')
+ ) {
// Header
// ======
newParagraph(i - 1).block = true
appendText(lineWithoutIndentation)
newParagraph(i).block = true
- } else if (lineWithoutIndentation.startsWith("#")
- // "## X" is a header, "##X" is not
- &&
- lineWithoutIndentation.firstOrNull { it != '#' }?.equals(' ') ==
- true) { // not isHeader() because is handled separately
+ } else if (
+ lineWithoutIndentation.startsWith("#")
+ // "## X" is a header, "##X" is not
+ && lineWithoutIndentation.firstOrNull { it != '#' }?.equals(' ') == true
+ ) { // not isHeader() because is handled separately
// ## Header
newParagraph(i - 1).block = true
appendText(lineWithoutIndentation)
newParagraph(i).block = true
- } else if (lineWithoutIndentation.startsWith("*") &&
- lineWithoutIndentation.containsOnly('*', ' ')) {
+ } else if (
+ lineWithoutIndentation.startsWith("*") && lineWithoutIndentation.containsOnly('*', ' ')
+ ) {
// Horizontal rule:
// *******
// * * *
@@ -356,11 +365,13 @@ class ParagraphListBuilder(
val qTrimmed = qLineContent.trim()
// Check termination conditions
- if (qTrimmed.isBlank() ||
- qTrimmed.isKDocTag() ||
- qTrimmed.isTodo() ||
- qTrimmed.isDirectiveMarker() ||
- qTrimmed.isHeader()) {
+ if (
+ qTrimmed.isBlank() ||
+ qTrimmed.isKDocTag() ||
+ qTrimmed.isTodo() ||
+ qTrimmed.isDirectiveMarker() ||
+ qTrimmed.isHeader()
+ ) {
break
}
@@ -408,8 +419,9 @@ class ParagraphListBuilder(
}
newParagraph(i)
- } else if (lineWithoutIndentation.equals("", true) ||
- lineWithoutIndentation.equals("", true)) {
+ } else if (
+ lineWithoutIndentation.equals("
", true))) {
+ if (
+ lineWithoutIndentation.equals("", true) ||
+ lineWithoutIndentation.equals("
", true) ||
+ (options.convertMarkup && lineWithoutIndentation.equals("", true))
+ ) {
if (options.convertMarkup) {
// Replace with a blank line
paragraph.separate = true
@@ -574,13 +594,17 @@ class ParagraphListBuilder(
newParagraph(i).block = true
}
continue
- } else if (lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true) ||
- lineWithoutIndentation.endsWith("", true)) {
- if (lineWithoutIndentation.startsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true) ||
+ lineWithoutIndentation.endsWith("", true)
+ ) {
+ if (
+ lineWithoutIndentation.startsWith("", true) || text.startsWith("", true))) {
+ return if (
+ options.convertMarkup && (text.startsWith("", true) || text.startsWith("
", true))
+ ) {
paragraph.separate = true
text.substring(text.indexOf('>') + 1).trim()
} else {
@@ -622,8 +647,10 @@ class ParagraphListBuilder(
}
private fun convertSuffix(trimmedPrefix: String): String {
- return if (options.convertMarkup &&
- (trimmedPrefix.endsWith("", true) || (trimmedPrefix.endsWith("
", true)))) {
+ return if (
+ options.convertMarkup &&
+ (trimmedPrefix.endsWith("", true) || (trimmedPrefix.endsWith("", true)))
+ ) {
trimmedPrefix.substring(0, trimmedPrefix.length - 4).trimEnd().removeSuffix("*").trimEnd()
} else {
trimmedPrefix
diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/Table.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/Table.kt
index a2289990..31ac2017 100644
--- a/core/src/main/java/com/facebook/ktfmt/kdoc/Table.kt
+++ b/core/src/main/java/com/facebook/ktfmt/kdoc/Table.kt
@@ -155,10 +155,12 @@ class Table(
}
val rowsAndDivider = rows + dividerRow
- if (rowsAndDivider.all { row ->
- val first = row.cells.firstOrNull()
- first != null && first.isBlank()
- }) {
+ if (
+ rowsAndDivider.all { row ->
+ val first = row.cells.firstOrNull()
+ first != null && first.isBlank()
+ }
+ ) {
rowsAndDivider.forEach { if (it.cells.isNotEmpty()) it.cells.removeAt(0) }
}
@@ -212,11 +214,13 @@ class Table(
count++
} else if (c.isWhitespace() || c == ':') {
continue
- } else if (c == '-' &&
- (s.startsWith("--", i) ||
- s.startsWith("-:", i) ||
- (i > 1 && s.startsWith(":-:", i - 2)) ||
- (i > 1 && s.startsWith(":--", i - 2)))) {
+ } else if (
+ c == '-' &&
+ (s.startsWith("--", i) ||
+ s.startsWith("-:", i) ||
+ (i > 1 && s.startsWith(":-:", i - 2)) ||
+ (i > 1 && s.startsWith(":--", i - 2)))
+ ) {
while (i < s.length && s[i] == '-') {
i++
}
diff --git a/core/src/test/java/com/facebook/ktfmt/cli/EditorConfigResolverTest.kt b/core/src/test/java/com/facebook/ktfmt/cli/EditorConfigResolverTest.kt
index 894500fd..70ffbc0d 100644
--- a/core/src/test/java/com/facebook/ktfmt/cli/EditorConfigResolverTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/cli/EditorConfigResolverTest.kt
@@ -64,7 +64,8 @@ class EditorConfigResolverTest {
[*.c]
max_line_length = 80
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -80,7 +81,8 @@ class EditorConfigResolverTest {
[*.kt]
max_line_length = 80
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -96,7 +98,8 @@ class EditorConfigResolverTest {
[*.kt]
max_line_length = off
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -112,7 +115,8 @@ class EditorConfigResolverTest {
[*.kt]
indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -128,7 +132,8 @@ class EditorConfigResolverTest {
[*.kt]
indent_size = tab
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -145,7 +150,8 @@ class EditorConfigResolverTest {
indent_size = tab
tab_width = 8
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -161,7 +167,8 @@ class EditorConfigResolverTest {
[*.kt]
ij_kotlin_indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -178,7 +185,8 @@ class EditorConfigResolverTest {
indent_size = 2
ij_kotlin_indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -194,7 +202,8 @@ class EditorConfigResolverTest {
[*.kt]
ij_continuation_indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -210,7 +219,8 @@ class EditorConfigResolverTest {
[*.kt]
ij_kotlin_continuation_indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -227,7 +237,8 @@ class EditorConfigResolverTest {
ij_continuation_indent_size = 6
ij_kotlin_continuation_indent_size = 3
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -243,7 +254,8 @@ class EditorConfigResolverTest {
[*.kt]
ktfmt_trailing_comma_management_strategy = only_add
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -260,7 +272,8 @@ class EditorConfigResolverTest {
[*.kt]
ktfmt_trailing_comma_management_strategy = whatever
"""
- .trimIndent())
+ .trimIndent()
+ )
val file = root.resolve("src/main/kotlin/Example.kt")
val resolved = EditorConfigResolver.resolveFormattingOptions(file, Formatter.GOOGLE_FORMAT)
@@ -279,7 +292,8 @@ class EditorConfigResolverTest {
[src/**/*.kts]
max_line_length = 120
"""
- .trimIndent())
+ .trimIndent()
+ )
val rootOptions =
Formatter.GOOGLE_FORMAT.copy(
blockIndent = 3,
@@ -295,7 +309,8 @@ class EditorConfigResolverTest {
max_line_length = 200
ktfmt_trailing_comma_management_strategy = only_add
"""
- .trimIndent())
+ .trimIndent()
+ )
val mainOptions =
Formatter.GOOGLE_FORMAT.copy(
maxWidth = 200,
@@ -314,7 +329,8 @@ class EditorConfigResolverTest {
ij_continuation_indent_size = 2
max_line_length = 300
"""
- .trimIndent())
+ .trimIndent()
+ )
val testOptions =
Formatter.GOOGLE_FORMAT.copy(
maxWidth = 300,
diff --git a/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt b/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
index a6652844..72fdf72e 100644
--- a/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
@@ -221,7 +221,8 @@ class ParsedArgsTest {
formattingOptions = Formatter.GOOGLE_FORMAT,
dryRun = true,
setExitIfChanged = true,
- ))
+ )
+ )
}
@Test
@@ -233,7 +234,8 @@ class ParsedArgsTest {
parseResultOk(
fileNames = listOf("File.kt"),
formattingOptions = Formatter.KOTLINLANG_FORMAT,
- ))
+ )
+ )
}
@Test
@@ -268,6 +270,7 @@ class ParsedArgsTest {
stdinName,
editorConfig,
quiet,
- ))
+ )
+ )
}
}
diff --git a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
index 281d1f9e..ee61bb2b 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
@@ -51,7 +51,8 @@ class FormatterTest {
|
|args.forEach { println(File + "-") }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `support script (kts) files with a shebang`() =
@@ -62,7 +63,8 @@ class FormatterTest {
|
|println("Called")
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `call chains`() =
@@ -239,7 +241,8 @@ class FormatterTest {
| val y = 0
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test fun `class without a body nor properties`() = assertFormatted("class Foo\n")
@@ -255,7 +258,8 @@ class FormatterTest {
| fun runIt()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle complex fun interface without body`() =
@@ -277,7 +281,8 @@ class FormatterTest {
| class Bar
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properties and fields with modifiers`() =
@@ -293,7 +298,8 @@ class FormatterTest {
| final var f4 = 0
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properties with multiple modifiers`() =
@@ -303,7 +309,8 @@ class FormatterTest {
| public open inner var f2 = 0
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `spaces around binary operations`() =
@@ -314,7 +321,8 @@ class FormatterTest {
| x + 1
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `breaking long binary operations`() =
@@ -546,7 +554,8 @@ class FormatterTest {
|
|/* Another comment */
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -556,7 +565,8 @@ class FormatterTest {
|
|/* Another comment */
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -567,7 +577,8 @@ class FormatterTest {
|
|/* Another comment */
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -576,7 +587,8 @@ class FormatterTest {
|// Adjacent line comments
|// Don't separate
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -603,7 +615,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properties with line comment above delegate`() =
@@ -629,7 +642,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properties with accessors`() =
@@ -654,7 +668,8 @@ class FormatterTest {
| private set
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properties with accessors and semicolons on same line`() {
@@ -716,7 +731,8 @@ class FormatterTest {
| a === b
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `package names stay in one line`() {
@@ -748,7 +764,8 @@ class FormatterTest {
|
|fun f() = `from doing this`()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `safe dot operator expression`() =
@@ -758,7 +775,8 @@ class FormatterTest {
| node?.name
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `safe dot operator expression with normal`() =
@@ -768,7 +786,8 @@ class FormatterTest {
| node?.name.hello
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `safe dot operator expression chain in expression function`() =
@@ -965,7 +984,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `don't one-line lambdas following argument breaks`() =
@@ -1252,7 +1272,8 @@ class FormatterTest {
|
|val x = `if` { we.`when`(wow) }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `backticks are ignored in import sort order ('as' directory)`() =
@@ -1265,7 +1286,8 @@ class FormatterTest {
|
|val x = `if` { we.`when`(wow) }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `imports are deduplicated`() {
@@ -1560,7 +1582,8 @@ class FormatterTest {
| */
|fun fetchBananas(count: Int)
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -1577,7 +1600,8 @@ class FormatterTest {
| */
|fun fetchBananas(count: Int)
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -1592,7 +1616,8 @@ class FormatterTest {
|import com.example.component4
|import com.example.component5
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `keep operator imports`() =
@@ -1632,7 +1657,8 @@ class FormatterTest {
|import com.example.unaryPlus
|import org.gradle.kotlin.dsl.assign
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `keep unused imports when formatting options has feature turned off`() {
@@ -1701,7 +1727,8 @@ class FormatterTest {
|bar
|*/
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `basic annotations`() =
@@ -1715,7 +1742,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `function calls with multiple arguments`() =
@@ -1730,7 +1758,8 @@ class FormatterTest {
| 123456789012345678901234567890)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `function calls with multiple named arguments`() =
@@ -1745,7 +1774,8 @@ class FormatterTest {
| c = 3456789012345678901234567890)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `named arguments indent their value expression`() =
@@ -1760,7 +1790,8 @@ class FormatterTest {
| },
| duration = duration)
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Trailing comma forces variable value in list onto new line with manageTrailingCommas turned off`() =
@@ -1876,7 +1907,8 @@ class FormatterTest {
| })
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `anonymous function with receiver`() =
@@ -1889,7 +1921,8 @@ class FormatterTest {
| })
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `newlines between clauses of when() are preserved`() {
@@ -1914,7 +1947,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|fun f(x: Int) {
@@ -1932,7 +1966,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -1952,7 +1987,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with complex predicates`() =
@@ -1968,7 +2004,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with several conditions`() =
@@ -1982,7 +2019,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with is and in`() =
@@ -2002,7 +2040,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with enum values`() =
@@ -2016,7 +2055,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with generic matcher and exhaustive`() =
@@ -2029,7 +2069,8 @@ class FormatterTest {
| }.exhaustive
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with multiline condition`() =
@@ -2073,7 +2114,8 @@ class FormatterTest {
| doItTwice()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression storing in local variable`() =
@@ -2086,7 +2128,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `line breaks inside when expressions and conditions`() =
@@ -2108,7 +2151,8 @@ class FormatterTest {
| .build()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with lambda body`() =
@@ -2125,7 +2169,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with no-param lambda body`() =
@@ -2140,7 +2185,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `when() expression with lambda body containing multiple statements`() =
@@ -2156,7 +2202,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `function return types`() =
@@ -2166,7 +2213,8 @@ class FormatterTest {
|
|fun f2(): Int {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `multi line function without a block body`() =
@@ -2223,7 +2271,8 @@ class FormatterTest {
|
|class Derived5 : Super3()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `list of superclasses over multiple lines`() =
@@ -2257,7 +2306,8 @@ class FormatterTest {
"""
|@AnnWithArrayValue(1, 2, 3) class C
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `method modifiers`() =
@@ -2265,7 +2315,8 @@ class FormatterTest {
"""
|override internal fun f() {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `class modifiers`() =
@@ -2279,7 +2330,8 @@ class FormatterTest {
|
|open class Foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `kdoc comments`() {
@@ -2332,7 +2384,8 @@ class FormatterTest {
| */
|fun foo() {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `formatting kdoc doesn't add p HTML tags`() =
@@ -2347,7 +2400,8 @@ class FormatterTest {
| * On the other hand, we respect existing tags, and don't remove them.
| */
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `formatting kdoc preserves lists`() =
@@ -2361,7 +2415,8 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `formatting kdoc lists with line wraps breaks and merges correctly`() {
@@ -2404,7 +2459,8 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `formatting kdoc preserves numbered`() =
@@ -2418,7 +2474,8 @@ class FormatterTest {
| * This is another paragraph
| */
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `formatting kdoc with markdown errors`() =
@@ -2427,7 +2484,8 @@ class FormatterTest {
|/** \[ */
|fun markdownError() = Unit
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `return statement with value`() =
@@ -2437,7 +2495,8 @@ class FormatterTest {
| return 4
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `return statement without value`() =
@@ -2448,7 +2507,8 @@ class FormatterTest {
| return
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `return expression without value`() =
@@ -2458,7 +2518,8 @@ class FormatterTest {
| print(b ?: return)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `if statement without else`() =
@@ -2470,7 +2531,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `if statement with else`() =
@@ -2484,7 +2546,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `if expression with else`() =
@@ -2500,7 +2563,8 @@ class FormatterTest {
| return if (b) 1 else 2
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `if expression with break before else`() =
@@ -2556,7 +2620,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `if expression with multiline condition`() =
@@ -2618,7 +2683,8 @@ class FormatterTest {
"""
|val x = 2
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `a few variations of constructors`() =
@@ -2713,7 +2779,8 @@ class FormatterTest {
| val offspring2: List
|) {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `a constructor with keyword and many arguments over breaking to next line`() =
@@ -2728,7 +2795,8 @@ class FormatterTest {
| val foo: String
|) {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `a constructor with many arguments over multiple lines`() =
@@ -2760,7 +2828,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `a secondary constructor with many arguments over multiple lines`() =
@@ -2838,7 +2907,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle calling super constructor in secondary constructor`() =
@@ -2848,7 +2918,8 @@ class FormatterTest {
| internal constructor(number: Int) : super(number) {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle super statement with with type argument`() =
@@ -2860,7 +2931,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle super statement with with label argument`() =
@@ -2877,7 +2949,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `primary constructor without parameters with a KDoc`() =
@@ -2887,7 +2960,8 @@ class FormatterTest {
|/** A comment */
|constructor() {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle objects`() =
@@ -2895,7 +2969,8 @@ class FormatterTest {
"""
|object Foo(n: Int) {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle object expression`() =
@@ -2905,7 +2980,8 @@ class FormatterTest {
| return object : Adapter() {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle object expression in parenthesis`() =
@@ -2915,7 +2991,8 @@ class FormatterTest {
| return (object : Adapter() {})
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle array indexing operator`() =
@@ -2926,7 +3003,8 @@ class FormatterTest {
| b[3, 4]
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `keep array indexing grouped with expression is possible`() =
@@ -3130,7 +3208,8 @@ class FormatterTest {
| .also { _somePropertyWithBackingOne = it }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `array access in middle of chain and end of it behaves similarly`() =
@@ -3170,7 +3249,8 @@ class FormatterTest {
|var x: (@Anno (Int?)) = null
|var x: (@Anno() (Int)?) = null
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `nullable function type`() =
@@ -3178,7 +3258,8 @@ class FormatterTest {
"""
|var listener: ((Boolean) -> Unit)? = null
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `redundant parenthesis in function types`() =
@@ -3188,7 +3269,8 @@ class FormatterTest {
|
|var listener: ((Boolean) -> Unit) = foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle string literals`() =
@@ -3200,7 +3282,8 @@ class FormatterTest {
| println("Hello! ${'$'}{"wor" + "ld"}")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle multiline string literals`() =
@@ -3217,7 +3300,8 @@ class FormatterTest {
| world!${TQ})
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Trailing whitespaces are preserved in multiline strings`() {
@@ -3255,7 +3339,8 @@ class FormatterTest {
|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|$TQ
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `multiline trimMargin special handling`() {
@@ -3348,7 +3433,8 @@ class FormatterTest {
| .trimIndent()
| )
|"""
- .trimMargin())
+ .trimMargin()
+ )
.withOptions(META_FORMAT)
.isEqualTo(
"""
@@ -3375,7 +3461,8 @@ class FormatterTest {
| .trimIndent()
| )
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -3387,7 +3474,8 @@ class FormatterTest {
| |is this the end of the line?$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3396,7 +3484,8 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertThatFormatting(
"""
@@ -3405,7 +3494,8 @@ class FormatterTest {
| is this the end of the line?$TQ
| .trimIndent()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3414,7 +3504,8 @@ class FormatterTest {
| $TQ
| .trimIndent()
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -3429,7 +3520,8 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3439,7 +3531,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properly handles trimMargin that has margin in the first line`() =
@@ -3451,7 +3544,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3461,7 +3555,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handles multiline trim with template expressions inside of it`() {
@@ -3485,7 +3580,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -3506,7 +3602,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -3521,7 +3618,8 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3532,7 +3630,8 @@ class FormatterTest {
| $TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -3546,7 +3645,8 @@ class FormatterTest {
| // This comment should be preserved
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `comments between multiline string and trimIndent are preserved`() =
@@ -3559,7 +3659,8 @@ class FormatterTest {
| // This comment should be preserved
| .trimIndent()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `multiple comments between multiline string and trimMargin are preserved`() =
@@ -3573,7 +3674,8 @@ class FormatterTest {
| // Second comment
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `comment between multiline string and trimMargin is not deleted in string concatenation`() {
@@ -3625,7 +3727,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertThatFormatting(
"""
@@ -3647,7 +3750,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin1 =
@@ -3668,7 +3772,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -3683,7 +3788,8 @@ class FormatterTest {
|
| $TQ.trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|val margin =
@@ -3694,7 +3800,8 @@ class FormatterTest {
| |$TQ
| .trimMargin()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Trailing spaces in a comment are not preserved`() {
@@ -3734,7 +3841,8 @@ class FormatterTest {
|
|class Foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle for loops`() =
@@ -3746,7 +3854,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle for loops with long dot chains`() =
@@ -3825,7 +3934,8 @@ class FormatterTest {
| .methodCall()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle where formatting, fits into single line`() =
@@ -3835,7 +3945,8 @@ class FormatterTest {
|
|fun foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle where formatting, full expression breaks into single line`() =
@@ -4058,7 +4169,8 @@ class FormatterTest {
| })
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Qualified type`() =
@@ -4070,7 +4182,8 @@ class FormatterTest {
| var x: List.Iterator
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle destructuring declaration in for loop`() =
@@ -4080,7 +4193,8 @@ class FormatterTest {
| for ((x, y: Int) in a) {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle function references`() =
@@ -4124,7 +4238,8 @@ class FormatterTest {
|
|class `more spaces`
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle annotations with arguments`() =
@@ -4140,7 +4255,8 @@ class FormatterTest {
| //
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `no newlines after annotations if entire expr fits in one line`() =
@@ -4236,7 +4352,8 @@ class FormatterTest {
"""
|val callback: (@Anno List<@JvmSuppressWildcards String>) -> Unit = foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on type parameters`() =
@@ -4246,7 +4363,8 @@ class FormatterTest {
| inline fun <@Anno reified @Anno X, @Anno reified @Anno Y> bar() {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on type constraints`() =
@@ -4256,7 +4374,8 @@ class FormatterTest {
| fun bar() where U : @Anno Kip, U : @Anno Qux {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on type arguments`() =
@@ -4264,7 +4383,8 @@ class FormatterTest {
"""
|fun foo(x: Foo) {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on destructuring declaration elements`() =
@@ -4272,7 +4392,8 @@ class FormatterTest {
"""
|val x = { (@Anno x, @Anno y) -> x }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on exceptions`() =
@@ -4286,7 +4407,8 @@ class FormatterTest {
| } catch (@Suppress("GeneralException") e: Exception) {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on return statements`() =
@@ -4297,7 +4419,8 @@ class FormatterTest {
| return map.asMap()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Unary prefix expressions`() =
@@ -4329,7 +4452,8 @@ class FormatterTest {
| !--a
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `Unary postfix expressions`() =
@@ -4346,7 +4470,8 @@ class FormatterTest {
| a!! !!
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle wildcard generics`() =
@@ -4357,7 +4482,8 @@ class FormatterTest {
| val p: Pair<*, *>
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle intersection generics`() =
@@ -4368,7 +4494,8 @@ class FormatterTest {
| val p = Ctor
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle covariant and contravariant type arguments`() =
@@ -4376,7 +4503,8 @@ class FormatterTest {
"""
|val p: Pair
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle covariant and contravariant type parameters`() =
@@ -4384,7 +4512,8 @@ class FormatterTest {
"""
|class Foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle bounds for type parameters`() =
@@ -4392,7 +4521,8 @@ class FormatterTest {
"""
|class Foo, out S : Any?>
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle compound generic bounds on classes`() =
@@ -4400,7 +4530,8 @@ class FormatterTest {
"""
|class Foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle compound generic bounds on functions`() =
@@ -4408,7 +4539,8 @@ class FormatterTest {
"""
|fun foo(n: Int) where T : Bar, T : FooBar {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle compound generic bounds on properties`() =
@@ -4419,7 +4551,8 @@ class FormatterTest {
| return 2 * sum()
| }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle compound generic bounds on class with delegate`() =
@@ -4428,7 +4561,8 @@ class FormatterTest {
|class Foo() : Bar by bar
| where T : Qux
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `explicit type on property getter`() =
@@ -4439,7 +4573,8 @@ class FormatterTest {
| get(): Int = 1
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `explicit backing field`() =
@@ -4453,7 +4588,8 @@ class FormatterTest {
| field: MutableList = mutableListOf()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `explicit backing field without type`() =
@@ -4464,7 +4600,8 @@ class FormatterTest {
| field = 0
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `explicit backing field with private set accessor`() =
@@ -4476,7 +4613,8 @@ class FormatterTest {
| private set
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle method calls with lambda arg only`() =
@@ -4486,7 +4624,8 @@ class FormatterTest {
| val a = g { 1 + 1 }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle method calls value args and a lambda arg`() =
@@ -4496,7 +4635,8 @@ class FormatterTest {
| val a = g(1, 2) { 1 + 1 }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle top level constants`() =
@@ -4521,7 +4661,8 @@ class FormatterTest {
| val b = { x: Int, y: Int -> x + y }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `avoid newline before lambda argument if it is named`() =
@@ -4538,7 +4679,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle labeled this pointer`() =
@@ -4550,7 +4692,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle extension and operator functions`() =
@@ -4558,7 +4701,8 @@ class FormatterTest {
"""
|operator fun Point.component1() = x
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle extension methods with very long names`() =
@@ -4584,7 +4728,8 @@ class FormatterTest {
|val Int.isPrime: Boolean
| get() = runMillerRabinPrimality(this)
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `generic extension property`() =
@@ -4592,7 +4737,8 @@ class FormatterTest {
"""
|val List.twiceSize = 2 * size()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle file annotations`() {
@@ -4608,7 +4754,8 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -4622,7 +4769,8 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -4638,7 +4786,8 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -4653,7 +4802,8 @@ class FormatterTest {
| val a = example2("and 1")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -4666,7 +4816,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle interface delegation`() =
@@ -4674,7 +4825,8 @@ class FormatterTest {
"""
|class MyList(impl: List) : Collection by impl
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle property delegation`() =
@@ -4682,7 +4834,8 @@ class FormatterTest {
"""
|val a by lazy { 1 + 1 }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle property delegation with type and breaks`() =
@@ -4724,7 +4877,8 @@ class FormatterTest {
| var httpClient: OkHttpClient
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle parameters with annoations with parameters`() =
@@ -4736,7 +4890,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle lambda types`() =
@@ -4750,7 +4905,8 @@ class FormatterTest {
|
|val listener4: Int.(Int, Boolean) -> Unit
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle unicode in string literals`() =
@@ -4758,7 +4914,8 @@ class FormatterTest {
"""
|val a = "\uD83D\uDC4D"
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle casting`() =
@@ -4771,7 +4928,8 @@ class FormatterTest {
| doIt(o as? Int)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle casting with breaks`() =
@@ -4831,7 +4989,8 @@ class FormatterTest {
| //
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle try, catch and finally`() =
@@ -4847,7 +5006,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle infix methods`() =
@@ -4857,7 +5017,8 @@ class FormatterTest {
| (0 until 100).size
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle while loops`() =
@@ -4869,7 +5030,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle do while loops`() =
@@ -4883,7 +5045,8 @@ class FormatterTest {
| do while (1 < 2)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle break and continue`() =
@@ -4900,7 +5063,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle all kinds of labels and jumps`() =
@@ -4923,7 +5087,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `don't crash on top level statements with semicolons`() {
@@ -5215,7 +5380,8 @@ class FormatterTest {
| a { println("a") }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle multi statement lambdas`() =
@@ -5228,7 +5394,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle multi line one statement lambda`() =
@@ -5256,7 +5423,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `properly break fully qualified nested user types`() =
@@ -5304,7 +5472,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle multi line lambdas with explicit args`() =
@@ -5330,7 +5499,8 @@ class FormatterTest {
| g { (a, b): List, (c, d): List -> a }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle parenthesis in lambda calls for now`() =
@@ -5340,7 +5510,8 @@ class FormatterTest {
| a() { println("a") }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle chaining of calls with lambdas`() =
@@ -5357,7 +5528,8 @@ class FormatterTest {
| .sum
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle break of lambda args per line with indentation`() =
@@ -5502,7 +5674,8 @@ class FormatterTest {
| println(t)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle suspended types`() =
@@ -5516,7 +5689,8 @@ class FormatterTest {
|
|inline fun bar(noinline block: (suspend () -> R)?): (suspend () -> R)?
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle simple enum classes`() =
@@ -5528,7 +5702,8 @@ class FormatterTest {
| FILE_NOT_FOUND,
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle enum class with functions`() =
@@ -5544,7 +5719,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle enum with annotations`() =
@@ -5555,7 +5731,8 @@ class FormatterTest {
| @False @WhatIsTruth FALSE,
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle enum constructor calls`() =
@@ -5566,7 +5743,8 @@ class FormatterTest {
| FALSE("false", false),
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle enum entries with body`() =
@@ -5579,7 +5757,8 @@ class FormatterTest {
| FISH(false) {},
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle empty enum`() =
@@ -5587,7 +5766,8 @@ class FormatterTest {
"""
|enum class YTho {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `expect enum class`() =
@@ -5595,7 +5775,8 @@ class FormatterTest {
"""
|expect enum class ExpectedEnum
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `enum without trailing comma`() =
@@ -5605,7 +5786,8 @@ class FormatterTest {
| ONE
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `enum comma and semicolon`() {
@@ -5615,14 +5797,16 @@ class FormatterTest {
| ONE,;
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|enum class Highlander {
| ONE,
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -5633,12 +5817,14 @@ class FormatterTest {
| ;
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|enum class Empty {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertThatFormatting(
"""
@@ -5648,12 +5834,14 @@ class FormatterTest {
| ;
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|enum class Empty {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -5668,7 +5856,8 @@ class FormatterTest {
| fun f() {}
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `semicolon is removed from empty enum`() {
@@ -5741,7 +5930,8 @@ class FormatterTest {
| foo3(options = *args)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle typealias`() =
@@ -5767,7 +5957,8 @@ class FormatterTest {
|
|val dyn: dynamic = 1
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle class expression with generics`() =
@@ -5777,7 +5968,8 @@ class FormatterTest {
| println(Array::class.java)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `ParseError contains correct line and column numbers`() {
@@ -5832,7 +6024,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations on function types`() =
@@ -5856,7 +6049,8 @@ class FormatterTest {
| (x) -> Unit)
|) {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle annotations with use-site targets`() =
@@ -5868,7 +6062,8 @@ class FormatterTest {
| @set:Magic(name = "Jane") var field: String
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle annotations mixed with keywords since we cannot reorder them for now`() =
@@ -5880,7 +6075,8 @@ class FormatterTest {
|
|@Magic(1) public final class Foo
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle annotations more`() =
@@ -5957,7 +6153,8 @@ class FormatterTest {
| add(10)
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotated class declarations`() =
@@ -5972,7 +6169,8 @@ class FormatterTest {
|@Anno("param")
|class F
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle type arguments in annotations`() =
@@ -5980,7 +6178,8 @@ class FormatterTest {
"""
|@TypeParceler() class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle one line KDoc`() =
@@ -5989,7 +6188,8 @@ class FormatterTest {
|/** Hi, I am a one line kdoc */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with Link`() =
@@ -5998,7 +6198,8 @@ class FormatterTest {
|/** This links to [AnotherClass] */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with paragraphs`() =
@@ -6011,7 +6212,8 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with blocks`() =
@@ -6025,7 +6227,8 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with code examples`() =
@@ -6049,7 +6252,8 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with tagged code examples`() =
@@ -6064,7 +6268,8 @@ class FormatterTest {
| */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle stray code markers in lines and produce stable output`() {
@@ -6131,7 +6336,8 @@ class FormatterTest {
|/** Doc line with a reference to [AnotherClass] in the middle of a sentence */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with links one after another`() =
@@ -6140,7 +6346,8 @@ class FormatterTest {
|/** Here are some links [AnotherClass] [AnotherClass2] */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `don't add spaces after links in Kdoc`() =
@@ -6149,7 +6356,8 @@ class FormatterTest {
|/** Here are some links [AnotherClass][AnotherClass2]hello */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `don't remove spaces after links in Kdoc`() =
@@ -6158,7 +6366,8 @@ class FormatterTest {
|/** Please see [onNext] (which has more details) */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `link anchor in KDoc are preserved`() =
@@ -6167,7 +6376,8 @@ class FormatterTest {
|/** [link anchor](the URL for the link anchor goes here) */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `don't add spaces between links in KDoc (because they're actually references)`() =
@@ -6179,7 +6389,8 @@ class FormatterTest {
|/** The final produced value may have [size][ByteString.size] < [bufferSize]. */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `collapse spaces after links in KDoc`() {
@@ -6239,7 +6450,8 @@ class FormatterTest {
|/** There are many [FooObject]s. */
|class MyClass {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle KDoc with multiple separated param tags, breaking and merging lines and missing asterisk`() {
@@ -6340,7 +6552,8 @@ class FormatterTest {
|
|/* this is the first comment */
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `preserve LF, CRLF and CR line endings`() {
@@ -6800,7 +7013,8 @@ class FormatterTest {
|const val SOME_CONST = foo.a
|val SOME_STR = bar.a
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|import com.example.bar
@@ -6809,7 +7023,8 @@ class FormatterTest {
|const val SOME_CONST = foo.a
|val SOME_STR = bar.a
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -6819,12 +7034,14 @@ class FormatterTest {
|
|fun f() {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|fun f() {}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `at most one newline between any adjacent top-level elements`() =
@@ -6853,7 +7070,8 @@ class FormatterTest {
|
|val x = Bar()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|import com.Bar
@@ -6871,7 +7089,8 @@ class FormatterTest {
|
|val x = Bar()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `at least one newline between any adjacent top-level elements, unless it's a property`() =
@@ -6886,7 +7105,8 @@ class FormatterTest {
|val x = Foo()
|val x = Bar()
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|import com.Bar
@@ -6903,7 +7123,8 @@ class FormatterTest {
|val x = Foo()
|val x = Bar()
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `handle array of annotations with field prefix`() {
@@ -6969,7 +7190,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
// Regression test against https://github.com/facebook/ktfmt/issues/557
@@ -7005,7 +7227,8 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `lambda with optional arrow`() =
@@ -7018,7 +7241,8 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `lambda missing optional arrow`() =
@@ -7031,7 +7255,8 @@ class FormatterTest {
| y
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `lambda with only comments`() {
@@ -7052,7 +7277,8 @@ class FormatterTest {
|}
|private val g: () -> Unit = { /* no-op */ }
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -7101,7 +7327,8 @@ class FormatterTest {
|
|private val d: () -> Unit = { TODO("implement me") }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `lambda block with comments and statements mix`() =
@@ -7127,7 +7354,8 @@ class FormatterTest {
|
|private val e: (String, Int) -> Unit = { _, i -> foo(i) /* do nothing ... */ }
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `lambda block with comments and with statements have same formatting treatment`() =
@@ -7157,7 +7385,8 @@ class FormatterTest {
| TODO("implement me")
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `last parameter with comment and with statements have same formatting treatment`() {
@@ -7180,7 +7409,8 @@ class FormatterTest {
|private val c = firstCall().prop.call(param) { /* no-op */ }
|private val C = firstCall().prop.call(param) { TODO("implement me") }
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -8159,7 +8389,8 @@ class FormatterTest {
| @Anno1 /* comment */ @Anno2 f(1) as Int
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `annotations for expressions 2`() {
@@ -8549,7 +8780,8 @@ class FormatterTest {
| }
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `trailing comment after function top-level`() {
@@ -8562,7 +8794,8 @@ class FormatterTest {
|
|// End of file
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -8571,7 +8804,8 @@ class FormatterTest {
|
|// End of file
|"""
- .trimMargin())
+ .trimMargin()
+ )
assertFormatted(
"""
@@ -8589,7 +8823,8 @@ class FormatterTest {
| return
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -8658,7 +8893,8 @@ class FormatterTest {
| fun foo(): Unit
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
.isEqualTo(
"""
|enum class Foo {
@@ -8667,7 +8903,8 @@ class FormatterTest {
| fun foo(): Unit
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
}
@Test
@@ -8961,7 +9198,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(code)
}
@@ -8985,7 +9223,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(code)
}
@@ -9015,7 +9254,8 @@ class FormatterTest {
preserveLambdaBreaks = false,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(expected)
}
@@ -9041,7 +9281,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(code)
}
@@ -9067,7 +9308,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(code)
}
@@ -9096,7 +9338,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(expected)
}
@@ -9118,7 +9361,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(code)
}
@@ -9152,7 +9396,8 @@ class FormatterTest {
preserveLambdaBreaks = true,
blockIndent = 2,
continuationIndent = 4,
- ))
+ )
+ )
.isEqualTo(expected)
}
diff --git a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
index 262f5236..1afd4a32 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt
@@ -1335,7 +1335,8 @@ class GoogleStyleFormatterKtTest {
| doItTwice()
|}
|"""
- .trimMargin())
+ .trimMargin()
+ )
@Test
fun `comma separated lists, no automatic trailing break after lambda params`() =
diff --git a/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
index 0e7d30d9..7943a923 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/MultilineStringFormatterTest.kt
@@ -32,28 +32,29 @@ class MultilineStringFormatterTest {
" |line2",
" $TQ",
" .trimMargin()",
- )) {
- assertThat(usesTrimMargin).isTrue()
- assertThat(indentationSuffix).isEqualTo("|")
- assertThat(isDollarString).isFalse()
- assertThat(indentCount).isEqualTo(0)
- assertThat(lines).hasSize(5)
- assertThat(lines)
- .containsExactly(
- TQ,
- " |line1",
- " |line2",
- " $TQ",
- " .trimMargin()",
- )
- .inOrder()
- assertThat(lineStart).isEqualTo(0)
- assertThat(lineEnd).isEqualTo(4)
- assertThat(lastStringLineIndex).isEqualTo(3)
- assertThat(openStringOffset).isEqualTo(0)
- assertThat(trimMethodCallOffset).isEqualTo(42)
- assertThat(isNestedMultiline).isFalse()
- }
+ )
+ ) {
+ assertThat(usesTrimMargin).isTrue()
+ assertThat(indentationSuffix).isEqualTo("|")
+ assertThat(isDollarString).isFalse()
+ assertThat(indentCount).isEqualTo(0)
+ assertThat(lines).hasSize(5)
+ assertThat(lines)
+ .containsExactly(
+ TQ,
+ " |line1",
+ " |line2",
+ " $TQ",
+ " .trimMargin()",
+ )
+ .inOrder()
+ assertThat(lineStart).isEqualTo(0)
+ assertThat(lineEnd).isEqualTo(4)
+ assertThat(lastStringLineIndex).isEqualTo(3)
+ assertThat(openStringOffset).isEqualTo(0)
+ assertThat(trimMethodCallOffset).isEqualTo(42)
+ assertThat(isNestedMultiline).isFalse()
+ }
with(
multilineTrimmedStringFromLines(
@@ -62,27 +63,28 @@ class MultilineStringFormatterTest {
" line1 |",
" |line2",
" $TQ.trimIndent()",
- )) {
- assertThat(usesTrimMargin).isFalse()
- assertThat(indentationSuffix).isEqualTo("")
- assertThat(isDollarString).isTrue()
- assertThat(indentCount).isEqualTo(2)
- assertThat(lines).hasSize(4)
- assertThat(lines)
- .containsExactly(
- " $$$TQ",
- " line1 |",
- " |line2",
- " $TQ.trimIndent()",
- )
- .inOrder()
- assertThat(lineStart).isEqualTo(1)
- assertThat(lineEnd).isEqualTo(4)
- assertThat(lastStringLineIndex).isEqualTo(3)
- assertThat(openStringOffset).isEqualTo(10)
- assertThat(trimMethodCallOffset).isEqualTo(46)
- assertThat(isNestedMultiline).isFalse()
- }
+ )
+ ) {
+ assertThat(usesTrimMargin).isFalse()
+ assertThat(indentationSuffix).isEqualTo("")
+ assertThat(isDollarString).isTrue()
+ assertThat(indentCount).isEqualTo(2)
+ assertThat(lines).hasSize(4)
+ assertThat(lines)
+ .containsExactly(
+ " $$$TQ",
+ " line1 |",
+ " |line2",
+ " $TQ.trimIndent()",
+ )
+ .inOrder()
+ assertThat(lineStart).isEqualTo(1)
+ assertThat(lineEnd).isEqualTo(4)
+ assertThat(lastStringLineIndex).isEqualTo(3)
+ assertThat(openStringOffset).isEqualTo(10)
+ assertThat(trimMethodCallOffset).isEqualTo(46)
+ assertThat(isNestedMultiline).isFalse()
+ }
}
@Test
@@ -110,7 +112,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isFalse()
// dollar string without dollar template expression
@@ -121,7 +124,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isFalse()
// simple string with template expression
@@ -132,7 +136,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isTrue()
// dollar string with template expression
@@ -143,7 +148,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isTrue()
// simple string with multiline template expression
@@ -157,7 +163,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isTrue()
// dollar string with multiline template expression
@@ -171,7 +178,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .hasTemplateExpression())
+ .hasTemplateExpression()
+ )
.isTrue()
}
@@ -185,7 +193,8 @@ class MultilineStringFormatterTest {
" |line3",
" $TQ.trimMargin()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
"line1",
"line2",
@@ -201,7 +210,8 @@ class MultilineStringFormatterTest {
" line3",
" |$TQ.trimMargin()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
" line1",
" line2",
@@ -222,7 +232,8 @@ class MultilineStringFormatterTest {
"",
" $TQ.trimIndent()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
"line1",
" line2",
@@ -241,7 +252,8 @@ class MultilineStringFormatterTest {
" $TQ",
" .trimIndent()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
"line1",
" line2",
@@ -261,7 +273,8 @@ class MultilineStringFormatterTest {
" $TQ",
" .trimMargin()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
"content",
"line1",
@@ -276,7 +289,8 @@ class MultilineStringFormatterTest {
" line2",
" $TQ.trimIndent()",
)
- .getStringContent())
+ .getStringContent()
+ )
.containsExactly(
"content",
"line1",
diff --git a/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt b/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
index 79ce6ce8..d2b423e7 100644
--- a/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/format/WhitespaceTombstonesTest.kt
@@ -39,9 +39,11 @@ class WhitespaceTombstonesTest {
.isEqualTo(" sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh")
assertThat(WhitespaceTombstones.replaceTrailingWhitespaceWithTombstone(" sdfl \n skdjfh "))
.isEqualTo(
- " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}")
+ " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}"
+ )
assertThat(WhitespaceTombstones.replaceTrailingWhitespaceWithTombstone(" sdfl \n\n skdjfh "))
.isEqualTo(
- " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}")
+ " sdfl ${WhitespaceTombstones.SPACE_TOMBSTONE}\n\n skdjfh${WhitespaceTombstones.SPACE_TOMBSTONE}"
+ )
}
}
diff --git a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt b/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
index 76fe54d2..5b19cf55 100644
--- a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
+++ b/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt
@@ -92,9 +92,10 @@ class DokkaVerifier(private val tempFolder: File) {
";" // instead of File.pathSeparator as would have been reasonable (e.g. : on Unix)
val path =
listOf(analysis, base, compiler, intellij, coroutines, html, freemarker).joinToString(
- pathSeparator) {
- it.path
- }
+ pathSeparator
+ ) {
+ it.path
+ }
args.add(path)
args.add("-sourceSet")
args.add("-src $src") // (nested parameter within -sourceSet)
diff --git a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt b/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
index 299630df..60a585aa 100644
--- a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
+++ b/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt
@@ -57,14 +57,16 @@ fun assertFormatted(
if (deduceMaxWidth) {
if (!isFirstLineAMaxWidthMarker) {
throw RuntimeException(
- "When deduceMaxWidth is true the first line needs to be all dashes only (i.e. ---)")
+ "When deduceMaxWidth is true the first line needs to be all dashes only (i.e. ---)"
+ )
}
deducedCode = code.substring(code.indexOf('\n') + 1)
maxWidth = first.length
} else {
if (isFirstLineAMaxWidthMarker) {
throw RuntimeException(
- "deduceMaxWidth is false, please remove the first dashes only line from the code (i.e. ---)")
+ "deduceMaxWidth is false, please remove the first dashes only line from the code (i.e. ---)"
+ )
}
}
assertThatFormatting(deducedCode)
@@ -104,7 +106,8 @@ class FormattedCodeSubject(metadata: FailureMetadata, private val code: String)
expectedFormatting
.lines()
.map { if (it.endsWith(" ")) "[$it]" else it }
- .joinToString("\n"))
+ .joinToString("\n")
+ )
}
val actualFormatting: String
try {
@@ -120,7 +123,8 @@ class FormattedCodeSubject(metadata: FailureMetadata, private val code: String)
println("#".repeat(20))
println(
"Need more information about the break operations? " +
- "Run test with assertion with \"FormattingOptions(debuggingPrintOpsAfterFormatting = true)\"")
+ "Run test with assertion with \"FormattingOptions(debuggingPrintOpsAfterFormatting = true)\""
+ )
}
} catch (e: Error) {
reportError(code)
From 0f195ab13c702c7553ee4051a4b11fe16db437bb Mon Sep 17 00:00:00 2001
From: Zac Sweers
Date: Sat, 13 Jun 2026 15:38:21 -0400
Subject: [PATCH 4/5] Clean up plugin repos setup
---
build.gradle.kts | 4 ----
settings.gradle.kts | 10 ++++++++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index 758b53d2..129ca3e7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -35,10 +35,6 @@ version = providers.gradleProperty("ktfmt.version").get()
tasks.wrapper { distributionType = Wrapper.DistributionType.ALL }
-repositories {
- mavenCentral()
-}
-
val ktfmtCliDependencies = configurations.dependencyScope("ktfmtCliDependencies")
val ktfmtCliClasspath =
configurations.resolvable("ktfmtCliClasspath") {
diff --git a/settings.gradle.kts b/settings.gradle.kts
index ea48f265..c747414e 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -14,6 +14,13 @@
* limitations under the License.
*/
+pluginManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
rootProject.name = "ktfmt-parent"
include(
@@ -35,4 +42,7 @@ dependencyResolutionManagement {
version("ktfmt", ktfmtVersion)
}
}
+ repositories {
+ mavenCentral()
+ }
}
From b96c15beb19685cb937901dc0baa839d0a9d7ded Mon Sep 17 00:00:00 2001
From: Zac Sweers
Date: Mon, 22 Jun 2026 00:02:45 -0400
Subject: [PATCH 5/5] Remove ktfmt-gradle from buildSrc
---
buildSrc/build.gradle.kts | 4 ----
1 file changed, 4 deletions(-)
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 0d3d2a8f..418b4cfc 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -14,12 +14,10 @@
* limitations under the License.
*/
-import com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask
import org.gradle.kotlin.dsl.`kotlin-dsl`
plugins {
`kotlin-dsl`
- alias(libs.plugins.ktfmt)
}
gradlePlugin {
@@ -30,5 +28,3 @@ gradlePlugin {
}
}
}
-
-tasks.named("jar") { dependsOn(tasks.withType()) }