Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ kotlin {

ktfmt {
trailingCommaManagementStrategy.set(
com.ncorti.ktfmt.gradle.TrailingCommaManagementStrategy.ONLY_ADD
com.ncorti.ktfmt.gradle.TrailingCommaManagementStrategy.ONLY_ADD,
)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/facebook/ktfmt/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Main(
result.addAll(
File(arg).walkTopDown().filter {
it.isFile && (it.extension == "kt" || it.extension == "kts")
}
},
)
}
return result
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ data class ParsedArgs(
stdinName =
parseKeyValueArg("--stdin-name", arg)
?: return ParseResult.Error(
"Found option '${arg}', expected '${"--stdin-name"}=<value>'"
"Found option '${arg}', expected '${"--stdin-name"}=<value>'",
)
arg.startsWith("--") -> return ParseResult.Error("Unexpected option: $arg")
arg.startsWith("@") -> return ParseResult.Error("Unexpected option: $arg")
Expand All @@ -148,7 +148,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) {
Expand All @@ -164,7 +164,7 @@ data class ParsedArgs(
stdinName,
editorConfig,
quiet,
)
),
)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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)),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ data class FormattingOptions(

/** @see FormattingOptions.trailingCommaManagementStrategy */
fun trailingCommaManagementStrategy(
trailingCommaManagementStrategy: TrailingCommaManagementStrategy
trailingCommaManagementStrategy: TrailingCommaManagementStrategy,
): Builder = apply { this.trailingCommaManagementStrategy = trailingCommaManagementStrategy }

/** @see FormattingOptions.removeUnusedImports */
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/facebook/ktfmt/format/KotlinInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class KotlinInput(private val text: String, file: KtFile) : Input() {
characterRangeToTokenRange(
characterRange.lowerEndpoint(),
characterRange.upperEndpoint() - characterRange.lowerEndpoint(),
)
),
)
}
return tokenRangeSet
Expand All @@ -107,7 +107,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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ class KotlinInputAstVisitor(

/** Example `a: String` which is part of `(a: String, b: String)` */
override fun visitDestructuringDeclarationEntry(
multiDeclarationEntry: KtDestructuringDeclarationEntry
multiDeclarationEntry: KtDestructuringDeclarationEntry,
) {
builder.sync(multiDeclarationEntry)
declareOne(
Expand Down Expand Up @@ -2690,7 +2690,7 @@ class KotlinInputAstVisitor(
child is PsiComment -> continue
child is KtScript && importListEmpty -> OpsBuilder.BlankLineWanted.PRESERVE
else -> OpsBuilder.BlankLineWanted.YES
}
},
)

visit(child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ class MultilineStringFormatter(val continuationIndentSize: Int) {
expression.getParentOfType<KtStringTemplateExpression>(strict = false) !=
null,
commentsBetweenStringAndTrimCall = comments,
)
),
)
}
}
}
},
)
return strings.toList()
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/facebook/ktfmt/format/ParseError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object RedundantElementManager {
redundantImportDetector.takeReferenceExpression(expression)
super.visitReferenceExpression(expression)
}
}
},
)

val elementsToRemove =
Expand Down Expand Up @@ -106,7 +106,7 @@ object RedundantElementManager {
trailingCommaSuggestor.takeElement(element)
super.visitElement(element)
}
}
},
)

val suggestionElements = trailingCommaSuggestor.getTrailingCommaSuggestions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ object TrailingCommas {
if (!element.textContains('\n')) {
return // Only suggest trailing commas where there is already a line break
}
if (list.items.size <= 1) {
return // Never insert commas to single-element lists
if (list.items.isEmpty()) {
return // Never insert commas to empty lists
}
if (list.trailingComma != null) {
return // Never insert a comma if there already is one somehow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class EditorConfigResolverTest {
[*.c]
max_line_length = 80
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -81,7 +81,7 @@ class EditorConfigResolverTest {
[*.kt]
max_line_length = 80
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -98,7 +98,7 @@ class EditorConfigResolverTest {
[*.kt]
max_line_length = off
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -115,7 +115,7 @@ class EditorConfigResolverTest {
[*.kt]
indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -132,7 +132,7 @@ class EditorConfigResolverTest {
[*.kt]
indent_size = tab
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -150,7 +150,7 @@ class EditorConfigResolverTest {
indent_size = tab
tab_width = 8
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -167,7 +167,7 @@ class EditorConfigResolverTest {
[*.kt]
ij_kotlin_indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -185,7 +185,7 @@ class EditorConfigResolverTest {
indent_size = 2
ij_kotlin_indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -202,7 +202,7 @@ class EditorConfigResolverTest {
[*.kt]
ij_continuation_indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -219,7 +219,7 @@ class EditorConfigResolverTest {
[*.kt]
ij_kotlin_continuation_indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -237,7 +237,7 @@ class EditorConfigResolverTest {
ij_continuation_indent_size = 6
ij_kotlin_continuation_indent_size = 3
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -254,7 +254,7 @@ class EditorConfigResolverTest {
[*.kt]
ktfmt_trailing_comma_management_strategy = only_add
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -272,7 +272,7 @@ class EditorConfigResolverTest {
[*.kt]
ktfmt_trailing_comma_management_strategy = whatever
"""
.trimIndent()
.trimIndent(),
)

val file = root.resolve("src/main/kotlin/Example.kt")
Expand All @@ -292,7 +292,7 @@ class EditorConfigResolverTest {
[src/**/*.kts]
max_line_length = 120
"""
.trimIndent()
.trimIndent(),
)
val rootOptions =
Formatter.GOOGLE_FORMAT.copy(
Expand All @@ -309,7 +309,7 @@ class EditorConfigResolverTest {
max_line_length = 200
ktfmt_trailing_comma_management_strategy = only_add
"""
.trimIndent()
.trimIndent(),
)
val mainOptions =
Formatter.GOOGLE_FORMAT.copy(
Expand All @@ -329,7 +329,7 @@ class EditorConfigResolverTest {
ij_continuation_indent_size = 2
max_line_length = 300
"""
.trimIndent()
.trimIndent(),
)
val testOptions =
Formatter.GOOGLE_FORMAT.copy(
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class ParsedArgsTest {
formattingOptions = Formatter.GOOGLE_FORMAT,
dryRun = true,
setExitIfChanged = true,
)
),
)
}

Expand All @@ -234,7 +234,7 @@ class ParsedArgsTest {
parseResultOk(
fileNames = listOf("File.kt"),
formattingOptions = Formatter.KOTLINLANG_FORMAT,
)
),
)
}

Expand Down Expand Up @@ -270,7 +270,7 @@ class ParsedArgsTest {
stdinName,
editorConfig,
quiet,
)
),
)
}
}
Loading
Loading