Skip to content

Commit

Permalink
Enable trailing comma (#1583)
Browse files Browse the repository at this point in the history
* Enable trailing comma on declaration site
* Enable trailing comma on call site
  • Loading branch information
paul-dingemans committed Aug 17, 2022
1 parent c3ac870 commit 1d9ca64
Show file tree
Hide file tree
Showing 200 changed files with 1,649 additions and 1,635 deletions.
7 changes: 2 additions & 5 deletions .editorconfig
Expand Up @@ -15,11 +15,8 @@ indent_size = 4

[*.{kt,kts}]
ij_kotlin_imports_layout=*
# Ideally, no experimental rule should be disabled. Ktlint should follow the dogfooding principle. This means that an
# experimental rule should only be added to the master branch no sooner than that this rule has been applied on the
# ktlint code base itself.
ij_kotlin_allow_trailing_comma=false
ij_kotlin_allow_trailing_comma_on_call_site=false
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true

[*.md]
trim_trailing_whitespace = false
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ToolchainForTests.kt
Expand Up @@ -17,7 +17,7 @@ private fun Project.addJdkVersionTests(jdkVersion: Int) {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(jdkVersion))
}
},
)
}
tasks.named("check") {
Expand Down
8 changes: 5 additions & 3 deletions buildSrc/src/main/kotlin/ktlint-publication.gradle.kts
Expand Up @@ -93,7 +93,9 @@ signing {
// useGpgCmd()

sign(publishing.publications["maven"])
setRequired({
!version.toString().endsWith("SNAPSHOT")
})
setRequired(
{
!version.toString().endsWith("SNAPSHOT")
},
)
}
Expand Up @@ -7,6 +7,6 @@ package com.github.shyiko.ktlint.core
*/
@Deprecated(
level = DeprecationLevel.ERROR,
message = "RuleSetProvider has moved to com.pinterest.ktlint.core"
message = "RuleSetProvider has moved to com.pinterest.ktlint.core",
)
public interface RuleSetProvider
Expand Up @@ -10,7 +10,7 @@ public data class IndentConfig(
/**
* The number of spaces that is equivalent to one tab
*/
val tabWidth: Int
val tabWidth: Int,
) {
/**
* To use the [IndentConfig] in a rule, the following needs to be done:
Expand All @@ -34,13 +34,13 @@ public data class IndentConfig(
/**
* The number of spaces that is equivalent to one tab
*/
tabWidth: Int
tabWidth: Int,
) : this(
indentStyle = when (indentStyle) {
PropertyType.IndentStyleValue.tab -> TAB
PropertyType.IndentStyleValue.space -> SPACE
},
tabWidth = tabWidth
tabWidth = tabWidth,
)

public enum class IndentStyle { SPACE, TAB }
Expand Down Expand Up @@ -143,7 +143,7 @@ public data class IndentConfig(

public val DEFAULT_INDENT_CONFIG: IndentConfig = IndentConfig(
indentStyle = SPACE,
tabWidth = 4
tabWidth = 4,
)
}
}
26 changes: 13 additions & 13 deletions ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt
Expand Up @@ -63,7 +63,7 @@ public object KtLint {
val text: String,
@Deprecated(
message = "Marked for removal in KtLint 0.48",
replaceWith = ReplaceWith("ruleProviders")
replaceWith = ReplaceWith("ruleProviders"),
)
val ruleSets: Iterable<RuleSet> = Iterable { emptySet<RuleSet>().iterator() },
val ruleProviders: Set<RuleProvider> = emptySet(),
Expand All @@ -73,7 +73,7 @@ public object KtLint {
val editorConfigPath: String? = null,
val debug: Boolean = false,
val editorConfigOverride: EditorConfigOverride = emptyEditorConfigOverride,
val isInvokedFromCli: Boolean = false
val isInvokedFromCli: Boolean = false,
) {
internal val ruleRunners: Set<RuleRunner> =
ruleProviders
Expand All @@ -89,7 +89,7 @@ public object KtLint {
// TODO: remove when removing the deprecated ruleSets.
ruleSets
.flatMap { it.rules.toList() }
.map { RuleRunner(createStaticRuleProvider(it)) }
.map { RuleRunner(createStaticRuleProvider(it)) },
).distinctBy { it.ruleId }
.toSet()

Expand Down Expand Up @@ -176,7 +176,7 @@ public object KtLint {
rule: Rule,
fqRuleId: String,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {
rule.startTraversalOfAST()
rule.beforeFirstNode(editorConfigProperties)
Expand All @@ -189,7 +189,7 @@ public object KtLint {
rule: Rule,
fqRuleId: String,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {
if (rule.shouldContinueTraversalOfAST()) {
try {
Expand Down Expand Up @@ -246,7 +246,7 @@ public object KtLint {
// updating the code
preparedCode.suppressedRegionLocator =
SuppressionLocatorBuilder.buildSuppressedRegionsLocator(
preparedCode.rootNode
preparedCode.rootNode,
)
}
}
Expand All @@ -256,8 +256,8 @@ public object KtLint {
LintError(line, col, fqRuleId, errorMessage, canBeAutoCorrected),
// It is assumed that a rule that emits that an error can be autocorrected, also
// does correct the error.
canBeAutoCorrected
)
canBeAutoCorrected,
),
)
}
}
Expand All @@ -272,8 +272,8 @@ public object KtLint {
LintError(line, col, fqRuleId, errorMessage, canBeAutoCorrected),
// It is assumed that a rule only corrects an error after it has emitted an
// error and indicating that it actually can be autocorrected.
false
)
false,
),
)
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ public object KtLint {
* ```
*/
public fun generateKotlinEditorConfigSection(
params: ExperimentalParams
params: ExperimentalParams,
): String {
val filePath = params.normalizedFilePath
requireNotNull(filePath) {
Expand All @@ -341,7 +341,7 @@ public object KtLint {
filePath,
params.getRules(),
params.debug,
codeStyle
codeStyle,
)
}

Expand Down Expand Up @@ -396,7 +396,7 @@ internal class RuleRunner(private val provider: RuleProvider) {
"maintainer of the rule."
}
runAfterRuleVisitorModifier.copy(
ruleId = qualifiedAfterRuleId
ruleId = qualifiedAfterRuleId,
)
}

Expand Down
Expand Up @@ -13,7 +13,7 @@ private var defaultLoggerModifier: ((KLogger) -> Unit)? = null
* [initKtLintKLogger].
*/
public fun KLogger.setDefaultLoggerModifier(
loggerModifier: (KLogger) -> Unit
loggerModifier: (KLogger) -> Unit,
): KLogger {
if (defaultLoggerModifier != null) {
warn {
Expand Down
Expand Up @@ -14,7 +14,7 @@ public data class LintError(
val line: Int,
val col: Int,
val ruleId: String,
val detail: String
val detail: String,
) : Serializable {

// fixme:
Expand All @@ -28,7 +28,7 @@ public data class LintError(
col: Int,
ruleId: String,
detail: String,
canBeAutoCorrected: Boolean
canBeAutoCorrected: Boolean,
) : this(line, col, ruleId, detail) {
this.canBeAutoCorrected = canBeAutoCorrected
}
Expand Down
Expand Up @@ -9,5 +9,5 @@ package com.pinterest.ktlint.core
public class ParseException(
public val line: Int,
public val col: Int,
message: String
message: String,
) : RuntimeException("$line:$col $message")
16 changes: 8 additions & 8 deletions ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt
Expand Up @@ -24,7 +24,7 @@ public open class Rule(
* Set of modifiers of the visitor. Preferably a rule has no modifiers at all, meaning that it is completely
* independent of all other rules.
*/
public val visitorModifiers: Set<VisitorModifier> = emptySet()
public val visitorModifiers: Set<VisitorModifier> = emptySet(),
) {
private var traversalState = TraversalState.NOT_STARTED

Expand All @@ -50,7 +50,7 @@ public open class Rule(
public open fun beforeVisitChildNodes(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
): Unit =
/**
* For backwards compatibility with ktlint 0.46.x or before, call [visit] when not implemented on node.
Expand All @@ -71,13 +71,13 @@ public open class Rule(
*/
@Deprecated(
message = "Marked for deletion in ktlint 0.48.0",
replaceWith = ReplaceWith("beforeVisitChildNodes(node, autocorrect, emit")
replaceWith = ReplaceWith("beforeVisitChildNodes(node, autocorrect, emit"),
)
@Suppress("UNUSED_PARAMETER")
public open fun visit(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {}

/**
Expand All @@ -87,7 +87,7 @@ public open class Rule(
public open fun afterVisitChildNodes(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public open class Rule(
/**
* Stops traversal of yet unvisited nodes in the AST. See [stopTraversalOfAST] for more details.
*/
STOP
STOP,
}

public sealed class VisitorModifier {
Expand All @@ -170,7 +170,7 @@ public open class Rule(
/**
* The annotated rule will only be run in case the other rule is enabled.
*/
val runOnlyWhenOtherRuleIsEnabled: Boolean = false
val runOnlyWhenOtherRuleIsEnabled: Boolean = false,
) : VisitorModifier()

public object RunAsLateAsPossible : VisitorModifier()
Expand All @@ -179,7 +179,7 @@ public open class Rule(
"""
Marked for removal in Ktlint 0.48. This modifier blocks the ability to suppress ktlint rules. See
changelog Ktlint 0.47 for details on how to modify a rule using this modifier.
"""
""",
)
public object RunOnRootNodeOnly : VisitorModifier()
}
Expand Down
Expand Up @@ -10,5 +10,5 @@ public class RuleExecutionException(
public val line: Int,
public val col: Int,
public val ruleId: String,
cause: Throwable
cause: Throwable,
) : RuntimeException(cause)
Expand Up @@ -10,7 +10,7 @@ public class RuleProvider(
/**
* Lambda which creates a new instance of the rule.
*/
private val provider: () -> Rule
private val provider: () -> Rule,
) {
/**
* Creates a RuleProvider based on a [RuleSet] to provide backwards compatability with KtLint 0.46. This will be
Expand All @@ -25,7 +25,7 @@ public class RuleProvider(
.get()
// but only use the instance for the rule at the specified index
.elementAt(ruleIndex)
}
},
)

public fun createNewRuleInstance(): Rule =
Expand Down
Expand Up @@ -10,7 +10,7 @@ import com.pinterest.ktlint.core.internal.IdNamingPolicy
@Deprecated("Marked for removal in KtLint 0.48. See KDoc.")
public open class RuleSet(
public val id: String,
public vararg val rules: Rule
public vararg val rules: Rule,
) : Iterable<Rule> {

init {
Expand Down
Expand Up @@ -29,7 +29,7 @@ public interface RuleSetProvider : Serializable {
* of the [Rule] is shared. As of this [Rule] have to clear their internal state.
*/
@Deprecated(
"Marked for removal in KtLint 0.48. See changelog or KDoc for more information."
"Marked for removal in KtLint 0.48. See changelog or KDoc for more information.",
)
public fun get(): RuleSet
}
Expand Up @@ -17,7 +17,7 @@ import java.io.Serializable

public abstract class RuleSetProviderV2(
public val id: String,
public val about: About
public val about: About,
) : Serializable {

init {
Expand Down Expand Up @@ -61,7 +61,7 @@ public abstract class RuleSetProviderV2(
val description: String?,
val license: String?,
val repositoryUrl: String?,
val issueTrackerUrl: String?
val issueTrackerUrl: String?,
) {
init {
require(maintainer == null || maintainer.length <= 50) {
Expand All @@ -88,7 +88,7 @@ public abstract class RuleSetProviderV2(
description = "Not specified",
license = "Not specified",
repositoryUrl = "Not specified",
issueTrackerUrl = "Not specified"
issueTrackerUrl = "Not specified",
)
}
}
Expand Up @@ -29,7 +29,7 @@ public class Baseline(
/**
* Status of the baseline file.
*/
public val status: Status
public val status: Status,
) {
public enum class Status {
/**
Expand All @@ -45,7 +45,7 @@ public class Baseline(
/**
* Baseline file is not successfully parsed. File needs to be regenerated by the consumer.
*/
INVALID
INVALID,
}
}

Expand All @@ -61,7 +61,7 @@ public fun loadBaseline(path: String): Baseline {
try {
return Baseline(
lintErrorsPerFile = parseBaseline(baselineFile.inputStream()),
status = VALID
status = VALID,
)
} catch (e: IOException) {
logger.error { "Unable to parse baseline file: $path" }
Expand Down Expand Up @@ -115,9 +115,9 @@ private fun Element.parseBaselineErrorsByFile(): List<LintError> {
line = getAttribute("line").toInt(),
col = getAttribute("column").toInt(),
ruleId = getAttribute("source"),
detail = "" // Not available in the baseline file
detail = "", // Not available in the baseline file
)
}
},
)
}
return errors
Expand Down

0 comments on commit 1d9ca64

Please sign in to comment.