From 1d9ca64458eb3cee4e21ec8252f22aa58445f4f5 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Wed, 17 Aug 2022 20:09:32 +0200 Subject: [PATCH] Enable trailing comma (#1583) * Enable trailing comma on declaration site * Enable trailing comma on call site --- .editorconfig | 7 +- buildSrc/src/main/kotlin/ToolchainForTests.kt | 2 +- .../main/kotlin/ktlint-publication.gradle.kts | 8 +- .../shyiko/ktlint/core/RuleSetProvider.kt | 2 +- .../com/pinterest/ktlint/core/IndentConfig.kt | 8 +- .../com/pinterest/ktlint/core/KtLint.kt | 26 +- .../ktlint/core/KtLintKLoggerInitializer.kt | 2 +- .../com/pinterest/ktlint/core/LintError.kt | 4 +- .../pinterest/ktlint/core/ParseException.kt | 2 +- .../kotlin/com/pinterest/ktlint/core/Rule.kt | 16 +- .../ktlint/core/RuleExecutionException.kt | 2 +- .../com/pinterest/ktlint/core/RuleProvider.kt | 4 +- .../com/pinterest/ktlint/core/RuleSet.kt | 2 +- .../pinterest/ktlint/core/RuleSetProvider.kt | 2 +- .../ktlint/core/RuleSetProviderV2.kt | 6 +- .../com/pinterest/ktlint/core/api/Baseline.kt | 10 +- .../ktlint/core/api/EditorConfigOverride.kt | 4 +- .../ktlint/core/api/OptInFeatures.kt | 8 +- .../core/api/UsesEditorConfigProperties.kt | 36 +- .../core/internal/EditorConfigGenerator.kt | 20 +- .../core/internal/EditorConfigLoader.kt | 12 +- .../core/internal/KotlinPsiFileFactory.kt | 12 +- .../core/internal/PositionInTextLocator.kt | 8 +- .../ktlint/core/internal/PreparedCode.kt | 8 +- .../ktlint/core/internal/QualifiedRuleId.kt | 2 +- .../ktlint/core/internal/RuleRunnerSorter.kt | 8 +- .../internal/SuppressionLocatorBuilder.kt | 24 +- .../internal/ThreadSafeEditorConfigCache.kt | 2 +- .../ktlint/core/internal/VisitorProvider.kt | 10 +- .../ktlint/core/DisabledRulesTest.kt | 74 +-- .../com/pinterest/ktlint/core/KtLintTest.kt | 436 +++++++++--------- .../core/UsesEditorConfigPropertiesTest.kt | 28 +- .../ktlint/core/VisitorProviderTest.kt | 90 ++-- .../pinterest/ktlint/core/api/BaselineTest.kt | 8 +- .../internal/EditorConfigGeneratorTest.kt | 72 +-- .../core/internal/EditorConfigLoaderTest.kt | 94 ++-- .../core/internal/QualifiedRuleIdKtTest.kt | 8 +- .../core/internal/RuleRunnerSorterTest.kt | 146 +++--- .../internal/SuppressionLocatorBuilderTest.kt | 22 +- .../reporter/baseline/BaselineReporter.kt | 2 +- .../reporter/baseline/BaselineReporterTest.kt | 12 +- .../reporter/checkstyle/CheckStyleReporter.kt | 2 +- .../checkstyle/CheckStyleReporterTest.kt | 22 +- .../ktlint/reporter/format/FormatReporter.kt | 4 +- .../reporter/format/FormatReporterProvider.kt | 2 +- .../ktlint/reporter/format/internal/Color.kt | 2 +- .../format/FormatReporterProviderTest.kt | 20 +- .../reporter/format/FormatReporterTest.kt | 30 +- .../ktlint/reporter/html/HtmlReporterTest.kt | 10 +- .../ktlint/reporter/json/JsonReporterTest.kt | 24 +- .../ktlint/reporter/plain/PlainReporter.kt | 6 +- .../reporter/plain/PlainReporterProvider.kt | 2 +- .../ktlint/reporter/plain/internal/Color.kt | 2 +- .../plain/PlainReporterProviderTest.kt | 8 +- .../reporter/plain/PlainReporterTest.kt | 52 +-- .../ktlint/reporter/sarif/SarifReporter.kt | 26 +- .../reporter/sarif/SarifReporterTest.kt | 10 +- .../BlockCommentInitialStarAlignmentRule.kt | 6 +- .../experimental/CommentWrappingRule.kt | 16 +- .../DiscouragedCommentLocationRule.kt | 4 +- .../ExperimentalRuleSetProvider.kt | 10 +- .../experimental/FunKeywordSpacingRule.kt | 4 +- .../FunctionReturnTypeSpacingRule.kt | 6 +- .../experimental/FunctionSignatureRule.kt | 80 ++-- .../FunctionStartOfBodySpacingRule.kt | 12 +- .../FunctionTypeReferenceSpacingRule.kt | 6 +- .../ruleset/experimental/KdocWrappingRule.kt | 12 +- .../experimental/ModifierListSpacingRule.kt | 8 +- .../experimental/NullableTypeSpacingRule.kt | 2 +- .../experimental/ParameterListSpacingRule.kt | 24 +- ...enFunctionNameAndOpeningParenthesisRule.kt | 2 +- .../TypeArgumentListSpacingRule.kt | 10 +- .../TypeParameterListSpacingRule.kt | 20 +- ...saryParenthesesBeforeTrailingLambdaRule.kt | 4 +- .../BlockCommentInitialStarTest.kt | 4 +- .../experimental/CommentWrappingRuleTest.kt | 4 +- .../ExperimentalRuleSetProviderTest.kt | 2 +- .../experimental/FunctionSignatureRuleTest.kt | 78 ++-- .../FunctionStartOfBodySpacingRuleTest.kt | 16 +- .../FunctionTypeReferenceSpacingRuleTest.kt | 8 +- .../experimental/KdocWrappingRuleTest.kt | 2 +- .../ModifierListSpacingRuleTest.kt | 10 +- .../ParameterListSpacingRuleTest.kt | 10 +- .../SpacingAroundUnaryOperatorRuleTest.kt | 14 +- .../TypeArgumentListSpacingRuleTest.kt | 4 +- .../TypeParameterListSpacingRuleTest.kt | 22 +- .../ktlint/ruleset/standard/AnnotationRule.kt | 26 +- .../ruleset/standard/AnnotationSpacingRule.kt | 8 +- .../standard/ArgumentListWrappingRule.kt | 11 +- .../ruleset/standard/ChainWrappingRule.kt | 2 +- .../ruleset/standard/CommentSpacingRule.kt | 2 +- .../ruleset/standard/EnumEntryNameCaseRule.kt | 4 +- .../ktlint/ruleset/standard/FilenameRule.kt | 14 +- .../ruleset/standard/FinalNewlineRule.kt | 4 +- .../ruleset/standard/ImportOrderingRule.kt | 28 +- .../ruleset/standard/IndentationRule.kt | 62 +-- .../ruleset/standard/MaxLineLengthRule.kt | 18 +- .../ruleset/standard/ModifierOrderRule.kt | 6 +- .../ruleset/standard/MultiLineIfElseRule.kt | 6 +- .../standard/NoBlankLineBeforeRbraceRule.kt | 4 +- .../NoBlankLinesInChainedMethodCallsRule.kt | 2 +- .../standard/NoConsecutiveBlankLinesRule.kt | 2 +- .../ruleset/standard/NoEmptyClassBodyRule.kt | 2 +- .../NoEmptyFirstLineInMethodBlockRule.kt | 4 +- .../standard/NoLineBreakAfterElseRule.kt | 2 +- .../ruleset/standard/NoMultipleSpacesRule.kt | 2 +- .../ruleset/standard/NoSemicolonsRule.kt | 2 +- .../ruleset/standard/NoTrailingSpacesRule.kt | 4 +- .../ruleset/standard/NoUnitReturnRule.kt | 2 +- .../ruleset/standard/NoUnusedImportsRule.kt | 16 +- .../ruleset/standard/NoWildcardImportsRule.kt | 16 +- .../ruleset/standard/PackageNameRule.kt | 2 +- .../standard/ParameterListWrappingRule.kt | 17 +- .../SpacingAroundAngleBracketsRule.kt | 2 +- .../standard/SpacingAroundColonRule.kt | 2 +- .../standard/SpacingAroundCommaRule.kt | 2 +- .../standard/SpacingAroundCurlyRule.kt | 2 +- .../ruleset/standard/SpacingAroundDotRule.kt | 2 +- .../standard/SpacingAroundDoubleColonRule.kt | 2 +- .../standard/SpacingAroundKeywordRule.kt | 4 +- .../standard/SpacingAroundOperatorsRule.kt | 4 +- .../standard/SpacingAroundParensRule.kt | 2 +- .../SpacingAroundRangeOperatorRule.kt | 2 +- .../SpacingAroundUnaryOperatorRule.kt | 2 +- ...gBetweenDeclarationsWithAnnotationsRule.kt | 4 +- ...cingBetweenDeclarationsWithCommentsRule.kt | 4 +- .../standard/StandardRuleSetProvider.kt | 6 +- .../ruleset/standard/StringTemplateRule.kt | 4 +- .../standard/TrailingCommaOnCallSiteRule.kt | 43 +- .../TrailingCommaOnDeclarationSiteRule.kt | 55 ++- .../ktlint/ruleset/standard/WrappingRule.kt | 30 +- .../internal/importordering/ImportSorter.kt | 4 +- .../internal/importordering/PatternEntry.kt | 8 +- .../ruleset/standard/AnnotationRuleTest.kt | 8 +- .../standard/AnnotationSpacingRuleTest.kt | 4 +- .../standard/ArgumentListWrappingRuleTest.kt | 22 +- .../ruleset/standard/ChainWrappingRuleTest.kt | 6 +- .../standard/CommentSpacingRuleTest.kt | 2 +- .../standard/EnumEntryNameCaseRuleTest.kt | 2 +- .../ruleset/standard/FilenameRuleTest.kt | 34 +- .../ruleset/standard/IndentationRuleTest.kt | 138 +++--- .../ruleset/standard/MaxLineLengthRuleTest.kt | 6 +- .../ruleset/standard/ModifierOrderRuleTest.kt | 4 +- .../standard/MultiLineIfElseRuleTest.kt | 24 +- .../NoBlankLineBeforeRbraceRuleTest.kt | 2 +- .../NoConsecutiveBlankLinesRuleTest.kt | 6 +- .../standard/NoEmptyClassBodyRuleTest.kt | 2 +- .../NoEmptyFirstLineInMethodBlockRuleTest.kt | 2 +- .../NoLineBreakBeforeAssignmentRuleTest.kt | 2 +- .../ruleset/standard/NoSemicolonsRuleTest.kt | 2 +- .../standard/NoTrailingSpacesRuleTest.kt | 10 +- .../ruleset/standard/NoUnitReturnRuleTest.kt | 2 +- .../standard/NoUnusedImportsRuleTest.kt | 18 +- .../standard/NoWildcardImportsRuleTest.kt | 4 +- .../standard/ParameterListWrappingRuleTest.kt | 24 +- .../SpacingAroundAngleBracketRuleTest.kt | 6 +- .../standard/SpacingAroundColonRuleTest.kt | 6 +- .../standard/SpacingAroundCommaRuleTest.kt | 4 +- .../standard/SpacingAroundCurlyRuleTest.kt | 14 +- .../standard/SpacingAroundDotRuleTest.kt | 4 +- .../SpacingAroundDoubleColonRuleTest.kt | 8 +- .../SpacingAroundOperatorsRuleTest.kt | 24 +- .../standard/SpacingAroundParensRuleTest.kt | 2 +- .../SpacingAroundRangeOperatorRuleTest.kt | 4 +- .../SpacingAroundUnaryOperatorRuleTest.kt | 14 +- .../standard/StandardRuleSetProviderTest.kt | 2 +- .../standard/StringTemplateRuleTest.kt | 4 +- .../TrailingCommaOnCallSiteRuleTest.kt | 26 +- .../TrailingCommaOnDeclarationSiteRuleTest.kt | 34 +- .../ruleset/standard/WrappingRuleTest.kt | 34 +- .../importordering/ImportLayoutParserTest.kt | 2 +- .../ImportOrderingRuleAsciiTest.kt | 4 +- .../ImportOrderingRuleCustomTest.kt | 4 +- .../ImportOrderingRuleIdeaTest.kt | 8 +- .../RemoveDiacriticsFromLettersTest.kt | 4 +- .../yourpkgname/CustomRuleSetProvider.kt | 6 +- .../src/main/kotlin/yourpkgname/NoVarRule.kt | 2 +- .../com/pinterest/ruleset/test/DumpASTRule.kt | 12 +- .../ruleset/test/TestRuleSetProvider.kt | 4 +- .../pinterest/ruleset/test/internal/Color.kt | 19 +- .../pinterest/ktlint/test/KtLintAssertThat.kt | 56 +-- .../pinterest/ktlint/test/RuleExtension.kt | 12 +- .../ktlint/test/RuleSetProviderTest.kt | 2 +- ktlint/build.gradle.kts | 2 +- .../main/kotlin/com/pinterest/ktlint/Main.kt | 2 +- .../pinterest/ktlint/internal/FileUtils.kt | 28 +- .../GenerateEditorConfigSubCommand.kt | 10 +- .../ktlint/internal/GitHookInstaller.kt | 4 +- .../internal/GitPreCommitHookSubCommand.kt | 6 +- .../internal/GitPrePushHookSubCommand.kt | 6 +- .../ktlint/internal/KtlintCommandLine.kt | 82 ++-- .../ktlint/internal/LoadRuleProviders.kt | 10 +- .../ktlint/internal/PrintASTSubCommand.kt | 16 +- .../PrintCommandLineHelpOrVersionUsage.kt | 2 +- .../com/pinterest/ktlint/BaseCLITest.kt | 20 +- .../com/pinterest/ktlint/BaselineTests.kt | 22 +- .../pinterest/ktlint/RuleSetsLoaderCLITest.kt | 16 +- .../com/pinterest/ktlint/SimpleCLITest.kt | 16 +- .../ktlint/internal/FileUtilsTest.kt | 72 +-- settings.gradle.kts | 2 +- 200 files changed, 1649 insertions(+), 1635 deletions(-) diff --git a/.editorconfig b/.editorconfig index ac0cadddec..ee20d99bcd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/buildSrc/src/main/kotlin/ToolchainForTests.kt b/buildSrc/src/main/kotlin/ToolchainForTests.kt index 98f69babd6..8cdc4ddde3 100644 --- a/buildSrc/src/main/kotlin/ToolchainForTests.kt +++ b/buildSrc/src/main/kotlin/ToolchainForTests.kt @@ -17,7 +17,7 @@ private fun Project.addJdkVersionTests(jdkVersion: Int) { javaLauncher.set( javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(jdkVersion)) - } + }, ) } tasks.named("check") { diff --git a/buildSrc/src/main/kotlin/ktlint-publication.gradle.kts b/buildSrc/src/main/kotlin/ktlint-publication.gradle.kts index 4f898d7bd0..b02fb43c93 100644 --- a/buildSrc/src/main/kotlin/ktlint-publication.gradle.kts +++ b/buildSrc/src/main/kotlin/ktlint-publication.gradle.kts @@ -93,7 +93,9 @@ signing { // useGpgCmd() sign(publishing.publications["maven"]) - setRequired({ - !version.toString().endsWith("SNAPSHOT") - }) + setRequired( + { + !version.toString().endsWith("SNAPSHOT") + }, + ) } diff --git a/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/RuleSetProvider.kt b/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/RuleSetProvider.kt index ef315fda21..28516a1955 100644 --- a/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/RuleSetProvider.kt +++ b/ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/RuleSetProvider.kt @@ -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 diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/IndentConfig.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/IndentConfig.kt index 449d0aad60..485aba2f63 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/IndentConfig.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/IndentConfig.kt @@ -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: @@ -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 } @@ -143,7 +143,7 @@ public data class IndentConfig( public val DEFAULT_INDENT_CONFIG: IndentConfig = IndentConfig( indentStyle = SPACE, - tabWidth = 4 + tabWidth = 4, ) } } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt index e75438b358..8877573e63 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt @@ -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 = Iterable { emptySet().iterator() }, val ruleProviders: Set = emptySet(), @@ -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 = ruleProviders @@ -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() @@ -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) @@ -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 { @@ -246,7 +246,7 @@ public object KtLint { // updating the code preparedCode.suppressedRegionLocator = SuppressionLocatorBuilder.buildSuppressedRegionsLocator( - preparedCode.rootNode + preparedCode.rootNode, ) } } @@ -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, + ), ) } } @@ -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, + ), ) } } @@ -324,7 +324,7 @@ public object KtLint { * ``` */ public fun generateKotlinEditorConfigSection( - params: ExperimentalParams + params: ExperimentalParams, ): String { val filePath = params.normalizedFilePath requireNotNull(filePath) { @@ -341,7 +341,7 @@ public object KtLint { filePath, params.getRules(), params.debug, - codeStyle + codeStyle, ) } @@ -396,7 +396,7 @@ internal class RuleRunner(private val provider: RuleProvider) { "maintainer of the rule." } runAfterRuleVisitorModifier.copy( - ruleId = qualifiedAfterRuleId + ruleId = qualifiedAfterRuleId, ) } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLintKLoggerInitializer.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLintKLoggerInitializer.kt index a3247a12c4..409ceac496 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLintKLoggerInitializer.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLintKLoggerInitializer.kt @@ -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 { diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/LintError.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/LintError.kt index 1ca30e880b..004bff58d4 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/LintError.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/LintError.kt @@ -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: @@ -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 } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/ParseException.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/ParseException.kt index b457114d99..8ef6a32529 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/ParseException.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/ParseException.kt @@ -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") diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt index ca1e130387..2411fb3cd9 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt @@ -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 = emptySet() + public val visitorModifiers: Set = emptySet(), ) { private var traversalState = TraversalState.NOT_STARTED @@ -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. @@ -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, ) {} /** @@ -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, ) {} /** @@ -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 { @@ -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() @@ -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() } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleExecutionException.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleExecutionException.kt index 6de2d26e1c..8f06226035 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleExecutionException.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleExecutionException.kt @@ -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) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleProvider.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleProvider.kt index 663e00f40b..8290398912 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleProvider.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleProvider.kt @@ -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 @@ -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 = diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSet.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSet.kt index 48b66a914f..09c8dafb13 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSet.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSet.kt @@ -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 { init { diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProvider.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProvider.kt index 332cac2f19..f4dd3cfcc4 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProvider.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProvider.kt @@ -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 } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProviderV2.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProviderV2.kt index b680944163..d06fd72f36 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProviderV2.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/RuleSetProviderV2.kt @@ -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 { @@ -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) { @@ -88,7 +88,7 @@ public abstract class RuleSetProviderV2( description = "Not specified", license = "Not specified", repositoryUrl = "Not specified", - issueTrackerUrl = "Not specified" + issueTrackerUrl = "Not specified", ) } } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/Baseline.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/Baseline.kt index 2f6bbaddee..07918cc064 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/Baseline.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/Baseline.kt @@ -29,7 +29,7 @@ public class Baseline( /** * Status of the baseline file. */ - public val status: Status + public val status: Status, ) { public enum class Status { /** @@ -45,7 +45,7 @@ public class Baseline( /** * Baseline file is not successfully parsed. File needs to be regenerated by the consumer. */ - INVALID + INVALID, } } @@ -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" } @@ -115,9 +115,9 @@ private fun Element.parseBaselineErrorsByFile(): List { 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 diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt index 75833b9798..8d9c28c31d 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/EditorConfigOverride.kt @@ -31,7 +31,7 @@ public class EditorConfigOverride { * Creates the [EditorConfigOverride] based on one or more property-value mappings. */ public fun from( - vararg properties: Pair, *> + vararg properties: Pair, *>, ): EditorConfigOverride { require(properties.isNotEmpty()) { "Can not create an EditorConfigOverride without properties. Use 'emptyEditorConfigOverride' instead." @@ -49,7 +49,7 @@ public class EditorConfigOverride { * the original [EditorConfigOverride] silently. */ public fun EditorConfigOverride.plus( - vararg properties: Pair, *> + vararg properties: Pair, *>, ): EditorConfigOverride { require(properties.isNotEmpty()) { "Can not add EditorConfigOverride without properties." diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/OptInFeatures.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/OptInFeatures.kt index 85dd361532..c52b04dcee 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/OptInFeatures.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/OptInFeatures.kt @@ -2,23 +2,23 @@ package com.pinterest.ktlint.core.api @RequiresOptIn( message = "This Ktlint feature is highly experimental, and most probably will change in the future releases.", - level = RequiresOptIn.Level.ERROR + level = RequiresOptIn.Level.ERROR, ) @Retention(AnnotationRetention.BINARY) @Target( AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, - AnnotationTarget.TYPEALIAS + AnnotationTarget.TYPEALIAS, ) public annotation class FeatureInAlphaState @RequiresOptIn( - message = "This Ktlint feature is experimental, and may change in the future releases." + message = "This Ktlint feature is experimental, and may change in the future releases.", ) @Retention(AnnotationRetention.BINARY) @Target( AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, - AnnotationTarget.TYPEALIAS + AnnotationTarget.TYPEALIAS, ) public annotation class FeatureInBetaState diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt index f32ff7a891..a5f2a72360 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/api/UsesEditorConfigProperties.kt @@ -61,7 +61,7 @@ public interface UsesEditorConfigProperties { codeStyleSetProperty .type .parse( - get(codeStyleSetProperty.type.name)?.sourceValue + get(codeStyleSetProperty.type.name)?.sourceValue, ).parsed ?: official @@ -77,13 +77,13 @@ public interface UsesEditorConfigProperties { val editorConfigPropertyValues = getUserData(KtLint.EDITOR_CONFIG_PROPERTIES_USER_DATA_KEY)!! return editorConfigPropertyValues.getEditorConfigValue( editorConfigProperty, - editorConfigPropertyValues.getEditorConfigCodeStyle() + editorConfigPropertyValues.getEditorConfigCodeStyle(), ) } private fun EditorConfigProperties.getEditorConfigValue( editorConfigProperty: EditorConfigProperty, - codeStyleValue: CodeStyleValue + codeStyleValue: CodeStyleValue, ): T { if (editorConfigProperty.deprecationWarning != null) { logger.warn { "Property '${editorConfigProperty.type.name}' is deprecated: ${editorConfigProperty.deprecationWarning}" } @@ -136,7 +136,7 @@ public interface UsesEditorConfigProperties { */ public fun EditorConfigProperties.writeEditorConfigProperty( editorConfigProperty: EditorConfigProperty, - codeStyleValue: CodeStyleValue + codeStyleValue: CodeStyleValue, ): String { return editorConfigProperty.propertyWriter(getEditorConfigValue(editorConfigProperty, codeStyleValue)) } @@ -187,7 +187,7 @@ public interface UsesEditorConfigProperties { /** * Optional message to be displayed whenever the value of the property is being retrieved. */ - internal val deprecationWarning: String? = null + internal val deprecationWarning: String? = null, ) } @@ -201,7 +201,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { @Suppress("EnumEntryName", "ktlint:enum-entry-name-case") public enum class CodeStyleValue { android, - official; + official, } public val codeStyleSetProperty: UsesEditorConfigProperties.EditorConfigProperty = @@ -210,15 +210,15 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { "ktlint_code_style", "The code style ('official' or 'android') to be applied. Defaults to 'official' when not set.", EnumValueParser(CodeStyleValue::class.java), - CodeStyleValue.values().map { it.name }.toSet() + CodeStyleValue.values().map { it.name }.toSet(), ), defaultValue = official, - defaultAndroidValue = android + defaultAndroidValue = android, ) @Deprecated( message = "Marked for removal in KtLint 0.48", - replaceWith = ReplaceWith("ktlintDisabledRulesProperty") + replaceWith = ReplaceWith("ktlintDisabledRulesProperty"), ) public val disabledRulesProperty: UsesEditorConfigProperties.EditorConfigProperty = UsesEditorConfigProperties.EditorConfigProperty( @@ -226,7 +226,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { "disabled_rules", "A comma separated list of rule ids which should not be run. For rules not defined in the 'standard' ruleset, the qualified rule-id should be used.", PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - emptySet() + emptySet(), ), defaultValue = "", propertyMapper = { property, _ -> @@ -241,7 +241,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { else -> property?.getValueAs() } }, - deprecationWarning = "Rename property 'disabled_rules' to 'ktlint_disabled_rules' in all '.editorconfig' files." + deprecationWarning = "Rename property 'disabled_rules' to 'ktlint_disabled_rules' in all '.editorconfig' files.", ) public val ktlintDisabledRulesProperty: UsesEditorConfigProperties.EditorConfigProperty = @@ -250,7 +250,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { "ktlint_disabled_rules", "A comma separated list of rule ids which should not be run. For rules not defined in the 'standard' ruleset, the qualified rule-id should be used.", PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - emptySet() + emptySet(), ), defaultValue = "", propertyMapper = { property, _ -> @@ -264,13 +264,13 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { } else -> property?.getValueAs() } - } + }, ) public val indentStyleProperty: UsesEditorConfigProperties.EditorConfigProperty = UsesEditorConfigProperties.EditorConfigProperty( type = PropertyType.indent_style, - defaultValue = PropertyType.IndentStyleValue.space + defaultValue = PropertyType.IndentStyleValue.space, ) public val indentSizeProperty: UsesEditorConfigProperties.EditorConfigProperty = @@ -284,13 +284,13 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth else -> property.getValueAs() } - } + }, ) public val insertNewLineProperty: UsesEditorConfigProperties.EditorConfigProperty = UsesEditorConfigProperties.EditorConfigProperty( type = PropertyType.insert_final_newline, - defaultValue = true + defaultValue = true, ) public val maxLineLengthProperty: UsesEditorConfigProperties.EditorConfigProperty = @@ -310,7 +310,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { property.sourceValue == "off" -> -1 else -> property.getValueAs() } - } + }, ) override val editorConfigProperties: List> = listOf( @@ -319,7 +319,7 @@ public object DefaultEditorConfigProperties : UsesEditorConfigProperties { indentStyleProperty, indentSizeProperty, insertNewLineProperty, - maxLineLengthProperty + maxLineLengthProperty, ) } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt index 0eaa3920a0..89f470567b 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGenerator.kt @@ -16,7 +16,7 @@ private val logger = KotlinLogging.logger {}.initKtLintKLogger() * Rule should implement [UsesEditorConfigProperties] interface to support this. */ internal class EditorConfigGenerator( - private val editorConfigLoader: EditorConfigLoader + private val editorConfigLoader: EditorConfigLoader, ) { /** * Method loads merged `.editorconfig` content using [com.pinterest.ktlint.core.KtLint.ExperimentalParams.fileName] path, @@ -33,12 +33,12 @@ internal class EditorConfigGenerator( filePath: Path, rules: Set, debug: Boolean = false, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue + codeStyle: DefaultEditorConfigProperties.CodeStyleValue, ): String { val editorConfig: Map = editorConfigLoader.loadPropertiesForFile( filePath = filePath, rules = rules, - debug = debug + debug = debug, ) val potentialEditorConfigSettings = @@ -56,7 +56,7 @@ internal class EditorConfigGenerator( private fun getConfigurationSettingsForRules( rules: Set, editorConfig: Map, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue + codeStyle: DefaultEditorConfigProperties.CodeStyleValue, ) = rules .mapNotNull { rule -> if (rule is UsesEditorConfigProperties && rule.editorConfigProperties.isNotEmpty()) { @@ -66,7 +66,7 @@ internal class EditorConfigGenerator( val value = with(rule) { editorConfig.writeEditorConfigProperty( property, - codeStyle + codeStyle, ) } logger.debug { @@ -75,7 +75,7 @@ internal class EditorConfigGenerator( ConfigurationSetting( key = property.type.name, value = value, - usage = "Rule '${rule.id}'" + usage = "Rule '${rule.id}'", ) } } else { @@ -85,14 +85,14 @@ internal class EditorConfigGenerator( private fun getConfigurationSettingsForDefaultEditorConfigProperties( editorConfig: Map, - codeStyle: DefaultEditorConfigProperties.CodeStyleValue + codeStyle: DefaultEditorConfigProperties.CodeStyleValue, ) = DefaultEditorConfigProperties .editorConfigProperties .map { editorConfigProperty -> val value = with((DefaultEditorConfigProperties as UsesEditorConfigProperties)) { editorConfig.writeEditorConfigProperty( editorConfigProperty, - codeStyle + codeStyle, ) } logger.debug { @@ -101,7 +101,7 @@ internal class EditorConfigGenerator( ConfigurationSetting( key = editorConfigProperty.type.name, value = value, - usage = "Class '${DefaultEditorConfigProperties::class.simpleName}'" + usage = "Class '${DefaultEditorConfigProperties::class.simpleName}'", ) } @@ -121,6 +121,6 @@ internal class EditorConfigGenerator( private data class ConfigurationSetting( val key: String, val value: String, - val usage: String + val usage: String, ) } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt index 0fa1c00355..aadf5abd62 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoader.kt @@ -25,7 +25,7 @@ private val logger = KotlinLogging.logger {}.initKtLintKLogger() * Contains internal in-memory cache to speedup lookup. */ public class EditorConfigLoader( - private val fs: FileSystem + private val fs: FileSystem, ) { private val cache = ThreadSafeEditorConfigCache() @@ -52,7 +52,7 @@ public class EditorConfigLoader( alternativeEditorConfig: Path? = null, rules: Set, editorConfigOverride: EditorConfigOverride = emptyEditorConfigOverride, - debug: Boolean = false + debug: Boolean = false, ): EditorConfigProperties { if (!isStdIn && (filePath == null || SUPPORTED_FILES.none { filePath.toString().endsWith(it) }) @@ -87,7 +87,7 @@ public class EditorConfigLoader( return propService .queryProperties( - Resource.Resources.ofPath(normalizedFilePath, StandardCharsets.UTF_8) + Resource.Resources.ofPath(normalizedFilePath, StandardCharsets.UTF_8), ) .properties .also { loaded -> @@ -107,7 +107,7 @@ public class EditorConfigLoader( .map { entry -> "${entry.key}: ${entry.value.sourceValue}" } .joinToString( prefix = "Resolving .editorconfig files for $normalizedFilePath file path:\n\t", - separator = ", " + separator = ", ", ) } } @@ -121,7 +121,7 @@ public class EditorConfigLoader( } private fun createLoaderService( - rules: Set + rules: Set, ): ResourcePropertiesService { val propertyTypeRegistry = PropertyTypeRegistry.builder() .defaults() @@ -148,7 +148,7 @@ public class EditorConfigLoader( */ internal val SUPPORTED_FILES = arrayOf( ".kt", - ".kts" + ".kts", ) /** diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/KotlinPsiFileFactory.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/KotlinPsiFileFactory.kt index 433c5526d2..997647d650 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/KotlinPsiFileFactory.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/KotlinPsiFileFactory.kt @@ -50,7 +50,7 @@ internal fun initPsiFileFactory(isFromCli: Boolean): PsiFileFactory { val extensionPath = extractCompilerExtension() compilerConfiguration.put( CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, - extensionPath.toAbsolutePath().toString() + extensionPath.toAbsolutePath().toString(), ) } @@ -59,7 +59,7 @@ internal fun initPsiFileFactory(isFromCli: Boolean): PsiFileFactory { val project = KotlinCoreEnvironment.createForProduction( disposable, compilerConfiguration, - EnvironmentConfigFiles.JVM_CONFIG_FILES + EnvironmentConfigFiles.JVM_CONFIG_FILES, ).project as MockProject project.enableASTMutations() @@ -97,7 +97,7 @@ private fun extractCompilerExtension(): Path { */ private class LoggerFactory : DiagnosticLogger.Factory { override fun getLoggerInstance( - p: String + p: String, ): DiagnosticLogger = object : DefaultLogger(null) { override fun warn(message: String?, t: Throwable?) {} override fun error(message: String?, vararg details: String?) {} @@ -122,14 +122,14 @@ private fun MockProject.enableASTMutations() { private class FormatPomModel : UserDataHolderBase(), PomModel { override fun runTransaction( - transaction: PomTransaction + transaction: PomTransaction, ) { (transaction as PomTransactionBase).run() } @Suppress("UNCHECKED_CAST") override fun getModelAspect( - aspect: Class + aspect: Class, ): T? { if (aspect == TreeAspect::class.java) { // using approach described in https://git.io/vKQTo due to the magical bytecode of TreeAspect @@ -139,7 +139,7 @@ private class FormatPomModel : UserDataHolderBase(), PomModel { .getReflectionFactory() .newConstructorForSerialization( aspect, - Any::class.java.getDeclaredConstructor(*arrayOfNulls>(0)) + Any::class.java.getDeclaredConstructor(*arrayOfNulls>(0)), ) return constructor.newInstance() as T } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PositionInTextLocator.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PositionInTextLocator.kt index 62aff7065e..eee999545b 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PositionInTextLocator.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PositionInTextLocator.kt @@ -6,7 +6,7 @@ internal typealias LineAndColumn = Pair * Builds function to locate position in text - line and column based on offset from the text start. */ internal fun buildPositionInTextLocator( - text: String + text: String, ): (offset: Int) -> LineAndColumn { val textLength = text.length val arr = ArrayList() @@ -33,7 +33,7 @@ internal fun buildPositionInTextLocator( } private class SegmentTree( - sortedArray: Array + sortedArray: Array, ) { init { @@ -56,7 +56,7 @@ private class SegmentTree( private fun binarySearch( v: Int, l: Int, - r: Int + r: Int, ): Int = when { l > r -> -1 else -> { @@ -73,5 +73,5 @@ private class SegmentTree( private data class Segment( val left: Int, - val right: Int + val right: Int, ) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PreparedCode.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PreparedCode.kt index 0312c391f6..9f807db9ed 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PreparedCode.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/PreparedCode.kt @@ -16,7 +16,7 @@ internal class PreparedCode( val rootNode: FileASTNode, val editorConfigProperties: EditorConfigProperties, val positionInTextLocator: (offset: Int) -> LineAndColumn, - var suppressedRegionLocator: SuppressionLocator + var suppressedRegionLocator: SuppressionLocator, ) internal fun prepareCodeForLinting(params: KtLint.ExperimentalParams): PreparedCode { @@ -32,7 +32,7 @@ internal fun prepareCodeForLinting(params: KtLint.ExperimentalParams): PreparedC val psiFile = psiFileFactory.createFileFromText( psiFileName, KotlinLanguage.INSTANCE, - normalizedText + normalizedText, ) as KtFile val errorElement = psiFile.findErrorElement() @@ -49,7 +49,7 @@ internal fun prepareCodeForLinting(params: KtLint.ExperimentalParams): PreparedC params.editorConfigPath?.let { Paths.get(it) }, params.getRules(), params.editorConfigOverride, - params.debug + params.debug, ) if (!params.isStdIn) { @@ -66,7 +66,7 @@ internal fun prepareCodeForLinting(params: KtLint.ExperimentalParams): PreparedC rootNode, editorConfigProperties, positionInTextLocator, - suppressedRegionLocator + suppressedRegionLocator, ) } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleId.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleId.kt index 88ce6d8e95..c2ea7df102 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleId.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleId.kt @@ -16,7 +16,7 @@ internal fun String.toQualifiedRuleId() = internal fun toQualifiedRuleId( ruleSetId: String, - ruleId: String + ruleId: String, ): String { if (ruleSetId.contains(" ") || ruleId.contains(" ")) { return toQualifiedRuleId(ruleSetId.removeSpaces(), ruleId.removeSpaces()) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorter.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorter.kt index 2ffe196c56..27fb982d89 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorter.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorter.kt @@ -16,7 +16,7 @@ internal class RuleRunnerSorter { @Synchronized fun getSortedRuleRunners( ruleRunners: Set, - debug: Boolean + debug: Boolean, ): List { val debugSorter = debug && @@ -40,7 +40,7 @@ internal class RuleRunnerSorter { private fun createHashCode( ruleRunners: Set, - debug: Boolean + debug: Boolean, ): Int { val cacheKey = ruleRunners .map { it.qualifiedRuleId } @@ -95,7 +95,7 @@ internal class RuleRunnerSorter { println( "[WARN] Skipping rule with id '${currentRuleRunner.qualifiedRuleId}' as it requires " + "that the rule with id '${runAfterRule.ruleId}' is loaded. However, " + - "no rule with this id is loaded." + "no rule with this id is loaded.", ) continue } else { @@ -104,7 +104,7 @@ internal class RuleRunnerSorter { "[DEBUG] Rule with id '${currentRuleRunner.qualifiedRuleId}' should run after the " + "rule with id '${runAfterRule.ruleId}'. However, the latter " + "rule is not loaded and is allowed to be ignored. For best results, it is " + - "advised load the rule." + "advised load the rule.", ) } // As it is not required that the rule is loaded, the runAfter condition is ignored. diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilder.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilder.kt index 1491d1c7fc..105d21de1b 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilder.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilder.kt @@ -22,7 +22,7 @@ internal object SuppressionLocatorBuilder { val noSuppression: SuppressionLocator = { _, _, _ -> false } private val suppressAnnotationRuleMap = mapOf( - "RemoveCurlyBracesFromTemplate" to "string-template" + "RemoveCurlyBracesFromTemplate" to "string-template", ) private val suppressAnnotations = setOf("Suppress", "SuppressWarnings") private const val suppressAllKtlintRules = "ktlint-all" @@ -33,7 +33,7 @@ internal object SuppressionLocatorBuilder { * Builds [SuppressionLocator] for given [rootNode] of AST tree. */ fun buildSuppressedRegionsLocator( - rootNode: ASTNode + rootNode: ASTNode, ): SuppressionLocator { val hintsList = collect(rootNode) return if (hintsList.isEmpty()) { @@ -56,11 +56,11 @@ internal object SuppressionLocatorBuilder { */ private data class SuppressionHint( val range: IntRange, - val disabledRules: Set = emptySet() + val disabledRules: Set = emptySet(), ) private fun collect( - rootNode: ASTNode + rootNode: ASTNode, ): List { val result = ArrayList() val open = ArrayList() @@ -90,8 +90,8 @@ internal object SuppressionLocatorBuilder { result.add( SuppressionHint( IntRange(openingHint.range.first, node.startOffset - 1), - disabledRules - ) + disabledRules, + ), ) } } @@ -109,7 +109,7 @@ internal object SuppressionLocatorBuilder { result.addAll( open.map { SuppressionHint(IntRange(it.range.first, rootNode.textLength), it.disabledRules) - } + }, ) return result } @@ -123,7 +123,7 @@ internal object SuppressionLocatorBuilder { private fun parseHintArgs( commentText: String, - key: String + key: String, ): List? { if (commentText.startsWith(key)) { val parsedComment = splitCommentBySpace(commentText) @@ -136,7 +136,7 @@ internal object SuppressionLocatorBuilder { } private fun splitCommentBySpace( - comment: String + comment: String, ) = comment .replace(commentRegex, " ") .replace(" {2,}", " ") @@ -152,7 +152,7 @@ internal object SuppressionLocatorBuilder { private fun createSuppressionHintFromAnnotations( psi: KtAnnotated, targetAnnotations: Collection, - annotationValueToRuleMapping: Map + annotationValueToRuleMapping: Map, ): SuppressionHint? = psi .annotationEntries @@ -168,12 +168,12 @@ internal object SuppressionLocatorBuilder { suppressedRules.contains(suppressAllKtlintRules) -> SuppressionHint( IntRange(psi.startOffset, psi.endOffset), - emptySet() + emptySet(), ) else -> SuppressionHint( IntRange(psi.startOffset, psi.endOffset), - suppressedRules.toSet() + suppressedRules.toSet(), ) } } diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/ThreadSafeEditorConfigCache.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/ThreadSafeEditorConfigCache.kt index 2f277f28d3..f23419a8d8 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/ThreadSafeEditorConfigCache.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/ThreadSafeEditorConfigCache.kt @@ -17,7 +17,7 @@ internal class ThreadSafeEditorConfigCache : Cache { override fun get( editorConfigFile: Resource, - loader: EditorConfigLoader + loader: EditorConfigLoader, ): EditorConfig { readWriteLock.read { return inMemoryMap[editorConfigFile] diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt index 7e1f458ab4..3ad6b2b989 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/VisitorProvider.kt @@ -21,11 +21,11 @@ internal class VisitorProvider( /** * Creates a new [RuleRunnerSorter]. Only to be used in unit tests where the same set of rules are used with distinct [Rule.VisitorModifier]s. */ - recreateRuleSorter: Boolean = false + recreateRuleSorter: Boolean = false, ) : UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( ktlintDisabledRulesProperty, - disabledRulesProperty + disabledRulesProperty, ) /** @@ -45,7 +45,7 @@ internal class VisitorProvider( if (enabledRuleRunners.isEmpty()) { if (params.debug && enabledRuleRunners.isEmpty()) { println( - "[DEBUG] Skipping file as no enabled rules are found to be executed" + "[DEBUG] Skipping file as no enabled rules are found to be executed", ) } return { _ -> } @@ -64,7 +64,7 @@ internal class VisitorProvider( println( "[DEBUG] Skipping rule with id '${it.qualifiedRuleId}'. This rule has to run after rule with " + "id '${it.runAfterRule?.ruleId?.toQualifiedRuleId()}' and will not run in case that rule is " + - "disabled." + "disabled.", ) } } @@ -72,7 +72,7 @@ internal class VisitorProvider( if (ruleRunnersToExecute.isEmpty()) { if (params.debug) { println( - "[DEBUG] Skipping file as no enabled rules are found to be executed" + "[DEBUG] Skipping file as no enabled rules are found to be executed", ) } return { _ -> } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt index 013d9a6d2c..3383f7153b 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/DisabledRulesTest.kt @@ -20,16 +20,16 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule("no-var") } + RuleProvider { NoVarRule("no-var") }, ), - cb = { e, _ -> add(e) } - ) + cb = { e, _ -> add(e) }, + ), ) - } + }, ).isEqualTo( listOf( - LintError(1, 1, "no-var", "Unexpected var, use val instead") - ) + LintError(1, 1, "no-var", "Unexpected var, use val instead"), + ), ) } @@ -44,12 +44,12 @@ class DisabledRulesTest { "standard:no-var,no-var", "standard:no-var,standard:no-var", "experimental:no-var,experimental:no-var", - "custom:no-var,custom:no-var" - ] + "custom:no-var,custom:no-var", + ], ) fun `Given some code and a disabled standard rule then no violation is reported`( ruleId: String, - disabledRuleId: String + disabledRuleId: String, ) { assertThat( ArrayList().apply { @@ -57,13 +57,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule(ruleId) } + RuleProvider { NoVarRule(ruleId) }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to disabledRuleId) - ) + editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to disabledRuleId), + ), ) - } + }, ).isEmpty() } @@ -75,13 +75,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule("no-var") } + RuleProvider { NoVarRule("no-var") }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to "no-var") - ) + editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to "no-var"), + ), ) - } + }, ).isEmpty() } @@ -93,13 +93,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule("experimental:no-var") } + RuleProvider { NoVarRule("experimental:no-var") }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to "experimental:no-var") - ) + editorConfigOverride = EditorConfigOverride.from(disabledRulesProperty to "experimental:no-var"), + ), ) - } + }, ).isEmpty() } } @@ -114,12 +114,12 @@ class DisabledRulesTest { "standard:no-var,no-var", "standard:no-var,standard:no-var", "experimental:no-var,experimental:no-var", - "custom:no-var,custom:no-var" - ] + "custom:no-var,custom:no-var", + ], ) fun `Given some code and a disabled standard rule then no violation is reported`( ruleId: String, - disabledRuleId: String + disabledRuleId: String, ) { assertThat( ArrayList().apply { @@ -127,13 +127,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule(ruleId) } + RuleProvider { NoVarRule(ruleId) }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to disabledRuleId) - ) + editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to disabledRuleId), + ), ) - } + }, ).isEmpty() } @@ -145,13 +145,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule("no-var") } + RuleProvider { NoVarRule("no-var") }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to "no-var") - ) + editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to "no-var"), + ), ) - } + }, ).isEmpty() } @@ -163,13 +163,13 @@ class DisabledRulesTest { KtLint.ExperimentalParams( text = "var foo", ruleProviders = setOf( - RuleProvider { NoVarRule("experimental:no-var") } + RuleProvider { NoVarRule("experimental:no-var") }, ), cb = { e, _ -> add(e) }, - editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to "experimental:no-var") - ) + editorConfigOverride = EditorConfigOverride.from(ktlintDisabledRulesProperty to "experimental:no-var"), + ), ) - } + }, ).isEmpty() } } @@ -178,7 +178,7 @@ class DisabledRulesTest { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == ElementType.VAR_KEYWORD) { emit(node.startOffset, "Unexpected var, use val instead", false) diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt index 5c8e01bca6..176ef44cd9 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/KtLintTest.kt @@ -52,8 +52,8 @@ class KtLintTest { cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalArgumentException::class.java) .hasMessage("Provide exactly one of parameters 'ruleSets' or 'ruleProviders'") @@ -67,17 +67,17 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalArgumentException::class.java) .hasMessage("Provide exactly one of parameters 'ruleSets' or 'ruleProviders'") @@ -101,15 +101,15 @@ class KtLintTest { if (node.isRoot()) { numberOfRootNodesVisited++ } - } - ) + }, + ), ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(numberOfRootNodesVisited).isEqualTo(1) } @@ -122,21 +122,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), userData = mapOf("max_line_length" to "80"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [max_line_length]. Such properties " + "should be passed via the 'ExperimentalParams.editorConfigOverride' field. Note that " + "this is only required for properties that (potentially) contain a value that differs " + - "from the actual value in the '.editorconfig' file." + "from the actual value in the '.editorconfig' file.", ) } @@ -148,24 +148,24 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), userData = mapOf( "indent_style" to "space", - "indent_size" to "4" + "indent_size" to "4", ), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [indent_size, indent_style]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -177,21 +177,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRuleWithCustomEditorConfigProperty()) + RuleSet("standard", DummyRuleWithCustomEditorConfigProperty()), ), userData = mapOf(SOME_CUSTOM_RULE_PROPERTY to "false"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [$SOME_CUSTOM_RULE_PROPERTY]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -207,7 +207,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleSets = listOf( - RuleSet("standard", AutoCorrectErrorRule()) + RuleSet("standard", AutoCorrectErrorRule()), ), userData = emptyMap(), cb = { e, corrected -> @@ -218,14 +218,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(callbacks).containsExactly( CallbackResult( @@ -234,7 +234,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -242,8 +242,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = false - ) + corrected = false, + ), ) } } @@ -265,14 +265,14 @@ class KtLintTest { numberOfRootNodesVisited++ } } - } + }, ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(numberOfRootNodesVisited).isEqualTo(1) } @@ -285,21 +285,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = mapOf("max_line_length" to "80"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [max_line_length]. Such properties " + "should be passed via the 'ExperimentalParams.editorConfigOverride' field. Note that " + "this is only required for properties that (potentially) contain a value that differs " + - "from the actual value in the '.editorconfig' file." + "from the actual value in the '.editorconfig' file.", ) } @@ -311,24 +311,24 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = mapOf( "indent_style" to "space", - "indent_size" to "4" + "indent_size" to "4", ), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [indent_size, indent_style]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -340,21 +340,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRuleWithCustomEditorConfigProperty() } + RuleProvider { DummyRuleWithCustomEditorConfigProperty() }, ), userData = mapOf(SOME_CUSTOM_RULE_PROPERTY to "false"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [$SOME_CUSTOM_RULE_PROPERTY]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -370,7 +370,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleProviders = setOf( - RuleProvider { AutoCorrectErrorRule() } + RuleProvider { AutoCorrectErrorRule() }, ), userData = emptyMap(), cb = { e, corrected -> @@ -381,14 +381,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(callbacks).containsExactly( CallbackResult( @@ -397,7 +397,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -405,8 +405,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = false - ) + corrected = false, + ), ) } } @@ -423,7 +423,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleSets = listOf( - RuleSet("standard", AutoCorrectErrorRule()) + RuleSet("standard", AutoCorrectErrorRule()), ), userData = emptyMap(), cb = { e, corrected -> @@ -434,14 +434,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(callbacks).containsExactly( CallbackResult( @@ -450,7 +450,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -458,8 +458,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = false - ) + corrected = false, + ), ) } } @@ -479,8 +479,8 @@ class KtLintTest { cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalArgumentException::class.java) .hasMessage("Provide exactly one of parameters 'ruleSets' or 'ruleProviders'") @@ -494,17 +494,17 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalArgumentException::class.java) .hasMessage("Provide exactly one of parameters 'ruleSets' or 'ruleProviders'") @@ -528,15 +528,15 @@ class KtLintTest { if (node.isRoot()) { numberOfRootNodesVisited++ } - } - ) + }, + ), ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(numberOfRootNodesVisited).isEqualTo(1) } @@ -549,21 +549,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), userData = mapOf("max_line_length" to "80"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [max_line_length]. Such properties " + "should be passed via the 'ExperimentalParams.editorConfigOverride' field. Note that " + "this is only required for properties that (potentially) contain a value that differs " + - "from the actual value in the '.editorconfig' file." + "from the actual value in the '.editorconfig' file.", ) } @@ -575,24 +575,24 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRule()) + RuleSet("standard", DummyRule()), ), userData = mapOf( "indent_style" to "space", - "indent_size" to "4" + "indent_size" to "4", ), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [indent_size, indent_style]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -604,21 +604,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleSets = listOf( - RuleSet("standard", DummyRuleWithCustomEditorConfigProperty()) + RuleSet("standard", DummyRuleWithCustomEditorConfigProperty()), ), userData = mapOf(SOME_CUSTOM_RULE_PROPERTY to "false"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [$SOME_CUSTOM_RULE_PROPERTY]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } } @@ -640,7 +640,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleSets = listOf( - RuleSet("standard", AutoCorrectErrorRule()) + RuleSet("standard", AutoCorrectErrorRule()), ), userData = emptyMap(), cb = { e, corrected -> @@ -651,14 +651,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(actualFormattedCode).isEqualTo(formattedCode) assertThat(callbacks).containsExactly( @@ -668,7 +668,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -676,8 +676,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = true - ) + corrected = true, + ), ) } } @@ -699,7 +699,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleSets = listOf( - RuleSet("standard", AutoCorrectErrorRule()) + RuleSet("standard", AutoCorrectErrorRule()), ), userData = emptyMap(), cb = { e, corrected -> @@ -710,14 +710,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(actualFormattedCode).isEqualTo(formattedCode) assertThat(callbacks).containsExactly( @@ -727,7 +727,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -735,8 +735,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = true - ) + corrected = true, + ), ) } } @@ -758,14 +758,14 @@ class KtLintTest { numberOfRootNodesVisited++ } } - } + }, ), userData = emptyMap(), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(numberOfRootNodesVisited).isEqualTo(1) } @@ -778,21 +778,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = mapOf("max_line_length" to "80"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [max_line_length]. Such properties " + "should be passed via the 'ExperimentalParams.editorConfigOverride' field. Note that " + "this is only required for properties that (potentially) contain a value that differs " + - "from the actual value in the '.editorconfig' file." + "from the actual value in the '.editorconfig' file.", ) } @@ -804,24 +804,24 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), userData = mapOf( "indent_style" to "space", - "indent_size" to "4" + "indent_size" to "4", ), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [indent_size, indent_style]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -833,21 +833,21 @@ class KtLintTest { fileName = "some-filename", text = "fun main() {}", ruleProviders = setOf( - RuleProvider { DummyRuleWithCustomEditorConfigProperty() } + RuleProvider { DummyRuleWithCustomEditorConfigProperty() }, ), userData = mapOf(SOME_CUSTOM_RULE_PROPERTY to "false"), cb = { _, _ -> }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage( "UserData should not contain '.editorconfig' properties [$SOME_CUSTOM_RULE_PROPERTY]. Such" + " properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. " + "Note that this is only required for properties that (potentially) contain a value that " + - "differs from the actual value in the '.editorconfig' file." + "differs from the actual value in the '.editorconfig' file.", ) } @@ -868,7 +868,7 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleProviders = setOf( - RuleProvider { AutoCorrectErrorRule() } + RuleProvider { AutoCorrectErrorRule() }, ), userData = emptyMap(), cb = { e, corrected -> @@ -879,14 +879,14 @@ class KtLintTest { ruleId = e.ruleId, detail = e.detail, canBeAutoCorrected = e.canBeAutoCorrected, - corrected = corrected - ) + corrected = corrected, + ), ) }, script = false, editorConfigPath = null, - debug = false - ) + debug = false, + ), ) assertThat(actualFormattedCode).isEqualTo(formattedCode) assertThat(callbacks).containsExactly( @@ -896,7 +896,7 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_NOT_BE_AUTOCORRECTED, canBeAutoCorrected = false, - corrected = false + corrected = false, ), CallbackResult( line = 2, @@ -904,8 +904,8 @@ class KtLintTest { ruleId = "auto-correct", detail = AutoCorrectErrorRule.ERROR_MESSAGE_CAN_BE_AUTOCORRECTED, canBeAutoCorrected = true, - corrected = true - ) + corrected = true, + ), ) } } @@ -926,19 +926,19 @@ class KtLintTest { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, id = "a", - visitorModifiers = setOf() + visitorModifiers = setOf(), ) }, RuleProvider { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, id = "b", - visitorModifiers = setOf(RunAsLateAsPossible) + visitorModifiers = setOf(RunAsLateAsPossible), ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( RuleExecutionCall("a", VISIT, ROOT, FILE), @@ -946,7 +946,7 @@ class KtLintTest { RuleExecutionCall("a", VISIT, CHILD, IMPORT_LIST), RuleExecutionCall("b", VISIT, ROOT, FILE), RuleExecutionCall("b", VISIT, CHILD, PACKAGE_DIRECTIVE), - RuleExecutionCall("b", VISIT, CHILD, IMPORT_LIST) + RuleExecutionCall("b", VISIT, CHILD, IMPORT_LIST), ) } @@ -961,7 +961,7 @@ class KtLintTest { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, id = "a", - visitorModifiers = setOf(RunOnRootNodeOnly) + visitorModifiers = setOf(RunOnRootNodeOnly), ) }, RuleProvider { @@ -970,17 +970,17 @@ class KtLintTest { id = "b", visitorModifiers = setOf( RunOnRootNodeOnly, - RunAsLateAsPossible - ) + RunAsLateAsPossible, + ), ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( RuleExecutionCall("a", VISIT, ROOT, FILE), - RuleExecutionCall("b", VISIT, ROOT, FILE) + RuleExecutionCall("b", VISIT, ROOT, FILE), ) } @@ -996,7 +996,7 @@ class KtLintTest { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, id = "e", - visitorModifiers = setOf(RunAsLateAsPossible) + visitorModifiers = setOf(RunAsLateAsPossible), ) }, RuleProvider { @@ -1005,14 +1005,14 @@ class KtLintTest { id = "d", visitorModifiers = setOf( RunOnRootNodeOnly, - RunAsLateAsPossible - ) + RunAsLateAsPossible, + ), ) }, RuleProvider { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, - id = "b" + id = "b", ) }, RuleProvider { @@ -1020,19 +1020,19 @@ class KtLintTest { ruleExecutionCalls = ruleExecutionCalls, id = "a", visitorModifiers = setOf( - RunOnRootNodeOnly - ) + RunOnRootNodeOnly, + ), ) }, RuleProvider { SimpleTestRuleLegacy( ruleExecutionCalls = ruleExecutionCalls, - id = "c" + id = "c", ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( RuleExecutionCall("a", VISIT, ROOT, FILE), @@ -1045,7 +1045,7 @@ class KtLintTest { RuleExecutionCall("d", VISIT, ROOT, FILE), RuleExecutionCall("e", VISIT, ROOT, FILE), RuleExecutionCall("e", VISIT, CHILD, PACKAGE_DIRECTIVE), - RuleExecutionCall("e", VISIT, CHILD, IMPORT_LIST) + RuleExecutionCall("e", VISIT, CHILD, IMPORT_LIST), ) } } @@ -1065,19 +1065,19 @@ class KtLintTest { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, id = "a", - visitorModifiers = setOf() + visitorModifiers = setOf(), ) }, RuleProvider { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, id = "b", - visitorModifiers = setOf(RunAsLateAsPossible) + visitorModifiers = setOf(RunAsLateAsPossible), ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( // File a @@ -1097,7 +1097,7 @@ class KtLintTest { RuleExecutionCall("b", BEFORE_CHILDREN, CHILD, IMPORT_LIST), RuleExecutionCall("b", AFTER_CHILDREN, CHILD, IMPORT_LIST), RuleExecutionCall("b", AFTER_CHILDREN, ROOT, FILE), - RuleExecutionCall("b", AFTER_LAST) + RuleExecutionCall("b", AFTER_LAST), ) } @@ -1112,19 +1112,19 @@ class KtLintTest { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, id = "a", - visitorModifiers = setOf(RunOnRootNodeOnly) + visitorModifiers = setOf(RunOnRootNodeOnly), ) }, RuleProvider { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, id = "b", - visitorModifiers = setOf(RunOnRootNodeOnly, RunAsLateAsPossible) + visitorModifiers = setOf(RunOnRootNodeOnly, RunAsLateAsPossible), ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( // File a @@ -1136,7 +1136,7 @@ class KtLintTest { RuleExecutionCall("b", BEFORE_FIRST), RuleExecutionCall("b", BEFORE_CHILDREN, ROOT, FILE), RuleExecutionCall("b", AFTER_CHILDREN, ROOT, FILE), - RuleExecutionCall("b", AFTER_LAST) + RuleExecutionCall("b", AFTER_LAST), ) } @@ -1152,7 +1152,7 @@ class KtLintTest { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, id = "e", - visitorModifiers = setOf(RunAsLateAsPossible) + visitorModifiers = setOf(RunAsLateAsPossible), ) }, RuleProvider { @@ -1161,14 +1161,14 @@ class KtLintTest { id = "d", visitorModifiers = setOf( RunOnRootNodeOnly, - RunAsLateAsPossible - ) + RunAsLateAsPossible, + ), ) }, RuleProvider { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, - id = "b" + id = "b", ) }, RuleProvider { @@ -1176,19 +1176,19 @@ class KtLintTest { ruleExecutionCalls = ruleExecutionCalls, id = "a", visitorModifiers = setOf( - RunOnRootNodeOnly - ) + RunOnRootNodeOnly, + ), ) }, RuleProvider { SimpleTestRule( ruleExecutionCalls = ruleExecutionCalls, - id = "c" + id = "c", ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( // File a (root only) @@ -1227,7 +1227,7 @@ class KtLintTest { RuleExecutionCall("e", BEFORE_CHILDREN, CHILD, IMPORT_LIST), RuleExecutionCall("e", AFTER_CHILDREN, CHILD, IMPORT_LIST), RuleExecutionCall("e", AFTER_CHILDREN, ROOT, FILE), - RuleExecutionCall("e", AFTER_LAST) + RuleExecutionCall("e", AFTER_LAST), ) } } @@ -1240,10 +1240,10 @@ class KtLintTest { KtLint.ExperimentalParams( text = code, ruleProviders = setOf( - RuleProvider { DummyRule() } + RuleProvider { DummyRule() }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(actual).isEqualTo(code) @@ -1262,17 +1262,17 @@ class KtLintTest { SimpleTestRule( id = "stop-traversal", ruleExecutionCalls = ruleExecutionCalls, - stopTraversalInBeforeFirstNode = true + stopTraversalInBeforeFirstNode = true, ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( RuleExecutionCall("stop-traversal", BEFORE_FIRST), - RuleExecutionCall("stop-traversal", AFTER_LAST) + RuleExecutionCall("stop-traversal", AFTER_LAST), ) } @@ -1300,12 +1300,12 @@ class KtLintTest { stopTraversalInBeforeVisitChildNodes = { node -> // Stop when Class Foo has been entered node.elementType == CLASS && node.findChildByType(IDENTIFIER)?.text == "Foo" - } + }, ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls) @@ -1316,7 +1316,7 @@ class KtLintTest { RuleExecutionCall("stop-traversal", BEFORE_CHILDREN, CHILD, CLASS, "Foo"), RuleExecutionCall("stop-traversal", AFTER_CHILDREN, CHILD, CLASS, "Foo"), RuleExecutionCall("stop-traversal", AFTER_CHILDREN, CHILD, CLASS, "FooBar"), - RuleExecutionCall("stop-traversal", AFTER_LAST) + RuleExecutionCall("stop-traversal", AFTER_LAST), ) } @@ -1344,12 +1344,12 @@ class KtLintTest { stopTraversalInAfterVisitChildNodes = { node -> // Stop when Class Foo has been visited node.elementType == CLASS && node.findChildByType(IDENTIFIER)?.text == "Foo" - } + }, ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls) @@ -1362,7 +1362,7 @@ class KtLintTest { RuleExecutionCall("stop-traversal", AFTER_CHILDREN, CHILD, CLASS, "InsideFoo"), RuleExecutionCall("stop-traversal", AFTER_CHILDREN, CHILD, CLASS, "Foo"), RuleExecutionCall("stop-traversal", AFTER_CHILDREN, CHILD, CLASS, "FooBar"), - RuleExecutionCall("stop-traversal", AFTER_LAST) + RuleExecutionCall("stop-traversal", AFTER_LAST), ) } @@ -1377,17 +1377,17 @@ class KtLintTest { SimpleTestRule( id = "stop-traversal", ruleExecutionCalls = ruleExecutionCalls, - stopTraversalInBeforeFirstNode = true + stopTraversalInBeforeFirstNode = true, ) - } + }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) assertThat(ruleExecutionCalls).containsExactly( RuleExecutionCall("stop-traversal", BEFORE_FIRST), - RuleExecutionCall("stop-traversal", AFTER_LAST) + RuleExecutionCall("stop-traversal", AFTER_LAST), ) } } @@ -1409,11 +1409,11 @@ class KtLintTest { ruleSets = listOf( RuleSet( "with-state-and-rule-sets", - WithStateRule() - ) + WithStateRule(), + ), ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) }.isInstanceOf(IllegalStateException::class.java) .hasMessage("Rule has been visited before") @@ -1430,10 +1430,10 @@ class KtLintTest { KtLint.ExperimentalParams( text = "", ruleProviders = setOf( - RuleProvider { WithStateRule() } + RuleProvider { WithStateRule() }, ), - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) } } @@ -1454,9 +1454,9 @@ private class DummyRuleWithCustomEditorConfigProperty : SOME_CUSTOM_RULE_PROPERTY, "some-custom-rule-property-description", PropertyType.PropertyValueParser.BOOLEAN_VALUE_PARSER, - setOf(true.toString(), false.toString()) + setOf(true.toString(), false.toString()), ), - defaultValue = false + defaultValue = false, ) } } @@ -1465,12 +1465,12 @@ private class DummyRuleWithCustomEditorConfigProperty : * A dummy rule for testing. Optionally the rule can be created with a lambda to be executed for each node visited. */ private open class DummyRule( - val block: (node: ASTNode) -> Unit = {} + val block: (node: ASTNode) -> Unit = {}, ) : Rule(DUMMY_RULE_ID) { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { block(node) } @@ -1488,7 +1488,7 @@ private class AutoCorrectErrorRule : Rule("auto-correct") { override fun visit( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == REGULAR_STRING_PART) { when (node.text) { @@ -1521,12 +1521,12 @@ private class AutoCorrectErrorRule : Rule("auto-correct") { private class SimpleTestRuleLegacy( private val ruleExecutionCalls: MutableList, id: String, - visitorModifiers: Set = emptySet() + visitorModifiers: Set = emptySet(), ) : Rule(id, visitorModifiers) { override fun visit( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { ruleExecutionCalls.add(RuleExecutionCall(id, VISIT, node.visitNodeType, node.elementType)) } @@ -1544,7 +1544,7 @@ private class SimpleTestRule( private val stopTraversalInBeforeFirstNode: Boolean = false, private val stopTraversalInBeforeVisitChildNodes: (ASTNode) -> Boolean = { false }, private val stopTraversalInAfterVisitChildNodes: (ASTNode) -> Boolean = { false }, - private val stopTraversalInAfterLastNode: Boolean = false + private val stopTraversalInAfterLastNode: Boolean = false, ) : Rule(id, visitorModifiers) { override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { ruleExecutionCalls.add(RuleExecutionCall(id, BEFORE_FIRST)) @@ -1556,7 +1556,7 @@ private class SimpleTestRule( override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { ruleExecutionCalls.add(node.toRuleExecutionCall(id, BEFORE_CHILDREN)) if (stopTraversalInBeforeVisitChildNodes(node)) { @@ -1567,7 +1567,7 @@ private class SimpleTestRule( override fun visit( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { ruleExecutionCalls.add(node.toRuleExecutionCall(id, VISIT)) } @@ -1575,7 +1575,7 @@ private class SimpleTestRule( override fun afterVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { ruleExecutionCalls.add(node.toRuleExecutionCall(id, AFTER_CHILDREN)) if (stopTraversalInAfterVisitChildNodes(node)) { @@ -1600,7 +1600,7 @@ private class SimpleTestRule( findChildByType(IDENTIFIER)?.text } else { null - } + }, ) } @@ -1609,7 +1609,7 @@ private data class RuleExecutionCall( val ruleMethod: RuleMethod, val visitNodeType: VisitNodeType? = null, val elementType: IElementType? = null, - val classIdentifier: String? = null + val classIdentifier: String? = null, ) { enum class RuleMethod { BEFORE_FIRST, BEFORE_CHILDREN, VISIT, AFTER_CHILDREN, AFTER_LAST } enum class VisitNodeType { ROOT, CHILD } @@ -1634,7 +1634,7 @@ private data class CallbackResult( val ruleId: String, val detail: String, val canBeAutoCorrected: Boolean, - val corrected: Boolean + val corrected: Boolean, ) /** @@ -1653,7 +1653,7 @@ private class WithStateRule : Rule("with-state") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { emit(node.startOffset, "Fake violation which can be autocorrected", true) } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/UsesEditorConfigPropertiesTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/UsesEditorConfigPropertiesTest.kt index da73a7341c..a895d15f34 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/UsesEditorConfigPropertiesTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/UsesEditorConfigPropertiesTest.kt @@ -18,7 +18,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property indent_size is set to an integer value then return that integer value via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( indentSizeProperty, - SOME_INTEGER_VALUE.toString() + SOME_INTEGER_VALUE.toString(), ) val actual = with(EditorConfigPropertiesTester(indentSizeProperty)) { @@ -32,7 +32,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property indent_size is set to value 'unset' then return -1 as value via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( indentSizeProperty, - "unset" + "unset", ) val actual = with(EditorConfigPropertiesTester(indentSizeProperty)) { @@ -46,7 +46,7 @@ class UsesEditorConfigPropertiesTest { fun `Issue 1485 - Given that editor config property indent_size is set to value 'tab' then return tabWidth as value via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( indentSizeProperty, - "tab" + "tab", ) val actual = with(EditorConfigPropertiesTester(indentSizeProperty)) { @@ -74,7 +74,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property max_line_length is set to an integer value then return that integer value via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( maxLineLengthProperty, - SOME_INTEGER_VALUE.toString() + SOME_INTEGER_VALUE.toString(), ) val actual = with(EditorConfigPropertiesTester(maxLineLengthProperty)) { @@ -88,7 +88,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property max_line_length is set to value 'off' then return -1 via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( maxLineLengthProperty, - "off" + "off", ) val actual = with(EditorConfigPropertiesTester(maxLineLengthProperty)) { @@ -102,7 +102,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property max_line_length is set to value 'unset' for android then return 100 via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( maxLineLengthProperty, - "unset" + "unset", ).plus(ANDROID_CODE_STYLE) val actual = with(EditorConfigPropertiesTester(maxLineLengthProperty)) { @@ -116,7 +116,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property max_line_length is set to value 'unset' for non-android then return -1 via the getEditorConfigValue of the node`() { val editorConfigProperties = createEditorConfigPropertiesFrom( maxLineLengthProperty, - "unset" + "unset", ).plus(OFFICIAL_CODE_STYLE) val actual = with(EditorConfigPropertiesTester(maxLineLengthProperty)) { @@ -150,7 +150,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property disabled_rules is set and has spacing around the comma, then retrieve the list without those spaces'`() { val editorConfigProperties = createEditorConfigPropertiesFrom( disabledRulesProperty, - "$RULE_A, $RULE_B,$RULE_C , $RULE_D" + "$RULE_A, $RULE_B,$RULE_C , $RULE_D", ) val actual = with(EditorConfigPropertiesTester(disabledRulesProperty)) { @@ -164,7 +164,7 @@ class UsesEditorConfigPropertiesTest { fun `Given that editor config property ktlint_disabled_rules is set and has spacing around the comma, then retrieve the list without those spaces'`() { val editorConfigProperties = createEditorConfigPropertiesFrom( ktlintDisabledRulesProperty, - "$RULE_A, $RULE_B,$RULE_C , $RULE_D" + "$RULE_A, $RULE_B,$RULE_C , $RULE_D", ) val actual = with(EditorConfigPropertiesTester(ktlintDisabledRulesProperty)) { @@ -175,7 +175,7 @@ class UsesEditorConfigPropertiesTest { } class EditorConfigPropertiesTester( - editorConfigProperty: UsesEditorConfigProperties.EditorConfigProperty + editorConfigProperty: UsesEditorConfigProperties.EditorConfigProperty, ) : UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf(editorConfigProperty) } @@ -188,16 +188,16 @@ class UsesEditorConfigPropertiesTest { const val SOME_INTEGER_VALUE = 123 val ANDROID_CODE_STYLE = createEditorConfigPropertiesFrom( DefaultEditorConfigProperties.codeStyleSetProperty, - DefaultEditorConfigProperties.CodeStyleValue.android.name.lowercase() + DefaultEditorConfigProperties.CodeStyleValue.android.name.lowercase(), ) val OFFICIAL_CODE_STYLE = createEditorConfigPropertiesFrom( DefaultEditorConfigProperties.codeStyleSetProperty, - DefaultEditorConfigProperties.CodeStyleValue.official.name.lowercase() + DefaultEditorConfigProperties.CodeStyleValue.official.name.lowercase(), ) private fun createEditorConfigPropertiesFrom( editorConfigProperty: UsesEditorConfigProperties.EditorConfigProperty, - value: String + value: String, ) = with(editorConfigProperty) { mapOf( @@ -205,7 +205,7 @@ class UsesEditorConfigPropertiesTest { .name(type.name) .type(type) .value(value) - .build() + .build(), ) } } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt index 6ddc1fbbe4..981a3d2abd 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/VisitorProviderTest.kt @@ -17,11 +17,11 @@ class VisitorProviderTest { @Test fun `A root only rule only visits the FILE node only`() { val actual = testVisitorProviderWithDisabledRulesProperty( - RuleProvider { RootNodeOnlyRule(ROOT_NODE_ONLY_RULE) } + RuleProvider { RootNodeOnlyRule(ROOT_NODE_ONLY_RULE) }, ) assertThat(actual).containsExactly( - Visit(ROOT_NODE_ONLY_RULE) + Visit(ROOT_NODE_ONLY_RULE), ) } @@ -30,24 +30,24 @@ class VisitorProviderTest { val actual = testVisitorProviderWithDisabledRulesProperty( RuleProvider { NormalRule(RULE_A) }, RuleProvider { RunAsLateAsPossibleRule(RULE_B) }, - RuleProvider { NormalRule(RULE_C) } + RuleProvider { NormalRule(RULE_C) }, ) assertThat(actual).containsExactly( Visit(RULE_A), Visit(RULE_C), - Visit(RULE_B) + Visit(RULE_B), ) } @Test fun `A run as late as possible on root node only rule visits the root node only`() { val actual = testVisitorProviderWithDisabledRulesProperty( - RuleProvider { RunAsLateAsPossibleOnRootNodeOnlyRule(RUN_AS_LATE_AS_POSSIBLE_RULE) } + RuleProvider { RunAsLateAsPossibleOnRootNodeOnlyRule(RUN_AS_LATE_AS_POSSIBLE_RULE) }, ) assertThat(actual).containsExactly( - Visit(RUN_AS_LATE_AS_POSSIBLE_RULE) + Visit(RUN_AS_LATE_AS_POSSIBLE_RULE), ) } @@ -59,20 +59,20 @@ class VisitorProviderTest { RuleProvider { NormalRule("$EXPERIMENTAL:$RULE_B") }, RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_EXPERIMENTAL_RULE_SET) }, RuleProvider { NormalRule("$CUSTOM_RULE_SET_A:$RULE_C") }, - RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A) } + RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A) }, ) assertThat(actual).containsExactly( Visit(RULE_A), Visit(EXPERIMENTAL, RULE_B), - Visit(CUSTOM_RULE_SET_A, RULE_C) + Visit(CUSTOM_RULE_SET_A, RULE_C), ) } @Test fun `When no enabled rules are found for the root node, the visit function on the root node is not executed`() { val actual = testVisitorProviderWithDisabledRulesProperty( - RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_STANDARD_RULE_SET) } + RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_STANDARD_RULE_SET) }, ) assertThat(actual).isNull() @@ -87,10 +87,10 @@ class VisitorProviderTest { id = RULE_A, visitorModifier = VisitorModifier.RunAfterRule( ruleId = SOME_DISABLED_RULE_IN_STANDARD_RULE_SET, - runOnlyWhenOtherRuleIsEnabled = true - ) + runOnlyWhenOtherRuleIsEnabled = true, + ), ) {} - } + }, ) assertThat(actual).isNull() @@ -108,19 +108,19 @@ class VisitorProviderTest { cb = { _, _ -> }, ruleProviders = ruleProviders.toSet(), // Enable debug mode as it is helpful when a test fails - debug = true + debug = true, ), // Creates a new VisitorProviderFactory for each unit test to prevent that tests for the exact same set of // ruleIds are influencing each other. - recreateRuleSorter = true + recreateRuleSorter = true, ).run { var visits: MutableList? = null visitor( disabledRulesEditorConfigProperties( SOME_DISABLED_RULE_IN_STANDARD_RULE_SET, SOME_DISABLED_RULE_IN_EXPERIMENTAL_RULE_SET, - SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A - ) + SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A, + ), ).invoke { _, fqRuleId -> if (visits == null) { visits = mutableListOf() @@ -139,7 +139,7 @@ class VisitorProviderTest { .name(type.name) .type(type) .value(ruleIds.joinToString(separator = ",")) - .build() + .build(), ) } } @@ -147,11 +147,11 @@ class VisitorProviderTest { @Test fun `A root only rule only visits the FILE node only`() { val actual = testVisitorProvider( - RuleProvider { RootNodeOnlyRule(ROOT_NODE_ONLY_RULE) } + RuleProvider { RootNodeOnlyRule(ROOT_NODE_ONLY_RULE) }, ) assertThat(actual).containsExactly( - Visit(ROOT_NODE_ONLY_RULE) + Visit(ROOT_NODE_ONLY_RULE), ) } @@ -160,24 +160,24 @@ class VisitorProviderTest { val actual = testVisitorProvider( RuleProvider { NormalRule(RULE_A) }, RuleProvider { RunAsLateAsPossibleRule(RULE_B) }, - RuleProvider { NormalRule(RULE_C) } + RuleProvider { NormalRule(RULE_C) }, ) assertThat(actual).containsExactly( Visit(RULE_A), Visit(RULE_C), - Visit(RULE_B) + Visit(RULE_B), ) } @Test fun `A run as late as possible on root node only rule visits the root node only`() { val actual = testVisitorProvider( - RuleProvider { RunAsLateAsPossibleOnRootNodeOnlyRule(RUN_AS_LATE_AS_POSSIBLE_RULE) } + RuleProvider { RunAsLateAsPossibleOnRootNodeOnlyRule(RUN_AS_LATE_AS_POSSIBLE_RULE) }, ) assertThat(actual).containsExactly( - Visit(RUN_AS_LATE_AS_POSSIBLE_RULE) + Visit(RUN_AS_LATE_AS_POSSIBLE_RULE), ) } @@ -189,20 +189,20 @@ class VisitorProviderTest { RuleProvider { NormalRule("$EXPERIMENTAL:$RULE_B") }, RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_EXPERIMENTAL_RULE_SET) }, RuleProvider { NormalRule("$CUSTOM_RULE_SET_A:$RULE_C") }, - RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A) } + RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A) }, ) assertThat(actual).containsExactly( Visit(RULE_A), Visit(EXPERIMENTAL, RULE_B), - Visit(CUSTOM_RULE_SET_A, RULE_C) + Visit(CUSTOM_RULE_SET_A, RULE_C), ) } @Test fun `When no enabled rules are found for the root node, the visit function on the root node is not executed`() { val actual = testVisitorProvider( - RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_STANDARD_RULE_SET) } + RuleProvider { NormalRule(SOME_DISABLED_RULE_IN_STANDARD_RULE_SET) }, ) assertThat(actual).isNull() @@ -217,10 +217,10 @@ class VisitorProviderTest { id = RULE_A, visitorModifier = VisitorModifier.RunAfterRule( ruleId = SOME_DISABLED_RULE_IN_STANDARD_RULE_SET, - runOnlyWhenOtherRuleIsEnabled = true - ) + runOnlyWhenOtherRuleIsEnabled = true, + ), ) {} - } + }, ) assertThat(actual).isNull() @@ -238,19 +238,19 @@ class VisitorProviderTest { cb = { _, _ -> }, ruleProviders = ruleProviders.toSet(), // Enable debug mode as it is helpful when a test fails - debug = true + debug = true, ), // Creates a new VisitorProviderFactory for each unit test to prevent that tests for the exact same set of // ruleIds are influencing each other. - recreateRuleSorter = true + recreateRuleSorter = true, ).run { var visits: MutableList? = null visitor( ktlintDisabledRulesEditorConfigProperties( SOME_DISABLED_RULE_IN_STANDARD_RULE_SET, SOME_DISABLED_RULE_IN_EXPERIMENTAL_RULE_SET, - SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A - ) + SOME_DISABLED_RULE_IN_CUSTOM_RULE_SET_A, + ), ).invoke { _, fqRuleId -> if (visits == null) { visits = mutableListOf() @@ -269,7 +269,7 @@ class VisitorProviderTest { .name(type.name) .type(type) .value(ruleIds.joinToString(separator = ",")) - .build() + .build(), ) } @@ -292,38 +292,38 @@ class VisitorProviderTest { class RootNodeOnlyRule(id: String) : R( id = id, visitorModifiers = setOf( - VisitorModifier.RunOnRootNodeOnly - ) + VisitorModifier.RunOnRootNodeOnly, + ), ) class RunAsLateAsPossibleRule(id: String) : R( id = id, visitorModifiers = setOf( - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ) class RunAsLateAsPossibleOnRootNodeOnlyRule(id: String) : R( id = id, visitorModifiers = setOf( VisitorModifier.RunOnRootNodeOnly, - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ) open class R( id: String, - visitorModifiers: Set = emptySet() + visitorModifiers: Set = emptySet(), ) : Rule(id, visitorModifiers) { constructor(id: String, visitorModifier: VisitorModifier) : this(id, setOf(visitorModifier)) override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { throw UnsupportedOperationException( - "Rule should never be really invoked because that is not the aim of this unit test." + "Rule should never be really invoked because that is not the aim of this unit test.", ) } } @@ -331,9 +331,9 @@ class VisitorProviderTest { private data class Visit(val shortenedQualifiedRuleId: String) { constructor( ruleSetId: String, - ruleId: String + ruleId: String, ) : this( - shortenedQualifiedRuleId = "$ruleSetId:$ruleId" + shortenedQualifiedRuleId = "$ruleSetId:$ruleId", ) { require(!ruleSetId.contains(':')) { "rule set id may not contain the ':' character" diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/api/BaselineTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/api/BaselineTest.kt index d84013ed5d..4050619345 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/api/BaselineTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/api/BaselineTest.kt @@ -14,13 +14,13 @@ class BaselineTest { line = 1, col = 1, ruleId = "final-new-line", - detail = "" + detail = "", ) val errorTwo = LintError( line = 62, col = 1, ruleId = "no-blank-line-before-rbrace", - detail = "" + detail = "", ) val baseline: InputStream = @@ -31,14 +31,14 @@ class BaselineTest { """.trimIndent() - .toByteArray() + .toByteArray(), ) val baselineFiles = parseBaseline(baseline) assertThat(baselineFiles).containsEntry( filename, - listOf(errorOne, errorTwo) + listOf(errorOne, errorTwo), ) } } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt index 152b84bedb..329e5a9af2 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigGeneratorTest.kt @@ -27,7 +27,7 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = emptySet(), - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).containsExactly( @@ -36,7 +36,7 @@ internal class EditorConfigGeneratorTest { "indent_style = space", "insert_final_newline = true", "ktlint_code_style = official", - "max_line_length = -1" + "max_line_length = -1", ) } @@ -46,19 +46,19 @@ internal class EditorConfigGeneratorTest { rootDir, """ root = true - """.trimIndent() + """.trimIndent(), ) val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) assertThat(generatedEditorConfig.lines()).contains( "$PROPERTY_1_NAME = $PROPERTY_1_DEFAULT_VALUE", - "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE" + "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE", ) } @@ -67,12 +67,12 @@ internal class EditorConfigGeneratorTest { val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = android + codeStyle = android, ) assertThat(generatedEditorConfig.lines()).contains( "$PROPERTY_1_NAME = $PROPERTY_1_DEFAULT_VALUE_ANDROID", - "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE_ANDROID" + "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE_ANDROID", ) } @@ -84,21 +84,21 @@ internal class EditorConfigGeneratorTest { object : TestRule("test-rule-two"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_2, - EDITOR_CONFIG_PROPERTY_1 + EDITOR_CONFIG_PROPERTY_1, ) }, object : TestRule("test-rule-two"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - EDITOR_CONFIG_PROPERTY_1 + EDITOR_CONFIG_PROPERTY_1, ) - } + }, ), - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).contains( "$PROPERTY_1_NAME = $PROPERTY_1_DEFAULT_VALUE", - "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE" + "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE", ) } @@ -109,21 +109,21 @@ internal class EditorConfigGeneratorTest { rules = setOf( object : TestRule("test-rule-two"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A + EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A, ) }, object : TestRule("test-rule-two"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_B + EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_B, ) - } + }, ), - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).contains( "$PROPERTY_3_NAME = $PROPERTY_3_VALUE_A", - "$PROPERTY_3_NAME = $PROPERTY_3_VALUE_B" + "$PROPERTY_3_NAME = $PROPERTY_3_VALUE_B", ) } @@ -137,19 +137,19 @@ internal class EditorConfigGeneratorTest { [*.{kt,kts}] $PROPERTY_1_NAME = false - """.trimIndent() + """.trimIndent(), ) val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) assertThat(generatedEditorConfig.lines()).contains( "$PROPERTY_1_NAME = false", - "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE" + "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE", ) } @@ -161,27 +161,27 @@ internal class EditorConfigGeneratorTest { root = true indent_size = 4 $PROPERTY_1_NAME = false - """.trimIndent() + """.trimIndent(), ) val generatedEditorConfig = editorConfigGenerator.generateEditorconfig( filePath = tempFileSystem.normalizedPath(rootDir).resolve("test.kt"), rules = rules, - codeStyle = official + codeStyle = official, ) assertThat(generatedEditorConfig.lines()).doesNotContainAnyElementsOf(listOf("root = true")) assertThat(generatedEditorConfig.lines()).contains( - "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE" + "$PROPERTY_2_NAME = $PROPERTY_2_DEFAULT_VALUE", ) assertThat(generatedEditorConfig.lines()).doesNotContain( - "$PROPERTY_1_NAME = false" + "$PROPERTY_1_NAME = false", ) } private fun FileSystem.writeEditorConfigFile( filePath: String, - content: String + content: String, ) { Files.createDirectories(normalizedPath(filePath)) Files.write(normalizedPath("$filePath/.editorconfig"), content.toByteArray()) @@ -195,13 +195,13 @@ internal class EditorConfigGeneratorTest { private class TestRule1 : TestRule("test-rule-one"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( EDITOR_CONFIG_PROPERTY_2, - EDITOR_CONFIG_PROPERTY_1 + EDITOR_CONFIG_PROPERTY_1, ) } private class TestRule2 : TestRule("test-rule-two"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - EDITOR_CONFIG_PROPERTY_1 + EDITOR_CONFIG_PROPERTY_1, ) } @@ -209,7 +209,7 @@ internal class EditorConfigGeneratorTest { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { throw UnsupportedOperationException("This method is not expected to be called") } @@ -230,29 +230,29 @@ internal class EditorConfigGeneratorTest { PROPERTY_1_NAME, "", PropertyType.PropertyValueParser.BOOLEAN_VALUE_PARSER, - setOf("true", "false") + setOf("true", "false"), ), defaultValue = PROPERTY_1_DEFAULT_VALUE, - defaultAndroidValue = PROPERTY_1_DEFAULT_VALUE_ANDROID + defaultAndroidValue = PROPERTY_1_DEFAULT_VALUE_ANDROID, ) val EDITOR_CONFIG_PROPERTY_2 = UsesEditorConfigProperties.EditorConfigProperty( type = PropertyType( PROPERTY_2_NAME, "", PropertyType.PropertyValueParser.POSITIVE_INT_VALUE_PARSER, - setOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "0") + setOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"), ), defaultValue = PROPERTY_2_DEFAULT_VALUE, - defaultAndroidValue = PROPERTY_2_DEFAULT_VALUE_ANDROID + defaultAndroidValue = PROPERTY_2_DEFAULT_VALUE_ANDROID, ) val EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_A = UsesEditorConfigProperties.EditorConfigProperty( type = PropertyType( PROPERTY_3_NAME, "", PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - setOf(PROPERTY_3_VALUE_A, PROPERTY_3_VALUE_B) + setOf(PROPERTY_3_VALUE_A, PROPERTY_3_VALUE_B), ), - defaultValue = PROPERTY_3_VALUE_A + defaultValue = PROPERTY_3_VALUE_A, ) val EDITOR_CONFIG_PROPERTY_3_WITH_DEFAULT_VALUE_B = UsesEditorConfigProperties.EditorConfigProperty( @@ -260,9 +260,9 @@ internal class EditorConfigGeneratorTest { PROPERTY_3_NAME, "", PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER, - setOf(PROPERTY_3_VALUE_A, PROPERTY_3_VALUE_B) + setOf(PROPERTY_3_VALUE_A, PROPERTY_3_VALUE_B), ), - defaultValue = PROPERTY_3_VALUE_B + defaultValue = PROPERTY_3_VALUE_B, ) } } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt index b9ac707d2c..c1be176290 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/EditorConfigLoaderTest.kt @@ -30,7 +30,7 @@ internal class EditorConfigLoaderTest { private fun FileSystem.writeEditorConfigFile( filePath: String, - content: String + content: String, ) { Files.createDirectories(normalizedPath(filePath)) Files.write(normalizedPath("$filePath/.editorconfig"), content.toByteArray()) @@ -68,7 +68,7 @@ internal class EditorConfigLoaderTest { indent_size = 4 [*] indent_size = 2 - """.trimIndent() + """.trimIndent(), ) editorConfigFiles.forEach { editorConfigFileContent -> @@ -82,13 +82,13 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig) .overridingErrorMessage( "Expected \n%s\nto yield indent_size = 2", - editorConfigFileContent + editorConfigFileContent, ) .isEqualTo( mapOf( "indent_size" to "2", - "tab_width" to "2" - ) + "tab_width" to "2", + ), ) } } @@ -106,7 +106,7 @@ internal class EditorConfigLoaderTest { root = true [*] end_of_line = lf - """.trimIndent() + """.trimIndent(), ) //language=EditorConfig @@ -117,7 +117,7 @@ internal class EditorConfigLoaderTest { [*.{kt,kts}] indent_size = 4 indent_style = space - """.trimIndent() + """.trimIndent(), ) //language=EditorConfig @@ -126,7 +126,7 @@ internal class EditorConfigLoaderTest { """ [*] indent_size = 2 - """.trimIndent() + """.trimIndent(), ) val lintFileSubdirectory = tempFileSystem.normalizedPath(project1Subdirectory).resolve("test.kt") @@ -137,8 +137,8 @@ internal class EditorConfigLoaderTest { mapOf( "indent_size" to "2", "tab_width" to "2", - "indent_style" to "space" - ) + "indent_style" to "space", + ), ) val lintFileMainDir = tempFileSystem.normalizedPath(project1Dir).resolve("test.kts") @@ -149,8 +149,8 @@ internal class EditorConfigLoaderTest { mapOf( "indent_size" to "4", "tab_width" to "4", - "indent_style" to "space" - ) + "indent_style" to "space", + ), ) val lintFileRoot = tempFileSystem.normalizedPath(rootDir).resolve("test.kt") @@ -159,8 +159,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( - "end_of_line" to "lf" - ) + "end_of_line" to "lf", + ), ) } @@ -185,8 +185,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( "insert_final_newline" to "true", - "disabled_rules" to "import-ordering" - ) + "disabled_rules" to "import-ordering", + ), ) } @@ -210,8 +210,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( "indent_size" to "unset", - "tab_width" to "unset" - ) + "tab_width" to "unset", + ), ) } @@ -234,8 +234,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isNotEmpty assertThat(parsedEditorConfig).isEqualTo( mapOf( - "disabled_rules" to "import-ordering, no-wildcard-imports" - ) + "disabled_rules" to "import-ordering, no-wildcard-imports", + ), ) } @@ -244,11 +244,11 @@ internal class EditorConfigLoaderTest { val parsedEditorConfig = editorConfigLoader.loadPropertiesForFile( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true") + editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true"), ) assertThat(parsedEditorConfig.convertToRawValues()).containsExactly( - entry("insert_final_newline", "true") + entry("insert_final_newline", "true"), ) } @@ -257,11 +257,11 @@ internal class EditorConfigLoaderTest { val parsedEditorConfig = editorConfigLoader.loadPropertiesForFile( filePath = null, rules = rules, - editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true") + editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true"), ) assertThat(parsedEditorConfig.convertToRawValues()).containsExactly( - entry("insert_final_newline", "true") + entry("insert_final_newline", "true"), ) } @@ -280,7 +280,7 @@ internal class EditorConfigLoaderTest { filePath = null, isStdIn = true, rules = rules, - debug = true + debug = true, ) val parsedEditorConfig = editorConfigProperties.convertToRawValues() @@ -288,8 +288,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( "insert_final_newline" to "true", - "disabled_rules" to "import-ordering" - ) + "disabled_rules" to "import-ordering", + ), ) } @@ -306,7 +306,7 @@ internal class EditorConfigLoaderTest { root = true [*] end_of_line = lf - """.trimIndent() + """.trimIndent(), ) //language=EditorConfig @@ -317,7 +317,7 @@ internal class EditorConfigLoaderTest { [*.{kt,kts}] indent_size = 4 indent_style = space - """.trimIndent() + """.trimIndent(), ) //language=EditorConfig @@ -326,14 +326,14 @@ internal class EditorConfigLoaderTest { """ [*] indent_size = 2 - """.trimIndent() + """.trimIndent(), ) val lintFile = tempFileSystem.normalizedPath(mainProjectDir).resolve("test.kt") val editorConfigProperties = editorConfigLoader.loadPropertiesForFile( filePath = lintFile, alternativeEditorConfig = tempFileSystem.normalizedPath(anotherDir).resolve(".editorconfig"), - rules = rules + rules = rules, ) val parsedEditorConfig = editorConfigProperties.convertToRawValues() @@ -342,8 +342,8 @@ internal class EditorConfigLoaderTest { mapOf( "end_of_line" to "lf", "indent_size" to "2", - "tab_width" to "2" - ) + "tab_width" to "2", + ), ) } @@ -359,7 +359,7 @@ internal class EditorConfigLoaderTest { root = true [*] end_of_line = lf - """.trimIndent() + """.trimIndent(), ) //language=EditorConfig @@ -368,14 +368,14 @@ internal class EditorConfigLoaderTest { """ [*] indent_size = 2 - """.trimIndent() + """.trimIndent(), ) val editorConfigProperties = editorConfigLoader.loadPropertiesForFile( filePath = null, alternativeEditorConfig = tempFileSystem.normalizedPath(anotherDir).resolve(".editorconfig"), isStdIn = true, - rules = rules + rules = rules, ) val parsedEditorConfig = editorConfigProperties.convertToRawValues() @@ -384,8 +384,8 @@ internal class EditorConfigLoaderTest { mapOf( "end_of_line" to "lf", "indent_size" to "2", - "tab_width" to "2" - ) + "tab_width" to "2", + ), ) } @@ -415,8 +415,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( "insert_final_newline" to "true", - "disabled_rules" to "class-must-be-internal" - ) + "disabled_rules" to "class-must-be-internal", + ), ) } @@ -437,7 +437,7 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.loadPropertiesForFile( lintFile, rules = rules.plus(FinalNewlineRule()), - editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true") + editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "true"), ) val parsedEditorConfig = editorConfigProperties.convertToRawValues() @@ -445,8 +445,8 @@ internal class EditorConfigLoaderTest { assertThat(parsedEditorConfig).isEqualTo( mapOf( "disabled_rules" to "import-ordering, no-wildcard-imports", - "insert_final_newline" to "true" - ) + "insert_final_newline" to "true", + ), ) } @@ -467,15 +467,15 @@ internal class EditorConfigLoaderTest { val editorConfigProperties = editorConfigLoader.loadPropertiesForFile( lintFile, rules = rules.plus(FinalNewlineRule()), - editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "false") + editorConfigOverride = EditorConfigOverride.from(insertNewLineProperty to "false"), ) val parsedEditorConfig = editorConfigProperties.convertToRawValues() assertThat(parsedEditorConfig).isNotEmpty assertThat(parsedEditorConfig).isEqualTo( mapOf( - "insert_final_newline" to "false" - ) + "insert_final_newline" to "false", + ), ) } @@ -485,7 +485,7 @@ internal class EditorConfigLoaderTest { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { throw NotImplementedError() } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleIdKtTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleIdKtTest.kt index f989c39b84..5042560568 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleIdKtTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/QualifiedRuleIdKtTest.kt @@ -19,17 +19,17 @@ class QualifiedRuleIdKtTest { "custom-rule-set:rule-id,custom-rule-set:rule-id", " custom-rule-set:rule-id,custom-rule-set:rule-id", "custom-rule-set:rule-id ,custom-rule-set:rule-id", - "custom - rule - set : rule - id ,custom-rule-set:rule-id" + "custom - rule - set : rule - id ,custom-rule-set:rule-id", ], ignoreLeadingAndTrailingWhitespace = false, - nullValues = [""] + nullValues = [""], ) fun `Given a rule id then return the qualified rule id`( ruleId: String, - qualifiedRuleId: String + qualifiedRuleId: String, ) { assertThat( - ruleId.toQualifiedRuleId() + ruleId.toQualifiedRuleId(), ).isEqualTo(qualifiedRuleId) } } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorterTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorterTest.kt index b7bb00af6a..50d51b43e2 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorterTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorterTest.kt @@ -18,15 +18,15 @@ class RuleRunnerSorterTest { .getSortedRuleRunners( ruleRunners = createRuleRunners( NormalRule(RULE_B), - NormalRule(RULE_A) + NormalRule(RULE_A), ), - debug = true + debug = true, ) .map { it.ruleId } assertThat(actual).containsExactly( RULE_A, - RULE_B + RULE_B, ) } @@ -43,9 +43,9 @@ class RuleRunnerSorterTest { NormalRule(RULE_B), NormalRule(RULE_A), NormalRule("$CUSTOM_RULE_SET_B:$RULE_B"), - NormalRule("$CUSTOM_RULE_SET_B:$RULE_A") + NormalRule("$CUSTOM_RULE_SET_B:$RULE_A"), ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( @@ -57,7 +57,7 @@ class RuleRunnerSorterTest { "$CUSTOM_RULE_SET_A:$RULE_A", "$CUSTOM_RULE_SET_A:$RULE_B", "$CUSTOM_RULE_SET_B:$RULE_A", - "$CUSTOM_RULE_SET_B:$RULE_B" + "$CUSTOM_RULE_SET_B:$RULE_B", ) } @@ -68,15 +68,15 @@ class RuleRunnerSorterTest { .getSortedRuleRunners( ruleRunners = createRuleRunners( RootNodeOnlyRule(ROOT_NODE_ONLY_RULE), - NormalRule(NORMAL_RULE) + NormalRule(NORMAL_RULE), ), - debug = true + debug = true, ) .map { it.ruleId } assertThat(actual).containsExactly( ROOT_NODE_ONLY_RULE, - NORMAL_RULE + NORMAL_RULE, ) } @@ -93,9 +93,9 @@ class RuleRunnerSorterTest { RootNodeOnlyRule(RULE_B), RootNodeOnlyRule(RULE_A), RootNodeOnlyRule("$CUSTOM_RULE_SET_B:$RULE_B"), - RootNodeOnlyRule("$CUSTOM_RULE_SET_B:$RULE_A") + RootNodeOnlyRule("$CUSTOM_RULE_SET_B:$RULE_A"), ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( @@ -107,7 +107,7 @@ class RuleRunnerSorterTest { "$CUSTOM_RULE_SET_A:$RULE_A", "$CUSTOM_RULE_SET_A:$RULE_B", "$CUSTOM_RULE_SET_B:$RULE_A", - "$CUSTOM_RULE_SET_B:$RULE_B" + "$CUSTOM_RULE_SET_B:$RULE_B", ) } @@ -119,16 +119,16 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( NormalRule(RULE_C), RunAsLateAsPossibleRule(RULE_A), - NormalRule(RULE_B) + NormalRule(RULE_B), ), - debug = true + debug = true, ) .map { it.ruleId } assertThat(actual).containsExactly( RULE_B, RULE_C, - RULE_A + RULE_A, ) } @@ -145,9 +145,9 @@ class RuleRunnerSorterTest { RunAsLateAsPossibleRule(RULE_B), RunAsLateAsPossibleRule(RULE_A), RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_B"), - RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_A") + RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_A"), ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( @@ -159,7 +159,7 @@ class RuleRunnerSorterTest { "$CUSTOM_RULE_SET_A:$RULE_A", "$CUSTOM_RULE_SET_A:$RULE_B", "$CUSTOM_RULE_SET_B:$RULE_A", - "$CUSTOM_RULE_SET_B:$RULE_B" + "$CUSTOM_RULE_SET_B:$RULE_B", ) } @@ -171,16 +171,16 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( NormalRule(RULE_C), RunAsLateAsPossibleOnRootNodeOnlyRule(RULE_A), - NormalRule(RULE_B) + NormalRule(RULE_B), ), - debug = true + debug = true, ) .map { it.ruleId } assertThat(actual).containsExactly( RULE_B, RULE_C, - RULE_A + RULE_A, ) } @@ -197,9 +197,9 @@ class RuleRunnerSorterTest { RunAsLateAsPossibleRule(RULE_B), RunAsLateAsPossibleRule(RULE_A), RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_B"), - RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_A") + RunAsLateAsPossibleRule("$CUSTOM_RULE_SET_B:$RULE_A"), ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( @@ -211,7 +211,7 @@ class RuleRunnerSorterTest { "$CUSTOM_RULE_SET_A:$RULE_A", "$CUSTOM_RULE_SET_A:$RULE_B", "$CUSTOM_RULE_SET_B:$RULE_A", - "$CUSTOM_RULE_SET_B:$RULE_B" + "$CUSTOM_RULE_SET_B:$RULE_B", ) } @@ -219,8 +219,8 @@ class RuleRunnerSorterTest { @ValueSource( strings = [ RULE_A, - "$CUSTOM_RULE_SET_A:$RULE_A" - ] + "$CUSTOM_RULE_SET_A:$RULE_A", + ], ) fun `A rule annotated with run after rule can not refer to itself`(ruleId: String) { assertThatIllegalStateException().isThrownBy { @@ -229,15 +229,15 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( object : R( id = ruleId, - visitorModifier = VisitorModifier.RunAfterRule(ruleId) - ) {} + visitorModifier = VisitorModifier.RunAfterRule(ruleId), + ) {}, ), - debug = true + debug = true, ) }.withMessage( "Rule with id '$ruleId' has a visitor modifier of type 'RunAfterRule' but it is not referring to another " + "rule but to the rule itself. A rule can not run after itself. This should be fixed by the maintainer " + - "of the rule." + "of the rule.", ) } @@ -249,19 +249,19 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( object : R( id = RULE_A, - visitorModifier = VisitorModifier.RunAfterRule(RULE_C) + visitorModifier = VisitorModifier.RunAfterRule(RULE_C), ) {}, NormalRule(RULE_B), object : R( id = RULE_D, - visitorModifier = VisitorModifier.RunAfterRule(RULE_B) + visitorModifier = VisitorModifier.RunAfterRule(RULE_B), ) {}, object : R( id = RULE_C, - visitorModifier = VisitorModifier.RunAfterRule(RULE_B) - ) {} + visitorModifier = VisitorModifier.RunAfterRule(RULE_B), + ) {}, ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( @@ -270,7 +270,7 @@ class RuleRunnerSorterTest { "$STANDARD:$RULE_A", // Although RULE_D like RULE_C depends on RULE_B it still comes after RULE_A because that rules according to // the default sort order comes before rule D - "$STANDARD:$RULE_D" + "$STANDARD:$RULE_D", ) } @@ -283,25 +283,25 @@ class RuleRunnerSorterTest { NormalRule(RULE_B), object : R( id = RULE_D, - visitorModifier = VisitorModifier.RunAfterRule(RULE_B) + visitorModifier = VisitorModifier.RunAfterRule(RULE_B), ) {}, object : R( id = RULE_C, - visitorModifier = VisitorModifier.RunAfterRule(RULE_B) + visitorModifier = VisitorModifier.RunAfterRule(RULE_B), ) {}, object : R( id = "$EXPERIMENTAL:$RULE_A", - visitorModifier = VisitorModifier.RunAfterRule(RULE_C) - ) {} + visitorModifier = VisitorModifier.RunAfterRule(RULE_C), + ) {}, ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( "$STANDARD:$RULE_B", "$STANDARD:$RULE_C", "$STANDARD:$RULE_D", - "$EXPERIMENTAL:$RULE_A" + "$EXPERIMENTAL:$RULE_A", ) } @@ -315,11 +315,11 @@ class RuleRunnerSorterTest { id = RULE_A, visitorModifier = VisitorModifier.RunAfterRule( ruleId = "not-loaded-rule", - loadOnlyWhenOtherRuleIsLoaded = true - ) - ) {} + loadOnlyWhenOtherRuleIsLoaded = true, + ), + ) {}, ), - debug = true + debug = true, ) }.withMessage("No runnable rules found. Please ensure that at least one is enabled.") } @@ -334,15 +334,15 @@ class RuleRunnerSorterTest { id = RULE_A, visitorModifier = VisitorModifier.RunAfterRule( ruleId = "not-loaded-rule", - loadOnlyWhenOtherRuleIsLoaded = false - ) - ) {} + loadOnlyWhenOtherRuleIsLoaded = false, + ), + ) {}, ), - debug = true + debug = true, ).map { it.qualifiedRuleId } assertThat(actual).containsExactly( - "$STANDARD:$RULE_A" + "$STANDARD:$RULE_A", ) } @@ -354,18 +354,18 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( object : R( id = RULE_A, - visitorModifier = VisitorModifier.RunAfterRule(RULE_B) + visitorModifier = VisitorModifier.RunAfterRule(RULE_B), ) {}, object : R( id = RULE_B, - visitorModifier = VisitorModifier.RunAfterRule("$EXPERIMENTAL:$RULE_C") + visitorModifier = VisitorModifier.RunAfterRule("$EXPERIMENTAL:$RULE_C"), ) {}, object : R( id = "$EXPERIMENTAL:$RULE_C", - visitorModifier = VisitorModifier.RunAfterRule(RULE_A) - ) {} + visitorModifier = VisitorModifier.RunAfterRule(RULE_A), + ) {}, ), - debug = true + debug = true, ) }.withMessage( """ @@ -373,7 +373,7 @@ class RuleRunnerSorterTest { - Rule with id '$STANDARD:$RULE_A' should run after rule with id '$STANDARD:$RULE_B' - Rule with id '$STANDARD:$RULE_B' should run after rule with id '$EXPERIMENTAL:$RULE_C' - Rule with id '$EXPERIMENTAL:$RULE_C' should run after rule with id '$STANDARD:$RULE_A' - """.trimIndent() + """.trimIndent(), ) } @@ -385,18 +385,18 @@ class RuleRunnerSorterTest { ruleRunners = createRuleRunners( object : R( id = RULE_C, - visitorModifier = VisitorModifier.RunAfterRule("$CUSTOM_RULE_SET_B:$RULE_B") + visitorModifier = VisitorModifier.RunAfterRule("$CUSTOM_RULE_SET_B:$RULE_B"), ) {}, object : R( id = "$CUSTOM_RULE_SET_B:$RULE_B", - visitorModifier = VisitorModifier.RunAfterRule("$CUSTOM_RULE_SET_A:$RULE_A") + visitorModifier = VisitorModifier.RunAfterRule("$CUSTOM_RULE_SET_A:$RULE_A"), ) {}, object : R( id = "$CUSTOM_RULE_SET_A:$RULE_A", - visitorModifier = VisitorModifier.RunAfterRule("$STANDARD:$RULE_C") - ) {} + visitorModifier = VisitorModifier.RunAfterRule("$STANDARD:$RULE_C"), + ) {}, ), - debug = true + debug = true, ) }.withMessage( """ @@ -404,7 +404,7 @@ class RuleRunnerSorterTest { - Rule with id '$STANDARD:$RULE_C' should run after rule with id '$CUSTOM_RULE_SET_B:$RULE_B' - Rule with id '$CUSTOM_RULE_SET_A:$RULE_A' should run after rule with id '$STANDARD:$RULE_C' - Rule with id '$CUSTOM_RULE_SET_B:$RULE_B' should run after rule with id '$CUSTOM_RULE_SET_A:$RULE_A' - """.trimIndent() + """.trimIndent(), ) } @@ -412,7 +412,7 @@ class RuleRunnerSorterTest { rules .map { RuleRunner( - RuleProvider { it } + RuleProvider { it }, ) }.toSet() @@ -434,38 +434,38 @@ class RuleRunnerSorterTest { class RootNodeOnlyRule(id: String) : R( id = id, visitorModifiers = setOf( - VisitorModifier.RunOnRootNodeOnly - ) + VisitorModifier.RunOnRootNodeOnly, + ), ) class RunAsLateAsPossibleRule(id: String) : R( id = id, visitorModifiers = setOf( - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ) class RunAsLateAsPossibleOnRootNodeOnlyRule(id: String) : R( id = id, visitorModifiers = setOf( VisitorModifier.RunOnRootNodeOnly, - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ) open class R( id: String, - visitorModifiers: Set = emptySet() + visitorModifiers: Set = emptySet(), ) : Rule(id, visitorModifiers) { constructor(id: String, visitorModifier: VisitorModifier) : this(id, setOf(visitorModifier)) override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { throw UnsupportedOperationException( - "Rule should never be really invoked because that is not the aim of this unit test." + "Rule should never be really invoked because that is not the aim of this unit test.", ) } } diff --git a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt index 6bfef14080..5fe230e62e 100644 --- a/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt +++ b/ktlint-core/src/test/kotlin/com/pinterest/ktlint/core/internal/SuppressionLocatorBuilderTest.kt @@ -21,7 +21,7 @@ class SuppressionLocatorBuilderTest { LintError(1, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), LintError(1, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), LintError(2, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(2, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(2, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -54,7 +54,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(4, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -69,7 +69,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(4, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -84,7 +84,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(4, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -99,7 +99,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(4, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(4, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -116,7 +116,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(6, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(6, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(6, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -133,7 +133,7 @@ class SuppressionLocatorBuilderTest { """.trimIndent() assertThat(lint(code)).containsExactly( LintError(6, 5, "no-foo-identifier-standard", "Line should not contain a foo identifier"), - LintError(6, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier") + LintError(6, 5, "custom:no-foo-identifier", "Line should not contain a foo identifier"), ) } @@ -207,7 +207,7 @@ class SuppressionLocatorBuilderTest { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == ElementType.IDENTIFIER && node.text.startsWith("foo")) { emit(node.startOffset, "Line should not contain a foo identifier", false) @@ -224,10 +224,10 @@ class SuppressionLocatorBuilderTest { // The same rule is supplied once a standard rule and once as non-standard rule. Note that the // ruleIds are different. RuleProvider { NoFooIdentifierRule("no-foo-identifier-standard") }, - RuleProvider { NoFooIdentifierRule("$NON_STANDARD_RULE_SET_ID:no-foo-identifier") } + RuleProvider { NoFooIdentifierRule("$NON_STANDARD_RULE_SET_ID:no-foo-identifier") }, ), - cb = { e, _ -> add(e) } - ) + cb = { e, _ -> add(e) }, + ), ) } diff --git a/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt b/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt index 53277a6f44..86fbd05c6f 100644 --- a/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt +++ b/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt @@ -32,7 +32,7 @@ public class BaselineReporter(private val out: PrintStream) : Reporter { out.println(""" """) for ((line, col, ruleId, _) in errList) { out.println( - """ """ + """ """, ) } out.println(""" """) diff --git a/ktlint-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporterTest.kt b/ktlint-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporterTest.kt index 80b1011b79..2795533b21 100644 --- a/ktlint-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporterTest.kt +++ b/ktlint-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporterTest.kt @@ -17,29 +17,29 @@ class BaselineReporterTest { reporter.onLintError( "$basePath/one-fixed-and-one-not.kt", LintError(1, 1, "rule-1", "<\"&'>"), - false + false, ) reporter.onLintError( "$basePath/one-fixed-and-one-not.kt", LintError(2, 1, "rule-2", "And if you see my friend"), - true + true, ) reporter.onLintError( "$basePath/two-not-fixed.kt", LintError(1, 10, "rule-1", "I thought I would again"), - false + false, ) reporter.onLintError( "$basePath/two-not-fixed.kt", LintError(2, 20, "rule-2", "A single thin straight line"), - false + false, ) reporter.onLintError( "$basePath/all-corrected.kt", LintError(1, 1, "rule-1", "I thought we had more time"), - true + true, ) reporter.afterAll() assertThat(String(out.toByteArray())).isEqualTo( @@ -55,7 +55,7 @@ class BaselineReporterTest { - """.trimIndent().replace("\n", System.lineSeparator()) + """.trimIndent().replace("\n", System.lineSeparator()), ) } } diff --git a/ktlint-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporter.kt b/ktlint-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporter.kt index 9d7d4913cb..889e842078 100644 --- a/ktlint-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporter.kt +++ b/ktlint-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporter.kt @@ -25,7 +25,7 @@ public class CheckStyleReporter(private val out: PrintStream) : Reporter { out.println( """ """ + }" source="$ruleId" />""", ) } out.println(""" """) diff --git a/ktlint-reporter-checkstyle/src/test/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporterTest.kt b/ktlint-reporter-checkstyle/src/test/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporterTest.kt index 8e162a7e8c..ebf56d76fd 100644 --- a/ktlint-reporter-checkstyle/src/test/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporterTest.kt +++ b/ktlint-reporter-checkstyle/src/test/kotlin/com/pinterest/ktlint/reporter/checkstyle/CheckStyleReporterTest.kt @@ -18,9 +18,9 @@ class CheckStyleReporterTest { 1, 1, "rule-1", - "<\"&'>" + "<\"&'>", ), - false + false, ) reporter.onLintError( "/one-fixed-and-one-not.kt", @@ -28,9 +28,9 @@ class CheckStyleReporterTest { 2, 1, "rule-2", - "And if you see my friend" + "And if you see my friend", ), - true + true, ) reporter.onLintError( @@ -39,9 +39,9 @@ class CheckStyleReporterTest { 1, 10, "rule-1", - "I thought I would again" + "I thought I would again", ), - false + false, ) reporter.onLintError( "/two-not-fixed.kt", @@ -49,9 +49,9 @@ class CheckStyleReporterTest { 2, 20, "rule-2", - "A single thin straight line" + "A single thin straight line", ), - false + false, ) reporter.onLintError( @@ -60,9 +60,9 @@ class CheckStyleReporterTest { 1, 1, "rule-1", - "I thought we had more time" + "I thought we had more time", ), - true + true, ) reporter.afterAll() assertThat(String(out.toByteArray())).isEqualTo( @@ -79,7 +79,7 @@ class CheckStyleReporterTest { """.trimIndent() - .replace("\n", System.lineSeparator()) + .replace("\n", System.lineSeparator()), ) } } diff --git a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporter.kt b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporter.kt index 991e18f6e0..7ac5f23194 100644 --- a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporter.kt +++ b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporter.kt @@ -12,7 +12,7 @@ public class FormatReporter( private val out: PrintStream, private val format: Boolean, private val shouldColorOutput: Boolean = false, - private val outputColor: Color = Color.DARK_GRAY + private val outputColor: Color = Color.DARK_GRAY, ) : Reporter { private val countAutoCorrectPossibleOrDone = ConcurrentHashMap() private val countCanNotBeAutoCorrected = ConcurrentHashMap() @@ -53,7 +53,7 @@ public class FormatReporter( "Format not needed (no violations found)" } out.println( - "${colorFileName(file)}${":".colored()} $result" + "${colorFileName(file)}${":".colored()} $result", ) } diff --git a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProvider.kt b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProvider.kt index 577687926b..c19df6b662 100644 --- a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProvider.kt +++ b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProvider.kt @@ -14,7 +14,7 @@ public class FormatReporterProvider : ReporterProvider { .getOrElse("format") { throw IllegalArgumentException("Format is not specified in config options") } .toBooleanStrict(), shouldColorOutput = opt["color"]?.emptyOrTrue() ?: false, - outputColor = getColor(opt["color_name"]) + outputColor = getColor(opt["color_name"]), ) private fun String.emptyOrTrue() = this == "" || this == "true" diff --git a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/internal/Color.kt b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/internal/Color.kt index 9ed3115387..887b13c7d2 100644 --- a/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/internal/Color.kt +++ b/ktlint-reporter-format/src/main/kotlin/com/pinterest/ktlint/reporter/format/internal/Color.kt @@ -25,5 +25,5 @@ public enum class Color(public val code: Int) { LIGHT_BLUE(94), LIGHT_MAGENTA(95), LIGHT_CYAN(96), - WHITE(97) + WHITE(97), } diff --git a/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProviderTest.kt b/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProviderTest.kt index ce0f8330b4..69c35da638 100644 --- a/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProviderTest.kt +++ b/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterProviderTest.kt @@ -14,7 +14,7 @@ class FormatReporterProviderTest { FormatReporterProvider() .get( out = PrintStream(out, true), - opt = emptyMap() + opt = emptyMap(), ) }.withMessage("Format is not specified in config options") } @@ -25,8 +25,8 @@ class FormatReporterProviderTest { out = PrintStream(out, true), opt = mapOf( "format" to "true", - "color_name" to "RED" - ) + "color_name" to "RED", + ), ) assertThat(formatReporter).isNotNull @@ -41,8 +41,8 @@ class FormatReporterProviderTest { out = PrintStream(out, true), opt = mapOf( "format" to "invalid", - "color_name" to "RED" - ) + "color_name" to "RED", + ), ) }.withMessage("The string doesn't represent a boolean value: invalid") } @@ -54,7 +54,7 @@ class FormatReporterProviderTest { FormatReporterProvider() .get( out = PrintStream(out, true), - opt = mapOf("format" to "true") + opt = mapOf("format" to "true"), ) }.withMessage("Invalid color parameter.") } @@ -68,8 +68,8 @@ class FormatReporterProviderTest { out = PrintStream(out, true), opt = mapOf( "format" to "true", - "color_name" to "" - ) + "color_name" to "", + ), ) }.withMessage("Invalid color parameter.") } @@ -83,8 +83,8 @@ class FormatReporterProviderTest { out = PrintStream(out, true), opt = mapOf( "format" to "true", - "color_name" to "GARBAGE_INPUT" - ) + "color_name" to "GARBAGE_INPUT", + ), ) }.withMessage("Invalid color parameter.") } diff --git a/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterTest.kt b/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterTest.kt index 993415e816..02aa692c4a 100644 --- a/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterTest.kt +++ b/ktlint-reporter-format/src/test/kotlin/com/pinterest/ktlint/reporter/format/FormatReporterTest.kt @@ -15,33 +15,33 @@ class FormatReporterTest { val out = ByteArrayOutputStream() val reporter = FormatReporter( out = PrintStream(out, true), - format = true + format = true, ) // File 1: 1 violation not autocorrected reporter.onLintError( SOME_FILE_PATH_1, SOME_LINT_ERROR_UNCORRECTABLE, - false + false, ) // File 2: 2 violations not autocorrected reporter.onLintError( SOME_FILE_PATH_2, SOME_LINT_ERROR_UNCORRECTABLE, - false + false, ) reporter.onLintError( SOME_FILE_PATH_2, SOME_LINT_ERROR_UNCORRECTABLE, - false + false, ) // File 3: At least 1 violation autocorrected reporter.onLintError( SOME_FILE_PATH_3, SOME_LINT_ERROR_CORRECTABLE, - true + true, ) reporter.after(SOME_FILE_PATH_1) @@ -58,7 +58,7 @@ class FormatReporterTest { $SOME_FILE_PATH_3: Format completed (all violations have been fixed) $SOME_FILE_PATH_4: Format not needed (no violations found) - """.trimIndent().replace("\n", System.lineSeparator()) + """.trimIndent().replace("\n", System.lineSeparator()), ) } @@ -67,14 +67,14 @@ class FormatReporterTest { val out = ByteArrayOutputStream() val reporter = FormatReporter( out = PrintStream(out, true), - format = false + format = false, ) // File 1: At least 1 violation can be autocorrected but is not (e.g. lint is running) reporter.onLintError( SOME_FILE_PATH_1, SOME_LINT_ERROR_CORRECTABLE, - false + false, ) reporter.after(SOME_FILE_PATH_1) @@ -87,7 +87,7 @@ class FormatReporterTest { $SOME_FILE_PATH_1: Format required (all violations can be autocorrected) $SOME_FILE_PATH_2: Format not needed (no violations found) - """.trimIndent().replace("\n", System.lineSeparator()) + """.trimIndent().replace("\n", System.lineSeparator()), ) } @@ -99,16 +99,16 @@ class FormatReporterTest { PrintStream(out, true), format = true, shouldColorOutput = true, - outputColor = outputColor + outputColor = outputColor, ) reporter.onLintError( File.separator.plus(SOME_FILE_NAME), SOME_LINT_ERROR_UNCORRECTABLE, - false + false, ) reporter.after( - File.separator.plus(SOME_FILE_NAME) + File.separator.plus(SOME_FILE_NAME), ) val outputString = String(out.toByteArray()) @@ -120,7 +120,7 @@ class FormatReporterTest { ":".color(outputColor) + " " + "Format not completed (1 violation needs manual fixing)" + - System.lineSeparator() + System.lineSeparator(), ) } @@ -130,14 +130,14 @@ class FormatReporterTest { 1, "some-rule", "This error can be autocorrected", - true + true, ) val SOME_LINT_ERROR_UNCORRECTABLE = LintError( 1, 1, "rule-1", "This error can *not* be autocorrected", - false + false, ) const val SOME_FILE_PATH_1 = "/path/to/some-file-1.kt" const val SOME_FILE_PATH_2 = "/path/to/some-file-2.kt" diff --git a/ktlint-reporter-html/src/test/kotlin/com/pinterest/ktlint/reporter/html/HtmlReporterTest.kt b/ktlint-reporter-html/src/test/kotlin/com/pinterest/ktlint/reporter/html/HtmlReporterTest.kt index de9de99ca7..2286c94012 100644 --- a/ktlint-reporter-html/src/test/kotlin/com/pinterest/ktlint/reporter/html/HtmlReporterTest.kt +++ b/ktlint-reporter-html/src/test/kotlin/com/pinterest/ktlint/reporter/html/HtmlReporterTest.kt @@ -69,7 +69,7 @@ class HtmlReporterTest { reporter.onLintError( "/file1.kt", LintError(1, 1, "rule-1", "rule-1 broken"), - false + false, ) reporter.afterAll() @@ -112,13 +112,13 @@ class HtmlReporterTest { reporter.onLintError( "/file1.kt", LintError(1, 1, "rule-1", "rule-1 broken"), - false + false, ) reporter.onLintError( "/file2.kt", LintError(1, 1, "rule-1", "rule-1 broken"), - true + true, ) reporter.afterAll() @@ -161,13 +161,13 @@ class HtmlReporterTest { reporter.onLintError( "/file1.kt", LintError(1, 1, "rule-1", "Error message contains a generic type like List (cannot be auto-corrected)"), - false + false, ) reporter.onLintError( "/file1.kt", LintError(2, 1, "rule-2", "Error message contains special html symbols like ac\"d'e&f (cannot be auto-corrected)"), - false + false, ) reporter.afterAll() diff --git a/ktlint-reporter-json/src/test/kotlin/com/pinterest/ktlint/reporter/json/JsonReporterTest.kt b/ktlint-reporter-json/src/test/kotlin/com/pinterest/ktlint/reporter/json/JsonReporterTest.kt index 437d5b98a9..7af7ad7af4 100644 --- a/ktlint-reporter-json/src/test/kotlin/com/pinterest/ktlint/reporter/json/JsonReporterTest.kt +++ b/ktlint-reporter-json/src/test/kotlin/com/pinterest/ktlint/reporter/json/JsonReporterTest.kt @@ -18,9 +18,9 @@ class JsonReporterTest { 1, 1, "rule-1", - "<\"&'>" + "<\"&'>", ), - false + false, ) reporter.onLintError( "/one-fixed-and-one-not.kt", @@ -28,9 +28,9 @@ class JsonReporterTest { 2, 1, "rule-2", - "And if you see my friend" + "And if you see my friend", ), - true + true, ) reporter.onLintError( @@ -39,9 +39,9 @@ class JsonReporterTest { 1, 10, "rule-1", - "I thought I would again" + "I thought I would again", ), - false + false, ) reporter.onLintError( "/two-not-fixed.kt", @@ -49,9 +49,9 @@ class JsonReporterTest { 2, 20, "rule-2", - "A single thin straight line" + "A single thin straight line", ), - false + false, ) reporter.onLintError( @@ -60,9 +60,9 @@ class JsonReporterTest { 1, 1, "rule-1", - "I thought we had more time" + "I thought we had more time", ), - true + true, ) reporter.afterAll() assertThat(String(out.toByteArray())).isEqualTo( @@ -99,7 +99,7 @@ class JsonReporterTest { ] """.trimIndent() - .replace("\n", System.lineSeparator()) + .replace("\n", System.lineSeparator()), ) } @@ -126,7 +126,7 @@ class JsonReporterTest { ] """.trimIndent() - .replace("\n", System.lineSeparator()) + .replace("\n", System.lineSeparator()), ) } } diff --git a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporter.kt b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporter.kt index 6b41c2194e..4ef9b09d89 100644 --- a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporter.kt +++ b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporter.kt @@ -15,7 +15,7 @@ public class PlainReporter( private val groupByFile: Boolean = false, private val shouldColorOutput: Boolean = false, private val outputColor: Color = Color.DARK_GRAY, - private val pad: Boolean = false + private val pad: Boolean = false, ) : Reporter { private val acc = ConcurrentHashMap>() @@ -28,7 +28,7 @@ public class PlainReporter( out.println( "${colorFileName(file)}${":".colored()}${err.line}${ ":${"${err.col}:".let { if (pad) String.format("%-4s", it) else it}}".colored() - } ${err.detail} ${"(${err.ruleId})".colored()}" + } ${err.detail} ${"(${err.ruleId})".colored()}", ) } } @@ -42,7 +42,7 @@ public class PlainReporter( out.println( " $line${ ":${if (pad) String.format("%-3s", col) else "$col"}".colored() - } $detail${if (verbose) " ($ruleId)".colored() else ""}" + } $detail${if (verbose) " ($ruleId)".colored() else ""}", ) } } diff --git a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProvider.kt b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProvider.kt index 2636990a9e..154a7fe7d5 100644 --- a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProvider.kt +++ b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProvider.kt @@ -15,7 +15,7 @@ public class PlainReporterProvider : ReporterProvider { groupByFile = opt["group_by_file"]?.emptyOrTrue() ?: false, shouldColorOutput = opt["color"]?.emptyOrTrue() ?: false, outputColor = getColor(opt["color_name"]), - pad = opt["pad"]?.emptyOrTrue() ?: false + pad = opt["pad"]?.emptyOrTrue() ?: false, ) private fun String.emptyOrTrue() = this == "" || this == "true" diff --git a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/internal/Color.kt b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/internal/Color.kt index e1efc2cf42..83117bb612 100644 --- a/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/internal/Color.kt +++ b/ktlint-reporter-plain/src/main/kotlin/com/pinterest/ktlint/reporter/plain/internal/Color.kt @@ -24,5 +24,5 @@ public enum class Color(public val code: Int) { LIGHT_BLUE(94), LIGHT_MAGENTA(95), LIGHT_CYAN(96), - WHITE(97) + WHITE(97), } diff --git a/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProviderTest.kt b/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProviderTest.kt index 77e4178094..c197aa4cf7 100644 --- a/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProviderTest.kt +++ b/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterProviderTest.kt @@ -11,7 +11,7 @@ class PlainReporterProviderTest { fun `Given that a valid color name is provided then the plain reporter provider is created without exception`() { val plainReporter = PlainReporterProvider().get( out = PrintStream(out, true), - opt = mapOf("color_name" to "RED") + opt = mapOf("color_name" to "RED"), ) assertThat(plainReporter).isNotNull @@ -24,7 +24,7 @@ class PlainReporterProviderTest { PlainReporterProvider() .get( out = PrintStream(out, true), - opt = mapOf() + opt = mapOf(), ) }.withMessage("Invalid color parameter.") } @@ -36,7 +36,7 @@ class PlainReporterProviderTest { PlainReporterProvider() .get( out = PrintStream(out, true), - opt = mapOf("color_name" to "") + opt = mapOf("color_name" to ""), ) }.withMessage("Invalid color parameter.") } @@ -48,7 +48,7 @@ class PlainReporterProviderTest { PlainReporterProvider() .get( out = PrintStream(out, true), - opt = mapOf("color_name" to "GARBAGE_INPUT") + opt = mapOf("color_name" to "GARBAGE_INPUT"), ) }.withMessage("Invalid color parameter.") } diff --git a/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterTest.kt b/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterTest.kt index 29a6ef6c41..aa46f10c11 100644 --- a/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterTest.kt +++ b/ktlint-reporter-plain/src/test/kotlin/com/pinterest/ktlint/reporter/plain/PlainReporterTest.kt @@ -20,9 +20,9 @@ class PlainReporterTest { 1, 1, "rule-1", - "<\"&'>" + "<\"&'>", ), - false + false, ) reporter.onLintError( "/one-fixed-and-one-not.kt", @@ -30,9 +30,9 @@ class PlainReporterTest { 2, 1, "rule-2", - "And if you see my friend" + "And if you see my friend", ), - true + true, ) reporter.onLintError( @@ -41,9 +41,9 @@ class PlainReporterTest { 1, 10, "rule-1", - "I thought I would again" + "I thought I would again", ), - false + false, ) reporter.onLintError( "/two-not-fixed.kt", @@ -51,9 +51,9 @@ class PlainReporterTest { 2, 20, "rule-2", - "A single thin straight line" + "A single thin straight line", ), - false + false, ) reporter.onLintError( @@ -62,9 +62,9 @@ class PlainReporterTest { 1, 1, "rule-1", - "I thought we had more time" + "I thought we had more time", ), - true + true, ) assertThat(String(out.toByteArray())).isEqualTo( """ @@ -72,7 +72,7 @@ class PlainReporterTest { /two-not-fixed.kt:1:10: I thought I would again (rule-1) /two-not-fixed.kt:2:20: A single thin straight line (rule-2) - """.trimIndent().replace("\n", System.lineSeparator()) + """.trimIndent().replace("\n", System.lineSeparator()), ) } @@ -83,7 +83,7 @@ class PlainReporterTest { val reporter = PlainReporter( PrintStream(out, true), shouldColorOutput = true, - outputColor = outputColor + outputColor = outputColor, ) reporter.onLintError( File.separator + "one-fixed-and-one-not.kt", @@ -91,9 +91,9 @@ class PlainReporterTest { 1, 1, "rule-1", - "<\"&'>" + "<\"&'>", ), - false + false, ) val outputString = String(out.toByteArray()) @@ -106,7 +106,7 @@ class PlainReporterTest { ":1:".color(outputColor) + " <\"&'> " + "(rule-1)".color(outputColor) + - System.lineSeparator() + System.lineSeparator(), ) } @@ -120,9 +120,9 @@ class PlainReporterTest { 1, 1, "rule-1", - "<\"&'>" + "<\"&'>", ), - false + false, ) reporter.onLintError( "/one-fixed-and-one-not.kt", @@ -130,9 +130,9 @@ class PlainReporterTest { 2, 1, "rule-2", - "And if you see my friend" + "And if you see my friend", ), - true + true, ) reporter.onLintError( @@ -141,9 +141,9 @@ class PlainReporterTest { 1, 10, "rule-1", - "I thought I would again" + "I thought I would again", ), - false + false, ) reporter.onLintError( "/two-not-fixed.kt", @@ -151,9 +151,9 @@ class PlainReporterTest { 2, 20, "rule-2", - "A single thin straight line" + "A single thin straight line", ), - false + false, ) reporter.onLintError( @@ -162,9 +162,9 @@ class PlainReporterTest { 1, 1, "rule-1", - "I thought we had more time" + "I thought we had more time", ), - true + true, ) reporter.after("/one-fixed-and-one-not.kt") reporter.after("/two-not-fixed.kt") @@ -177,7 +177,7 @@ class PlainReporterTest { 1:10 I thought I would again 2:20 A single thin straight line - """.trimIndent().replace("\n", System.lineSeparator()) + """.trimIndent().replace("\n", System.lineSeparator()), ) } } diff --git a/ktlint-reporter-sarif/src/main/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporter.kt b/ktlint-reporter-sarif/src/main/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporter.kt index 7e8f11fd73..bb24294edc 100644 --- a/ktlint-reporter-sarif/src/main/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporter.kt +++ b/ktlint-reporter-sarif/src/main/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporter.kt @@ -45,21 +45,21 @@ public class SarifReporter(private val out: PrintStream) : Reporter { physicalLocation = PhysicalLocation( region = Region( startLine = err.line.toLong(), - startColumn = err.col.toLong() + startColumn = err.col.toLong(), ), artifactLocation = workingDirectory?.let { workingDirectory -> ArtifactLocation( uri = File(file).relativeTo(workingDirectory).path, - uriBaseID = SRCROOT + uriBaseID = SRCROOT, ) } ?: ArtifactLocation( - uri = file - ) - ) - ) + uri = file, + ), + ), + ), ), - message = Message(text = err.detail) - ) + message = Message(text = err.detail), + ), ) } @@ -80,15 +80,15 @@ public class SarifReporter(private val out: PrintStream) : Reporter { rules = listOf(), organization = "pinterest", semanticVersion = version, - version = version - ) + version = version, + ), ), originalURIBaseIDS = workingDirectory?.let { mapOf(SRCROOT to ArtifactLocation(uri = "file://${it.path.sanitize()}")) }, - results = results - ) - ) + results = results, + ), + ), ) out.println(SarifSerializer.toJson(sarifSchema210)) } diff --git a/ktlint-reporter-sarif/src/test/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporterTest.kt b/ktlint-reporter-sarif/src/test/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporterTest.kt index 62874065a7..118ee2183f 100644 --- a/ktlint-reporter-sarif/src/test/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporterTest.kt +++ b/ktlint-reporter-sarif/src/test/kotlin/com/pinterest/ktlint/reporter/sarif/SarifReporterTest.kt @@ -19,27 +19,27 @@ class SarifReporterTest { reporter.onLintError( "$workingDirectory/one-fixed-and-one-not.kt", LintError(1, 1, "rule-1", "<\"&'>"), - false + false, ) reporter.onLintError( "$workingDirectory/one-fixed-and-one-not.kt", LintError(2, 1, "rule-2", "And if you see my friend"), - true + true, ) reporter.onLintError( "$workingDirectory/two-not-fixed.kt", LintError(1, 10, "rule-1", "I thought I would again"), - false + false, ) reporter.onLintError( "$workingDirectory/two-not-fixed.kt", LintError(2, 20, "rule-2", "A single thin straight line"), - false + false, ) reporter.onLintError( "$workingDirectory/all-corrected.kt", LintError(1, 1, "rule-1", "I thought we had more time"), - true + true, ) reporter.afterAll() diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarAlignmentRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarAlignmentRule.kt index 6a5f7e9801..dec78d3133 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarAlignmentRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarAlignmentRule.kt @@ -16,13 +16,13 @@ public class BlockCommentInitialStarAlignmentRule : // The block comment is a node which can contain multiple lines. The indent of the second and later line // should be determined based on the indent of the block comment node. This indent is determined by the // indentation rule. - VisitorModifier.RunAfterRule("standard:indent") - ) + VisitorModifier.RunAfterRule("standard:indent"), + ), ) { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == BLOCK_COMMENT) { val expectedIndentForLineWithInitialStar = node.lineIndent() + " *" diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt index 22fdd65f8f..6eaa816e60 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRule.kt @@ -25,13 +25,13 @@ public class CommentWrappingRule : override val editorConfigProperties: List> = listOf( DefaultEditorConfigProperties.indentSizeProperty, - DefaultEditorConfigProperties.indentStyleProperty + DefaultEditorConfigProperties.indentStyleProperty, ) override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == BLOCK_COMMENT) { val nonIndentLeafOnSameLinePrecedingBlockComment = @@ -52,7 +52,7 @@ public class CommentWrappingRule : emit( node.startOffset, "A block comment in between other elements on the same line is disallowed", - false + false, ) } else { // Do not try to fix constructs like below: @@ -62,7 +62,7 @@ public class CommentWrappingRule : emit( node.startOffset, "A block comment starting on same line as another element and ending on another line before another element is disallowed", - false + false, ) } return @@ -79,14 +79,14 @@ public class CommentWrappingRule : private fun ASTNode.precedesBlockCommentOnSameLine( blockCommentNode: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val leafAfterBlockComment = blockCommentNode.nextLeaf() if (!blockCommentNode.textContains('\n') && leafAfterBlockComment.isLastElementOnLine()) { emit( startOffset, "A single line block comment after a code element on the same line must be replaced with an EOL comment", - true + true, ) if (autoCorrect) { blockCommentNode.replaceWithEndOfLineComment() @@ -96,7 +96,7 @@ public class CommentWrappingRule : emit( blockCommentNode.startOffset, "A block comment after any other element on the same line must be separated by a new line", - false + false, ) } } @@ -111,7 +111,7 @@ public class CommentWrappingRule : private fun ASTNode.followsBlockCommentOnSameLine( blockCommentNode: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { emit(startOffset, "A block comment may not be followed by any other element on that same line", true) if (autoCorrect) { diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/DiscouragedCommentLocationRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/DiscouragedCommentLocationRule.kt index 401fe93847..146276ae6a 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/DiscouragedCommentLocationRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/DiscouragedCommentLocationRule.kt @@ -31,7 +31,7 @@ public class DiscouragedCommentLocationRule : Rule("$experimentalRulesetId:disco override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .takeIf { it.isPartOfComment() } @@ -43,7 +43,7 @@ public class DiscouragedCommentLocationRule : Rule("$experimentalRulesetId:disco emit( node.startOffset, "No comment expected at this location", - false + false, ) } } diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProvider.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProvider.kt index bdf313911d..7e0b6424f7 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProvider.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProvider.kt @@ -15,13 +15,13 @@ public class ExperimentalRuleSetProvider : description = "Experimental rules based on the Kotlin coding conventions (https://kotlinlang.org/docs/coding-conventions.html) and Android Kotlin styleguide (https://developer.android.com/kotlin/style-guide). Rules are intended to be promoted to the standard ruleset once they are stable", license = "https://github.com/pinterest/ktlint/blob/master/LICENSE", repositoryUrl = "https://github.com/pinterest/ktlint", - issueTrackerUrl = "https://github.com/pinterest/ktlint/issues" - ) + issueTrackerUrl = "https://github.com/pinterest/ktlint/issues", + ), ), RuleSetProvider { @Deprecated( message = "Marked for removal in KtLint 0.48. See changelog for more information.", - replaceWith = ReplaceWith("getRuleProviders()") + replaceWith = ReplaceWith("getRuleProviders()"), ) override fun get(): RuleSet = RuleSet( experimentalRulesetId, @@ -40,7 +40,7 @@ public class ExperimentalRuleSetProvider : FunctionReturnTypeSpacingRule(), FunctionStartOfBodySpacingRule(), NullableTypeSpacingRule(), - FunctionSignatureRule() + FunctionSignatureRule(), ) override fun getRuleProviders(): Set = @@ -60,6 +60,6 @@ public class ExperimentalRuleSetProvider : RuleProvider { FunctionReturnTypeSpacingRule() }, RuleProvider { FunctionStartOfBodySpacingRule() }, RuleProvider { NullableTypeSpacingRule() }, - RuleProvider { FunctionSignatureRule() } + RuleProvider { FunctionSignatureRule() }, ) } diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunKeywordSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunKeywordSpacingRule.kt index f25a4af4a7..685de417fd 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunKeywordSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunKeywordSpacingRule.kt @@ -14,7 +14,7 @@ public class FunKeywordSpacingRule : Rule("$experimentalRulesetId:fun-keyword-sp override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .takeIf { it.elementType == FUN_KEYWORD } @@ -24,7 +24,7 @@ public class FunKeywordSpacingRule : Rule("$experimentalRulesetId:fun-keyword-sp emit( whiteSpaceAfterFunKeyword.startOffset, "Single space expected after the fun keyword", - true + true, ) if (autoCorrect) { (whiteSpaceAfterFunKeyword as LeafPsiElement).rawReplaceWithText(" ") diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionReturnTypeSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionReturnTypeSpacingRule.kt index 1c2cba5d41..fe6db6b09b 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionReturnTypeSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionReturnTypeSpacingRule.kt @@ -14,7 +14,7 @@ public class FunctionReturnTypeSpacingRule : Rule("$experimentalRulesetId:functi override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node.firstChildNode node @@ -29,7 +29,7 @@ public class FunctionReturnTypeSpacingRule : Rule("$experimentalRulesetId:functi private fun removeWhiteSpaceBetweenClosingParenthesisAndColon( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == COLON) node @@ -46,7 +46,7 @@ public class FunctionReturnTypeSpacingRule : Rule("$experimentalRulesetId:functi private fun fixWhiteSpaceBetweenColonAndReturnType( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == COLON) node diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt index 8169344ab8..eddf2a29f3 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRule.kt @@ -48,8 +48,8 @@ public class FunctionSignatureRule : id = "$experimentalRulesetId:function-signature", visitorModifiers = setOf( // Run after wrapping and spacing rules - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ), UsesEditorConfigProperties { override val editorConfigProperties: List> = @@ -58,7 +58,7 @@ public class FunctionSignatureRule : indentStyleProperty, maxLineLengthProperty, forceMultilineWhenParameterCountGreaterOrEqualThanProperty, - functionBodyExpressionWrappingProperty + functionBodyExpressionWrappingProperty, ) private var indent: String? = null @@ -72,7 +72,7 @@ public class FunctionSignatureRule : functionBodyExpressionWrapping = getEditorConfigValue(functionBodyExpressionWrappingProperty) val indentConfig = IndentConfig( indentStyle = getEditorConfigValue(indentStyleProperty), - tabWidth = getEditorConfigValue(indentSizeProperty) + tabWidth = getEditorConfigValue(indentSizeProperty), ) indent = indentConfig.indent maxLineLength = getEditorConfigValue(maxLineLengthProperty) @@ -82,7 +82,7 @@ public class FunctionSignatureRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == FUN) { node @@ -115,7 +115,7 @@ public class FunctionSignatureRule : return collectLeavesRecursively() .childrenBetween( startASTNodePredicate = { it == firstCodeChild }, - endASTNodePredicate = { it == startOfBodyBlock || it == startOfBodyExpression } + endASTNodePredicate = { it == startOfBodyBlock || it == startOfBodyExpression }, ) } @@ -144,7 +144,7 @@ public class FunctionSignatureRule : private fun visitFunctionSignature( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == FUN) @@ -190,7 +190,7 @@ public class FunctionSignatureRule : .functionSignatureNodes() .childrenBetween( startASTNodePredicate = { it == closingParenthesis }, - endASTNodePredicate = { false } + endASTNodePredicate = { false }, ) return node.lineIndent().length + @@ -210,7 +210,7 @@ public class FunctionSignatureRule : private fun calculateFunctionSignatureLengthAsSingleLineSignature( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ): Int { val actualFunctionSignatureLength = node.getFunctionSignatureLength() @@ -232,7 +232,7 @@ public class FunctionSignatureRule : emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, multiline: Boolean, - dryRun: Boolean + dryRun: Boolean, ): Int { var whiteSpaceCorrection = 0 @@ -258,7 +258,7 @@ public class FunctionSignatureRule : node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, - dryRun: Boolean + dryRun: Boolean, ): Int { var whiteSpaceCorrection = 0 @@ -278,7 +278,7 @@ public class FunctionSignatureRule : emit( whiteSpace.startOffset, "No whitespace expected in empty parameter list", - true + true, ) } if (autoCorrect && !dryRun) { @@ -296,7 +296,7 @@ public class FunctionSignatureRule : emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, multiline: Boolean, - dryRun: Boolean + dryRun: Boolean, ): Int { var whiteSpaceCorrection = 0 @@ -320,7 +320,7 @@ public class FunctionSignatureRule : emit( firstParameterInList.startOffset, "Newline expected after opening parenthesis", - true + true, ) } if (autoCorrect && !dryRun) { @@ -328,7 +328,7 @@ public class FunctionSignatureRule : (valueParameterList.firstChildNode as LeafElement).upsertWhitespaceAfterMe(expectedParameterIndent) } else { (whiteSpaceBeforeIdentifier as LeafElement).rawReplaceWithText( - expectedParameterIndent + expectedParameterIndent, ) } } else { @@ -341,7 +341,7 @@ public class FunctionSignatureRule : emit( firstParameter!!.startOffset, "No whitespace expected between opening parenthesis and first parameter name", - true + true, ) } if (autoCorrect && !dryRun) { @@ -361,7 +361,7 @@ public class FunctionSignatureRule : emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, multiline: Boolean, - dryRun: Boolean + dryRun: Boolean, ): Int { var whiteSpaceCorrection = 0 @@ -390,7 +390,7 @@ public class FunctionSignatureRule : emit( valueParameter.startOffset, "Parameter should start on a newline", - true + true, ) } if (autoCorrect && !dryRun) { @@ -398,7 +398,7 @@ public class FunctionSignatureRule : (firstChildNodeInValueParameter as LeafElement).upsertWhitespaceBeforeMe(expectedParameterIndent) } else { (whiteSpaceBeforeIdentifier as LeafElement).rawReplaceWithText( - expectedParameterIndent + expectedParameterIndent, ) } } else { @@ -411,7 +411,7 @@ public class FunctionSignatureRule : emit( firstChildNodeInValueParameter!!.startOffset, "Single whitespace expected before parameter", - true + true, ) } if (autoCorrect && !dryRun) { @@ -436,7 +436,7 @@ public class FunctionSignatureRule : emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, multiline: Boolean, - dryRun: Boolean + dryRun: Boolean, ): Int { var whiteSpaceCorrection = 0 @@ -456,7 +456,7 @@ public class FunctionSignatureRule : emit( closingParenthesis!!.startOffset, "Newline expected before closing parenthesis", - true + true, ) } if (autoCorrect && !dryRun) { @@ -473,7 +473,7 @@ public class FunctionSignatureRule : emit( whiteSpaceBeforeClosingParenthesis.startOffset, "No whitespace expected between last parameter and closing parenthesis", - true + true, ) } if (autoCorrect && !dryRun) { @@ -491,7 +491,7 @@ public class FunctionSignatureRule : node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, - maxLengthRemainingForFirstLineOfBodyExpression: Int + maxLengthRemainingForFirstLineOfBodyExpression: Int, ) { if (node.findChildByType(EQ) == null) { fixFunctionBodyBlock(node, emit, autoCorrect) @@ -504,7 +504,7 @@ public class FunctionSignatureRule : node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, autoCorrect: Boolean, - maxLengthRemainingForFirstLineOfBodyExpression: Int + maxLengthRemainingForFirstLineOfBodyExpression: Int, ) { val lastNodeOfFunctionSignatureWithBodyExpression = node @@ -524,7 +524,7 @@ public class FunctionSignatureRule : if (whiteSpaceBeforeFunctionBodyExpression.isWhiteSpaceWithNewline()) { val mergeWithFunctionSignature = functionBodyExpressionWrapping.keepFirstLineOfBodyExpressionTogetherWithFunctionSignature( - firstLineOfBodyExpression.length < maxLengthRemainingForFirstLineOfBodyExpression + firstLineOfBodyExpression.length < maxLengthRemainingForFirstLineOfBodyExpression, ) if (mergeWithFunctionSignature || node.isMultilineFunctionSignatureWithoutExplicitReturnType(lastNodeOfFunctionSignatureWithBodyExpression) @@ -532,7 +532,7 @@ public class FunctionSignatureRule : emit( whiteSpaceBeforeFunctionBodyExpression!!.startOffset, "First line of body expression fits on same line as function signature", - true + true, ) if (autoCorrect) { (whiteSpaceBeforeFunctionBodyExpression as LeafPsiElement).rawReplaceWithText(" ") @@ -550,7 +550,7 @@ public class FunctionSignatureRule : emit( functionBodyExpressionNodes.first().startOffset, "Single whitespace expected before expression body", - true + true, ) if (autoCorrect) { if (whiteSpaceBeforeFunctionBodyExpression != null) { @@ -567,7 +567,7 @@ public class FunctionSignatureRule : emit( functionBodyExpressionNodes.first().startOffset, "Newline expected before expression body", - true + true, ) if (autoCorrect) { val newLineAndIndent = "\n" + node.lineIndent() + indent @@ -583,11 +583,11 @@ public class FunctionSignatureRule : } private fun ASTNode.isMultilineFunctionSignatureWithoutExplicitReturnType( - lastNodeOfFunctionSignatureWithBodyExpression: ASTNode? + lastNodeOfFunctionSignatureWithBodyExpression: ASTNode?, ) = functionSignatureNodes() .childrenBetween( startASTNodePredicate = { true }, - endASTNodePredicate = { it == lastNodeOfFunctionSignatureWithBodyExpression } + endASTNodePredicate = { it == lastNodeOfFunctionSignatureWithBodyExpression }, ).joinToString(separator = "") { it.text } .split("\n") .lastOrNull() @@ -597,7 +597,7 @@ public class FunctionSignatureRule : private fun fixFunctionBodyBlock( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val lastNodeOfFunctionSignatureWithBlockBody = node @@ -636,7 +636,7 @@ public class FunctionSignatureRule : endASTNodePredicate = { // collect all remaining nodes false - } + }, ) private fun List.getStartingWhitespaceOrNull() = @@ -661,7 +661,7 @@ public class FunctionSignatureRule : private fun List.childrenBetween( startASTNodePredicate: (ASTNode) -> Boolean = { _ -> true }, - endASTNodePredicate: (ASTNode) -> Boolean = { _ -> false } + endASTNodePredicate: (ASTNode) -> Boolean = { _ -> false }, ): List { val iterator = iterator() var currentNode: ASTNode @@ -714,9 +714,9 @@ public class FunctionSignatureRule : "number of parameters even in case the entire function signature would fit on a single line. " + "By default this parameter is not enabled.", PropertyType.PropertyValueParser.POSITIVE_INT_VALUE_PARSER, - setOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "unset") + setOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "unset"), ), - defaultValue = -1 + defaultValue = -1, ) public val functionBodyExpressionWrappingProperty: UsesEditorConfigProperties.EditorConfigProperty = @@ -728,9 +728,9 @@ public class FunctionSignatureRule : "line as the function signature. Use 'multiline' to force wrapping of body expressions that " + "consists of multiple line. Use 'always' to force wrapping of body expression always.", EnumValueParser(FunctionBodyExpressionWrapping::class.java), - FunctionBodyExpressionWrapping.values().map { it.name }.toSet() + FunctionBodyExpressionWrapping.values().map { it.name }.toSet(), ), - defaultValue = default + defaultValue = default, ) private val INDENT_WITH_CLOSING_PARENTHESIS = Regex("\\s*\\) =") @@ -756,7 +756,9 @@ public class FunctionSignatureRule : /** * Always force the body expression to start on a separate line. */ - always; + always, + + ; internal fun keepFirstLineOfBodyExpressionTogetherWithFunctionSignature(fitOnSameLine: Boolean) = if (this == default || this == multiline) { diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRule.kt index 8cd0b1ea00..e50c2451a7 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRule.kt @@ -18,7 +18,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == FUN) { node @@ -34,7 +34,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct private fun visitFunctionFollowedByBodyExpression( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { fixWhiteSpaceBeforeAssignmentOfBodyExpression(node, emit, autoCorrect) fixWhiteSpaceBetweenAssignmentAndBodyExpression(node, emit, autoCorrect) @@ -43,7 +43,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct private fun fixWhiteSpaceBeforeAssignmentOfBodyExpression( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { node .findChildByType(ElementType.EQ) @@ -70,7 +70,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct private fun fixWhiteSpaceBetweenAssignmentAndBodyExpression( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { node .findChildByType(ElementType.EQ) @@ -83,7 +83,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct emit( assignmentExpression.startOffset, "Expected a single white space between assignment and expression body on same line", - true + true, ) if (autoCorrect) { (assignmentExpression as LeafPsiElement).upsertWhitespaceAfterMe(" ") @@ -101,7 +101,7 @@ public class FunctionStartOfBodySpacingRule : Rule("$experimentalRulesetId:funct private fun visitFunctionFollowedByBodyBlock( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { node .findChildByType(ElementType.BLOCK) diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRule.kt index 0f7f831668..bf14e64a63 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRule.kt @@ -13,7 +13,7 @@ public class FunctionTypeReferenceSpacingRule : Rule("$experimentalRulesetId:fun override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == FUN) { node @@ -48,7 +48,7 @@ public class FunctionTypeReferenceSpacingRule : Rule("$experimentalRulesetId:fun private fun visitNodesUntilStartOfValueParameterList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { var currentNode: ASTNode? = node while (currentNode != null && currentNode.elementType != VALUE_PARAMETER_LIST) { @@ -61,7 +61,7 @@ public class FunctionTypeReferenceSpacingRule : Rule("$experimentalRulesetId:fun private fun removeIfNonEmptyWhiteSpace( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { if (node.elementType == WHITE_SPACE && node.text.isNotEmpty()) { emit(node.startOffset, "Unexpected whitespace", true) diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt index 8df1218a59..0511106ad0 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRule.kt @@ -24,13 +24,13 @@ public class KdocWrappingRule : override val editorConfigProperties: List> = listOf( DefaultEditorConfigProperties.indentSizeProperty, - DefaultEditorConfigProperties.indentStyleProperty + DefaultEditorConfigProperties.indentStyleProperty, ) override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == KDOC) { val nonIndentLeafOnSameLinePrecedingKdocComment = @@ -53,7 +53,7 @@ public class KdocWrappingRule : emit( node.startOffset, "A KDoc comment in between other elements on the same line is disallowed", - false + false, ) } else { // Do not try to fix constructs like below: @@ -63,7 +63,7 @@ public class KdocWrappingRule : emit( node.startOffset, "A KDoc comment starting on same line as another element and ending on another line before another element is disallowed", - false + false, ) } return @@ -75,7 +75,7 @@ public class KdocWrappingRule : emit( node.startOffset, "A KDoc comment after any other element on the same line must be separated by a new line", - false + false, ) } @@ -87,7 +87,7 @@ public class KdocWrappingRule : private fun ASTNode.followsKdocCommentOnSameLine( kdocCommentNode: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { emit(startOffset, "A KDoc comment may not be followed by any other element on that same line", true) if (autoCorrect) { diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRule.kt index 6ebd17ff22..a94ea368a8 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRule.kt @@ -21,7 +21,7 @@ public class ModifierListSpacingRule : Rule("$experimentalRulesetId:modifier-lis override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == MODIFIER_LIST) { node @@ -35,7 +35,7 @@ public class ModifierListSpacingRule : Rule("$experimentalRulesetId:modifier-lis private fun visitModifierChild( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == WHITE_SPACE) { return @@ -61,7 +61,7 @@ public class ModifierListSpacingRule : Rule("$experimentalRulesetId:modifier-lis emit( whitespace.startOffset, "Single whitespace or newline expected after annotation", - true + true, ) if (autoCorrect) { (whitespace as LeafPsiElement).rawReplaceWithText(expectedWhiteSpace) @@ -71,7 +71,7 @@ public class ModifierListSpacingRule : Rule("$experimentalRulesetId:modifier-lis emit( whitespace.startOffset, "Single whitespace expected after modifier", - true + true, ) if (autoCorrect) { (whitespace as LeafPsiElement).rawReplaceWithText(" ") diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/NullableTypeSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/NullableTypeSpacingRule.kt index 7731e0912b..ae2a6e94d7 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/NullableTypeSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/NullableTypeSpacingRule.kt @@ -11,7 +11,7 @@ public class NullableTypeSpacingRule : Rule("$experimentalRulesetId:nullable-typ override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .takeIf { node.elementType == QUEST } diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRule.kt index 74883a144d..f6427467ab 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRule.kt @@ -29,7 +29,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == VALUE_PARAMETER_LIST) { visitValueParameterList(node, emit, autoCorrect) @@ -39,7 +39,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun visitValueParameterList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == VALUE_PARAMETER_LIST) val countValueParameters = @@ -107,7 +107,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun visitValueParameter( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { visitModifierList(node, emit, autoCorrect) removeWhiteSpaceBetweenParameterIdentifierAndColon(node, emit, autoCorrect) @@ -117,7 +117,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun visitModifierList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val modifierList = node.findChildByType(MODIFIER_LIST) ?: return removeWhiteSpaceBetweenModifiersInList(modifierList, emit, autoCorrect) @@ -127,7 +127,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun removeWhiteSpaceBetweenModifiersInList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == MODIFIER_LIST) node @@ -141,7 +141,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun visitWhiteSpaceAfterModifier( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { node .takeUnless { @@ -155,7 +155,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun removeWhiteSpaceBetweenModifierListAndParameterIdentifier( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == MODIFIER_LIST) node @@ -167,7 +167,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun removeWhiteSpaceBetweenParameterIdentifierAndColon( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { node .findChildByType(COLON) @@ -181,7 +181,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun fixWhiteSpaceAfterColonInParameter( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val colonNode = node.findChildByType(COLON) ?: return colonNode @@ -199,7 +199,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun addMissingWhiteSpaceAfterMe( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == COLON || node.elementType == COMMA) emit(node.startOffset, "Whitespace after '${node.text}' is missing", true) @@ -223,7 +223,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun removeUnexpectedWhiteSpace( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { emit(node.startOffset, "Unexpected whitespace", true) if (autoCorrect) { @@ -234,7 +234,7 @@ public class ParameterListSpacingRule : Rule("$experimentalRulesetId:parameter-l private fun replaceWithSingleSpace( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { emit(node.startOffset, "Expected a single space", true) if (autoCorrect) { diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt index fc1509a9f0..fed365b1ce 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt @@ -10,7 +10,7 @@ public class SpacingBetweenFunctionNameAndOpeningParenthesisRule : Rule("$experi override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .takeIf { node.elementType == ElementType.FUN } diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRule.kt index 58a3700538..a33d7f5930 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRule.kt @@ -26,7 +26,7 @@ public class TypeArgumentListSpacingRule : Rule("$experimentalRulesetId:type-arg override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when (node.elementType) { TYPE_ARGUMENT_LIST -> { @@ -41,7 +41,7 @@ public class TypeArgumentListSpacingRule : Rule("$experimentalRulesetId:type-arg private fun visitFunctionDeclaration( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // No whitespace expected before type argument list of function call // val list = listOf () @@ -73,7 +73,7 @@ public class TypeArgumentListSpacingRule : Rule("$experimentalRulesetId:type-arg private fun visitInsideTypeArgumentList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // No whitespace expected after opening angle bracket of type argument list // val list = listOf< String>() @@ -95,13 +95,13 @@ public class TypeArgumentListSpacingRule : Rule("$experimentalRulesetId:type-arg private fun noWhitespaceExpected( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.text != "") { emit( node.startOffset, "No whitespace expected at this position", - true + true, ) if (autoCorrect) { node.treeParent.removeChild(node) diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRule.kt index 8da3b37063..f9a22b2f3c 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRule.kt @@ -28,7 +28,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType != TYPE_PARAMETER_LIST) { return @@ -45,7 +45,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun visitClassDeclaration( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // No white space expected between class name and parameter list // class Bar @@ -83,7 +83,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun visitTypeAliasDeclaration( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // No white space expected between typealias keyword name and parameter list // typealias Bar @@ -103,7 +103,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun visitFunctionDeclaration( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // Single space expected before type parameter list of function // fun foo(...) @@ -131,7 +131,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun visitInsideTypeParameterList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .findChildByType(LT) @@ -149,13 +149,13 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun noWhitespaceExpected( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.text != "") { emit( node.startOffset, "No whitespace expected at this position", - true + true, ) if (autoCorrect) { node.treeParent.removeChild(node) @@ -166,7 +166,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa private fun singleSpaceExpected( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when { node.text == " " -> Unit @@ -174,7 +174,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa emit( node.startOffset, "Expected a single space instead of newline", - true + true, ) if (autoCorrect) { (node as LeafPsiElement).rawReplaceWithText(" ") @@ -184,7 +184,7 @@ public class TypeParameterListSpacingRule : Rule("$experimentalRulesetId:type-pa emit( node.startOffset, "Expected a single space", - true + true, ) if (autoCorrect) { if (node.elementType == WHITE_SPACE) { diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt index 2cb212b393..1c5781d8cf 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt @@ -18,7 +18,7 @@ public class UnnecessaryParenthesesBeforeTrailingLambdaRule : Rule("$experimenta override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isPartOf(CALL_EXPRESSION) && node.isEmptyArgumentList() && @@ -27,7 +27,7 @@ public class UnnecessaryParenthesesBeforeTrailingLambdaRule : Rule("$experimenta emit( node.startOffset, "Empty parentheses in function call followed by lambda are unnecessary", - true + true, ) if (autoCorrect) { node.removeChild(node) diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarTest.kt index be77efee0f..daf897632c 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/BlockCommentInitialStarTest.kt @@ -57,7 +57,7 @@ class BlockCommentInitialStarTest { blockCommentInitialStarAlignmentRuleAssertThat(code) .hasLintViolations( LintViolation(2, 8, "Initial star should be align with start of block comment"), - LintViolation(3, 6, "Initial star should be align with start of block comment") + LintViolation(3, 6, "Initial star should be align with start of block comment"), ).isFormattedAs(formattedCode) } @@ -85,7 +85,7 @@ class BlockCommentInitialStarTest { .hasLintViolations( LintViolation(3, 12, "Initial star should be align with start of block comment"), LintViolation(4, 4, "Initial star should be align with start of block comment"), - LintViolation(5, 10, "Initial star should be align with start of block comment") + LintViolation(5, 10, "Initial star should be align with start of block comment"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRuleTest.kt index 805dacf9fd..4d1e9e212b 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/CommentWrappingRuleTest.kt @@ -52,7 +52,7 @@ class CommentWrappingRuleTest { LintViolation(1, 21, "A block comment may not be followed by any other element on that same line"), LintViolation(2, 21, "A block comment may not be followed by any other element on that same line"), LintViolation(3, 21, "A block comment may not be followed by any other element on that same line"), - LintViolation(4, 21, "A block comment may not be followed by any other element on that same line") + LintViolation(4, 21, "A block comment may not be followed by any other element on that same line"), ).isFormattedAs(formattedCode) } @@ -93,7 +93,7 @@ class CommentWrappingRuleTest { .hasLintViolationWithoutAutoCorrect( 1, 9, - "A block comment in between other elements on the same line is disallowed" + "A block comment in between other elements on the same line is disallowed", ) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProviderTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProviderTest.kt index 84db04cafe..682fbc3846 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProviderTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ExperimentalRuleSetProviderTest.kt @@ -4,5 +4,5 @@ import com.pinterest.ktlint.test.RuleSetProviderTest class ExperimentalRuleSetProviderTest : RuleSetProviderTest( rulesetClass = ExperimentalRuleSetProvider::class.java, - packageName = "com.pinterest.ktlint.ruleset.experimental" + packageName = "com.pinterest.ktlint.ruleset.experimental", ) diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRuleTest.kt index 8341659730..faf7f1facf 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionSignatureRuleTest.kt @@ -93,7 +93,7 @@ class FunctionSignatureRuleTest { LintViolation(2, 7, "Newline expected after opening parenthesis"), LintViolation(2, 15, "Parameter should start on a newline"), LintViolation(2, 23, "Parameter should start on a newline"), - LintViolation(2, 29, "Newline expected before closing parenthesis") + LintViolation(2, 29, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } @@ -160,7 +160,7 @@ class FunctionSignatureRuleTest { LintViolation(2, 7, "Newline expected after opening parenthesis"), LintViolation(2, 15, "Parameter should start on a newline"), LintViolation(2, 23, "Parameter should start on a newline"), - LintViolation(2, 29, "Newline expected before closing parenthesis") + LintViolation(2, 29, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } @@ -186,7 +186,7 @@ class FunctionSignatureRuleTest { LintViolation(2, 7, "Newline expected after opening parenthesis"), LintViolation(2, 20, "Parameter should start on a newline"), LintViolation(2, 28, "Parameter should start on a newline"), - LintViolation(2, 34, "Newline expected before closing parenthesis") + LintViolation(2, 34, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } @@ -237,7 +237,7 @@ class FunctionSignatureRuleTest { .hasLintViolations( LintViolation(2, 7, "Newline expected after opening parenthesis"), LintViolation(2, 15, "Parameter should start on a newline"), - LintViolation(2, 23, "Parameter should start on a newline") + LintViolation(2, 23, "Parameter should start on a newline"), ).isFormattedAs(formattedCode) } @@ -377,7 +377,7 @@ class FunctionSignatureRuleTest { LintViolation(6, 5, "Single whitespace expected before parameter"), LintViolation(7, 5, "Single whitespace expected before parameter"), LintViolation(7, 11, "No whitespace expected between last parameter and closing parenthesis"), - LintViolation(8, 5, "Newline expected before expression body") + LintViolation(8, 5, "Newline expected before expression body"), ).isFormattedAs(formattedCode) } @@ -413,7 +413,7 @@ class FunctionSignatureRuleTest { LintViolation(7, 9, "Single whitespace expected before parameter"), LintViolation(8, 9, "Single whitespace expected before parameter"), LintViolation(8, 15, "No whitespace expected between last parameter and closing parenthesis"), - LintViolation(9, 9, "Newline expected before expression body") + LintViolation(9, 9, "Newline expected before expression body"), ).isFormattedAs(formattedCode) } @@ -447,7 +447,7 @@ class FunctionSignatureRuleTest { LintViolation(2, 7, "Newline expected after opening parenthesis"), LintViolation(2, 15, "Parameter should start on a newline"), LintViolation(2, 23, "Parameter should start on a newline"), - LintViolation(2, 29, "Newline expected before closing parenthesis") + LintViolation(2, 29, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } @@ -475,7 +475,7 @@ class FunctionSignatureRuleTest { LintViolation(1, 7, "Newline expected after opening parenthesis"), LintViolation(1, 15, "Parameter should start on a newline"), LintViolation(1, 23, "Parameter should start on a newline"), - LintViolation(1, 29, "Newline expected before closing parenthesis") + LintViolation(1, 29, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } } @@ -614,16 +614,16 @@ class FunctionSignatureRuleTest { { SpacingAroundParensRule() }, { SpacingAroundDotRule() }, { SpacingAroundCommaRule() }, - { SpacingAroundColonRule() } + { SpacingAroundColonRule() }, ).hasLintViolations( LintViolation(3, 10, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(7, 17, "Single whitespace expected before parameter"), LintViolation( 8, 22, - "No whitespace expected between last parameter and closing parenthesis" + "No whitespace expected between last parameter and closing parenthesis", ), - LintViolation(9, 10, "No whitespace expected between opening parenthesis and first parameter name") + LintViolation(9, 10, "No whitespace expected between opening parenthesis and first parameter name"), ).isFormattedAs(formattedCode) } @@ -664,7 +664,7 @@ class FunctionSignatureRuleTest { { FunctionTypeReferenceSpacingRule() }, { SpacingAroundColonRule() }, { SpacingAroundCommaRule() }, - { SpacingAroundOperatorsRule() } + { SpacingAroundOperatorsRule() }, ).hasLintViolation(2, 15, "Single whitespace expected before parameter") .isFormattedAs(formattedCode) } @@ -676,10 +676,10 @@ class FunctionSignatureRuleTest { @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["default", "multiline"] + names = ["default", "multiline"], ) fun `Given that the function signature and a single line body expression body fit on the same line then do not reformat function signature or body expression`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -695,10 +695,10 @@ class FunctionSignatureRuleTest { @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["always"] + names = ["always"], ) fun `Given that the function signature and a single line body expression body fit on the same line then do not reformat function signature but move the body expression to a separate line`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -722,10 +722,10 @@ class FunctionSignatureRuleTest { @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["multiline", "always"] + names = ["multiline", "always"], ) fun `Given that the function signature and first line of a multiline body expression body fit on the same line then do not reformat the function signature, move the body expression to a separate line`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -755,10 +755,10 @@ class FunctionSignatureRuleTest { @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["default", "multiline"] + names = ["default", "multiline"], ) fun `Given that the function signature and a single line body expression body fit on the same line then do reformat as single line signature`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -782,17 +782,17 @@ class FunctionSignatureRuleTest { LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(4, 5, "Single whitespace expected before parameter"), LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis"), - LintViolation(5, 12, "First line of body expression fits on same line as function signature") + LintViolation(5, 12, "First line of body expression fits on same line as function signature"), ).isFormattedAs(formattedCode) } @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["default", "multiline", "always"] + names = ["default", "multiline", "always"], ) fun `Given that the function signature and first line of a multi line body expression body do not fit on the same line then do reformat`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -816,17 +816,17 @@ class FunctionSignatureRuleTest { LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(4, 5, "Single whitespace expected before parameter"), LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis"), - LintViolation(5, 13, "Newline expected before expression body") + LintViolation(5, 13, "Newline expected before expression body"), ).isFormattedAs(formattedCode) } @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["always"] + names = ["always"], ) fun `Given that the function signature and the first line of a multi line body expression body fit on the same line then reformat to single line signature but keep body expression on separate line`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -852,17 +852,17 @@ class FunctionSignatureRuleTest { .hasLintViolations( LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(4, 5, "Single whitespace expected before parameter"), - LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis") + LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis"), ).isFormattedAs(formattedCode) } @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["default", "multiline"] + names = ["default", "multiline"], ) fun `Given that the function signature and first line of a multiline body expression body fit on the same line then do reformat as single line signature`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -888,17 +888,17 @@ class FunctionSignatureRuleTest { LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(4, 5, "Single whitespace expected before parameter"), LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis"), - LintViolation(5, 12, "First line of body expression fits on same line as function signature") + LintViolation(5, 12, "First line of body expression fits on same line as function signature"), ).isFormattedAs(formattedCode) } @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, - names = ["always"] + names = ["always"], ) fun `Given that the function signature and first line of a multiline body expression body fit on the same line then do reformat as single line signature, keep the body expression on a separate line`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -924,17 +924,17 @@ class FunctionSignatureRuleTest { .hasLintViolations( LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), LintViolation(4, 5, "Single whitespace expected before parameter"), - LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis") + LintViolation(4, 11, "No whitespace expected between last parameter and closing parenthesis"), ).isFormattedAs(formattedCode) } } @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( - value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class + value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, ) fun `Given a multiline function signature without explicit return type and start of body expression on next line then keep first line of body expression body on the same line as the last line of the function signature`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -965,10 +965,10 @@ class FunctionSignatureRuleTest { @ParameterizedTest(name = "bodyExpressionWrapping: {0}") @EnumSource( - value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class + value = FunctionSignatureRule.FunctionBodyExpressionWrapping::class, ) fun `Given a multiline function signature without explicit return type and start of body expression on same line as last line of function signature then do not reformat`( - bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping + bodyExpressionWrapping: FunctionSignatureRule.FunctionBodyExpressionWrapping, ) { val code = """ @@ -1004,7 +1004,7 @@ class FunctionSignatureRuleTest { .setMaxLineLength() .hasLintViolations( LintViolation(3, 5, "No whitespace expected between opening parenthesis and first parameter name"), - LintViolation(3, 21, "No whitespace expected between last parameter and closing parenthesis") + LintViolation(3, 21, "No whitespace expected between last parameter and closing parenthesis"), ).isFormattedAs(formattedCode) } @@ -1028,7 +1028,7 @@ class FunctionSignatureRuleTest { .setMaxLineLength() .hasLintViolations( LintViolation(2, 9, "Newline expected after opening parenthesis"), - LintViolation(3, 16, "Newline expected before closing parenthesis") + LintViolation(3, 16, "Newline expected before closing parenthesis"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRuleTest.kt index eedab7c5f7..b411ecf44e 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionStartOfBodySpacingRuleTest.kt @@ -40,7 +40,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Expected a single white space before assignment of expression body"), - LintViolation(2, 18, "Expected a single white space before assignment of expression body") + LintViolation(2, 18, "Expected a single white space before assignment of expression body"), ).isFormattedAs(formattedCode) } @@ -59,7 +59,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Unexpected whitespace"), - LintViolation(2, 18, "Unexpected whitespace") + LintViolation(2, 18, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -80,7 +80,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Unexpected whitespace"), - LintViolation(3, 18, "Unexpected whitespace") + LintViolation(3, 18, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } } @@ -103,7 +103,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 11, "Expected a single white space between assignment and expression body on same line"), - LintViolation(2, 19, "Expected a single white space between assignment and expression body on same line") + LintViolation(2, 19, "Expected a single white space between assignment and expression body on same line"), ).isFormattedAs(formattedCode) } @@ -122,7 +122,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 12, "Unexpected whitespace"), - LintViolation(2, 20, "Unexpected whitespace") + LintViolation(2, 20, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -180,7 +180,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Expected a single white space before start of function body"), - LintViolation(4, 18, "Expected a single white space before start of function body") + LintViolation(4, 18, "Expected a single white space before start of function body"), ).isFormattedAs(formattedCode) } @@ -207,7 +207,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Unexpected whitespace"), - LintViolation(4, 18, "Unexpected whitespace") + LintViolation(4, 18, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -236,7 +236,7 @@ class FunctionStartOfBodySpacingRuleTest { functionStartOfBodySpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Unexpected whitespace"), - LintViolation(5, 18, "Unexpected whitespace") + LintViolation(5, 18, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRuleTest.kt index 9224056a43..6c4750aed2 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/FunctionTypeReferenceSpacingRuleTest.kt @@ -23,7 +23,7 @@ class FunctionTypeReferenceSpacingRuleTest { functionTypeReferenceSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 11, "Unexpected whitespace"), - LintViolation(2, 11, "Unexpected whitespace") + LintViolation(2, 11, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -43,7 +43,7 @@ class FunctionTypeReferenceSpacingRuleTest { functionTypeReferenceSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 11, "Unexpected whitespace"), - LintViolation(2, 11, "Unexpected whitespace") + LintViolation(2, 11, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -63,7 +63,7 @@ class FunctionTypeReferenceSpacingRuleTest { functionTypeReferenceSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 12, "Unexpected whitespace"), - LintViolation(2, 12, "Unexpected whitespace") + LintViolation(2, 12, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } @@ -108,7 +108,7 @@ class FunctionTypeReferenceSpacingRuleTest { .hasLintViolations( LintViolation(1, 36, "Unexpected whitespace"), LintViolation(1, 38, "Unexpected whitespace"), - LintViolation(1, 40, "Unexpected whitespace") + LintViolation(1, 40, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRuleTest.kt index ea659239a4..5d460d6c7a 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/KdocWrappingRuleTest.kt @@ -52,7 +52,7 @@ class KdocWrappingRuleTest { LintViolation(1, 27, "A KDoc comment may not be followed by any other element on that same line"), LintViolation(2, 27, "A KDoc comment may not be followed by any other element on that same line"), LintViolation(3, 27, "A KDoc comment may not be followed by any other element on that same line"), - LintViolation(4, 27, "A KDoc comment may not be followed by any other element on that same line") + LintViolation(4, 27, "A KDoc comment may not be followed by any other element on that same line"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRuleTest.kt index 9955aff5d2..fb28b95297 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ModifierListSpacingRuleTest.kt @@ -28,7 +28,7 @@ class ModifierListSpacingRuleTest { LintViolation(1, 9, "Single whitespace expected after modifier"), LintViolation(3, 14, "Single whitespace expected after modifier"), LintViolation(3, 24, "Single whitespace expected after modifier"), - LintViolation(3, 33, "Single whitespace expected after modifier") + LintViolation(3, 33, "Single whitespace expected after modifier"), ).isFormattedAs(formattedCode) } @@ -57,7 +57,7 @@ class ModifierListSpacingRuleTest { LintViolation(1, 9, "Single whitespace expected after modifier"), LintViolation(4, 14, "Single whitespace expected after modifier"), LintViolation(5, 13, "Single whitespace expected after modifier"), - LintViolation(6, 12, "Single whitespace expected after modifier") + LintViolation(6, 12, "Single whitespace expected after modifier"), ).isFormattedAs(formattedCode) } @@ -94,7 +94,7 @@ class ModifierListSpacingRuleTest { modifierListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 15, "Single whitespace expected after modifier"), - LintViolation(3, 11, "Single whitespace expected after modifier") + LintViolation(3, 11, "Single whitespace expected after modifier"), ).isFormattedAs(formattedCode) } @@ -121,7 +121,7 @@ class ModifierListSpacingRuleTest { modifierListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 6, "Single whitespace or newline expected after annotation"), - LintViolation(1, 13, "Single whitespace or newline expected after annotation") + LintViolation(1, 13, "Single whitespace or newline expected after annotation"), ).isFormattedAs(formattedCode) } @@ -144,7 +144,7 @@ class ModifierListSpacingRuleTest { modifierListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 6, "Single whitespace or newline expected after annotation"), - LintViolation(3, 6, "Single whitespace or newline expected after annotation") + LintViolation(3, 6, "Single whitespace or newline expected after annotation"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRuleTest.kt index 46697c9148..b6b43f002a 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/ParameterListSpacingRuleTest.kt @@ -233,7 +233,7 @@ class ParameterListSpacingRuleTest { .hasLintViolations( LintViolation(1, 16, "Expected a single space"), LintViolation(2, 25, "Expected a single space"), - LintViolation(5, 28, "Expected a single space") + LintViolation(5, 28, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -266,7 +266,7 @@ class ParameterListSpacingRuleTest { .hasLintViolations( LintViolation(1, 16, "Expected a single space"), LintViolation(3, 25, "Expected a single space"), - LintViolation(7, 28, "Expected a single space") + LintViolation(7, 28, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -286,7 +286,7 @@ class ParameterListSpacingRuleTest { .hasLintViolations( LintViolation(2, 15, "Expected a single space"), LintViolation(2, 25, "Expected a single space"), - LintViolation(2, 38, "Expected a single space") + LintViolation(2, 38, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -313,7 +313,7 @@ class ParameterListSpacingRuleTest { .hasLintViolations( LintViolation(3, 11, "Expected a single space"), LintViolation(4, 13, "Expected a single space"), - LintViolation(5, 16, "Expected a single space") + LintViolation(5, 16, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -427,7 +427,7 @@ class ParameterListSpacingRuleTest { LintViolation(1, 48, "Expected a single space"), LintViolation(1, 51, "Unexpected whitespace"), LintViolation(1, 53, "Expected a single space"), - LintViolation(1, 58, "Unexpected whitespace") + LintViolation(1, 58, "Unexpected whitespace"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingAroundUnaryOperatorRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingAroundUnaryOperatorRuleTest.kt index a8afd11f59..ec06797f0e 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingAroundUnaryOperatorRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/SpacingAroundUnaryOperatorRuleTest.kt @@ -31,7 +31,7 @@ class SpacingAroundUnaryOperatorRuleTest { .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in i ++"), LintViolation(4, 22, "Unexpected spacing in ++ i"), - LintViolation(5, 22, "Unexpected spacing in ++\\n i") + LintViolation(5, 22, "Unexpected spacing in ++\\n i"), ).isFormattedAs(formattedCode) } @@ -58,7 +58,7 @@ class SpacingAroundUnaryOperatorRuleTest { .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in i --"), LintViolation(4, 22, "Unexpected spacing in -- i"), - LintViolation(5, 22, "Unexpected spacing in --\\n i") + LintViolation(5, 22, "Unexpected spacing in --\\n i"), ).isFormattedAs(formattedCode) } @@ -103,7 +103,7 @@ class SpacingAroundUnaryOperatorRuleTest { LintViolation(8, 25, "Unexpected spacing in - 1"), LintViolation(9, 13, "Unexpected spacing in -\\n 1"), LintViolation(11, 19, "Unexpected spacing in -\\n 100"), - LintViolation(13, 26, "Unexpected spacing in -\\n 1") + LintViolation(13, 26, "Unexpected spacing in -\\n 1"), ).isFormattedAs(formattedCode) } @@ -125,7 +125,7 @@ class SpacingAroundUnaryOperatorRuleTest { spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in ! i"), - LintViolation(3, 21, "Unexpected spacing in !\\n i") + LintViolation(3, 21, "Unexpected spacing in !\\n i"), ).isFormattedAs(formattedCode) } @@ -149,7 +149,7 @@ class SpacingAroundUnaryOperatorRuleTest { """.trimIndent() spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( - LintViolation(2, 17, "Unexpected spacing in \"foo\" !!") + LintViolation(2, 17, "Unexpected spacing in \"foo\" !!"), // TODO: "foo3" should also be disallowed ).isFormattedAs(formattedCode) } @@ -195,7 +195,7 @@ class SpacingAroundUnaryOperatorRuleTest { LintViolation(6, 23, "Unexpected spacing in + f"), LintViolation(6, 29, "Unexpected spacing in - 10"), LintViolation(7, 24, "Unexpected spacing in - 3"), - LintViolation(7, 35, "Unexpected spacing in - 4") + LintViolation(7, 35, "Unexpected spacing in - 4"), ).isFormattedAs(formattedCode) } @@ -216,7 +216,7 @@ class SpacingAroundUnaryOperatorRuleTest { spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( LintViolation(2, 26, "Unexpected spacing in - 1"), - LintViolation(3, 13, "Unexpected spacing in - 1") + LintViolation(3, 13, "Unexpected spacing in - 1"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRuleTest.kt index b148562740..b35db8da45 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeArgumentListSpacingRuleTest.kt @@ -22,7 +22,7 @@ class TypeArgumentListSpacingRuleTest { LintViolation(1, 20, "No whitespace expected at this position"), LintViolation(1, 22, "No whitespace expected at this position"), LintViolation(1, 32, "No whitespace expected at this position"), - LintViolation(1, 34, "No whitespace expected at this position") + LintViolation(1, 34, "No whitespace expected at this position"), ).isFormattedAs(formattedCode) } @@ -45,7 +45,7 @@ class TypeArgumentListSpacingRuleTest { LintViolation(1, 16, "No whitespace expected at this position"), LintViolation(1, 18, "No whitespace expected at this position"), LintViolation(2, 30, "No whitespace expected at this position"), - LintViolation(2, 32, "No whitespace expected at this position") + LintViolation(2, 32, "No whitespace expected at this position"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRuleTest.kt b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRuleTest.kt index 756e9c702d..bdf794f186 100644 --- a/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRuleTest.kt +++ b/ktlint-ruleset-experimental/src/test/kotlin/com/pinterest/ktlint/ruleset/experimental/TypeParameterListSpacingRuleTest.kt @@ -36,7 +36,7 @@ class TypeParameterListSpacingRuleTest { LintViolation(1, 4, "Expected a single space"), LintViolation(2, 8, "Expected a single space"), LintViolation(3, 4, "Expected a single space"), - LintViolation(3, 7, "Expected a single space") + LintViolation(3, 7, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -59,7 +59,7 @@ class TypeParameterListSpacingRuleTest { LintViolation(1, 4, "Expected a single space"), LintViolation(2, 8, "Expected a single space"), LintViolation(3, 4, "Expected a single space"), - LintViolation(3, 9, "Expected a single space") + LintViolation(3, 9, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -86,7 +86,7 @@ class TypeParameterListSpacingRuleTest { LintViolation(1, 4, "Expected a single space instead of newline"), LintViolation(3, 8, "Expected a single space instead of newline"), LintViolation(5, 4, "Expected a single space instead of newline"), - LintViolation(6, 4, "Expected a single space instead of newline") + LintViolation(6, 4, "Expected a single space instead of newline"), ).isFormattedAs(formattedCode) } @@ -132,7 +132,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 13, "Expected a single space"), - LintViolation(4, 17, "Expected a single space") + LintViolation(4, 17, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -161,7 +161,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 13, "Expected a single space instead of newline"), - LintViolation(5, 17, "Expected a single space instead of newline") + LintViolation(5, 17, "Expected a single space instead of newline"), ).isFormattedAs(formattedCode) } @@ -206,7 +206,7 @@ class TypeParameterListSpacingRuleTest { LintViolation(3, 16, "Expected a single space"), LintViolation(4, 16, "Expected a single space"), LintViolation(5, 16, "Expected a single space"), - LintViolation(6, 16, "Expected a single space") + LintViolation(6, 16, "Expected a single space"), ).isFormattedAs(formattedCode) } @@ -243,7 +243,7 @@ class TypeParameterListSpacingRuleTest { LintViolation(5, 16, "Expected a single space instead of newline"), LintViolation(7, 16, "Expected a single space instead of newline"), LintViolation(9, 16, "Expected a single space instead of newline"), - LintViolation(11, 16, "Expected a single space instead of newline") + LintViolation(11, 16, "Expected a single space instead of newline"), ).isFormattedAs(formattedCode) } @@ -260,7 +260,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "No whitespace expected at this position"), - LintViolation(1, 14, "No whitespace expected at this position") + LintViolation(1, 14, "No whitespace expected at this position"), ).isFormattedAs(formattedCode) } @@ -279,7 +279,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 6, "No whitespace expected at this position"), - LintViolation(2, 11, "No whitespace expected at this position") + LintViolation(2, 11, "No whitespace expected at this position"), ).isFormattedAs(formattedCode) } @@ -298,7 +298,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 7, "No whitespace expected at this position"), - LintViolation(2, 12, "No whitespace expected at this position") + LintViolation(2, 12, "No whitespace expected at this position"), ).isFormattedAs(formattedCode) } @@ -315,7 +315,7 @@ class TypeParameterListSpacingRuleTest { typeParameterListSpacingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 14, "No whitespace expected at this position"), - LintViolation(1, 19, "Expected a single space") + LintViolation(1, 19, "Expected a single space"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt index 10f8b12a5a..bce2bccbe2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt @@ -46,7 +46,7 @@ public class AnnotationRule : Rule("annotation") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when (node.elementType) { FILE_ANNOTATION_LIST -> { @@ -60,7 +60,7 @@ public class AnnotationRule : Rule("annotation") { private fun visitAnnotationEntry( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == ANNOTATION_ENTRY) @@ -87,13 +87,13 @@ public class AnnotationRule : Rule("annotation") { private fun checkForAnnotationWithParameterToBePlacedOnSeparateLine( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { if (node.isPrecededByOtherAnnotationEntry() && node.isOnSameLineAsPreviousAnnotationEntry()) { emit( node.startOffset, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct", - true + true, ) if (autoCorrect) { node @@ -107,7 +107,7 @@ public class AnnotationRule : Rule("annotation") { emit( node.startOffset, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct", - true + true, ) if (autoCorrect) { node @@ -119,7 +119,7 @@ public class AnnotationRule : Rule("annotation") { it.replaceWithText(getNewlineWithIndent(node.treeParent)) } else { it.rawInsertBeforeMe( - PsiWhiteSpaceImpl(getNewlineWithIndent(node.treeParent)) + PsiWhiteSpaceImpl(getNewlineWithIndent(node.treeParent)), ) } } @@ -130,7 +130,7 @@ public class AnnotationRule : Rule("annotation") { private fun checkForMultipleAnnotationsOnSameLineAsAnnotatedConstruct( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { if (node.isLastAnnotationEntry()) { val noAnnotationWithParameters = @@ -141,7 +141,7 @@ public class AnnotationRule : Rule("annotation") { emit( node.treeParent.startOffset, "Multiple annotations should not be placed on the same line as the annotated construct", - true + true, ) if (autoCorrect) { node @@ -157,7 +157,7 @@ public class AnnotationRule : Rule("annotation") { private fun checkForAnnotationToBePlacedOnSeparateLine( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val isFollowedWithAnnotationHavingValueArgumentList = node @@ -171,7 +171,7 @@ public class AnnotationRule : Rule("annotation") { emit( node.startOffset, "Annotation must be placed on separate line", - true + true, ) if (autoCorrect) { node @@ -183,7 +183,7 @@ public class AnnotationRule : Rule("annotation") { it.replaceWithText(getNewlineWithIndent(node.treeParent)) } else { it.upsertWhitespaceBeforeMe( - getNewlineWithIndent(node.treeParent) + getNewlineWithIndent(node.treeParent), ) } } @@ -245,7 +245,7 @@ public class AnnotationRule : Rule("annotation") { private fun visitFileAnnotationList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val lineNumber = node.lineNumber() val next = node.nextSibling { it.textLength > 0 }?.let { next -> @@ -262,7 +262,7 @@ public class AnnotationRule : Rule("annotation") { emit( psi.endOffset - 1, "File annotations should be separated from file contents with a blank line", - true + true, ) if (autoCorrect) { if (diff == 0) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRule.kt index b0522a6ed6..e055a9a70c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRule.kt @@ -33,7 +33,7 @@ public class AnnotationSpacingRule : Rule("annotation-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType != ElementType.MODIFIER_LIST && node.elementType != ElementType.FILE_ANNOTATION_LIST) { return @@ -76,7 +76,7 @@ public class AnnotationSpacingRule : Rule("annotation-spacing") { } else { it.isPartOfComment() && !it.isCommentOnSameLineAsPrevLeaf() } - } + }, ) if (next != null) { if (node.elementType != ElementType.FILE_ANNOTATION_LIST) { @@ -126,7 +126,7 @@ public class AnnotationSpacingRule : Rule("annotation-spacing") { private inline fun ASTNode.nextSiblingWithAtLeastOneOf( p: (ASTNode) -> Boolean, - needsToOccur: (ASTNode) -> Boolean + needsToOccur: (ASTNode) -> Boolean, ): ASTNode? { var n = this.treeNext var occurrenceCount = 0 @@ -167,7 +167,7 @@ public class AnnotationSpacingRule : Rule("annotation-spacing") { private fun removeIntraLineBreaks( node: ASTNode, - last: KtAnnotationEntry + last: KtAnnotationEntry, ) { val txt = node.text // Pull the next before raw replace or it will blow up diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt index db14df8cdd..fc16e43067 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRule.kt @@ -43,7 +43,7 @@ public class ArgumentListWrappingRule : listOf( indentSizeProperty, indentStyleProperty, - maxLineLengthProperty + maxLineLengthProperty, ) private var editorConfigIndent = IndentConfig.DEFAULT_INDENT_CONFIG @@ -53,7 +53,7 @@ public class ArgumentListWrappingRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { editorConfigIndent = IndentConfig( indentStyle = editorConfigProperties.getEditorConfigValue(indentStyleProperty), - tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty) + tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty), ) maxLineLength = editorConfigProperties.getEditorConfigValue(maxLineLengthProperty) } @@ -61,7 +61,7 @@ public class ArgumentListWrappingRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (editorConfigIndent.disabled) { return @@ -144,7 +144,7 @@ public class ArgumentListWrappingRule : newIndentLevel: Int, child: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val indent = "\n" + editorConfigIndent.indent.repeat(newIndentLevel) when (child.elementType) { @@ -158,7 +158,8 @@ public class ArgumentListWrappingRule : } } ElementType.VALUE_ARGUMENT, - ElementType.RPAR -> { + ElementType.RPAR, + -> { // aiming for // ... LPAR // VALUE_PARAMETER... diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt index 4af34c1332..e811e24559 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRule.kt @@ -43,7 +43,7 @@ public class ChainWrappingRule : Rule("chain-wrapping") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { /* org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement (DOT) | "." diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRule.kt index b69be2fea5..7cbf9cd07a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRule.kt @@ -13,7 +13,7 @@ public class CommentSpacingRule : Rule("comment-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiComment && node is LeafPsiElement && node.getText().startsWith("//")) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRule.kt index 547bf9c3c8..6fe1795ebd 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRule.kt @@ -17,7 +17,7 @@ public class EnumEntryNameCaseRule : Rule("enum-entry-name-case") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node !is CompositeElement) { return @@ -29,7 +29,7 @@ public class EnumEntryNameCaseRule : Rule("enum-entry-name-case") { emit( node.startOffset, "Enum entry name should be uppercase underscore-separated names like \"ENUM_ENTRY\" or upper camel-case like \"EnumEntry\"", - false + false, ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRule.kt index c1664f06c7..9cab0a252d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRule.kt @@ -45,7 +45,7 @@ public class FilenameRule : Rule("filename") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isRoot()) { node as FileASTNode? ?: error("node is not ${FileASTNode::class} but ${node::class}") @@ -125,13 +125,13 @@ public class FilenameRule : Rule("filename") { private fun String.shouldMatchClassName( className: String, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (this != className) { emit( 0, "File '$this.kt' contains a single class and possibly also extension functions for that class and should be named same after that class '$className.kt'", - false + false, ) } } @@ -141,19 +141,19 @@ public class FilenameRule : Rule("filename") { private fun String.shouldMatchFileName( filename: String, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (this != filename) { emit( 0, "File '$this.kt' contains a single top level declaration and should be named '$filename.kt'", - false + false, ) } } private fun String.shouldMatchPascalCase( - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (!this.matches(pascalCaseRegEx)) { emit(0, "File name '$this.kt' should conform PascalCase", false) @@ -162,7 +162,7 @@ public class FilenameRule : Rule("filename") { private data class TopLevelDeclaration( val elementType: IElementType, - val identifier: String + val identifier: String, ) private fun ASTNode.toTopLevelDeclaration(): TopLevelDeclaration? = diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt index 3723b74a06..4ae1ecaa2e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt @@ -15,7 +15,7 @@ public class FinalNewlineRule : UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - insertNewLineProperty + insertNewLineProperty, ) private var insertFinalNewline by Delegates.notNull() @@ -27,7 +27,7 @@ public class FinalNewlineRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isRoot()) { if (node.textLength == 0) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt index 38755969b4..2338d1dd18 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt @@ -41,7 +41,7 @@ public class ImportOrderingRule : UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - ideaImportsLayoutProperty + ideaImportsLayoutProperty, ) private lateinit var importsLayout: List @@ -55,7 +55,7 @@ public class ImportOrderingRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == ElementType.IMPORT_LIST) { val children = node.getChildren(null) @@ -99,7 +99,7 @@ public class ImportOrderingRule : node.startOffset, errorMessages.getOrDefault(importsLayout, CUSTOM_ERROR_MESSAGE) + " -- no autocorrection due to comments in the import list", - false + false, ) } else { val autoCorrectWhitespace = hasTooMuchWhitespace(children) && !isCustomLayout() @@ -108,7 +108,7 @@ public class ImportOrderingRule : emit( node.startOffset, errorMessages.getOrDefault(importsLayout, CUSTOM_ERROR_MESSAGE), - true + true, ) } if (autoCorrect && (autoCorrectDuplicateImports || autoCorrectSortOrder || autoCorrectWhitespace)) { @@ -129,7 +129,7 @@ public class ImportOrderingRule : private fun getUniqueImportsAndBlankLines( children: Array, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ): Pair> { var autoCorrectDuplicateImports = false val imports = mutableListOf() @@ -147,7 +147,7 @@ public class ImportOrderingRule : emit( current.startOffset, "Duplicate '${current.text}' found", - true + true, ) autoCorrectDuplicateImports = true } @@ -205,7 +205,7 @@ public class ImportOrderingRule : private val errorMessages = mapOf( IDEA_PATTERN to IDEA_ERROR_MESSAGE, - ASCII_PATTERN to ASCII_ERROR_MESSAGE + ASCII_PATTERN to ASCII_ERROR_MESSAGE, ) private val editorConfigPropertyParser: (String, String?) -> PropertyType.PropertyValue> = @@ -213,31 +213,31 @@ public class ImportOrderingRule : when { value.isNullOrBlank() -> PropertyType.PropertyValue.invalid( value, - "Import layout must contain at least one entry of a wildcard symbol (*)" + "Import layout must contain at least one entry of a wildcard symbol (*)", ) value == "idea" -> { logger.warn { "`idea` is deprecated! Please use `*,java.**,javax.**,kotlin.**,^` instead to ensure that the Kotlin IDE plugin recognizes the value" } PropertyType.PropertyValue.valid( value, - IDEA_PATTERN + IDEA_PATTERN, ) } value == "ascii" -> { logger.warn { "`ascii` is deprecated! Please use `*` instead to ensure that the Kotlin IDE plugin recognizes the value" } PropertyType.PropertyValue.valid( value, - ASCII_PATTERN + ASCII_PATTERN, ) } else -> try { PropertyType.PropertyValue.valid( value, - parseImportsLayout(value) + parseImportsLayout(value), ) } catch (e: IllegalArgumentException) { PropertyType.PropertyValue.invalid( value, - "Unexpected imports layout: $value" + "Unexpected imports layout: $value", ) } } @@ -248,11 +248,11 @@ public class ImportOrderingRule : type = PropertyType( IDEA_IMPORTS_LAYOUT_PROPERTY_NAME, PROPERTY_DESCRIPTION, - editorConfigPropertyParser + editorConfigPropertyParser, ), defaultValue = IDEA_PATTERN, defaultAndroidValue = ASCII_PATTERN, - propertyWriter = { it.joinToString(separator = ",") } + propertyWriter = { it.joinToString(separator = ",") }, ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt index 1b35a11b0c..fc3f43f785 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRule.kt @@ -104,15 +104,15 @@ public class IndentationRule : VisitorModifier.RunAfterRule( ruleId = "experimental:function-signature", loadOnlyWhenOtherRuleIsLoaded = false, - runOnlyWhenOtherRuleIsEnabled = false - ) - ) + runOnlyWhenOtherRuleIsEnabled = false, + ), + ), ), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( indentSizeProperty, - indentStyleProperty + indentStyleProperty, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG @@ -124,7 +124,7 @@ public class IndentationRule : override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { indentConfig = IndentConfig( indentStyle = editorConfigProperties.getEditorConfigValue(indentStyleProperty), - tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty) + tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty), ) if (indentConfig.disabled) { stopTraversalOfAST() @@ -134,7 +134,7 @@ public class IndentationRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isRoot()) { val firstNotEmptyLeaf = node.nextLeaf() @@ -154,7 +154,7 @@ public class IndentationRule : "expected indent is kept unchanged -> $expectedIndent" } ctx.blockStack.push( - Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK) + Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK), ) } node.isAfterValueParameterOnSameLine() -> { @@ -163,7 +163,7 @@ public class IndentationRule : "parameter value ended, expected indent is kept unchanged -> $expectedIndent" } ctx.blockStack.push( - Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK) + Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK), ) } prevBlock != null && line == prevBlock.line -> { @@ -172,20 +172,20 @@ public class IndentationRule : "expected indent is kept unchanged -> $expectedIndent" } ctx.blockStack.push( - Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK) + Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK), ) } else -> { if (node.isPartOfForLoopConditionWithMultilineExpression()) { logger.trace { "$line: block starting with ${node.text} -> Keep at $expectedIndent" } ctx.blockStack.push( - Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK) + Block(node.elementType, line, SAME_AS_PREVIOUS_BLOCK), ) } else { expectedIndent++ logger.trace { "$line: block starting with ${node.text} -> Increase to $expectedIndent" } ctx.blockStack.push( - Block(node.elementType, line, REGULAR) + Block(node.elementType, line, REGULAR), ) } } @@ -194,7 +194,7 @@ public class IndentationRule : ctx.blockStack.iterator().asSequence().toList() .joinToString( separator = "\n\t", - prefix = "Stack (newest first) after pushing new element:\n\t" + prefix = "Stack (newest first) after pushing new element:\n\t", ) } } @@ -204,7 +204,7 @@ public class IndentationRule : ctx.blockStack.iterator().asSequence().toList() .joinToString( separator = "\n\t", - prefix = "Stack before popping newest element from top of stack:\n\t" + prefix = "Stack before popping newest element from top of stack:\n\t", ) } val block = ctx.blockStack.pop() @@ -361,7 +361,7 @@ public class IndentationRule : override fun afterVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when (node.elementType) { SUPER_TYPE_LIST -> @@ -386,7 +386,7 @@ public class IndentationRule : private fun adjustExpectedIndentInsideQualifiedExpression(n: ASTNode, ctx: IndentContext) { val p = n.parent({ it.treeParent.elementType != DOT_QUALIFIED_EXPRESSION && it.treeParent.elementType != SAFE_ACCESS_EXPRESSION - }) ?: return + },) ?: return val nextSibling = n.treeNext if (!ctx.ignored.contains(p) && nextSibling != null) { if (p.treeParent.elementType == PROPERTY_DELEGATE && @@ -561,7 +561,7 @@ public class IndentationRule : private fun indentStringTemplate( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .let { it.psi as KtStringTemplateExpression } @@ -575,7 +575,7 @@ public class IndentationRule : emit( node.startOffset, "Indentation of multiline string should not contain both tab(s) and space(s)", - false + false, ) return } @@ -629,11 +629,11 @@ public class IndentationRule : emit( it.startOffset + offsetFirstWrongIndentChar, "Unexpected '${indentConfig.unexpectedIndentCharDescription}' character(s) in margin of multiline string", - true + true, ) if (autoCorrect) { (it.firstChildNode as LeafPsiElement).rawReplaceWithText( - expectedIndentation + actualContent + expectedIndentation + actualContent, ) } } else if (actualIndent != expectedIndentation && it.isIndentBeforeClosingQuote()) { @@ -642,16 +642,16 @@ public class IndentationRule : emit( it.startOffset, "Unexpected indent of multiline string closing quotes", - true + true, ) if (autoCorrect) { if (it.firstChildNode == null) { (it as LeafPsiElement).rawInsertBeforeMe( - LeafPsiElement(REGULAR_STRING_PART, expectedIndentation) + LeafPsiElement(REGULAR_STRING_PART, expectedIndentation), ) } else { (it.firstChildNode as LeafPsiElement).rawReplaceWithText( - expectedIndentation + actualContent + expectedIndentation + actualContent, ) } } @@ -680,7 +680,7 @@ public class IndentationRule : node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - ctx: IndentContext + ctx: IndentContext, ) { val text = node.text val nodeIndent = text.substringAfterLast("\n") @@ -800,7 +800,7 @@ public class IndentationRule : emit( node.startOffset + text.length - nodeIndent.length, "Unexpected tab character(s)", - true + true, ) indentConfig.toNormalizedIndent(nodeIndent) } else { @@ -819,7 +819,7 @@ public class IndentationRule : emit( node.startOffset + text.length - nodeIndent.length, "Unexpected space character(s)", - true + true, ) indentConfig.toNormalizedIndent(indentWithoutKdocIndent) + // Re-add the kdoc indent when it was present before @@ -840,7 +840,7 @@ public class IndentationRule : emit( node.startOffset + text.length - nodeIndent.length, "Unexpected indentation (${normalizedNodeIndent.length}) (should be ${expectedIndent.length})", - true + true, ) logger.trace { "$line: " + (if (!autoCorrect) "would have " else "") + "changed indentation to ${expectedIndent.length} (from ${normalizedNodeIndent.length})" @@ -849,7 +849,7 @@ public class IndentationRule : if (autoCorrect) { if (nodeIndent != normalizedNodeIndent || normalizedNodeIndent != expectedIndent) { (node as LeafPsiElement).rawReplaceWithText( - text.substringBeforeLast("\n") + "\n" + expectedIndent + text.substringBeforeLast("\n") + "\n" + expectedIndent, ) } } @@ -971,7 +971,7 @@ public class IndentationRule : // Line at which the block is opened val line: Int, // Type of indentation to be used for the block - val blockIndentationType: BlockIndentationType + val blockIndentationType: BlockIndentationType, ) { enum class BlockIndentationType { /** @@ -985,7 +985,7 @@ public class IndentationRule : * the expected indentation level. The indentation of the closing element has to be decreased one level * without altering the expected indentation level. */ - SAME_AS_PREVIOUS_BLOCK + SAME_AS_PREVIOUS_BLOCK, } } } @@ -995,7 +995,7 @@ public class IndentationRule : private val rTokenSet = TokenSet.create(RPAR, RBRACE, RBRACKET, GT) private val matchingRToken = lTokenSet.types.zip( - rTokenSet.types + rTokenSet.types, ).toMap() } } @@ -1059,7 +1059,7 @@ private fun String.splitIndentAt(index: Int): Pair { val safeIndex = kotlin.math.min(firstNonWhitespaceIndex, index) return Pair( first = this.take(safeIndex), - second = this.substring(safeIndex) + second = this.substring(safeIndex), ) } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt index da47291c5d..9c1f936f44 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRule.kt @@ -30,7 +30,7 @@ public class MaxLineLengthRule : // won't be affected by that rule. ruleId = "trailing-comma-on-call-site", loadOnlyWhenOtherRuleIsLoaded = false, - runOnlyWhenOtherRuleIsEnabled = false + runOnlyWhenOtherRuleIsEnabled = false, ), VisitorModifier.RunAfterRule( // This rule should run after all other rules. Each time a rule visitor is modified with @@ -38,16 +38,16 @@ public class MaxLineLengthRule : // won't be affected by that rule. ruleId = "trailing-comma-on-declaration-site", loadOnlyWhenOtherRuleIsLoaded = false, - runOnlyWhenOtherRuleIsEnabled = false + runOnlyWhenOtherRuleIsEnabled = false, ), - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( maxLineLengthProperty, - ignoreBackTickedIdentifierProperty + ignoreBackTickedIdentifierProperty, ) private var maxLineLength: Int = maxLineLengthProperty.defaultValue @@ -62,7 +62,7 @@ public class MaxLineLengthRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (maxLineLength <= 0) { return @@ -125,9 +125,9 @@ public class MaxLineLengthRule : KTLINT_IGNORE_BACKTICKED_IDENTIFIER_NAME, PROPERTY_DESCRIPTION, PropertyType.PropertyValueParser.BOOLEAN_VALUE_PARSER, - setOf(true.toString(), false.toString()) + setOf(true.toString(), false.toString()), ), - defaultValue = false + defaultValue = false, ) } } @@ -152,7 +152,7 @@ private fun ASTNode.getElementsPerLine(): List { private data class ParsedLine( val line: String, val offset: Int, - val elements: List + val elements: List, ) { fun lineLength(ignoreBackTickedIdentifier: Boolean): Int { return if (ignoreBackTickedIdentifier) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRule.kt index 9f9be1716a..b47aa57354 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRule.kt @@ -53,7 +53,7 @@ public class ModifierOrderRule : Rule("modifier-order") { INLINE_KEYWORD, INFIX_KEYWORD, OPERATOR_KEYWORD, - DATA_KEYWORD + DATA_KEYWORD, // NOINLINE_KEYWORD, CROSSINLINE_KEYWORD, OUT_KEYWORD, IN_KEYWORD, REIFIED_KEYWORD // HEADER_KEYWORD, IMPL_KEYWORD ) @@ -62,7 +62,7 @@ public class ModifierOrderRule : Rule("modifier-order") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.psi is KtDeclarationModifierList) { val modifierArr = node.getChildren(tokenSet) @@ -75,7 +75,7 @@ public class ModifierOrderRule : Rule("modifier-order") { "Incorrect modifier order (should be \"${ squashAnnotations(sorted).joinToString(" ") }\")", - true + true, ) if (autoCorrect) { modifierArr.forEachIndexed { i, n -> diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt index 64c833008f..f09eea7bf7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRule.kt @@ -35,21 +35,21 @@ public class MultiLineIfElseRule : override val editorConfigProperties: List> = listOf( DefaultEditorConfigProperties.indentSizeProperty, - DefaultEditorConfigProperties.indentStyleProperty + DefaultEditorConfigProperties.indentStyleProperty, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG override fun beforeFirstNode(editorConfigProperties: EditorConfigProperties) { indentConfig = IndentConfig( indentStyle = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentStyleProperty), - tabWidth = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentSizeProperty) + tabWidth = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentSizeProperty), ) } override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == THEN || node.elementType == ELSE) { if (node.firstChildNode?.elementType == BLOCK) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRule.kt index 3900fd935e..5f63e21087 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRule.kt @@ -12,7 +12,7 @@ public class NoBlankLineBeforeRbraceRule : Rule("no-blank-line-before-rbrace") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiWhiteSpace && node.textContains('\n') && @@ -23,7 +23,7 @@ public class NoBlankLineBeforeRbraceRule : Rule("no-blank-line-before-rbrace") { emit( node.startOffset + split[0].length + split[1].length + 1, "Unexpected blank line(s) before \"}\"", - true + true, ) if (autoCorrect) { (node as LeafPsiElement).rawReplaceWithText("${split.first()}\n${split.last()}") diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLinesInChainedMethodCallsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLinesInChainedMethodCallsRule.kt index 253a2fb2c9..74c5ea192a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLinesInChainedMethodCallsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLinesInChainedMethodCallsRule.kt @@ -10,7 +10,7 @@ public class NoBlankLinesInChainedMethodCallsRule : Rule("no-blank-lines-in-chai override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val isBlankLine = node is PsiWhiteSpace && node.getText().contains("\n\n") if (isBlankLine && node.treeParent.elementType == DOT_QUALIFIED_EXPRESSION) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRule.kt index a075327fc4..e26ca22dcb 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRule.kt @@ -14,7 +14,7 @@ public class NoConsecutiveBlankLinesRule : Rule("no-consecutive-blank-lines") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiWhiteSpace && node.prevSibling != null diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRule.kt index 1b637e240f..3961337cbc 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRule.kt @@ -16,7 +16,7 @@ public class NoEmptyClassBodyRule : Rule("no-empty-class-body") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == CLASS_BODY && node.firstChildNode?.let { n -> diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRule.kt index 73d089552b..8df2698fe2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRule.kt @@ -14,7 +14,7 @@ public class NoEmptyFirstLineInMethodBlockRule : Rule("no-empty-first-line-in-me override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiWhiteSpace && node.textContains('\n') && node.prevLeaf()?.elementType == ElementType.LBRACE && node.isPartOf(FUN) && @@ -25,7 +25,7 @@ public class NoEmptyFirstLineInMethodBlockRule : Rule("no-empty-first-line-in-me emit( node.startOffset + 1, "First line in a method block should not be empty", - true + true, ) if (autoCorrect) { (node as LeafPsiElement).rawReplaceWithText("${split.first()}\n${split.last()}") diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakAfterElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakAfterElseRule.kt index f7e5b13c72..88d305a657 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakAfterElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakAfterElseRule.kt @@ -15,7 +15,7 @@ public class NoLineBreakAfterElseRule : Rule("no-line-break-after-else") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiWhiteSpace && node.textContains('\n') diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoMultipleSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoMultipleSpacesRule.kt index 1c49f27487..0b49c95ad0 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoMultipleSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoMultipleSpacesRule.kt @@ -11,7 +11,7 @@ public class NoMultipleSpacesRule : Rule("no-multi-spaces") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .takeIf { node is PsiWhiteSpace } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRule.kt index 21135b4ce0..786f686686 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRule.kt @@ -32,7 +32,7 @@ public class NoSemicolonsRule : Rule("no-semi") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == KDOC_TEXT) { return diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRule.kt index 7e0de85324..2a31779793 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRule.kt @@ -14,7 +14,7 @@ public class NoTrailingSpacesRule : Rule("no-trailing-spaces") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isPartOfKDoc()) { if (node.elementType == WHITE_SPACE && node.hasTrailingSpacesBeforeNewline()) { @@ -69,7 +69,7 @@ public class NoTrailingSpacesRule : Rule("no-trailing-spaces") { private fun ASTNode.removeTrailingSpacesBeforeNewline() { val newText = text.replace( regex = SPACE_OR_TAB_BEFORE_NEWLINE_REGEX, - replacement = "\n" + replacement = "\n", ) (this as LeafPsiElement).replaceWithText(newText) } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRule.kt index 864495b4b3..b582c4465a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRule.kt @@ -13,7 +13,7 @@ public class NoUnitReturnRule : Rule("no-unit-return") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == TYPE_REFERENCE && node.treeParent.elementType == FUN && diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt index 23efe2335c..595e389fd2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs public class NoUnusedImportsRule : Rule("no-unused-imports") { private val ref = mutableSetOf( - Reference("*", false) + Reference("*", false), ) private val parentExpressions = mutableSetOf() private val imports = mutableMapOf() @@ -40,7 +40,7 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.isRoot()) { rootNode = node @@ -91,8 +91,8 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { ref.add( Reference( it.removeBackticksAndTrim(), - node.psi.parentDotQualifiedExpression() != null - ) + node.psi.parentDotQualifiedExpression() != null, + ), ) } } @@ -104,7 +104,7 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { override fun afterVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == FILE) { val directCalls = ref.filter { !it.inDotQualifiedExpression }.map { it.text } @@ -184,7 +184,7 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { } val methodCallExpression = text.substringBeforeLast( - "(" + "(", ) // Only check static imports; identified if they start with a capital letter indicating a @@ -198,7 +198,7 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { .forEach { import -> val count = imports.count { it.key.pathStr.removeBackticksAndTrim().startsWith( - import.key.pathStr.removeBackticksAndTrim().substringBefore(methodCallExpression) + import.key.pathStr.removeBackticksAndTrim().substringBefore(methodCallExpression), ) } // Parent import and static import both are present @@ -253,7 +253,7 @@ public class NoUnusedImportsRule : Rule("no-unused-imports") { // iteration (https://github.com/shyiko/ktlint/issues/40) "iterator", // by (https://github.com/shyiko/ktlint/issues/54) - "getValue", "setValue" + "getValue", "setValue", ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt index 99756959a8..fc84d16d2a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRule.kt @@ -13,7 +13,7 @@ public class NoWildcardImportsRule : Rule("no-wildcard-imports"), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - packagesToUseImportOnDemandProperty + packagesToUseImportOnDemandProperty, ) private lateinit var allowedWildcardImports: List @@ -25,7 +25,7 @@ public class NoWildcardImportsRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == IMPORT_DIRECTIVE) { val importDirective = node.psi as KtImportDirective @@ -49,13 +49,13 @@ public class NoWildcardImportsRule : PatternEntry( packageName = import.removeSuffix(WILDCARD_WITH_SUBPACKAGES).plus(WILDCARD_WITHOUT_SUBPACKAGES), withSubpackages = true, - hasAlias = false + hasAlias = false, ) } else { PatternEntry( packageName = import, withSubpackages = false, - hasAlias = false + hasAlias = false, ) } } @@ -67,12 +67,12 @@ public class NoWildcardImportsRule : else -> try { PropertyType.PropertyValue.valid( value, - value?.let(::parseAllowedWildcardImports) ?: emptyList() + value?.let(::parseAllowedWildcardImports) ?: emptyList(), ) } catch (e: IllegalArgumentException) { PropertyType.PropertyValue.invalid( value, - "Unexpected imports layout: $value" + "Unexpected imports layout: $value", ) } } @@ -83,7 +83,7 @@ public class NoWildcardImportsRule : type = PropertyType( "ij_kotlin_packages_to_use_import_on_demand", "Defines allowed wildcard imports", - packagesToUseImportOnDemandPropertyParser + packagesToUseImportOnDemandPropertyParser, ), /** * Default IntelliJ IDEA style: Use wildcard imports for packages in "java.util", "kotlin.android.synthetic" and @@ -92,7 +92,7 @@ public class NoWildcardImportsRule : * https://github.com/JetBrains/kotlin/blob/ffdab473e28d0d872136b910eb2e0f4beea2e19c/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java#L81-L82 */ defaultValue = parseAllowedWildcardImports("java.util.*,kotlinx.android.synthetic.**"), - propertyWriter = { it.joinToString(separator = ",") } + propertyWriter = { it.joinToString(separator = ",") }, ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/PackageNameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/PackageNameRule.kt index 91706774df..36f81810d3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/PackageNameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/PackageNameRule.kt @@ -12,7 +12,7 @@ public class PackageNameRule : Rule("package-name") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == PACKAGE_DIRECTIVE) { val qualifiedName = (node.psi as KtPackageDirective).qualifiedName diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt index 8e38d9bff6..3e42f708a3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRule.kt @@ -39,7 +39,7 @@ public class ParameterListWrappingRule : listOf( indentSizeProperty, indentStyleProperty, - maxLineLengthProperty + maxLineLengthProperty, ) private var indentConfig = IndentConfig.DEFAULT_INDENT_CONFIG @@ -49,7 +49,7 @@ public class ParameterListWrappingRule : maxLineLength = editorConfigProperties.getEditorConfigValue(maxLineLengthProperty) indentConfig = IndentConfig( indentStyle = editorConfigProperties.getEditorConfigValue(indentStyleProperty), - tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty) + tabWidth = editorConfigProperties.getEditorConfigValue(indentSizeProperty), ) if (indentConfig.disabled) { stopTraversalOfAST() @@ -59,7 +59,7 @@ public class ParameterListWrappingRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when (node.elementType) { NULLABLE_TYPE -> wrapNullableType(node, emit, autoCorrect) @@ -74,7 +74,7 @@ public class ParameterListWrappingRule : private fun wrapNullableType( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { require(node.elementType == NULLABLE_TYPE) node @@ -94,7 +94,7 @@ public class ParameterListWrappingRule : emit( it.startOffset, "Parameter of nullable type should be on a separate line (unless the type fits on a single line)", - true + true, ) if (autoCorrect) { (it as LeafElement).upsertWhitespaceAfterMe("\n${indentConfig.indent}") @@ -132,7 +132,7 @@ public class ParameterListWrappingRule : private fun wrapParameterList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val newIndentLevel = getNewIndentLevel(node) node @@ -167,7 +167,7 @@ public class ParameterListWrappingRule : newIndentLevel: Int, child: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val indent = "\n" + indentConfig.indent.repeat(newIndentLevel) when (child.elementType) { @@ -181,7 +181,8 @@ public class ParameterListWrappingRule : } } VALUE_PARAMETER, - RPAR -> { + RPAR, + -> { // aiming for // ... LPAR // VALUE_PARAMETER... diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketsRule.kt index 59c62fe544..11bc8361fa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketsRule.kt @@ -19,7 +19,7 @@ public class SpacingAroundAngleBracketsRule : Rule("spacing-around-angle-bracket override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType.let { it == TYPE_PARAMETER_LIST || it == TYPE_ARGUMENT_LIST }) { val openingBracket = node.firstChildNode diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRule.kt index 52bd77033b..fc55594b5c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRule.kt @@ -31,7 +31,7 @@ public class SpacingAroundColonRule : Rule("colon-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is LeafPsiElement && node.textMatches(":") && !node.isPartOfString() && !node.isPartOfComment()) { if (node.isPartOf(ANNOTATION) || node.isPartOf(ANNOTATION_ENTRY)) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt index 87ecda9429..a720f9fc05 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRule.kt @@ -24,7 +24,7 @@ public class SpacingAroundCommaRule : Rule("comma-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is LeafPsiElement && node.textMatches(",") && !node.isPartOfString()) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt index d7fb1e01db..6597219091 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt @@ -36,7 +36,7 @@ public class SpacingAroundCurlyRule : Rule("curly-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is LeafPsiElement && !node.isPartOfString()) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRule.kt index d9e36e4e25..98dc301abc 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRule.kt @@ -14,7 +14,7 @@ public class SpacingAroundDotRule : Rule("dot-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is LeafPsiElement && node.textMatches(".") && !node.isPartOfString() && !node.isPartOfComment()) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRule.kt index ec45a5bd38..ff1a569007 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRule.kt @@ -15,7 +15,7 @@ public class SpacingAroundDoubleColonRule : Rule("double-colon-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == COLONCOLON) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt index 1643146e44..44c3c5e1a5 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt @@ -32,7 +32,7 @@ public class SpacingAroundKeywordRule : Rule("keyword-spacing") { private val noLFBeforeSet = create(ELSE_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD) private val tokenSet = create( FOR_KEYWORD, IF_KEYWORD, ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD, - TRY_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD, WHEN_KEYWORD + TRY_KEYWORD, CATCH_KEYWORD, FINALLY_KEYWORD, WHEN_KEYWORD, ) private val keywordsWithoutSpaces = create(GET_KEYWORD, SET_KEYWORD) @@ -40,7 +40,7 @@ public class SpacingAroundKeywordRule : Rule("keyword-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is LeafPsiElement) { if (tokenSet.contains(node.elementType) && node.parent !is KDocName && node.nextLeaf() !is PsiWhiteSpace) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRule.kt index b0fbf8c7db..c408ca7a11 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRule.kt @@ -42,13 +42,13 @@ public class SpacingAroundOperatorsRule : Rule("op-spacing") { private val tokenSet = TokenSet.create( MUL, PLUS, MINUS, DIV, PERC, LT, GT, LTEQ, GTEQ, EQEQEQ, EXCLEQEQEQ, EQEQ, - EXCLEQ, ANDAND, OROR, ELVIS, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ, ARROW + EXCLEQ, ANDAND, OROR, ELVIS, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ, ARROW, ) override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (tokenSet.contains(node.elementType) && node is LeafElement && diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRule.kt index 231f81bd37..d5209e56af 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRule.kt @@ -27,7 +27,7 @@ public class SpacingAroundParensRule : Rule("paren-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == LPAR || node.elementType == RPAR) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRule.kt index 883ea894c6..4e22e4d379 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRule.kt @@ -12,7 +12,7 @@ public class SpacingAroundRangeOperatorRule : Rule("range-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == RANGE) { val prevLeaf = node.prevLeaf() diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRule.kt index a5253529c3..f426c326a3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRule.kt @@ -16,7 +16,7 @@ public class SpacingAroundUnaryOperatorRule : Rule("unary-op-spacing") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == ElementType.PREFIX_EXPRESSION || node.elementType == ElementType.POSTFIX_EXPRESSION diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithAnnotationsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithAnnotationsRule.kt index 7ef3af1707..b8bc411cfa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithAnnotationsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithAnnotationsRule.kt @@ -21,7 +21,7 @@ public class SpacingBetweenDeclarationsWithAnnotationsRule : Rule("spacing-betwe override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == MODIFIER_LIST && node.hasAnnotationsAsChildren()) { val declaration = node.psi.parent as? KtDeclaration @@ -35,7 +35,7 @@ public class SpacingBetweenDeclarationsWithAnnotationsRule : Rule("spacing-betwe emit( node.startOffset, "Declarations and declarations with annotations should have an empty space between.", - true + true, ) if (autoCorrect) { val indent = whiteSpaceAfterPreviousDeclaration.text.substringAfter('\n') diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithCommentsRule.kt index dd5c253fdd..b5b1697f19 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingBetweenDeclarationsWithCommentsRule.kt @@ -20,7 +20,7 @@ public class SpacingBetweenDeclarationsWithCommentsRule : Rule("spacing-between- override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node is PsiComment) { val declaration = node.parent as? KtDeclaration ?: return @@ -36,7 +36,7 @@ public class SpacingBetweenDeclarationsWithCommentsRule : Rule("spacing-between- emit( node.startOffset, "Declarations and declarations with comments should have an empty space between.", - true + true, ) if (autoCorrect) { val indent = node.prevLeaf()?.text?.trim('\n') ?: "" diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProvider.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProvider.kt index 562383b960..4211aae6aa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProvider.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProvider.kt @@ -11,8 +11,8 @@ public class StandardRuleSetProvider : description = "Standard rules based on the Kotlin coding conventions (https://kotlinlang.org/docs/coding-conventions.html) and Android Kotlin styleguide (https://developer.android.com/kotlin/style-guide)", license = "https://github.com/pinterest/ktlint/blob/master/LICENSE", repositoryUrl = "https://github.com/pinterest/ktlint", - issueTrackerUrl = "https://github.com/pinterest/ktlint/issues" - ) + issueTrackerUrl = "https://github.com/pinterest/ktlint/issues", + ), ) { override fun getRuleProviders(): Set = setOf( @@ -60,6 +60,6 @@ public class StandardRuleSetProvider : RuleProvider { StringTemplateRule() }, RuleProvider { TrailingCommaOnCallSiteRule() }, RuleProvider { TrailingCommaOnDeclarationSiteRule() }, - RuleProvider { WrappingRule() } + RuleProvider { WrappingRule() }, ) } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRule.kt index b1bf1b1422..449ec2298b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRule.kt @@ -21,7 +21,7 @@ public class StringTemplateRule : Rule("string-template") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val elementType = node.elementType // code below is commented out because (setting aside potentially dangerous replaceChild part) @@ -43,7 +43,7 @@ public class StringTemplateRule : Rule("string-template") { emit( entryExpression.operationTokenNode.startOffset, "Redundant \"toString()\" call in string template", - true + true, ) if (autoCorrect) { entryExpression.replace(receiver) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt index f1b963bb33..067f849b96 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRule.kt @@ -36,15 +36,15 @@ public class TrailingCommaOnCallSiteRule : VisitorModifier.RunAfterRule( ruleId = "standard:indent", loadOnlyWhenOtherRuleIsLoaded = true, - runOnlyWhenOtherRuleIsEnabled = true + runOnlyWhenOtherRuleIsEnabled = true, ), - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - allowTrailingCommaOnCallSiteProperty + allowTrailingCommaOnCallSiteProperty, ) private var allowTrailingCommaOnCallSite by Delegates.notNull() @@ -59,7 +59,7 @@ public class TrailingCommaOnCallSiteRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // Keep processing of element types in sync with Intellij Kotlin formatting settings. // https://github.com/JetBrains/intellij-kotlin/blob/master/formatter/src/org/jetbrains/kotlin/idea/formatter/trailingComma/util.kt @@ -75,7 +75,7 @@ public class TrailingCommaOnCallSiteRule : private fun visitCollectionLiteralExpression( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -84,14 +84,14 @@ public class TrailingCommaOnCallSiteRule : inspectNode = inspectNode, emit = emit, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), - autoCorrect = autoCorrect + autoCorrect = autoCorrect, ) } private fun visitIndices( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -100,14 +100,14 @@ public class TrailingCommaOnCallSiteRule : inspectNode = inspectNode, emit = emit, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), - autoCorrect = autoCorrect + autoCorrect = autoCorrect, ) } private fun visitValueList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.treeParent.elementType != ElementType.FUNCTION_LITERAL) { node @@ -118,7 +118,7 @@ public class TrailingCommaOnCallSiteRule : inspectNode = inspectNode, emit = emit, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), - autoCorrect = autoCorrect + autoCorrect = autoCorrect, ) } } @@ -127,7 +127,7 @@ public class TrailingCommaOnCallSiteRule : private fun visitTypeList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -136,7 +136,7 @@ public class TrailingCommaOnCallSiteRule : inspectNode = inspectNode, emit = emit, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), - autoCorrect = autoCorrect + autoCorrect = autoCorrect, ) } @@ -144,7 +144,7 @@ public class TrailingCommaOnCallSiteRule : inspectNode: ASTNode, isTrailingCommaAllowed: Boolean, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val prevLeaf = inspectNode.prevLeaf() val trailingCommaNode = prevLeaf.findPreviousTrailingCommaNodeOrNull() @@ -157,7 +157,7 @@ public class TrailingCommaOnCallSiteRule : emit( trailingCommaNode!!.startOffset, "Unnecessary trailing comma before \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { this.removeChild(trailingCommaNode) @@ -168,7 +168,7 @@ public class TrailingCommaOnCallSiteRule : emit( prevNode.startOffset + prevNode.textLength, "Missing trailing comma before \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { val comma = KtPsiFactory(prevNode.psi).createComma() @@ -179,7 +179,7 @@ public class TrailingCommaOnCallSiteRule : emit( trailingCommaNode!!.startOffset, "Unnecessary trailing comma before \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { this.removeChild(trailingCommaNode) @@ -252,8 +252,7 @@ public class TrailingCommaOnCallSiteRule : /** * The trailing comma isn't needed, but exists */ - REDUNDANT - ; + REDUNDANT, } public companion object { @@ -271,16 +270,16 @@ public class TrailingCommaOnCallSiteRule : ALLOW_TRAILING_COMMA_ON_CALL_SITE_NAME, ALLOW_TRAILING_COMMA_ON_CALL_SITE_DESCRIPTION, PropertyValueParser.BOOLEAN_VALUE_PARSER, - BOOLEAN_VALUES_SET + BOOLEAN_VALUES_SET, ), - defaultValue = false + defaultValue = false, ) private val TYPES_ON_CALL_SITE = TokenSet.create( ElementType.COLLECTION_LITERAL_EXPRESSION, ElementType.INDICES, ElementType.TYPE_ARGUMENT_LIST, - ElementType.VALUE_ARGUMENT_LIST + ElementType.VALUE_ARGUMENT_LIST, ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt index e4d6702f07..92760ed639 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRule.kt @@ -50,15 +50,15 @@ public class TrailingCommaOnDeclarationSiteRule : VisitorModifier.RunAfterRule( ruleId = "standard:indent", loadOnlyWhenOtherRuleIsLoaded = true, - runOnlyWhenOtherRuleIsEnabled = true + runOnlyWhenOtherRuleIsEnabled = true, ), - VisitorModifier.RunAsLateAsPossible - ) + VisitorModifier.RunAsLateAsPossible, + ), ), UsesEditorConfigProperties { override val editorConfigProperties: List> = listOf( - allowTrailingCommaProperty + allowTrailingCommaProperty, ) private var allowTrailingComma by Delegates.notNull() @@ -73,7 +73,7 @@ public class TrailingCommaOnDeclarationSiteRule : override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { // Keep processing of element types in sync with Intellij Kotlin formatting settings. // https://github.com/JetBrains/intellij-kotlin/blob/master/formatter/src/org/jetbrains/kotlin/idea/formatter/trailingComma/util.kt @@ -91,7 +91,7 @@ public class TrailingCommaOnDeclarationSiteRule : private fun visitDestructuringDeclaration( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -100,14 +100,14 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = inspectNode, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } private fun visitFunctionLiteral( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -118,14 +118,14 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = inspectNode, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } private fun visitValueList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.treeParent.elementType != ElementType.FUNCTION_LITERAL) { node @@ -136,7 +136,7 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = inspectNode, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } } @@ -145,7 +145,7 @@ public class TrailingCommaOnDeclarationSiteRule : private fun visitTypeList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val inspectNode = node .children() @@ -154,14 +154,14 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = inspectNode, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } private fun visitWhenEntry( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val psi = node.psi require(psi is KtWhenEntry) @@ -177,13 +177,13 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = inspectNode, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } private fun visitClass( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - autoCorrect: Boolean + autoCorrect: Boolean, ) { val psi = node.psi require(psi is KtClass) @@ -200,7 +200,7 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode = nodeAfterTrailingCommaPosition, isTrailingCommaAllowed = node.isTrailingCommaAllowed(), autoCorrect = autoCorrect, - emit = emit + emit = emit, ) } } @@ -235,7 +235,7 @@ public class TrailingCommaOnDeclarationSiteRule : inspectNode: ASTNode, isTrailingCommaAllowed: Boolean, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val prevLeaf = inspectNode.prevLeaf() val trailingCommaNode = prevLeaf.findPreviousTrailingCommaNodeOrNull() @@ -256,7 +256,7 @@ public class TrailingCommaOnDeclarationSiteRule : emit( trailingCommaNode!!.startOffset, "Expected a newline between the trailing comma and \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { val parentIndent = "\n" + inspectNode.getWhenEntryIndent() @@ -272,7 +272,7 @@ public class TrailingCommaOnDeclarationSiteRule : emit( trailingCommaNode!!.startOffset, "Unnecessary trailing comma before \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { this.removeChild(trailingCommaNode) @@ -286,13 +286,13 @@ public class TrailingCommaOnDeclarationSiteRule : emit( prevNode.startOffset + prevNode.textLength, "Missing trailing comma and newline before \"${inspectNode.text}\"", - true + true, ) } else { emit( prevNode.startOffset + prevNode.textLength, "Missing trailing comma before \"${inspectNode.text}\"", - true + true, ) } if (autoCorrect) { @@ -329,7 +329,7 @@ public class TrailingCommaOnDeclarationSiteRule : emit( trailingCommaNode!!.startOffset, "Unnecessary trailing comma before \"${inspectNode.text}\"", - true + true, ) if (autoCorrect) { this.removeChild(trailingCommaNode) @@ -416,8 +416,7 @@ public class TrailingCommaOnDeclarationSiteRule : /** * The trailing comma isn't needed, but exists */ - REDUNDANT - ; + REDUNDANT, } public companion object { @@ -437,9 +436,9 @@ public class TrailingCommaOnDeclarationSiteRule : ALLOW_TRAILING_COMMA_NAME, ALLOW_TRAILING_COMMA_DESCRIPTION, PropertyValueParser.BOOLEAN_VALUE_PARSER, - BOOLEAN_VALUES_SET + BOOLEAN_VALUES_SET, ), - defaultValue = false + defaultValue = false, ) private val TYPES_ON_DECLARATION_SITE = TokenSet.create( @@ -449,7 +448,7 @@ public class TrailingCommaOnDeclarationSiteRule : ElementType.FUNCTION_TYPE, ElementType.TYPE_PARAMETER_LIST, ElementType.VALUE_PARAMETER_LIST, - ElementType.WHEN_ENTRY + ElementType.WHEN_ENTRY, ) } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt index 92eb2fe7b8..efa17d68e9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRule.kt @@ -79,7 +79,7 @@ public class WrappingRule : override val editorConfigProperties: List> = listOf( DefaultEditorConfigProperties.indentSizeProperty, - DefaultEditorConfigProperties.indentStyleProperty + DefaultEditorConfigProperties.indentStyleProperty, ) private var line = 1 @@ -89,14 +89,14 @@ public class WrappingRule : line = 1 indentConfig = IndentConfig( indentStyle = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentStyleProperty), - tabWidth = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentSizeProperty) + tabWidth = editorConfigProperties.getEditorConfigValue(DefaultEditorConfigProperties.indentSizeProperty), ) } override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { when (node.elementType) { LPAR, LBRACE, LBRACKET -> rearrangeBlock(node, autoCorrect, emit) // TODO: LT @@ -111,7 +111,7 @@ public class WrappingRule : private fun rearrangeBlock( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val rElementType = matchingRToken[node.elementType] var newlineInBetween = false @@ -190,7 +190,7 @@ public class WrappingRule : private fun rearrangeSuperTypeList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val entries = (node.psi as KtSuperTypeList).entries if ( @@ -234,7 +234,7 @@ public class WrappingRule : nodeAfterWhichNewlineIsRequired = c, autoCorrect = autoCorrect, emit = emit, - indent = node.lineIndent() + indent = node.lineIndent(), ) } } @@ -248,7 +248,7 @@ public class WrappingRule : private fun rearrangeValueList( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { for (c in node.children()) { val hasLineBreak = when (c.elementType) { @@ -303,7 +303,7 @@ public class WrappingRule : private fun rearrangeClosingQuote( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { node .treeParent @@ -325,7 +325,7 @@ public class WrappingRule : emit( node.startOffset, "Missing newline before \"\"\"", - true + true, ) if (autoCorrect) { node as LeafPsiElement @@ -365,7 +365,7 @@ public class WrappingRule : private fun rearrangeArrow( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { val p = node.treeParent if ( @@ -406,12 +406,12 @@ public class WrappingRule : node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, - indent: String + indent: String, ) { emit( node.startOffset - 1, """Missing newline before "${node.text}"""", - true + true, ) logger.trace { "$line: " + ((if (!autoCorrect) "would have " else "") + "inserted newline before ${node.text}") } if (autoCorrect) { @@ -424,12 +424,12 @@ public class WrappingRule : autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, indent: String? = null, - nodeToFix: ASTNode = nodeAfterWhichNewlineIsRequired + nodeToFix: ASTNode = nodeAfterWhichNewlineIsRequired, ) { emit( nodeAfterWhichNewlineIsRequired.startOffset + 1, """Missing newline after "${nodeAfterWhichNewlineIsRequired.text}"""", - true + true, ) logger.trace { "$line: " + (if (!autoCorrect) "would have " else "") + "inserted newline after ${nodeAfterWhichNewlineIsRequired.text}" } if (autoCorrect) { @@ -508,7 +508,7 @@ public class WrappingRule : private val rTokenSet = TokenSet.create(RPAR, RBRACE, RBRACKET, GT) private val matchingRToken = lTokenSet.types.zip( - rTokenSet.types + rTokenSet.types, ).toMap() } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/ImportSorter.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/ImportSorter.kt index cc92311d66..53e959e471 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/ImportSorter.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/ImportSorter.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.resolve.ImportPath * Adopted from https://github.com/JetBrains/kotlin/blob/a270ee094c4d7b9520e0898a242bb6ce4dfcad7b/idea/src/org/jetbrains/kotlin/idea/util/ImportPathComparator.kt#L15 */ internal class ImportSorter( - val patterns: List + val patterns: List, ) : Comparator { override fun compare(import1: KtImportDirective, import2: KtImportDirective): Int { @@ -20,7 +20,7 @@ internal class ImportSorter( importPath1, importPath2, { import -> findImportIndex(import) }, - { import -> import.toString().replace("`", "") } + { import -> import.toString().replace("`", "") }, ) } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/PatternEntry.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/PatternEntry.kt index dddd8f0681..4249c89ac7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/PatternEntry.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/internal/importordering/PatternEntry.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.resolve.ImportPath public class PatternEntry( packageName: String, public val withSubpackages: Boolean, - public val hasAlias: Boolean + public val hasAlias: Boolean, ) { private val packageName = packageName.removeSuffix(".*") @@ -79,21 +79,21 @@ public class PatternEntry( PatternEntry( BLANK_LINE_CHAR, withSubpackages = true, - hasAlias = false + hasAlias = false, ) public val ALL_OTHER_IMPORTS_ENTRY: PatternEntry = PatternEntry( WILDCARD_CHAR, withSubpackages = true, - hasAlias = false + hasAlias = false, ) public val ALL_OTHER_ALIAS_IMPORTS_ENTRY: PatternEntry = PatternEntry( ALIAS_CHAR, withSubpackages = true, - hasAlias = true + hasAlias = true, ) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt index 1b727eef01..782ea7fe54 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt @@ -101,7 +101,7 @@ class AnnotationRuleTest { LintViolation(7, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), LintViolation(9, 1, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), LintViolation(10, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), - LintViolation(11, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct") + LintViolation(11, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), ).isFormattedAs(formattedCode) } @@ -128,7 +128,7 @@ class AnnotationRuleTest { .hasLintViolations( LintViolation(1, 1, "Multiple annotations should not be placed on the same line as the annotated construct"), LintViolation(2, 5, "Multiple annotations should not be placed on the same line as the annotated construct"), - LintViolation(3, 5, "Multiple annotations should not be placed on the same line as the annotated construct") + LintViolation(3, 5, "Multiple annotations should not be placed on the same line as the annotated construct"), ).isFormattedAs(formattedCode) } @@ -187,7 +187,7 @@ class AnnotationRuleTest { .hasLintViolations( LintViolation(1, 1, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), LintViolation(2, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), - LintViolation(3, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct") + LintViolation(3, 5, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), ).isFormattedAs(formattedCode) } @@ -395,7 +395,7 @@ class AnnotationRuleTest { annotationRuleAssertThat(code) .hasLintViolations( LintViolation(1, 1, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct"), - LintViolation(1, 25, "File annotations should be separated from file contents with a blank line") + LintViolation(1, 25, "File annotations should be separated from file contents with a blank line"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRuleTest.kt index 9cf0ec8c0e..978321b26d 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationSpacingRuleTest.kt @@ -81,7 +81,7 @@ class AnnotationSpacingRuleTest { .hasLintViolations( // TODO: It is not correct that the error is reported twice LintViolation(1, 20, "Annotations should occur immediately before the annotated construct"), - LintViolation(1, 20, "Annotations should occur immediately before the annotated construct") + LintViolation(1, 20, "Annotations should occur immediately before the annotated construct"), ).isFormattedAs(formattedCode) } @@ -104,7 +104,7 @@ class AnnotationSpacingRuleTest { .hasLintViolations( // TODO: It is not correct that the error is reported twice LintViolation(2, 10, "Annotations should occur immediately before the annotated construct"), - LintViolation(2, 10, "Annotations should occur immediately before the annotated construct") + LintViolation(2, 10, "Annotations should occur immediately before the annotated construct"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt index b105e9d033..0771d222a2 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ArgumentListWrappingRuleTest.kt @@ -31,7 +31,7 @@ class ArgumentListWrappingRuleTest { .hasLintViolation( 3, 8, - "Argument should be on a separate line (unless all arguments can fit a single line)" + "Argument should be on a separate line (unless all arguments can fit a single line)", ) .isFormattedAs(formattedCode) } @@ -62,7 +62,7 @@ class ArgumentListWrappingRuleTest { .hasLintViolations( LintViolation(2, 9, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(2, 14, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(3, 8, "Missing newline before \")\"") + LintViolation(3, 8, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -86,7 +86,7 @@ class ArgumentListWrappingRuleTest { LintViolation(1, 11, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(1, 14, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(1, 17, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(1, 18, "Missing newline before \")\"") + LintViolation(1, 18, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -164,7 +164,7 @@ class ArgumentListWrappingRuleTest { .hasLintViolations( LintViolation(13, 10, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(13, 19, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(13, 26, "Missing newline before \")\"") + LintViolation(13, 26, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -202,7 +202,7 @@ class ArgumentListWrappingRuleTest { LintViolation(3, 18, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(5, 6, "Missing newline before \")\""), LintViolation(7, 9, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(8, 26, "Missing newline before \")\"") + LintViolation(8, 26, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -251,7 +251,7 @@ class ArgumentListWrappingRuleTest { .hasLintViolations( LintViolation(5, 17, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(6, 31, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(6, 32, "Missing newline before \")\"") + LintViolation(6, 32, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -283,7 +283,7 @@ class ArgumentListWrappingRuleTest { .hasLintViolations( LintViolation(2, 10, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(2, 19, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(5, 12, "Missing newline before \")\"") + LintViolation(5, 12, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -358,7 +358,7 @@ class ArgumentListWrappingRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(4, 21, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(7, 10, "Missing newline before \")\"") + LintViolation(7, 10, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -524,7 +524,7 @@ class ArgumentListWrappingRuleTest { .withEditorConfigOverride(maxLineLengthProperty to 33) .hasLintViolations( LintViolation(8, 23, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(8, 34, "Missing newline before \")\"") + LintViolation(8, 34, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -556,7 +556,7 @@ class ArgumentListWrappingRuleTest { .withEditorConfigOverride(maxLineLengthProperty to 65) .hasLintViolations( LintViolation(4, 15, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(4, 70, "Missing newline before \")\"") + LintViolation(4, 70, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -758,7 +758,7 @@ class ArgumentListWrappingRuleTest { LintViolation(27, 26, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(28, 22, "Argument should be on a separate line (unless all arguments can fit a single line)"), LintViolation(29, 22, "Argument should be on a separate line (unless all arguments can fit a single line)"), - LintViolation(32, 22, "Argument should be on a separate line (unless all arguments can fit a single line)") + LintViolation(32, 22, "Argument should be on a separate line (unless all arguments can fit a single line)"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRuleTest.kt index 461ae0e371..e255c6a454 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ChainWrappingRuleTest.kt @@ -28,7 +28,7 @@ class ChainWrappingRuleTest { .hasLintViolations( LintViolation(1, 26, "Line must not end with \".\""), LintViolation(2, 24, "Line must not end with \".\""), - LintViolation(3, 32, "Line must not end with \"?.\"") + LintViolation(3, 32, "Line must not end with \"?.\""), ).isFormattedAs(formattedCode) } @@ -78,7 +78,7 @@ class ChainWrappingRuleTest { chainWrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 5, "Line must not begin with \"&&\""), - LintViolation(4, 5, "Line must not begin with \"||\"") + LintViolation(4, 5, "Line must not begin with \"||\""), ).isFormattedAs(formattedCode) } @@ -218,7 +218,7 @@ class ChainWrappingRuleTest { LintViolation(7, 9, "Line must not begin with \"&&\""), LintViolation(8, 18, "Line must not end with \".\""), LintViolation(10, 14, "Line must not end with \".\""), - LintViolation(13, 14, "Line must not end with \".\"") + LintViolation(13, 14, "Line must not end with \".\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRuleTest.kt index 2b05bdc442..8774c9eb2c 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/CommentSpacingRuleTest.kt @@ -61,7 +61,7 @@ class CommentSpacingRuleTest { LintViolation(4, 22, "Missing space after //"), LintViolation(6, 24, "Missing space before //"), LintViolation(6, 24, "Missing space after //"), - LintViolation(10, 5, "Missing space after //") + LintViolation(10, 5, "Missing space after //"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRuleTest.kt index efdeaf0dbd..67264094ca 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/EnumEntryNameCaseRuleTest.kt @@ -58,7 +58,7 @@ class EnumEntryNameCaseRuleTest { .hasLintViolationsWithoutAutoCorrect( LintViolation(2, 5, "Enum entry name should be uppercase underscore-separated names like \"ENUM_ENTRY\" or upper camel-case like \"EnumEntry\""), LintViolation(3, 5, "Enum entry name should be uppercase underscore-separated names like \"ENUM_ENTRY\" or upper camel-case like \"EnumEntry\""), - LintViolation(4, 5, "Enum entry name should be uppercase underscore-separated names like \"ENUM_ENTRY\" or upper camel-case like \"EnumEntry\"") + LintViolation(4, 5, "Enum entry name should be uppercase underscore-separated names like \"ENUM_ENTRY\" or upper camel-case like \"EnumEntry\""), ) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRuleTest.kt index 47001d2f3a..735f5d61fb 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/FilenameRuleTest.kt @@ -68,8 +68,8 @@ class FilenameRuleTest { "sealed class Foo", "sealed class `Foo`", "interface Foo", - "interface `Foo`" - ] + "interface `Foo`", + ], ) fun `Given a file containing a single declaration of a class type then the filename should match the class name`(code: String) { fileNameRuleAssertThat(code) @@ -81,11 +81,11 @@ class FilenameRuleTest { @ValueSource( strings = [ "object Foo", - "typealias Foo = String" - ] + "typealias Foo = String", + ], ) fun `Given a file containing one top level declaration then the file should be named after the identifier`( - code: String + code: String, ) { fileNameRuleAssertThat(code) .asFileWithPath(UNEXPECTED_FILE_NAME) @@ -99,11 +99,11 @@ class FilenameRuleTest { "const val FOO", "fun String.foo() = {}", "fun foo() = {}", - "operator fun Foo.plus(other: Foo): Foo { /* ... */ }" - ] + "operator fun Foo.plus(other: Foo): Foo { /* ... */ }", + ], ) fun `Given a file containing one top level then the file should conform to PascalCase`( - code: String + code: String, ) { fileNameRuleAssertThat(code) .asFileWithPath(NON_PASCAL_CASE_NAME) @@ -114,11 +114,11 @@ class FilenameRuleTest { @ValueSource( strings = [ "val foo", - "const val FOO" - ] + "const val FOO", + ], ) fun `Given a file containing a single top level property declaration (non-private) and one private top level class declaration then the file should conform to PascalCase`( - topLevelDeclaration: String + topLevelDeclaration: String, ) { val code = """ @@ -138,11 +138,11 @@ class FilenameRuleTest { "fun bar() = {}", "object Bar", "typealias Bar = String", - "val bar" - ] + "val bar", + ], ) fun `Given a file containing a single top level class (non-private) and another top level declaration (non-private, not extending that class) then the file should conform to PascalCase notation but does not need to be named after that class`( - otherTopLevelDeclaration: String + otherTopLevelDeclaration: String, ) { val code = """ @@ -158,11 +158,11 @@ class FilenameRuleTest { @ValueSource( strings = [ "fun Foo.foo() = {}", - "private object Bar" - ] + "private object Bar", + ], ) fun `Given a file containing a single top level class (non-private) and another top level declaration (private and,x xor extending that class) then the file should be named after that class`( - otherTopLevelDeclaration: String + otherTopLevelDeclaration: String, ) { val code = """ diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt index 1103a1c411..f77ab7ace5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt @@ -47,7 +47,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -68,7 +68,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 2)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 2)"), ).isFormattedAs(formattedCode) } } @@ -101,7 +101,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -121,7 +121,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(INDENT_STYLE_TAB) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -154,7 +154,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -175,7 +175,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -206,7 +206,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -226,7 +226,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -266,7 +266,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -292,7 +292,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -360,7 +360,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -380,7 +380,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -420,7 +420,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -446,7 +446,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -480,7 +480,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(5, 1, "Unexpected indentation (0) (should be 12)"), - LintViolation(6, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -502,7 +502,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(5, 1, "Unexpected indentation (0) (should be 3)"), - LintViolation(6, 1, "Unexpected indentation (0) (should be 2)") + LintViolation(6, 1, "Unexpected indentation (0) (should be 2)"), ).isFormattedAs(formattedCode) } } @@ -529,7 +529,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -546,7 +546,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(INDENT_STYLE_TAB) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -584,7 +584,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -607,7 +607,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -643,7 +643,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(7, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(7, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -666,7 +666,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(5, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(7, 1, "Unexpected indentation (0) (should be 2)") + LintViolation(7, 1, "Unexpected indentation (0) (should be 2)"), ).isFormattedAs(formattedCode) } } @@ -706,7 +706,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -731,7 +731,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 2)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 2)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -761,7 +761,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(4, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(4, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -780,7 +780,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), LintViolation(3, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(4, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(4, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -828,7 +828,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -845,7 +845,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(INDENT_STYLE_TAB) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(3, 1, "Unexpected indentation (0) (should be 1)") + LintViolation(3, 1, "Unexpected indentation (0) (should be 1)"), ).isFormattedAs(formattedCode) } } @@ -888,7 +888,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(indentSizeProperty to 2) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (3) (should be 2)"), - LintViolation(3, 1, "Unexpected indentation (4) (should be 2)") + LintViolation(3, 1, "Unexpected indentation (4) (should be 2)"), ).isFormattedAs(formattedCode) } @@ -930,7 +930,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(INDENT_STYLE_TAB) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 1)"), - LintViolation(3, 1, "Unexpected indentation (2) (should be 1)") + LintViolation(3, 1, "Unexpected indentation (2) (should be 1)"), ).isFormattedAs(formattedCode) } @@ -976,7 +976,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (10) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (10) (should be 8)"), LintViolation(5, 1, "Unexpected indentation (10) (should be 8)"), - LintViolation(6, 1, "Unexpected indentation (10) (should be 4)") + LintViolation(6, 1, "Unexpected indentation (10) (should be 4)"), ) .isFormattedAs(formattedCode) } @@ -1006,7 +1006,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (2) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (3) (should be 5)"), LintViolation(4, 1, "Unexpected indentation (3) (should be 5)"), - LintViolation(5, 1, "Unexpected indentation (2) (should be 4)") + LintViolation(5, 1, "Unexpected indentation (2) (should be 4)"), ) .isFormattedAs(formattedCode) } @@ -1112,7 +1112,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (8) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (9) (should be 5)"), - LintViolation(4, 1, "Unexpected indentation (9) (should be 5)") + LintViolation(4, 1, "Unexpected indentation (9) (should be 5)"), ).isFormattedAs(formattedCode) } @@ -1186,7 +1186,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (8) (should be 4)"), LintViolation(3, 1, "Unexpected indentation (9) (should be 5)"), - LintViolation(4, 1, "Unexpected indentation (9) (should be 5)") + LintViolation(4, 1, "Unexpected indentation (9) (should be 5)"), ).isFormattedAs(formattedCode) } @@ -1254,7 +1254,7 @@ internal class IndentationRuleTest { LintViolation(10, 1, "Unexpected indentation (0) (should be 20)"), LintViolation(11, 1, "Unexpected indentation (0) (should be 20)"), LintViolation(12, 1, "Unexpected indentation (0) (should be 12)"), - LintViolation(13, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(13, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1319,7 +1319,7 @@ internal class IndentationRuleTest { LintViolation(14, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(15, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(16, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(17, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(17, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -1384,7 +1384,7 @@ internal class IndentationRuleTest { LintViolation(14, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(15, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(16, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(17, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(17, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } } @@ -1494,7 +1494,7 @@ internal class IndentationRuleTest { LintViolation(30, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(32, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(33, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(34, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(34, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1522,7 +1522,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(3, 1, "Unexpected indentation (8) (should be 4)"), LintViolation(4, 1, "Unexpected indentation (12) (should be 8)"), - LintViolation(5, 1, "Unexpected indentation (12) (should be 8)") + LintViolation(5, 1, "Unexpected indentation (12) (should be 8)"), ) // Can't check the formatted code here as the template string expression results in an error in AssertJ } @@ -1548,7 +1548,7 @@ internal class IndentationRuleTest { @ParameterizedTest(name = "As Kotlin script: {0}") @ValueSource(booleans = [true, false]) fun `Given a file with blanks only on the first line then do not report unexpected indentation for that first line`( - asKotlinScript: Boolean + asKotlinScript: Boolean, ) { val code = """ @@ -1597,7 +1597,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(4, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1635,7 +1635,7 @@ internal class IndentationRuleTest { LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(8, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(9, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(9, 1, "Unexpected indentation (0) (should be 4)"), ) .isFormattedAs(formattedCode) } @@ -1677,7 +1677,7 @@ internal class IndentationRuleTest { LintViolation(7, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(8, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(9, 1, "Unexpected indentation (0) (should be 12)"), - LintViolation(10, 1, "Unexpected indentation (0) (should be 12)") + LintViolation(10, 1, "Unexpected indentation (0) (should be 12)"), ).isFormattedAs(formattedCode) } @@ -1715,7 +1715,7 @@ internal class IndentationRuleTest { LintViolation(5, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 12)"), - LintViolation(8, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(8, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } } @@ -1743,7 +1743,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(5, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1776,7 +1776,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(6, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(7, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(7, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -1906,7 +1906,7 @@ internal class IndentationRuleTest { LintViolation(11, 1, "Unexpected indentation (0) (should be 16)"), LintViolation(12, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(13, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(14, 1, "Unexpected indentation (0) (should be 8)") + LintViolation(14, 1, "Unexpected indentation (0) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1936,7 +1936,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(5, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(6, 1, "Unexpected indentation (8) (should be 12)"), - LintViolation(7, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(7, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -1970,7 +1970,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(7, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(8, 1, "Unexpected indentation (8) (should be 12)"), - LintViolation(9, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(9, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -2003,7 +2003,7 @@ internal class IndentationRuleTest { .addAdditionalRuleProvider { WrappingRule() } .hasLintViolations( LintViolation(3, 1, "Unexpected indentation (4) (should be 8)"), - LintViolation(4, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(4, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -2041,7 +2041,7 @@ internal class IndentationRuleTest { .addAdditionalRuleProvider { WrappingRule() } .hasLintViolations( LintViolation(5, 1, "Unexpected indent of multiline string closing quotes"), - LintViolation(7, 1, "Unexpected indent of multiline string closing quotes") + LintViolation(7, 1, "Unexpected indent of multiline string closing quotes"), ).isFormattedAs(formattedCode) } @@ -2083,7 +2083,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(4, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(7, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(8, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(8, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -2146,7 +2146,7 @@ internal class IndentationRuleTest { LintViolation(7, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(8, 1, "Unexpected indentation (0) (should be 8)"), LintViolation(9, 1, "Unexpected indentation (0) (should be 12)"), - LintViolation(10, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(10, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -2214,7 +2214,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (8) (should be 12)"), LintViolation(4, 1, "Unexpected indentation (12) (should be 8)"), LintViolation(5, 1, "Unexpected indentation (12) (should be 8)"), - LintViolation(6, 1, "Unexpected indentation (8) (should be 4)") + LintViolation(6, 1, "Unexpected indentation (8) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -2255,7 +2255,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(4, 1, "Unexpected indentation (0) (should be 4)"), LintViolation(5, 1, "Unexpected indentation (0) (should be 8)"), - LintViolation(6, 1, "Unexpected indentation (0) (should be 4)") + LintViolation(6, 1, "Unexpected indentation (0) (should be 4)"), ).isFormattedAs(formattedCode) } @@ -2311,7 +2311,7 @@ internal class IndentationRuleTest { .withEditorConfigOverride(INDENT_STYLE_TAB) .hasLintViolations( LintViolation(2, 1, "Unexpected space character(s)"), - LintViolation(3, 1, "Unexpected space character(s)") + LintViolation(3, 1, "Unexpected space character(s)"), ).isFormattedAs(formattedCode) } @@ -2334,7 +2334,7 @@ internal class IndentationRuleTest { LintViolation(2, 1, "Unexpected tab character(s)"), LintViolation(2, 1, "Unexpected indentation (8) (should be 4)"), LintViolation(3, 1, "Unexpected tab character(s)"), - LintViolation(3, 1, "Unexpected indentation (4) (should be 0)") + LintViolation(3, 1, "Unexpected indentation (4) (should be 0)"), ).isFormattedAs(formattedCode) } @@ -2360,7 +2360,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected tab character(s)"), LintViolation(3, 1, "Unexpected tab character(s)"), - LintViolation(4, 1, "Unexpected tab character(s)") + LintViolation(4, 1, "Unexpected tab character(s)"), ).isFormattedAs(formattedCode) } @@ -2387,7 +2387,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected tab character(s)"), LintViolation(3, 1, "Unexpected tab character(s)"), - LintViolation(4, 1, "Unexpected tab character(s)") + LintViolation(4, 1, "Unexpected tab character(s)"), ).isFormattedAs(formattedCode) } @@ -2472,7 +2472,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (8) (should be 4)"), - LintViolation(6, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(6, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -2662,7 +2662,7 @@ internal class IndentationRuleTest { .addAdditionalRuleProvider { WrappingRule() } .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (0) (should be 4)"), - LintViolation(6, 1, "Unexpected indent of multiline string closing quotes") + LintViolation(6, 1, "Unexpected indent of multiline string closing quotes"), ).isFormattedAs(formattedCode) } @@ -2690,7 +2690,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(3, 3, "Unexpected indent of multiline string closing quotes"), - LintViolation(5, 1, "Unexpected indent of multiline string closing quotes") + LintViolation(5, 1, "Unexpected indent of multiline string closing quotes"), ).isFormattedAs(formattedCode) } @@ -2770,7 +2770,7 @@ internal class IndentationRuleTest { LintViolation(7, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(10, 1, "Unexpected indent of multiline string closing quotes"), LintViolation(12, 1, "Unexpected indentation (4) (should be 8)"), - LintViolation(15, 1, "Unexpected indent of multiline string closing quotes") + LintViolation(15, 1, "Unexpected indent of multiline string closing quotes"), ).isFormattedAs(formattedCode) } @@ -2847,7 +2847,7 @@ internal class IndentationRuleTest { .hasLintViolationWithoutAutoCorrect( 1, 11, - "Indentation of multiline string should not contain both tab(s) and space(s)" + "Indentation of multiline string should not contain both tab(s) and space(s)", ) } @@ -3043,7 +3043,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(4, 1, "Unexpected indentation (16) (should be 12)"), - LintViolation(5, 1, "Unexpected indentation (20) (should be 12)") + LintViolation(5, 1, "Unexpected indentation (20) (should be 12)"), ) .isFormattedAs(formattedCode) } @@ -3556,7 +3556,7 @@ internal class IndentationRuleTest { LintViolation(9, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(15, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(21, 1, "Unexpected indentation (4) (should be 8)"), - LintViolation(22, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(22, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -3596,7 +3596,7 @@ internal class IndentationRuleTest { .hasLintViolations( LintViolation(2, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(8, 1, "Unexpected indentation (4) (should be 8)"), - LintViolation(9, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(9, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -3642,7 +3642,7 @@ internal class IndentationRuleTest { LintViolation(3, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(9, 1, "Unexpected indentation (4) (should be 8)"), LintViolation(10, 1, "Unexpected indentation (4) (should be 8)"), - LintViolation(11, 1, "Unexpected indentation (4) (should be 8)") + LintViolation(11, 1, "Unexpected indentation (4) (should be 8)"), ).isFormattedAs(formattedCode) } @@ -3788,7 +3788,7 @@ internal class IndentationRuleTest { indentationRuleAssertThat(code) .hasLintViolations( LintViolation(3, 1, "Unexpected indentation (12) (should be 20)"), - LintViolation(4, 1, "Unexpected indentation (12) (should be 20)") + LintViolation(4, 1, "Unexpected indentation (12) (should be 20)"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt index 7c9b2d421f..fd7f898ba0 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MaxLineLengthRuleTest.kt @@ -33,7 +33,7 @@ class MaxLineLengthRuleTest { .hasLintViolationsWithoutAutoCorrect( LintViolation(2, 1, "Exceeded max line length (46)"), LintViolation(3, 1, "Exceeded max line length (46)"), - LintViolation(5, 1, "Exceeded max line length (46)") + LintViolation(5, 1, "Exceeded max line length (46)"), ) } } @@ -141,7 +141,7 @@ class MaxLineLengthRuleTest { .setMaxLineLength() .hasLintViolationsWithoutAutoCorrect( LintViolation(3, 1, "Exceeded max line length (37)"), - LintViolation(8, 1, "Exceeded max line length (37)") + LintViolation(8, 1, "Exceeded max line length (37)"), ) } } @@ -181,7 +181,7 @@ class MaxLineLengthRuleTest { .hasLintViolationsWithoutAutoCorrect( // Note that no error was generated on line 2 with the long fun name but on another line LintViolation(3, 1, "Exceeded max line length (37)"), - LintViolation(4, 1, "Exceeded max line length (37)") + LintViolation(4, 1, "Exceeded max line length (37)"), ) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRuleTest.kt index 58f9ea9666..530aee4f8b 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ModifierOrderRuleTest.kt @@ -46,7 +46,7 @@ class ModifierOrderRuleTest { .hasLintViolations( LintViolation(2, 5, "Incorrect modifier order (should be \"protected open\")"), LintViolation(3, 5, "Incorrect modifier order (should be \"internal open suspend\")"), - LintViolation(4, 5, "Incorrect modifier order (should be \"protected lateinit\")") + LintViolation(4, 5, "Incorrect modifier order (should be \"protected lateinit\")"), ).isFormattedAs(formattedCode) } @@ -97,7 +97,7 @@ class ModifierOrderRuleTest { LintViolation(3, 5, "Incorrect modifier order (should be \"override suspend\")"), LintViolation(4, 5, "Incorrect modifier order (should be \"override tailrec\")"), LintViolation(5, 5, "Incorrect modifier order (should be \"@Annotation... override\")"), - LintViolation(6, 5, "Incorrect modifier order (should be \"@Annotation... public override suspend\")") + LintViolation(6, 5, "Incorrect modifier order (should be \"@Annotation... public override suspend\")"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRuleTest.kt index 8ac7f2403d..88982c68d5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/MultiLineIfElseRuleTest.kt @@ -118,7 +118,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(3, 9, "Missing { ... }"), - LintViolation(5, 9, "Missing { ... }") + LintViolation(5, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -148,7 +148,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(5, 9, "Missing { ... }"), - LintViolation(7, 9, "Missing { ... }") + LintViolation(7, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -179,7 +179,7 @@ class MultiLineIfElseRuleTest { .hasLintViolations( LintViolation(3, 9, "Missing { ... }"), LintViolation(5, 9, "Missing { ... }"), - LintViolation(7, 9, "Missing { ... }") + LintViolation(7, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -268,7 +268,7 @@ class MultiLineIfElseRuleTest { LintViolation(23, 13, "Missing { ... }"), LintViolation(25, 9, "Missing { ... }"), LintViolation(26, 13, "Missing { ... }"), - LintViolation(28, 13, "Missing { ... }") + LintViolation(28, 13, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -300,7 +300,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(5, 9, "Missing { ... }"), - LintViolation(7, 9, "Missing { ... }") + LintViolation(7, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -360,7 +360,7 @@ class MultiLineIfElseRuleTest { LintViolation(11, 13, "Missing { ... }"), LintViolation(13, 9, "Missing { ... }"), LintViolation(14, 13, "Missing { ... }"), - LintViolation(16, 13, "Missing { ... }") + LintViolation(16, 13, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -394,7 +394,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(4, 13, "Missing { ... }"), - LintViolation(6, 13, "Missing { ... }") + LintViolation(6, 13, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -427,7 +427,7 @@ class MultiLineIfElseRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(4, 9, "Missing { ... }"), - LintViolation(7, 9, "Missing { ... }") + LintViolation(7, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -456,7 +456,7 @@ class MultiLineIfElseRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(3, 9, "Missing { ... }"), - LintViolation(5, 9, "Missing { ... }") + LintViolation(5, 9, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -492,7 +492,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(5, 18, "Missing { ... }"), - LintViolation(6, 13, "Missing { ... }") + LintViolation(6, 13, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -515,7 +515,7 @@ class MultiLineIfElseRuleTest { multiLineIfElseRuleAssertThat(code) .hasLintViolations( LintViolation(2, 5, "Missing { ... }"), - LintViolation(3, 5, "Missing { ... }") + LintViolation(3, 5, "Missing { ... }"), ).isFormattedAs(formattedCode) } @@ -566,7 +566,7 @@ class MultiLineIfElseRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(2, 15, "Missing { ... }"), - LintViolation(3, 10, "Missing { ... }") + LintViolation(3, 10, "Missing { ... }"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRuleTest.kt index d3880f0f57..a294331a55 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoBlankLineBeforeRbraceRuleTest.kt @@ -31,7 +31,7 @@ class NoBlankLineBeforeRbraceRuleTest { noBlankLineBeforeRbraceRuleAssertThat(code) .hasLintViolations( LintViolation(3, 1, "Unexpected blank line(s) before \"}\""), - LintViolation(6, 1, "Unexpected blank line(s) before \"}\"") + LintViolation(6, 1, "Unexpected blank line(s) before \"}\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRuleTest.kt index 6e75a98c1a..6fe0491a27 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoConsecutiveBlankLinesRuleTest.kt @@ -46,7 +46,7 @@ class NoConsecutiveBlankLinesRuleTest { LintViolation(3, 1, "Needless blank line(s)"), LintViolation(6, 1, "Needless blank line(s)"), LintViolation(9, 1, "Needless blank line(s)"), - LintViolation(13, 1, "Needless blank line(s)") + LintViolation(13, 1, "Needless blank line(s)"), ).isFormattedAs(formattedCode) } @@ -138,7 +138,7 @@ class NoConsecutiveBlankLinesRuleTest { // TODO: Line number is incorrect LintViolation(3, 1, "Needless blank line(s)"), // TODO: Line number is incorrect - LintViolation(7, 1, "Needless blank line(s)") + LintViolation(7, 1, "Needless blank line(s)"), ).isFormattedAs(formattedCode) } @@ -206,7 +206,7 @@ class NoConsecutiveBlankLinesRuleTest { .lowercase(Locale.getDefault()) } - """.trimIndent() + """.trimIndent(), ) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRuleTest.kt index f2c697e761..9c42218f07 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyClassBodyRuleTest.kt @@ -52,7 +52,7 @@ class NoEmptyClassBodyRuleTest { LintViolation(9, 14, "Unnecessary block (\"{}\")"), LintViolation(10, 10, "Unnecessary block (\"{}\")"), LintViolation(11, 11, "Unnecessary block (\"{}\")"), - LintViolation(12, 11, "Unnecessary block (\"{}\")") + LintViolation(12, 11, "Unnecessary block (\"{}\")"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRuleTest.kt index 4798fc0e26..b15d2a8a8a 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoEmptyFirstLineInMethodBlockRuleTest.kt @@ -71,7 +71,7 @@ class NoEmptyFirstLineInMethodBlockRuleTest { .hasLintViolations( LintViolation(3, 1, "First line in a method block should not be empty"), LintViolation(6, 1, "First line in a method block should not be empty"), - LintViolation(9, 1, "First line in a method block should not be empty") + LintViolation(9, 1, "First line in a method block should not be empty"), ).isFormattedAs(formattedFunction) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakBeforeAssignmentRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakBeforeAssignmentRuleTest.kt index 6a25194aad..d58e9dbb05 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakBeforeAssignmentRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoLineBreakBeforeAssignmentRuleTest.kt @@ -123,7 +123,7 @@ class NoLineBreakBeforeAssignmentRuleTest { .hasLintViolations( // TODO: The error description is not correct LintViolation(2, 5, "Line break before assignment is not allowed"), - LintViolation(4, 5, "Line break before assignment is not allowed") + LintViolation(4, 5, "Line break before assignment is not allowed"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt index 99d385e2e4..f559fd694f 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt @@ -303,7 +303,7 @@ class NoSemicolonsRuleTest { // TODO: It is not consistent that the semicolon is only reported in one of cases above .hasLintViolations( LintViolation(11, 5, "Unnecessary semicolon"), - LintViolation(15, 5, "Unnecessary semicolon") + LintViolation(15, 5, "Unnecessary semicolon"), ) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRuleTest.kt index 7f2177036e..e838c00702 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoTrailingSpacesRuleTest.kt @@ -32,7 +32,7 @@ class NoTrailingSpacesRuleTest { LintViolation(2, 14, "Trailing space(s)"), LintViolation(3, 1, "Trailing space(s)"), LintViolation(4, 1, "Trailing space(s)"), - LintViolation(5, 2, "Trailing space(s)") + LintViolation(5, 2, "Trailing space(s)"), ).isFormattedAs(formattedCode) } @@ -63,7 +63,7 @@ class NoTrailingSpacesRuleTest { LintViolation(1, 3, "Trailing space(s)"), LintViolation(2, 16, "Trailing space(s)"), LintViolation(4, 7, "Trailing space(s)"), - LintViolation(5, 20, "Trailing space(s)") + LintViolation(5, 20, "Trailing space(s)"), ).isFormattedAs(formattedCode) } @@ -98,7 +98,7 @@ class NoTrailingSpacesRuleTest { LintViolation(1, 3, "Trailing space(s)"), LintViolation(2, 16, "Trailing space(s)"), LintViolation(5, 7, "Trailing space(s)"), - LintViolation(6, 20, "Trailing space(s)") + LintViolation(6, 20, "Trailing space(s)"), ).isFormattedAs(formattedCode) } @@ -139,7 +139,7 @@ class NoTrailingSpacesRuleTest { LintViolation(3, 3, "Trailing space(s)"), LintViolation(6, 8, "Trailing space(s)"), LintViolation(7, 20, "Trailing space(s)"), - LintViolation(8, 7, "Trailing space(s)") + LintViolation(8, 7, "Trailing space(s)"), ).isFormattedAs(formattedCode) } @@ -174,7 +174,7 @@ class NoTrailingSpacesRuleTest { noTrailingSpacesRuleAssertThat(code) .hasLintViolations( LintViolation(3, 1, "Trailing space(s)"), - LintViolation(8, 1, "Trailing space(s)") + LintViolation(8, 1, "Trailing space(s)"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRuleTest.kt index bfc12f1e03..30e0321295 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnitReturnRuleTest.kt @@ -73,7 +73,7 @@ class NoUnitReturnRuleTest { LintViolation(1, 13, "Unnecessary \"Unit\" return type"), LintViolation(2, 13, "Unnecessary \"Unit\" return type"), LintViolation(3, 13, "Unnecessary \"Unit\" return type"), - LintViolation(5, 13, "Unnecessary \"Unit\" return type") + LintViolation(5, 13, "Unnecessary \"Unit\" return type"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt index f890713f7f..d3db07fa72 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt @@ -203,7 +203,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unused import"), - LintViolation(3, 1, "Unused import") + LintViolation(3, 1, "Unused import"), ).isFormattedAs(formattedCode) } } @@ -259,7 +259,7 @@ class NoUnusedImportsRuleTest { LintViolation(7, 1, "Unused import"), LintViolation(8, 1, "Unused import"), LintViolation(9, 1, "Unused import"), - LintViolation(10, 1, "Unused import") + LintViolation(10, 1, "Unused import"), ).isFormattedAs(formattedCode) } @@ -292,7 +292,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unnecessary import"), - LintViolation(4, 1, "Unnecessary import") + LintViolation(4, 1, "Unnecessary import"), ).isFormattedAs(formattedCode) } @@ -327,7 +327,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(3, 1, "Unnecessary import"), - LintViolation(5, 1, "Unnecessary import") + LintViolation(5, 1, "Unnecessary import"), ).isFormattedAs(formattedCode) } @@ -362,7 +362,7 @@ class NoUnusedImportsRuleTest { .hasLintViolations( LintViolation(4, 1, "Unused import"), LintViolation(5, 1, "Unused import"), - LintViolation(6, 1, "Unused import") + LintViolation(6, 1, "Unused import"), ).isFormattedAs(formattedCode) } @@ -418,7 +418,7 @@ class NoUnusedImportsRuleTest { // .hasLintViolation(4, 1, "Unused import") .hasLintViolations( LintViolation(4, 1, "Unused import"), - LintViolation(5, 1, "Unused import") + LintViolation(5, 1, "Unused import"), ).isFormattedAs(formattedCode) } @@ -491,7 +491,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unused import"), - LintViolation(5, 1, "Unused import") + LintViolation(5, 1, "Unused import"), ).isFormattedAs(formattedCode) } } @@ -545,7 +545,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(1, 1, "Unused import"), - LintViolation(2, 1, "Unused import") + LintViolation(2, 1, "Unused import"), ).isFormattedAs(formattedCode) } @@ -785,7 +785,7 @@ class NoUnusedImportsRuleTest { noUnusedImportsRuleAssertThat(code) .hasLintViolations( LintViolation(1, 1, "Unnecessary import"), - LintViolation(2, 1, "Unnecessary import") + LintViolation(2, 1, "Unnecessary import"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt index d83cc37394..252488bc31 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoWildcardImportsRuleTest.kt @@ -26,7 +26,7 @@ class NoWildcardImportsRuleTest { noWildcardImportsRuleAssertThat(code) .hasLintViolationsWithoutAutoCorrect( LintViolation(2, 1, "Wildcard import"), - LintViolation(4, 1, "Wildcard import") + LintViolation(4, 1, "Wildcard import"), ) } @@ -57,7 +57,7 @@ class NoWildcardImportsRuleTest { .withEditorConfigOverride(packagesToUseImportOnDemandProperty to "unset") .hasLintViolationsWithoutAutoCorrect( LintViolation(3, 1, "Wildcard import"), - LintViolation(4, 1, "Wildcard import") + LintViolation(4, 1, "Wildcard import"), ) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt index 8b17408081..d5f7d54bc5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt @@ -13,8 +13,8 @@ class ParameterListWrappingRuleTest { additionalRuleProviders = setOf( // Apply the IndentationRule always as additional rule, so that the formattedCode in the unit test looks // correct. - RuleProvider { IndentationRule() } - ) + RuleProvider { IndentationRule() }, + ), ) @Test @@ -36,7 +36,7 @@ class ParameterListWrappingRuleTest { .hasLintViolations( LintViolation(1, 14, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 30, "Parameter should be on a separate line (unless all parameters can fit a single line)"), - LintViolation(2, 28, """Missing newline before ")"""") + LintViolation(2, 28, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -60,7 +60,7 @@ class ParameterListWrappingRuleTest { LintViolation(1, 14, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 30, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 46, "Parameter should be on a separate line (unless all parameters can fit a single line)"), - LintViolation(1, 60, """Missing newline before ")"""") + LintViolation(1, 60, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -118,7 +118,7 @@ class ParameterListWrappingRuleTest { parameterListWrappingRuleAssertThat(code) .hasLintViolations( LintViolation(1, 7, "Parameter should be on a separate line (unless all parameters can fit a single line)"), - LintViolation(3, 13, """Missing newline before ")"""") + LintViolation(3, 13, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -143,7 +143,7 @@ class ParameterListWrappingRuleTest { .hasLintViolation( 3, 13, - "Parameter should be on a separate line (unless all parameters can fit a single line)" + "Parameter should be on a separate line (unless all parameters can fit a single line)", ) .isFormattedAs(formattedCode) } @@ -170,7 +170,7 @@ class ParameterListWrappingRuleTest { LintViolation(1, 7, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 15, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 23, "Parameter should be on a separate line (unless all parameters can fit a single line)"), - LintViolation(1, 29, """Missing newline before ")"""") + LintViolation(1, 29, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -224,7 +224,7 @@ class ParameterListWrappingRuleTest { .hasLintViolations( LintViolation(2, 11, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(6, 19, "Parameter should be on a separate line (unless all parameters can fit a single line)"), - LintViolation(6, 37, """Missing newline before ")"""") + LintViolation(6, 37, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -255,7 +255,7 @@ class ParameterListWrappingRuleTest { .hasLintViolation( 2, 11, - "Parameter should be on a separate line (unless all parameters can fit a single line)" + "Parameter should be on a separate line (unless all parameters can fit a single line)", ) .isFormattedAs(formattedCode) } @@ -287,7 +287,7 @@ class ParameterListWrappingRuleTest { LintViolation(4, 12, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(4, 25, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(5, 32, """Missing newline before ")""""), - LintViolation(5, 41, """Missing newline before ")"""") + LintViolation(5, 41, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } @@ -319,7 +319,7 @@ class ParameterListWrappingRuleTest { LintViolation(1, 68, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 90, "Parameter should be on a separate line (unless all parameters can fit a single line)"), LintViolation(1, 117, "Missing newline before \")\""), - LintViolation(1, 126, "Missing newline before \")\"") + LintViolation(1, 126, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -479,7 +479,7 @@ class ParameterListWrappingRuleTest { .withEditorConfigOverride(maxLineLengthProperty to 80) .hasLintViolations( LintViolation(1, 22, "Parameter of nullable type should be on a separate line (unless the type fits on a single line)"), - LintViolation(1, 95, """Missing newline before ")"""") + LintViolation(1, 95, """Missing newline before ")""""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketRuleTest.kt index 292380f7ab..d5cdb450b8 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundAngleBracketRuleTest.kt @@ -68,7 +68,7 @@ class SpacingAroundAngleBracketRuleTest { LintViolation(16, 21, "Unexpected spacing before \"<\""), LintViolation(16, 23, "Unexpected spacing after \"<\""), LintViolation(16, 30, "Unexpected spacing before \">\""), - LintViolation(16, 32, "Unexpected spacing before \">\"") + LintViolation(16, 32, "Unexpected spacing before \">\""), ).isFormattedAs(formattedCode) } @@ -119,7 +119,7 @@ class SpacingAroundAngleBracketRuleTest { LintViolation(8, 6, "Unexpected spacing after \"<\""), LintViolation(8, 19, "Unexpected spacing before \">\""), LintViolation(13, 14, "Unexpected spacing after \"<\""), - LintViolation(13, 21, "Unexpected spacing before \">\"") + LintViolation(13, 21, "Unexpected spacing before \">\""), ).isFormattedAs(formattedCode) } @@ -155,7 +155,7 @@ class SpacingAroundAngleBracketRuleTest { spacingAroundAngleBracketsRuleAssertThat(code) .hasLintViolations( LintViolation(1, 20, "Unexpected spacing after \"<\""), - LintViolation(1, 30, "Unexpected spacing before \">\"") + LintViolation(1, 30, "Unexpected spacing before \">\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRuleTest.kt index b90b022b26..f702ec7765 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundColonRuleTest.kt @@ -170,7 +170,7 @@ class SpacingAroundColonRuleTest { LintViolation(4, 9, "Missing spacing around \":\""), LintViolation(5, 18, "Missing spacing around \":\""), LintViolation(6, 31, "Missing spacing around \":\""), - LintViolation(8, 20, "Missing spacing around \":\"") + LintViolation(8, 20, "Missing spacing around \":\""), ).isFormattedAs(formattedCode) } @@ -270,7 +270,7 @@ class SpacingAroundColonRuleTest { LintViolation(1, 8, "Unexpected newline before \":\""), LintViolation(4, 19, "Unexpected newline before \":\""), LintViolation(8, 3, "Unexpected newline before \":\""), - LintViolation(10, 17, "Unexpected newline before \":\"") + LintViolation(10, 17, "Unexpected newline before \":\""), ).isFormattedAs(formattedCode) } @@ -363,7 +363,7 @@ class SpacingAroundColonRuleTest { LintViolation(19, 19, "Unexpected newline before \":\""), LintViolation(22, 13, "Unexpected newline before \":\""), LintViolation(27, 24, "Unexpected newline before \":\""), - LintViolation(33, 19, "Unexpected newline before \":\"") + LintViolation(33, 19, "Unexpected newline before \":\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt index 15ce2b862c..af2c5b7e07 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCommaRuleTest.kt @@ -94,7 +94,7 @@ class SpacingAroundCommaRuleTest { spacingAroundCommaRuleAssertThat(code) .hasLintViolations( LintViolation(2, 14, "Unexpected spacing before \",\""), - LintViolation(3, 14, "Unexpected spacing before \",\"") + LintViolation(3, 14, "Unexpected spacing before \",\""), ).isFormattedAs(formattedCode) } @@ -124,7 +124,7 @@ class SpacingAroundCommaRuleTest { .hasLintViolations( LintViolation(2, 14, "Unexpected spacing before \",\""), LintViolation(3, 30, "Unexpected spacing before \",\""), - LintViolation(5, 21, "Unexpected spacing before \",\"") + LintViolation(5, 21, "Unexpected spacing before \",\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt index ae38e4c252..faba1946f6 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundCurlyRuleTest.kt @@ -21,7 +21,7 @@ class SpacingAroundCurlyRuleTest { spacingAroundCurlyRuleAssertThat(code) .hasLintViolations( LintViolation(1, 10, "Missing spacing around \"{\""), - LintViolation(1, 25, "Missing spacing before \"}\"") + LintViolation(1, 25, "Missing spacing before \"}\""), ).isFormattedAs(formattedCode) } @@ -40,7 +40,7 @@ class SpacingAroundCurlyRuleTest { LintViolation(1, 19, "Missing spacing around \"{\""), LintViolation(1, 21, "Missing spacing around \"}\""), LintViolation(1, 26, "Missing spacing around \"{\""), - LintViolation(1, 28, "Missing spacing before \"}\"") + LintViolation(1, 28, "Missing spacing before \"}\""), ).isFormattedAs(formattedCode) } @@ -83,7 +83,7 @@ class SpacingAroundCurlyRuleTest { .hasLintViolations( // TODO: Col offset is not correct LintViolation(1, 17, "Missing spacing after \"{\""), - LintViolation(1, 23, "Missing spacing before \"}\"") + LintViolation(1, 23, "Missing spacing before \"}\""), ).isFormattedAs(formattedCode) } @@ -220,7 +220,7 @@ class SpacingAroundCurlyRuleTest { LintViolation(3, 61, "Missing spacing before \"{\""), // TODO: Col offset is not correct LintViolation(3, 63, "Missing spacing after \"}\""), - LintViolation(3, 63, "Missing spacing before \"}\"") + LintViolation(3, 63, "Missing spacing before \"}\""), ).isFormattedAs(formattedCode) } @@ -238,7 +238,7 @@ class SpacingAroundCurlyRuleTest { .hasLintViolations( LintViolation(1, 18, "Missing spacing before \"{\""), LintViolation(1, 26, "Missing spacing before \"{\""), - LintViolation(1, 33, "Missing spacing before \"{\"") + LintViolation(1, 33, "Missing spacing before \"{\""), ).isFormattedAs(formattedCode) } @@ -372,7 +372,7 @@ class SpacingAroundCurlyRuleTest { spacingAroundCurlyRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected newline before \"{\""), - LintViolation(4, 1, "Unexpected newline before \"{\"") + LintViolation(4, 1, "Unexpected newline before \"{\""), ).isFormattedAs(formattedCode) } @@ -465,7 +465,7 @@ class SpacingAroundCurlyRuleTest { spacingAroundCurlyRuleAssertThat(code) .hasLintViolations( LintViolation(2, 1, "Unexpected newline before \"{\""), - LintViolation(5, 1, "Unexpected newline before \"{\"") + LintViolation(5, 1, "Unexpected newline before \"{\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRuleTest.kt index 224bb5344b..1fcc30f3c8 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDotRuleTest.kt @@ -50,7 +50,7 @@ class SpacingAroundDotRuleTest { spacingAroundDotRuleAssertThat(code) .hasLintViolations( LintViolation(1, 11, "Unexpected spacing before \".\""), - LintViolation(1, 13, "Unexpected spacing after \".\"") + LintViolation(1, 13, "Unexpected spacing after \".\""), ).isFormattedAs(formattedCode) } @@ -103,7 +103,7 @@ class SpacingAroundDotRuleTest { .hasLintViolations( LintViolation(1, 22, "Unexpected spacing after \".\""), LintViolation(3, 6, "Unexpected spacing after \".\""), - LintViolation(6, 6, "Unexpected spacing after \".\"") + LintViolation(6, 6, "Unexpected spacing after \".\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRuleTest.kt index 7c06a941da..448318edf8 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundDoubleColonRuleTest.kt @@ -33,7 +33,7 @@ class SpacingAroundDoubleColonRuleTest { LintViolation(3, 15, "Unexpected spacing before \"::\""), LintViolation(4, 17, "Unexpected spacing after \"::\""), LintViolation(5, 16, "Unexpected spacing around \"::\""), - LintViolation(6, 17, "Unexpected spacing after \"::\"") + LintViolation(6, 17, "Unexpected spacing after \"::\""), ).isFormattedAs(formattedCode) } @@ -67,7 +67,7 @@ class SpacingAroundDoubleColonRuleTest { LintViolation(2, 41, "Unexpected spacing after \"::\""), LintViolation(3, 38, "Unexpected spacing before \"::\""), LintViolation(4, 40, "Unexpected spacing around \"::\""), - LintViolation(8, 41, "Unexpected spacing after \"::\"") + LintViolation(8, 41, "Unexpected spacing after \"::\""), ).isFormattedAs(formattedCode) } @@ -132,7 +132,7 @@ class SpacingAroundDoubleColonRuleTest { spacingAroundDoubleColonRuleAssertThat(code) .hasLintViolations( LintViolation(5, 11, "Unexpected spacing after \"::\""), - LintViolation(7, 11, "Unexpected spacing after \"::\"") + LintViolation(7, 11, "Unexpected spacing after \"::\""), ).isFormattedAs(formattedCode) } @@ -164,7 +164,7 @@ class SpacingAroundDoubleColonRuleTest { .hasLintViolations( LintViolation(5, 22, "Unexpected spacing after \"::\""), LintViolation(6, 20, "Unexpected spacing before \"::\""), - LintViolation(7, 21, "Unexpected spacing around \"::\"") + LintViolation(7, 21, "Unexpected spacing around \"::\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRuleTest.kt index e9bed1115a..7b7b19ab8d 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundOperatorsRuleTest.kt @@ -25,8 +25,8 @@ class SpacingAroundOperatorsRuleTest { "==", "===", "!=", - "!==" - ] + "!==", + ], ) fun `Given a simple operator`(operator: String) { val code = @@ -47,7 +47,7 @@ class SpacingAroundOperatorsRuleTest { .hasLintViolations( LintViolation(1, 13, "Missing spacing around \"${operator}\""), LintViolation(2, 13, "Missing spacing before \"${operator}\""), - LintViolation(3, 15, "Missing spacing after \"${operator}\"") + LintViolation(3, 15, "Missing spacing after \"${operator}\""), ).isFormattedAs(formattedCode) } @@ -58,8 +58,8 @@ class SpacingAroundOperatorsRuleTest { "++", "-", "--", - "!" - ] + "!", + ], ) fun `Given a unary prefix operator`(operator: String) { val code = @@ -73,8 +73,8 @@ class SpacingAroundOperatorsRuleTest { @ValueSource( strings = [ "++", - "--" - ] + "--", + ], ) fun `Given a unary postfix operator`(operator: String) { val code = @@ -123,7 +123,7 @@ class SpacingAroundOperatorsRuleTest { .hasLintViolations( LintViolation(1, 11, "Missing spacing around \"=\""), LintViolation(2, 11, "Missing spacing before \"=\""), - LintViolation(3, 13, "Missing spacing after \"=\"") + LintViolation(3, 13, "Missing spacing after \"=\""), ).isFormattedAs(formattedCode) } @@ -156,7 +156,7 @@ class SpacingAroundOperatorsRuleTest { .hasLintViolations( LintViolation(1, 9, "Missing spacing around \"=\""), LintViolation(2, 9, "Missing spacing before \"=\""), - LintViolation(3, 11, "Missing spacing after \"=\"") + LintViolation(3, 11, "Missing spacing after \"=\""), ).isFormattedAs(formattedCode) } @@ -189,7 +189,7 @@ class SpacingAroundOperatorsRuleTest { LintViolation(3, 6, "Missing spacing around \"+=\""), LintViolation(4, 6, "Missing spacing around \"-=\""), LintViolation(5, 6, "Missing spacing around \"/=\""), - LintViolation(6, 6, "Missing spacing around \"*=\"") + LintViolation(6, 6, "Missing spacing around \"*=\""), ).isFormattedAs(formattedCode) } @@ -220,7 +220,7 @@ class SpacingAroundOperatorsRuleTest { LintViolation(3, 6, "Missing spacing before \"+=\""), LintViolation(4, 6, "Missing spacing before \"-=\""), LintViolation(5, 6, "Missing spacing before \"/=\""), - LintViolation(6, 6, "Missing spacing before \"*=\"") + LintViolation(6, 6, "Missing spacing before \"*=\""), ).isFormattedAs(formattedCode) } @@ -251,7 +251,7 @@ class SpacingAroundOperatorsRuleTest { LintViolation(3, 8, "Missing spacing after \"+=\""), LintViolation(4, 8, "Missing spacing after \"-=\""), LintViolation(5, 8, "Missing spacing after \"/=\""), - LintViolation(6, 8, "Missing spacing after \"*=\"") + LintViolation(6, 8, "Missing spacing after \"*=\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRuleTest.kt index dadacae89e..98ebc9d411 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundParensRuleTest.kt @@ -92,7 +92,7 @@ class SpacingAroundParensRuleTest { spacingAroundParensRuleAssertThat(code) .hasLintViolations( LintViolation(1, 15, "Unexpected spacing around \"(\""), - LintViolation(2, 15, "Unexpected spacing after \"(\"") + LintViolation(2, 15, "Unexpected spacing after \"(\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRuleTest.kt index 66cb7bbfee..6756ab0d97 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundRangeOperatorRuleTest.kt @@ -33,7 +33,7 @@ class SpacingAroundRangeOperatorRuleTest { .hasLintViolations( LintViolation(2, 16, "Unexpected spacing after \"..\""), LintViolation(3, 15, "Unexpected spacing around \"..\""), - LintViolation(4, 14, "Unexpected spacing before \"..\"") + LintViolation(4, 14, "Unexpected spacing before \"..\""), ).isFormattedAs(formattedCode) } @@ -61,7 +61,7 @@ class SpacingAroundRangeOperatorRuleTest { .hasLintViolations( LintViolation(3, 18, "Unexpected spacing after \"..\""), LintViolation(4, 17, "Unexpected spacing around \"..\""), - LintViolation(5, 16, "Unexpected spacing before \"..\"") + LintViolation(5, 16, "Unexpected spacing before \"..\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRuleTest.kt index ba0a8d6dde..a7dd19700e 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/SpacingAroundUnaryOperatorRuleTest.kt @@ -30,7 +30,7 @@ class SpacingAroundUnaryOperatorRuleTest { .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in i ++"), LintViolation(4, 22, "Unexpected spacing in ++ i"), - LintViolation(5, 22, "Unexpected spacing in ++\\n i") + LintViolation(5, 22, "Unexpected spacing in ++\\n i"), ).isFormattedAs(formattedCode) } @@ -57,7 +57,7 @@ class SpacingAroundUnaryOperatorRuleTest { .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in i --"), LintViolation(4, 22, "Unexpected spacing in -- i"), - LintViolation(5, 22, "Unexpected spacing in --\\n i") + LintViolation(5, 22, "Unexpected spacing in --\\n i"), ).isFormattedAs(formattedCode) } @@ -102,7 +102,7 @@ class SpacingAroundUnaryOperatorRuleTest { LintViolation(8, 25, "Unexpected spacing in - 1"), LintViolation(9, 13, "Unexpected spacing in -\\n 1"), LintViolation(11, 19, "Unexpected spacing in -\\n 100"), - LintViolation(13, 26, "Unexpected spacing in -\\n 1") + LintViolation(13, 26, "Unexpected spacing in -\\n 1"), ).isFormattedAs(formattedCode) } @@ -124,7 +124,7 @@ class SpacingAroundUnaryOperatorRuleTest { spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( LintViolation(2, 21, "Unexpected spacing in ! i"), - LintViolation(3, 21, "Unexpected spacing in !\\n i") + LintViolation(3, 21, "Unexpected spacing in !\\n i"), ).isFormattedAs(formattedCode) } @@ -148,7 +148,7 @@ class SpacingAroundUnaryOperatorRuleTest { """.trimIndent() spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( - LintViolation(2, 17, "Unexpected spacing in \"foo\" !!") + LintViolation(2, 17, "Unexpected spacing in \"foo\" !!"), // TODO: "foo3" should also be disallowed ).isFormattedAs(formattedCode) } @@ -194,7 +194,7 @@ class SpacingAroundUnaryOperatorRuleTest { LintViolation(6, 23, "Unexpected spacing in + f"), LintViolation(6, 29, "Unexpected spacing in - 10"), LintViolation(7, 24, "Unexpected spacing in - 3"), - LintViolation(7, 35, "Unexpected spacing in - 4") + LintViolation(7, 35, "Unexpected spacing in - 4"), ).isFormattedAs(formattedCode) } @@ -215,7 +215,7 @@ class SpacingAroundUnaryOperatorRuleTest { spacingAroundUnaryOperatorRuleAssertThat(code) .hasLintViolations( LintViolation(2, 26, "Unexpected spacing in - 1"), - LintViolation(3, 13, "Unexpected spacing in - 1") + LintViolation(3, 13, "Unexpected spacing in - 1"), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProviderTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProviderTest.kt index 919211d609..d424de8784 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProviderTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StandardRuleSetProviderTest.kt @@ -4,5 +4,5 @@ import com.pinterest.ktlint.test.RuleSetProviderTest class StandardRuleSetProviderTest : RuleSetProviderTest( rulesetClass = StandardRuleSetProvider::class.java, - packageName = "com.pinterest.ktlint.ruleset.standard" + packageName = "com.pinterest.ktlint.ruleset.standard", ) diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRuleTest.kt index 9286d78338..1512900799 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/StringTemplateRuleTest.kt @@ -38,7 +38,7 @@ class StringTemplateRuleTest { .hasLintViolations( LintViolation(1, 28, "Redundant \"toString()\" call in string template"), LintViolation(2, 27, "Redundant \"toString()\" call in string template"), - LintViolation(5, 78, "Redundant \"toString()\" call in string template") + LintViolation(5, 78, "Redundant \"toString()\" call in string template"), ).isFormattedAs(formattedCode) } @@ -82,7 +82,7 @@ class StringTemplateRuleTest { stringTemplateRuleAssertThat(code) .hasLintViolations( LintViolation(1, 14, "Redundant curly braces"), - LintViolation(2, 14, "Redundant curly braces") + LintViolation(2, 14, "Redundant curly braces"), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRuleTest.kt index 909779444d..0bb2171087 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnCallSiteRuleTest.kt @@ -13,8 +13,8 @@ class TrailingCommaOnCallSiteRuleTest { additionalRuleProviders = setOf( // Apply the IndentationRule always as additional rule, so that the formattedCode in the unit test looks // correct. - RuleProvider { IndentationRule() } - ) + RuleProvider { IndentationRule() }, + ), ) @Test @@ -55,7 +55,7 @@ class TrailingCommaOnCallSiteRuleTest { LintViolation(3, 21, "Unnecessary trailing comma before \")\""), LintViolation(5, 22, "Unnecessary trailing comma before \">\""), LintViolation(8, 18, "Unnecessary trailing comma before \"]\""), - LintViolation(11, 12, "Unnecessary trailing comma before \"]\"") + LintViolation(11, 12, "Unnecessary trailing comma before \"]\""), ).isFormattedAs(formattedCode) } @@ -90,7 +90,7 @@ class TrailingCommaOnCallSiteRuleTest { .hasLintViolations( LintViolation(1, 28, "Unnecessary trailing comma before \")\""), LintViolation(4, 8, "Unnecessary trailing comma before \")\""), - LintViolation(8, 8, "Unnecessary trailing comma before \")\"") + LintViolation(8, 8, "Unnecessary trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -124,7 +124,7 @@ class TrailingCommaOnCallSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaOnCallSiteProperty to true) .hasLintViolations( LintViolation(4, 8, "Missing trailing comma before \")\""), - LintViolation(8, 8, "Missing trailing comma before \")\"") + LintViolation(8, 8, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -155,7 +155,7 @@ class TrailingCommaOnCallSiteRuleTest { .hasLintViolations( LintViolation(1, 23, "Unnecessary trailing comma before \">\""), LintViolation(3, 11, "Unnecessary trailing comma before \">\""), - LintViolation(6, 11, "Unnecessary trailing comma before \">\"") + LintViolation(6, 11, "Unnecessary trailing comma before \">\""), ).isFormattedAs(formattedCode) } @@ -185,7 +185,7 @@ class TrailingCommaOnCallSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaOnCallSiteProperty to true) .hasLintViolations( LintViolation(3, 11, "Missing trailing comma before \">\""), - LintViolation(6, 11, "Missing trailing comma before \">\"") + LintViolation(6, 11, "Missing trailing comma before \">\""), ).isFormattedAs(formattedCode) } @@ -218,7 +218,7 @@ class TrailingCommaOnCallSiteRuleTest { .hasLintViolations( LintViolation(2, 17, "Unnecessary trailing comma before \"]\""), LintViolation(4, 6, "Unnecessary trailing comma before \"]\""), - LintViolation(7, 6, "Unnecessary trailing comma before \"]\"") + LintViolation(7, 6, "Unnecessary trailing comma before \"]\""), ).isFormattedAs(formattedCode) } @@ -250,7 +250,7 @@ class TrailingCommaOnCallSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaOnCallSiteProperty to true) .hasLintViolations( LintViolation(4, 6, "Missing trailing comma before \"]\""), - LintViolation(7, 6, "Missing trailing comma before \"]\"") + LintViolation(7, 6, "Missing trailing comma before \"]\""), ).isFormattedAs(formattedCode) } @@ -299,7 +299,7 @@ class TrailingCommaOnCallSiteRuleTest { .hasLintViolations( LintViolation(3, 18, "Unnecessary trailing comma before \"]\""), LintViolation(8, 6, "Unnecessary trailing comma before \"]\""), - LintViolation(14, 6, "Unnecessary trailing comma before \"]\"") + LintViolation(14, 6, "Unnecessary trailing comma before \"]\""), ).isFormattedAs(formattedCode) } @@ -374,7 +374,7 @@ class TrailingCommaOnCallSiteRuleTest { LintViolation(14, 6, "Missing trailing comma before \"]\""), LintViolation(21, 10, "Missing trailing comma before \"]\""), LintViolation(25, 10, "Missing trailing comma before \"]\""), - LintViolation(26, 6, "Missing trailing comma before \")\"") + LintViolation(26, 6, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -433,7 +433,7 @@ class TrailingCommaOnCallSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaOnCallSiteProperty to true) .hasLintViolations( LintViolation(9, 16, "Missing trailing comma before \"]\""), - LintViolation(12, 19, "Missing trailing comma before \")\"") + LintViolation(12, 19, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -467,7 +467,7 @@ class TrailingCommaOnCallSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaOnCallSiteProperty to true) .hasLintViolations( LintViolation(6, 19, "Missing trailing comma before \"]\""), - LintViolation(7, 6, "Missing trailing comma before \")\"") + LintViolation(7, 6, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRuleTest.kt index f258117fd6..3d04a8fd58 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/TrailingCommaOnDeclarationSiteRuleTest.kt @@ -14,8 +14,8 @@ class TrailingCommaOnDeclarationSiteRuleTest { additionalRuleProviders = setOf( // Apply the IndentationRule always as additional rule, so that the formattedCode in the unit test looks // correct. - RuleProvider { IndentationRule() } - ) + RuleProvider { IndentationRule() }, + ), ) @Test @@ -70,7 +70,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { LintViolation(13, 14, "Unnecessary trailing comma before \")\""), LintViolation(16, 20, "Unnecessary trailing comma before \")\""), LintViolation(18, 20, "Unnecessary trailing comma before \")\""), - LintViolation(18, 42, "Unnecessary trailing comma before \"->\"") + LintViolation(18, 42, "Unnecessary trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -101,7 +101,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(1, 29, "Unnecessary trailing comma before \")\""), LintViolation(3, 17, "Unnecessary trailing comma before \")\""), - LintViolation(6, 17, "Unnecessary trailing comma before \")\"") + LintViolation(6, 17, "Unnecessary trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -131,7 +131,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(3, 17, "Missing trailing comma before \")\""), - LintViolation(6, 17, "Missing trailing comma before \")\"") + LintViolation(6, 17, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -166,7 +166,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(1, 16, "Unnecessary trailing comma before \">\""), LintViolation(4, 6, "Unnecessary trailing comma before \">\""), - LintViolation(8, 6, "Unnecessary trailing comma before \">\"") + LintViolation(8, 6, "Unnecessary trailing comma before \">\""), ).isFormattedAs(formattedCode) } @@ -200,7 +200,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(4, 6, "Missing trailing comma before \">\""), - LintViolation(8, 6, "Missing trailing comma before \">\"") + LintViolation(8, 6, "Missing trailing comma before \">\""), ).isFormattedAs(formattedCode) } @@ -235,7 +235,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(2, 9, "Unnecessary trailing comma before \"->\""), LintViolation(3, 9, "Unnecessary trailing comma before \"->\""), - LintViolation(6, 6, "Unnecessary trailing comma before \"->\"") + LintViolation(6, 6, "Unnecessary trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -269,7 +269,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(3, 9, "Missing trailing comma before \"->\""), - LintViolation(6, 6, "Missing trailing comma before \"->\"") + LintViolation(6, 6, "Missing trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -303,7 +303,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(3, 33, "Missing trailing comma before \"->\""), - LintViolation(6, 18, "Missing trailing comma before \"->\"") + LintViolation(6, 18, "Missing trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -357,7 +357,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(3, 6, "Expected a newline between the trailing comma and \"->\""), LintViolation(7, 6, "Expected a newline between the trailing comma and \"->\""), - LintViolation(11, 25, "Expected a newline between the trailing comma and \"->\"") + LintViolation(11, 25, "Expected a newline between the trailing comma and \"->\""), ).isFormattedAs(formattedCode) } @@ -400,7 +400,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(4, 14, "Unnecessary trailing comma before \")\""), LintViolation(7, 10, "Unnecessary trailing comma before \")\""), - LintViolation(11, 10, "Unnecessary trailing comma before \")\"") + LintViolation(11, 10, "Unnecessary trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -442,7 +442,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(7, 10, "Missing trailing comma before \")\""), - LintViolation(11, 10, "Missing trailing comma before \")\"") + LintViolation(11, 10, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -481,7 +481,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .hasLintViolations( LintViolation(1, 44, "Unnecessary trailing comma before \"->\""), LintViolation(4, 12, "Unnecessary trailing comma before \"->\""), - LintViolation(9, 12, "Unnecessary trailing comma before \"->\"") + LintViolation(9, 12, "Unnecessary trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -519,7 +519,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(4, 12, "Missing trailing comma before \"->\""), - LintViolation(9, 12, "Missing trailing comma before \"->\"") + LintViolation(9, 12, "Missing trailing comma before \"->\""), ).isFormattedAs(formattedCode) } @@ -553,7 +553,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(4, 29, "Missing trailing comma before \")\""), - LintViolation(6, 13, "Missing trailing comma before \")\"") + LintViolation(6, 13, "Missing trailing comma before \")\""), ).isFormattedAs(formattedCode) } @@ -602,7 +602,7 @@ class TrailingCommaOnDeclarationSiteRuleTest { .withEditorConfigOverride(allowTrailingCommaProperty to true) .hasLintViolations( LintViolation(4, 6, "Missing trailing comma and newline before \"->\""), - LintViolation(6, 6, "Missing trailing comma and newline before \"->\"") + LintViolation(6, 6, "Missing trailing comma and newline before \"->\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt index 20f21fc934..14c5932f65 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/WrappingRuleTest.kt @@ -38,7 +38,7 @@ internal class WrappingRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(2, 13, "Missing newline after \"(\""), - LintViolation(4, 6, "Missing newline before \")\"") + LintViolation(4, 6, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -80,7 +80,7 @@ internal class WrappingRuleTest { LintViolation(4, 13, "Missing newline after \"(\""), LintViolation(5, 20, "Missing newline before \")\""), LintViolation(6, 13, "Missing newline after \"(\""), - LintViolation(7, 20, "Missing newline before \")\"") + LintViolation(7, 20, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -122,7 +122,7 @@ internal class WrappingRuleTest { LintViolation(2, 10, "Missing newline after \"(\""), LintViolation(8, 6, "Missing newline before \"\"\""), LintViolation(8, 23, "Missing newline after \",\""), - LintViolation(8, 33, "Missing newline before \")\"") + LintViolation(8, 33, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -154,7 +154,7 @@ internal class WrappingRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(2, 9, "Missing newline after \"(\""), - LintViolation(6, 30, "Missing newline before \")\"") + LintViolation(6, 30, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -188,7 +188,7 @@ internal class WrappingRuleTest { .hasLintViolations( LintViolation(2, 11, "Missing newline after \"(\""), LintViolation(2, 49, "Missing newline after \",\""), - LintViolation(6, 34, "Missing newline before \")\"") + LintViolation(6, 34, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -232,7 +232,7 @@ internal class WrappingRuleTest { LintViolation(4, 7, "Missing newline after \"(\""), LintViolation(4, 22, "Missing newline after \",\""), LintViolation(6, 11, "Missing newline after \",\""), - LintViolation(6, 25, "Missing newline before \")\"") + LintViolation(6, 25, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -268,7 +268,7 @@ internal class WrappingRuleTest { .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(6, 8, "Missing newline after \"(\""), - LintViolation(8, 8, "Missing newline before \")\"") + LintViolation(8, 8, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -512,7 +512,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 13, "Missing newline after \"(\""), - LintViolation(5, 24, "Missing newline before \")\"") + LintViolation(5, 24, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -543,7 +543,7 @@ internal class WrappingRuleTest { .withEditorConfigOverride(DefaultEditorConfigProperties.indentStyleProperty to tab) .hasLintViolations( LintViolation(2, 10, "Missing newline after \"(\""), - LintViolation(5, 18, "Missing newline before \")\"") + LintViolation(5, 18, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -576,7 +576,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 13, "Missing newline after \"(\""), - LintViolation(7, 24, "Missing newline before \")\"") + LintViolation(7, 24, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -608,7 +608,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 13, "Missing newline after \"(\""), - LintViolation(6, 24, "Missing newline before \")\"") + LintViolation(6, 24, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -1128,7 +1128,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 12, "Missing newline after \"(\""), - LintViolation(6, 24, "Missing newline before \")\"") + LintViolation(6, 24, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -1349,7 +1349,7 @@ internal class WrappingRuleTest { .hasLintViolations( LintViolation(1, 15, "Missing newline after \":\""), LintViolation(1, 21, "Missing newline after \",\""), - LintViolation(2, 10, "Missing newline after \",\"") + LintViolation(2, 10, "Missing newline after \",\""), ).isFormattedAs(formattedCode) } @@ -1383,7 +1383,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 10, "Missing newline after \",\""), - LintViolation(3, 10, "Missing newline after \",\"") + LintViolation(3, 10, "Missing newline after \",\""), ).isFormattedAs(formattedCode) } @@ -1446,7 +1446,7 @@ internal class WrappingRuleTest { wrappingRuleAssertThat(code) .hasLintViolations( LintViolation(2, 9, "Missing newline after \"(\""), - LintViolation(4, 9, "Missing newline before \")\"") + LintViolation(4, 9, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -1473,7 +1473,7 @@ internal class WrappingRuleTest { .hasLintViolations( LintViolation(1, 18, "Missing newline after \"(\""), LintViolation(3, 11, "Missing newline after \"(\""), - LintViolation(4, 5, "Missing newline before \")\"") + LintViolation(4, 5, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } @@ -1507,7 +1507,7 @@ internal class WrappingRuleTest { .hasLintViolations( LintViolation(2, 13, "Missing newline after \"(\""), LintViolation(6, 2, "Missing newline before \"\"\""), - LintViolation(6, 17, "Missing newline before \")\"") + LintViolation(6, 17, "Missing newline before \")\""), ).isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportLayoutParserTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportLayoutParserTest.kt index 67e3885c31..6705dedf0a 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportLayoutParserTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportLayoutParserTest.kt @@ -31,7 +31,7 @@ class ImportLayoutParserTest { PatternEntry("android.*", withSubpackages = true, hasAlias = true), PatternEntry.ALL_OTHER_IMPORTS_ENTRY, PatternEntry("kotlin.io.Closeable.*", withSubpackages = false, hasAlias = false), - PatternEntry.ALL_OTHER_ALIAS_IMPORTS_ENTRY + PatternEntry.ALL_OTHER_ALIAS_IMPORTS_ENTRY, ) val actual = parseImportsLayout("android.**,|,org.junit.**,|,^android.**,*,kotlin.io.Closeable.*,^") diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleAsciiTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleAsciiTest.kt index 829487584e..3c7b8fe26a 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleAsciiTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleAsciiTest.kt @@ -126,7 +126,7 @@ class ImportOrderingRuleAsciiTest { .hasLintViolationWithoutAutoCorrect( 1, 1, - "Imports must be ordered in lexicographic order without any empty lines in-between -- no autocorrection due to comments in the import list" + "Imports must be ordered in lexicographic order without any empty lines in-between -- no autocorrection due to comments in the import list", ) } @@ -144,7 +144,7 @@ class ImportOrderingRuleAsciiTest { .hasLintViolationWithoutAutoCorrect( 1, 1, - "Imports must be ordered in lexicographic order without any empty lines in-between -- no autocorrection due to comments in the import list" + "Imports must be ordered in lexicographic order without any empty lines in-between -- no autocorrection due to comments in the import list", ) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleCustomTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleCustomTest.kt index 4f651258cc..b3a1899435 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleCustomTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleCustomTest.kt @@ -107,7 +107,7 @@ class ImportOrderingRuleCustomTest { """.trimIndent() importOrderingRuleAssertThat(code) .withEditorConfigOverride( - ideaImportsLayoutProperty to "android.**,|,org.junit.**,|,net.**,|,org.**,|,java.**,|,com.**,|,javax.**,|,*" + ideaImportsLayoutProperty to "android.**,|,org.junit.**,|,net.**,|,org.**,|,java.**,|,com.**,|,javax.**,|,*", ).hasNoLintViolations() } @@ -147,7 +147,7 @@ class ImportOrderingRuleCustomTest { """.trimIndent() importOrderingRuleAssertThat(code) .withEditorConfigOverride( - ideaImportsLayoutProperty to "android.**,|,org.junit.**,|,net.**,|,org.**,|,java.**,|,com.**,|,javax.**,|,*" + ideaImportsLayoutProperty to "android.**,|,org.junit.**,|,net.**,|,org.**,|,java.**,|,com.**,|,javax.**,|,*", ).hasLintViolation(1, 1, "Imports must be ordered according to the pattern specified in .editorconfig") .isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleIdeaTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleIdeaTest.kt index 406af5c811..c8e74caf9d 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleIdeaTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/importordering/ImportOrderingRuleIdeaTest.kt @@ -43,7 +43,7 @@ class ImportOrderingRuleIdeaTest { .hasLintViolation( 1, 1, - "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end" + "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end", ) .isFormattedAs(formattedCode) } @@ -91,7 +91,7 @@ class ImportOrderingRuleIdeaTest { .withEditorConfigOverride(IDEA_DEFAULT_IMPORT_ORDERING) .hasLintViolations( LintViolation(3, 1, "Duplicate 'import android.view.View' found"), - LintViolation(6, 1, "Duplicate 'import android.content.Context as Ctx1' found") + LintViolation(6, 1, "Duplicate 'import android.content.Context as Ctx1' found"), ).isFormattedAs(formattedCode) } @@ -117,7 +117,7 @@ class ImportOrderingRuleIdeaTest { .hasLintViolation( 1, 1, - "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end" + "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end", ) .isFormattedAs(formattedCode) } @@ -157,7 +157,7 @@ class ImportOrderingRuleIdeaTest { .hasLintViolation( 1, 1, - "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end" + "Imports must be ordered in lexicographic order without any empty lines in-between with \"java\", \"javax\", \"kotlin\" and aliases in the end", ) .isFormattedAs(formattedCode) } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/internal/RemoveDiacriticsFromLettersTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/internal/RemoveDiacriticsFromLettersTest.kt index a242f28c2f..ecab3fab7b 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/internal/RemoveDiacriticsFromLettersTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/internal/RemoveDiacriticsFromLettersTest.kt @@ -29,8 +29,8 @@ class RemoveDiacriticsFromLettersTest { "ŚŠ", "ÛÜÙÚŪ", "Ÿ", - "ŽŹŻ" - ] + "ŽŹŻ", + ], ) fun `Given a letter with a diacritic then remove it`(original: String) { assertThat(original.matches("[A-Za-z]*".regExIgnoringDiacriticsAndStrokesOnLetters())).isTrue diff --git a/ktlint-ruleset-template/src/main/kotlin/yourpkgname/CustomRuleSetProvider.kt b/ktlint-ruleset-template/src/main/kotlin/yourpkgname/CustomRuleSetProvider.kt index 898f311236..079acc0708 100644 --- a/ktlint-ruleset-template/src/main/kotlin/yourpkgname/CustomRuleSetProvider.kt +++ b/ktlint-ruleset-template/src/main/kotlin/yourpkgname/CustomRuleSetProvider.kt @@ -11,11 +11,11 @@ public class CustomRuleSetProvider : description = "Example of a custom rule set", license = "https://github.com/pinterest/ktlint/blob/master/LICENSE", repositoryUrl = "https://github.com/pinterest/ktlint", - issueTrackerUrl = "https://github.com/pinterest/ktlint/issues" - ) + issueTrackerUrl = "https://github.com/pinterest/ktlint/issues", + ), ) { override fun getRuleProviders(): Set = setOf( - RuleProvider { NoVarRule() } + RuleProvider { NoVarRule() }, ) } diff --git a/ktlint-ruleset-template/src/main/kotlin/yourpkgname/NoVarRule.kt b/ktlint-ruleset-template/src/main/kotlin/yourpkgname/NoVarRule.kt index 3081d026c1..b5c3b97265 100644 --- a/ktlint-ruleset-template/src/main/kotlin/yourpkgname/NoVarRule.kt +++ b/ktlint-ruleset-template/src/main/kotlin/yourpkgname/NoVarRule.kt @@ -9,7 +9,7 @@ public class NoVarRule : Rule("no-var") { override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit, ) { if (node.elementType == VAR_KEYWORD) { emit(node.startOffset, "Unexpected var, use val instead", false) diff --git a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/DumpASTRule.kt b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/DumpASTRule.kt index 17afab7045..af330c6d17 100644 --- a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/DumpASTRule.kt +++ b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/DumpASTRule.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.lexer.KtTokens public class DumpASTRule @JvmOverloads constructor( private val out: PrintStream = System.err, - private val color: Boolean = false + private val color: Boolean = false, ) : Rule("dump") { private companion object { @@ -28,7 +28,7 @@ public class DumpASTRule @JvmOverloads constructor( override fun beforeVisitChildNodes( node: ASTNode, autoCorrect: Boolean, - emit: (offset: Int, errorMessage: String, corrected: Boolean) -> Unit + emit: (offset: Int, errorMessage: String, corrected: Boolean) -> Unit, ) { if (node.isRoot()) { lineNumberColumnLength = node @@ -53,23 +53,23 @@ public class DumpASTRule @JvmOverloads constructor( " ".repeat(level).dim() + colorClassName(node.psi.className) + " (".dim() + colorClassName(elementTypeClassName(node.elementType)) + ")".dim() + - if (node.getChildren(null).isEmpty()) " \"" + node.text.escape().brighten() + "\"" else "" + if (node.getChildren(null).isEmpty()) " \"" + node.text.escape().brighten() + "\"" else "", ) if (lastNode == node) { out.println() out.println( " ".repeat(lineNumberColumnLength) + - " format: () \"\"".dim() + " format: () \"\"".dim(), ) if (node.lineNumberOrUnknown() == "Unknown") { out.println( " ".repeat(lineNumberColumnLength) + - " line_number 'Unknown' is caused by mutations in the AST during formatting".dim() + " line_number 'Unknown' is caused by mutations in the AST during formatting".dim(), ) } out.println( " ".repeat(lineNumberColumnLength) + - " legend: ~ = org.jetbrains.kotlin, c.i.p = com.intellij.psi".dim() + " legend: ~ = org.jetbrains.kotlin, c.i.p = com.intellij.psi".dim(), ) out.println() } diff --git a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/TestRuleSetProvider.kt b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/TestRuleSetProvider.kt index 950c84fb9d..7ab8d9dfe2 100644 --- a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/TestRuleSetProvider.kt +++ b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/TestRuleSetProvider.kt @@ -6,10 +6,10 @@ import com.pinterest.ktlint.core.RuleSetProviderV2 public class TestRuleSetProvider : RuleSetProviderV2( id = "test", - about = NO_ABOUT + about = NO_ABOUT, ) { override fun getRuleProviders(): Set = setOf( - RuleProvider { DumpASTRule() } + RuleProvider { DumpASTRule() }, ) } diff --git a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/internal/Color.kt b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/internal/Color.kt index ab19631f85..67f68bf91f 100644 --- a/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/internal/Color.kt +++ b/ktlint-ruleset-test/src/main/kotlin/com/pinterest/ruleset/test/internal/Color.kt @@ -8,8 +8,19 @@ internal fun String.color(foreground: Color) = "\u001B[${foreground.code}m$this\ @Suppress("unused") internal enum class Color(val code: Int) { BLACK(30), - RED(31), GREEN(32), YELLOW(33), BLUE(34), MAGENTA(35), CYAN(36), - LIGHT_GRAY(37), DARK_GRAY(90), - LIGHT_RED(91), LIGHT_GREEN(92), LIGHT_YELLOW(93), LIGHT_BLUE(94), LIGHT_MAGENTA(95), LIGHT_CYAN(96), - WHITE(97) + RED(31), + GREEN(32), + YELLOW(33), + BLUE(34), + MAGENTA(35), + CYAN(36), + LIGHT_GRAY(37), + DARK_GRAY(90), + LIGHT_RED(91), + LIGHT_GREEN(92), + LIGHT_YELLOW(93), + LIGHT_BLUE(94), + LIGHT_MAGENTA(95), + LIGHT_CYAN(96), + WHITE(97), } diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt index fae4c6c91c..46a5e91d23 100644 --- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt +++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt @@ -42,7 +42,7 @@ public class KtLintAssertThat( * Providers of rules which have to be executed in addition to the main rule when linting/formatting the code. Note * that lint errors for those rules are suppressed. */ - private val additionalRuleProviders: MutableSet + private val additionalRuleProviders: MutableSet, ) { private var filePath: String? = null private var kotlinScript = false @@ -53,7 +53,7 @@ public class KtLintAssertThat( * Properties which have been set before, are silently overwritten with the new vale. */ public fun withEditorConfigOverride( - vararg properties: Pair, *> + vararg properties: Pair, *>, ): KtLintAssertThat { editorConfigProperties = editorConfigProperties + properties.toSet() @@ -127,7 +127,7 @@ public class KtLintAssertThat( */ public fun addAdditionalRuleProviders(vararg providers: (() -> Rule)): KtLintAssertThat { additionalRuleProviders.addAll( - providers.map { RuleProvider(it) } + providers.map { RuleProvider(it) }, ) return this @@ -155,7 +155,7 @@ public class KtLintAssertThat( public fun hasLintViolation( line: Int, col: Int, - detail: String + detail: String, ): KtLintAssertThatAssertable = ktLintAssertThatAssertable().hasLintViolation(line, col, detail) @@ -174,7 +174,7 @@ public class KtLintAssertThat( public fun hasLintViolationForAdditionalRule( line: Int, col: Int, - detail: String + detail: String, ): KtLintAssertThatAssertable = ktLintAssertThatAssertable().hasLintViolationForAdditionalRule(line, col, detail) @@ -198,7 +198,7 @@ public class KtLintAssertThat( public fun hasLintViolationWithoutAutoCorrect( line: Int, col: Int, - detail: String + detail: String, ): Unit = ktLintAssertThatAssertable().hasLintViolationWithoutAutoCorrect(line, col, detail) @@ -217,7 +217,7 @@ public class KtLintAssertThat( filePath = filePath, kotlinScript = kotlinScript, editorConfigOverride = EditorConfigOverride.emptyEditorConfigOverride, - additionalRuleProviders = additionalRuleProviders.toSet() + additionalRuleProviders = additionalRuleProviders.toSet(), ) } else { KtLintAssertThatAssertable( @@ -226,7 +226,7 @@ public class KtLintAssertThat( filePath = filePath, kotlinScript = kotlinScript, editorConfigOverride = EditorConfigOverride.from(*editorConfigProperties.toTypedArray()), - additionalRuleProviders = additionalRuleProviders.toSet() + additionalRuleProviders = additionalRuleProviders.toSet(), ) } @@ -248,18 +248,18 @@ public class KtLintAssertThat( public fun assertThatRule( provider: () -> Rule, - additionalRuleProviders: Set + additionalRuleProviders: Set, ): (String) -> KtLintAssertThat = RuleProvider { provider() }.assertThat(additionalRuleProviders) private fun RuleProvider.assertThat( - additionalRuleProviders: Set = emptySet() + additionalRuleProviders: Set = emptySet(), ): (String) -> KtLintAssertThat = { code -> KtLintAssertThat( ruleProvider = this, code = code, - additionalRuleProviders = additionalRuleProviders.toMutableSet() + additionalRuleProviders = additionalRuleProviders.toMutableSet(), ) } @@ -291,7 +291,7 @@ public class KtLintAssertThatAssertable( * The rules which have to be executed in addition to the main rule when linting/formatting the code. Note that * lint errors for those rules are suppressed. */ - private val additionalRuleProviders: Set + private val additionalRuleProviders: Set, ) : AbstractAssert(code, KtLintAssertThatAssertable::class.java) { private val ruleId = ruleProvider.createNewRuleInstance().id @@ -342,14 +342,14 @@ public class KtLintAssertThatAssertable( public fun hasLintViolation( line: Int, col: Int, - detail: String + detail: String, ): KtLintAssertThatAssertable = hasLintViolations( LintViolation( line = line, col = col, - detail = detail - ) + detail = detail, + ), ) /** @@ -359,14 +359,14 @@ public class KtLintAssertThatAssertable( public fun hasLintViolationForAdditionalRule( line: Int, col: Int, - detail: String + detail: String, ): KtLintAssertThatAssertable = hasLintViolationsForAdditionalRules( LintViolation( line = line, col = col, - detail = detail - ) + detail = detail, + ), ) /** @@ -425,14 +425,14 @@ public class KtLintAssertThatAssertable( public fun hasLintViolationWithoutAutoCorrect( line: Int, col: Int, - detail: String + detail: String, ): Unit = hasLintViolationsWithoutAutocorrect( LintViolation( line = line, col = col, - detail = detail - ) + detail = detail, + ), ) /** @@ -458,7 +458,7 @@ public class KtLintAssertThatAssertable( line = it.line, col = it.col, detail = it.detail, - canBeAutoCorrected = canBeAutoCorrected + canBeAutoCorrected = canBeAutoCorrected, ) }.toTypedArray() } @@ -475,7 +475,7 @@ public class KtLintAssertThatAssertable( line = it.line, col = it.col, detail = it.detail, - canBeAutoCorrected = it.canBeAutoCorrected + canBeAutoCorrected = it.canBeAutoCorrected, ) }.toTypedArray() @@ -488,7 +488,7 @@ public class KtLintAssertThatAssertable( lintedFilePath = filePath, script = kotlinScript, text = code, - editorConfigOverride = editorConfigOverride + editorConfigOverride = editorConfigOverride, ) } @@ -499,7 +499,7 @@ public class KtLintAssertThatAssertable( lintedFilePath = filePath, script = kotlinScript, text = code, - editorConfigOverride = editorConfigOverride + editorConfigOverride = editorConfigOverride, ) /* Representation of the field of the [LintError] that should be identical. Note that no comparison can be made @@ -509,7 +509,7 @@ public class KtLintAssertThatAssertable( val line: Int, val col: Int, val detail: String, - val canBeAutoCorrected: Boolean + val canBeAutoCorrected: Boolean, ) } @@ -518,7 +518,7 @@ internal class MissingEolMarker : RuntimeException( The first line of the provide code sample should contain text '$MAX_LINE_LENGTH_MARKER' which is provided by the constant '${::MAX_LINE_LENGTH_MARKER.name}' and ends with the EOL_CHAR'$EOL_CHAR' provided by the constant '${::EOL_CHAR.name}' which indicates the last position that is allowed. - """.trimIndent() + """.trimIndent(), ) /** @@ -528,5 +528,5 @@ internal class MissingEolMarker : RuntimeException( public data class LintViolation( val line: Int, val col: Int, - val detail: String + val detail: String, ) diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt index 3364da045b..2e903aa613 100644 --- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt +++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleExtension.kt @@ -50,7 +50,7 @@ private fun Set.toRuleProviders(): Set { DumpASTRule( // Write to STDOUT. The focus in a failed unit test should first go to the error in the rule that is // to be tested and not to the AST, - out = System.out + out = System.out, ) } } @@ -62,7 +62,7 @@ public fun Set.lint( text: String, editorConfigOverride: EditorConfigOverride = EditorConfigOverride.emptyEditorConfigOverride, userData: Map = emptyMap(), - script: Boolean = false + script: Boolean = false, ): List { val res = ArrayList() val experimentalParams = KtLint.ExperimentalParams( @@ -72,10 +72,10 @@ public fun Set.lint( editorConfigOverride = editorConfigOverride, userData = userData, script = script, - cb = { e, _ -> res.add(e) } + cb = { e, _ -> res.add(e) }, ) KtLint.lint( - experimentalParams + experimentalParams, ) return res } @@ -86,7 +86,7 @@ public fun Set.format( editorConfigOverride: EditorConfigOverride = EditorConfigOverride.emptyEditorConfigOverride, userData: Map = emptyMap(), cb: (e: LintError, corrected: Boolean) -> Unit = { _, _ -> }, - script: Boolean = false + script: Boolean = false, ): String { val experimentalParams = KtLint.ExperimentalParams( fileName = lintedFilePath, @@ -95,7 +95,7 @@ public fun Set.format( editorConfigOverride = editorConfigOverride, userData = userData, script = script, - cb = cb + cb = cb, ) return KtLint.format(experimentalParams) } diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleSetProviderTest.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleSetProviderTest.kt index bff5266cdd..e0dedf463b 100644 --- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleSetProviderTest.kt +++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/RuleSetProviderTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test public open class RuleSetProviderTest( private val rulesetClass: Class, - private val packageName: String + private val packageName: String, ) { private val ruleSetProvider = rulesetClass diff --git a/ktlint/build.gradle.kts b/ktlint/build.gradle.kts index 68d3fc7f11..2b3c563c8b 100644 --- a/ktlint/build.gradle.kts +++ b/ktlint/build.gradle.kts @@ -90,7 +90,7 @@ tasks.withType().configureEach { doFirst { systemProperty( "ktlint-cli", - shadowJarExecutable.get().outputs.files.first { it.name == "ktlint" }.absolutePath + shadowJarExecutable.get().outputs.files.first { it.name == "ktlint" }.absolutePath, ) systemProperty("ktlint-version", version) } diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt index 2e9ba019bc..0f563122d7 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt @@ -30,7 +30,7 @@ public fun main(args: Array) { private fun handleSubCommand( commandLine: CommandLine, - parseResult: CommandLine.ParseResult + parseResult: CommandLine.ParseResult, ) { when (val subCommand = parseResult.subcommand().commandSpec().userObject()) { is GitPreCommitHookSubCommand -> subCommand.run() diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt index 570cb2edfe..d2a59730a9 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/FileUtils.kt @@ -39,7 +39,7 @@ internal val defaultPatterns = defaultKotlinFileExtensions.map { "**$globSeparat */ internal fun FileSystem.fileSequence( patterns: List, - rootDir: Path = Paths.get(".").toAbsolutePath().normalize() + rootDir: Path = Paths.get(".").toAbsolutePath().normalize(), ): Sequence { val result = mutableListOf() @@ -93,7 +93,7 @@ internal fun FileSystem.fileSequence( object : SimpleFileVisitor() { override fun visitFile( filePath: Path, - fileAttrs: BasicFileAttributes + fileAttrs: BasicFileAttributes, ): FileVisitResult { if (negatedPathMatchers.none { it.matches(filePath) } && pathMatchers.any { it.matches(filePath) } @@ -108,7 +108,7 @@ internal fun FileSystem.fileSequence( override fun preVisitDirectory( dirPath: Path, - dirAttr: BasicFileAttributes + dirAttr: BasicFileAttributes, ): FileVisitResult { return if (Files.isHidden(dirPath)) { logger.debug { "- Dir: $dirPath: Ignore" } @@ -118,7 +118,7 @@ internal fun FileSystem.fileSequence( FileVisitResult.CONTINUE } } - } + }, ) } logger.debug { "Results: include ${result.count()} files in $duration ms" } @@ -128,7 +128,7 @@ internal fun FileSystem.fileSequence( private fun FileSystem.expand( patterns: List, - rootDir: Path + rootDir: Path, ) = patterns .map { it.expandTildeToFullPath() } @@ -137,7 +137,7 @@ private fun FileSystem.expand( private fun FileSystem.toGlob( path: String, - rootDir: Path + rootDir: Path, ): List { val negation = if (path.startsWith(NEGATION_PREFIX)) { NEGATION_PREFIX @@ -165,7 +165,7 @@ private fun getDefaultPatternsForPath(path: Path?) = defaultKotlinFileExtensions .flatMap { listOf( "$path$globSeparator*.$it", - "$path$globSeparator**$globSeparator*.$it" + "$path$globSeparator**$globSeparator*.$it", ) } @@ -205,7 +205,7 @@ private fun String.expandTildeToFullPath(): String = } internal fun File.location( - relative: Boolean + relative: Boolean, ) = if (relative) this.toRelativeString(File(workDir)) else this.path /** @@ -218,7 +218,7 @@ internal fun lintFile( editorConfigOverride: EditorConfigOverride, editorConfigPath: String? = null, debug: Boolean = false, - lintErrorCallback: (LintError) -> Unit = {} + lintErrorCallback: (LintError) -> Unit = {}, ) = KtLint.lint( KtLint.ExperimentalParams( fileName = fileName, @@ -231,8 +231,8 @@ internal fun lintFile( lintErrorCallback(e) }, debug = debug, - isInvokedFromCli = true - ) + isInvokedFromCli = true, + ), ) /** @@ -245,7 +245,7 @@ internal fun formatFile( editorConfigOverride: EditorConfigOverride, editorConfigPath: String?, debug: Boolean, - cb: (e: LintError, corrected: Boolean) -> Unit + cb: (e: LintError, corrected: Boolean) -> Unit, ): String = KtLint.format( KtLint.ExperimentalParams( @@ -257,6 +257,6 @@ internal fun formatFile( editorConfigPath = editorConfigPath, cb = cb, debug = debug, - isInvokedFromCli = true - ) + isInvokedFromCli = true, + ), ) diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt index 5e468790e9..c35014f1ea 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GenerateEditorConfigSubCommand.kt @@ -13,10 +13,10 @@ private val logger = KotlinLogging.logger {}.initKtLintKLogger() @CommandLine.Command( description = [ "EXPERIMENTAL!!! Generate kotlin style section for '.editorconfig' file.", - "Add output content into '.editorconfig' file" + "Add output content into '.editorconfig' file", ], mixinStandardHelpOptions = true, - versionProvider = KtlintVersionProvider::class + versionProvider = KtlintVersionProvider::class, ) internal class GenerateEditorConfigSubCommand : Runnable { @CommandLine.ParentCommand @@ -38,12 +38,12 @@ internal class GenerateEditorConfigSubCommand : Runnable { .loadRuleProviders( ktlintCommand.experimental, ktlintCommand.debug, - ktlintCommand.disabledRules + ktlintCommand.disabledRules, ), editorConfigOverride = EditorConfigOverride.from(codeStyleSetProperty to codeStyle()), debug = ktlintCommand.debug, - cb = { _, _ -> } - ) + cb = { _, _ -> }, + ), ) if (generatedEditorConfig.isNotBlank()) { diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitHookInstaller.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitHookInstaller.kt index 83b3d1c78f..f5edcd8b59 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitHookInstaller.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitHookInstaller.kt @@ -15,7 +15,7 @@ private const val DEFAULT_GIT_HOOKS_DIR = "hooks" internal object GitHookInstaller { fun installGitHook( gitHookName: String, - gitHookLoader: () -> ByteArray + gitHookLoader: () -> ByteArray, ) { val gitHooksDir = try { resolveGitHooksDir() @@ -90,7 +90,7 @@ internal object GitHookInstaller { hooksDir: File, hookFile: File, expectedHookContent: ByteArray, - gitHookName: String + gitHookName: String, ) { // backup existing hook (if any) val actualHookContent = hookFile.readBytes() diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPreCommitHookSubCommand.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPreCommitHookSubCommand.kt index 7a9ae612bb..03ff584ff0 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPreCommitHookSubCommand.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPreCommitHookSubCommand.kt @@ -5,11 +5,11 @@ import picocli.CommandLine @CommandLine.Command( description = [ "Install git hook to automatically check files for style violations on commit", - "Usage of \"--install-git-pre-commit-hook\" command line option is deprecated!" + "Usage of \"--install-git-pre-commit-hook\" command line option is deprecated!", ], aliases = ["--install-git-pre-commit-hook"], mixinStandardHelpOptions = true, - versionProvider = KtlintVersionProvider::class + versionProvider = KtlintVersionProvider::class, ) internal class GitPreCommitHookSubCommand : Runnable { @CommandLine.ParentCommand @@ -29,7 +29,7 @@ internal class GitPreCommitHookSubCommand : Runnable { private fun loadHookContent(): ByteArray = ClassLoader .getSystemClassLoader() .getResourceAsStream( - "ktlint-git-pre-commit-hook${if (ktlintCommand.android) "-android" else ""}.sh" + "ktlint-git-pre-commit-hook${if (ktlintCommand.android) "-android" else ""}.sh", ).use { it.readBytes() } internal companion object { diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPrePushHookSubCommand.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPrePushHookSubCommand.kt index fa6a0e71e7..7215426077 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPrePushHookSubCommand.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/GitPrePushHookSubCommand.kt @@ -5,11 +5,11 @@ import picocli.CommandLine @CommandLine.Command( description = [ "Install git hook to automatically check files for style violations before push", - "Usage of \"--install-git-pre-push-hook\" command line option is deprecated!" + "Usage of \"--install-git-pre-push-hook\" command line option is deprecated!", ], aliases = ["--install-git-pre-push-hook"], mixinStandardHelpOptions = true, - versionProvider = KtlintVersionProvider::class + versionProvider = KtlintVersionProvider::class, ) internal class GitPrePushHookSubCommand : Runnable { @CommandLine.ParentCommand @@ -29,7 +29,7 @@ internal class GitPrePushHookSubCommand : Runnable { private fun loadHookContent() = ClassLoader .getSystemClassLoader() .getResourceAsStream( - "ktlint-git-pre-push-hook${if (ktlintCommand.android) "-android" else ""}.sh" + "ktlint-git-pre-push-hook${if (ktlintCommand.android) "-android" else ""}.sh", ) .readBytes() diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt index 62ab39d3ef..bd714e3f10 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/KtlintCommandLine.kt @@ -85,37 +85,37 @@ Flags: customSynopsis = [""], sortOptions = false, mixinStandardHelpOptions = true, - versionProvider = KtlintVersionProvider::class + versionProvider = KtlintVersionProvider::class, ) internal class KtlintCommandLine { @Option( names = ["--android", "-a"], - description = ["Turn on Android Kotlin Style Guide compatibility"] + description = ["Turn on Android Kotlin Style Guide compatibility"], ) var android: Boolean = false @Option( names = ["--color"], - description = ["Make output colorful"] + description = ["Make output colorful"], ) var color: Boolean = false @Option( names = ["--color-name"], - description = ["Customize the output color"] + description = ["Customize the output color"], ) var colorName: String = Color.DARK_GRAY.name @Option( names = ["--debug"], - description = ["Turn on debug output"] + description = ["Turn on debug output"], ) var debug: Boolean = false @Option( names = ["--trace"], - description = ["Turn on trace output"] + description = ["Turn on trace output"], ) var trace: Boolean = false @@ -123,21 +123,21 @@ internal class KtlintCommandLine { names = ["--disabled_rules"], description = [ "Comma-separated list of rules to globally disable." + - " To disable standard ktlint rule-set use --disabled_rules=standard" - ] + " To disable standard ktlint rule-set use --disabled_rules=standard", + ], ) var disabledRules: String = "" // TODO: this should have been a command, not a flag (consider changing in 1.0.0) @Option( names = ["--format", "-F"], - description = ["Fix any deviations from the code style"] + description = ["Fix any deviations from the code style"], ) private var format: Boolean = false @Option( names = ["--limit"], - description = ["Maximum number of errors to show (default: show all)"] + description = ["Maximum number of errors to show (default: show all)"], ) private var limit: Int = -1 get() = if (field < 0) Int.MAX_VALUE else field @@ -146,8 +146,8 @@ internal class KtlintCommandLine { names = ["--relative"], description = [ "Print files relative to the working directory " + - "(e.g. dir/file.kt instead of /home/user/project/dir/file.kt)" - ] + "(e.g. dir/file.kt instead of /home/user/project/dir/file.kt)", + ], ) var relative: Boolean = false @@ -156,44 +156,44 @@ internal class KtlintCommandLine { description = [ "A reporter to use (built-in: plain (default), plain?group_by_file, json, sarif, checkstyle, html). " + "To use a third-party reporter specify a path to a JAR file on the filesystem via ',artifact=' option. " + - "To override reporter output, use ',output=' option." - ] + "To override reporter output, use ',output=' option.", + ], ) private var reporters: JarFiles = ArrayList() @Option( names = ["--ruleset", "-R"], - description = ["A path to a JAR file containing additional ruleset(s)"] + description = ["A path to a JAR file containing additional ruleset(s)"], ) var rulesetJarFiles: JarFiles = ArrayList() @Option( names = ["--stdin"], - description = ["Read file from stdin"] + description = ["Read file from stdin"], ) private var stdin: Boolean = false @Option( names = ["--verbose", "-v"], - description = ["Show error codes"] + description = ["Show error codes"], ) private var verbose: Boolean = false @Option( names = ["--editorconfig"], - description = ["Path to .editorconfig"] + description = ["Path to .editorconfig"], ) private var editorConfigPath: String? = null @Option( names = ["--experimental"], - description = ["Enabled experimental rules (ktlint-ruleset-experimental)"] + description = ["Enabled experimental rules (ktlint-ruleset-experimental)"], ) var experimental: Boolean = false @Option( names = ["--baseline"], - description = ["Defines a baseline file to check against"] + description = ["Defines a baseline file to check against"], ) private var baselinePath: String = "" @@ -251,7 +251,7 @@ internal class KtlintCommandLine { ruleProviders, editorConfigOverride, baselineLintErrorsPerFile, - reporter + reporter, ) } reporter.afterAll() @@ -281,7 +281,7 @@ internal class KtlintCommandLine { ruleProviders: Set, editorConfigOverride: EditorConfigOverride, lintErrorsPerFile: Map>, - reporter: Reporter + reporter: Reporter, ) { FileSystems.getDefault() .fileSequence(patterns) @@ -294,7 +294,7 @@ internal class KtlintCommandLine { fileContent = file.readText(), editorConfigOverride = editorConfigOverride, baselineLintErrors = lintErrorsPerFile.getOrDefault(file.relativeRoute, emptyList()), - ruleProviders = ruleProviders + ruleProviders = ruleProviders, ) } }.parallel({ (file, errList) -> report(file.location(relative), errList, reporter) }) @@ -303,7 +303,7 @@ internal class KtlintCommandLine { private fun lintStdin( ruleProviders: Set, editorConfigOverride: EditorConfigOverride, - reporter: Reporter + reporter: Reporter, ) { report( KtLint.STDIN_FILE, @@ -312,16 +312,16 @@ internal class KtlintCommandLine { fileContent = String(System.`in`.readBytes()), editorConfigOverride = editorConfigOverride, baselineLintErrors = emptyList(), - ruleProviders = ruleProviders + ruleProviders = ruleProviders, ), - reporter + reporter, ) } private fun report( fileName: String, errList: List, - reporter: Reporter + reporter: Reporter, ) { fileNumber.incrementAndGet() val errListLimit = minOf(errList.size, maxOf(limit - errorNumber.get(), 0)) @@ -332,7 +332,7 @@ internal class KtlintCommandLine { reporter.onLintError( fileName, if (!err.canBeAutoCorrected) err.copy(detail = err.detail + " (cannot be auto-corrected)") else err, - corrected + corrected, ) } reporter.after(fileName) @@ -343,7 +343,7 @@ internal class KtlintCommandLine { fileContent: String, editorConfigOverride: EditorConfigOverride, baselineLintErrors: List, - ruleProviders: Set + ruleProviders: Set, ): List { logger.trace { val fileLocation = if (fileName != KtLint.STDIN_FILE) File(fileName).location(relative) else fileName @@ -358,7 +358,7 @@ internal class KtlintCommandLine { ruleProviders, editorConfigOverride, editorConfigPath, - debug + debug, ) { lintError, corrected -> if (baselineLintErrors.doesNotContain(lintError)) { result.add(LintErrorWithCorrectionInfo(lintError, corrected)) @@ -387,7 +387,7 @@ internal class KtlintCommandLine { ruleProviders, editorConfigOverride, editorConfigPath, - debug + debug, ) { lintError -> if (baselineLintErrors.doesNotContain(lintError)) { result.add(LintErrorWithCorrectionInfo(lintError, false)) @@ -416,9 +416,9 @@ internal class KtlintCommandLine { "verbose" to verbose.toString(), "color" to color.toString(), "color_name" to colorName, - "format" to format.toString() + "format" to format.toString(), ) + parseQuery(rawReporterConfig), - split.lastOrNull { it.startsWith("output=") }?.let { it.split("=")[1] } + split.lastOrNull { it.startsWith("output=") }?.let { it.split("=")[1] }, ) } .distinct() @@ -427,7 +427,7 @@ internal class KtlintCommandLine { } private fun ReporterTemplate.toReporter( - reporterProviderById: Map> + reporterProviderById: Map>, ): Reporter { val reporterProvider = reporterProviderById[id] if (reporterProvider == null) { @@ -473,7 +473,7 @@ internal class KtlintCommandLine { e.line, e.col, "", - "Not a valid Kotlin file (${e.message?.lowercase(Locale.getDefault())})" + "Not a valid Kotlin file (${e.message?.lowercase(Locale.getDefault())})", ) is RuleExecutionException -> { logger.debug("Internal Error (${e.ruleId}) in file '$filename' at position '${e.line}:${e.col}", e) @@ -484,7 +484,7 @@ internal class KtlintCommandLine { "Internal Error (${e.ruleId}) in file '$filename' at position '${e.line}:${e.col}. " + "Please create a ticket at https://github.com/pinterest/ktlint/issues " + "(if possible, please re-run with the --debug flag to get the stacktrace " + - "and provide the source code that triggered an error)" + "and provide the source code that triggered an error)", ) } else -> throw e @@ -498,7 +498,7 @@ internal class KtlintCommandLine { s.split("=", limit = 2).let { e -> map.put( e[0], - URLDecoder.decode(e.getOrElse(1) { "true" }, "UTF-8") + URLDecoder.decode(e.getOrElse(1) { "true" }, "UTF-8"), ) } } @@ -536,7 +536,7 @@ internal class KtlintCommandLine { */ private fun Sequence>.parallel( cb: (T) -> Unit, - numberOfThreads: Int = Runtime.getRuntime().availableProcessors() + numberOfThreads: Int = Runtime.getRuntime().availableProcessors(), ) { val pill = object : Future { override fun isDone(): Boolean { @@ -587,7 +587,7 @@ internal class KtlintCommandLine { private fun loadReporters(externalReportersJarPaths: List) = ServiceLoader .load( ReporterProvider::class.java, - URLClassLoader(externalReportersJarPaths.toFilesURIList().toTypedArray()) + URLClassLoader(externalReportersJarPaths.toFilesURIList().toTypedArray()), ) .associateBy { it.id } .onEach { entry -> @@ -596,13 +596,13 @@ internal class KtlintCommandLine { private data class LintErrorWithCorrectionInfo( val err: LintError, - val corrected: Boolean + val corrected: Boolean, ) private data class ReporterTemplate( val id: String, val artifact: String?, val config: Map, - val output: String? + val output: String?, ) } diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt index 0b5953f2f7..00cedccc83 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/LoadRuleProviders.kt @@ -19,13 +19,13 @@ private val logger = KotlinLogging.logger {}.initKtLintKLogger() internal fun JarFiles.loadRuleProviders( loadExperimental: Boolean, debug: Boolean, - disabledRules: String + disabledRules: String, ): Set = toFilesURIList() .plus( // Ensure that always at least one element exists in this list so that the rule sets provided by the KtLint // CLI module itself will be found even in case no JAR files are specified - null + null, ) // Remove JAR files which were provided multiple times .distinct() @@ -42,7 +42,7 @@ internal fun JarFiles.loadRuleProviders( private fun getRuleProvidersFromJar( url: URL?, - debug: Boolean + debug: Boolean, ): Map> { if (url != null && debug) { logger.debug { "JAR ruleset provided with path \"${url.path}\"" } @@ -51,7 +51,7 @@ private fun getRuleProvidersFromJar( ServiceLoader .load( RuleSetProviderV2::class.java, - URLClassLoader(listOfNotNull(url).toTypedArray()) + URLClassLoader(listOfNotNull(url).toTypedArray()), ).filter { // The KtLint-root (CLI) module includes the standard and experimental rule sets. When those rule sets // are also included in the specified JAR (url != null) then ignore them. @@ -84,7 +84,7 @@ private fun getLegacyRuleProvidersFromJar(url: URL?) = ServiceLoader .load( RuleSetProvider::class.java, - URLClassLoader(listOfNotNull(url).toTypedArray()) + URLClassLoader(listOfNotNull(url).toTypedArray()), ).filter { // The standard and experimental KtLint rule sets are included the ktlint CLI module itself (url == // null). When those rule set are also included in the specified JAR (url != null) then ignore them. diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintASTSubCommand.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintASTSubCommand.kt index 925d31c9a5..fdd9291a89 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintASTSubCommand.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintASTSubCommand.kt @@ -17,11 +17,11 @@ private val logger = KotlinLogging.logger {}.initKtLintKLogger() @CommandLine.Command( description = [ "Print AST (useful when writing/debugging rules)", - "Usage of \"--print-ast\" command line option is deprecated!" + "Usage of \"--print-ast\" command line option is deprecated!", ], aliases = ["--print-ast"], mixinStandardHelpOptions = true, - versionProvider = KtlintVersionProvider::class + versionProvider = KtlintVersionProvider::class, ) internal class PrintASTSubCommand : Runnable { @CommandLine.ParentCommand @@ -31,13 +31,13 @@ internal class PrintASTSubCommand : Runnable { private lateinit var commandSpec: CommandLine.Model.CommandSpec @CommandLine.Parameters( - description = ["include all files under this .gitignore-like patterns"] + description = ["include all files under this .gitignore-like patterns"], ) private var patterns = ArrayList() @CommandLine.Option( names = ["--stdin"], - description = ["Read file content from stdin"] + description = ["Read file content from stdin"], ) private var stdin: Boolean = false @@ -58,7 +58,7 @@ internal class PrintASTSubCommand : Runnable { private fun printAST( fileName: String, - fileContent: String + fileContent: String, ) { logger.debug { "Analyzing " + if (fileName != KtLint.STDIN_FILE) { @@ -73,17 +73,17 @@ internal class PrintASTSubCommand : Runnable { fileName = fileName, fileContents = fileContent, ruleProviders = setOf( - RuleProvider { DumpASTRule(System.out, ktlintCommand.color) } + RuleProvider { DumpASTRule(System.out, ktlintCommand.color) }, ), editorConfigOverride = emptyEditorConfigOverride, - debug = ktlintCommand.debug + debug = ktlintCommand.debug, ) } catch (e: Exception) { if (e is ParseException) { throw ParseException( e.line, e.col, - "Not a valid Kotlin file (${e.message?.lowercase(Locale.getDefault())})" + "Not a valid Kotlin file (${e.message?.lowercase(Locale.getDefault())})", ) } throw e diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintCommandLineHelpOrVersionUsage.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintCommandLineHelpOrVersionUsage.kt index e92a5a1c06..a648d9fbd0 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintCommandLineHelpOrVersionUsage.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/PrintCommandLineHelpOrVersionUsage.kt @@ -8,7 +8,7 @@ import picocli.CommandLine * and exit process with [exitCode] exit code. */ internal fun CommandLine.printCommandLineHelpOrVersionUsage( - exitCode: Int = 0 + exitCode: Int = 0, ) { if (isUsageHelpRequested) { usage(System.out, CommandLine.Help.Ansi.OFF) diff --git a/ktlint/src/test/kotlin/com/pinterest/ktlint/BaseCLITest.kt b/ktlint/src/test/kotlin/com/pinterest/ktlint/BaseCLITest.kt index 0cdbbb399d..003fcf0cdf 100644 --- a/ktlint/src/test/kotlin/com/pinterest/ktlint/BaseCLITest.kt +++ b/ktlint/src/test/kotlin/com/pinterest/ktlint/BaseCLITest.kt @@ -26,7 +26,7 @@ abstract class BaseCLITest { fun runKtLintCliProcess( testProjectName: String, arguments: List = emptyList(), - executionAssertions: ExecutionResult.() -> Unit + executionAssertions: ExecutionResult.() -> Unit, ) { val projectPath = prepareTestProject(testProjectName) val ktlintCommand = @@ -66,7 +66,7 @@ abstract class BaseCLITest { object : SimpleFileVisitor() { override fun preVisitDirectory( dir: Path, - attrs: BasicFileAttributes + attrs: BasicFileAttributes, ): FileVisitResult { Files.createDirectories(dest.resolve(relativize(dir))) return FileVisitResult.CONTINUE @@ -74,12 +74,12 @@ abstract class BaseCLITest { override fun visitFile( file: Path, - attrs: BasicFileAttributes + attrs: BasicFileAttributes, ): FileVisitResult { Files.copy(file, dest.resolve(relativize(file))) return FileVisitResult.CONTINUE } - } + }, ) } @@ -87,7 +87,7 @@ abstract class BaseCLITest { val exitCode: Int, val normalOutput: List, val errorOutput: List, - val testProject: Path + val testProject: Path, ) { fun assertNormalExitCode() { assertThat(exitCode) @@ -96,9 +96,9 @@ abstract class BaseCLITest { .followedByIndentedList( listOf( "RESULTS OF STDOUT:".followedByIndentedList(normalOutput, 2), - "RESULTS OF STDERR:".followedByIndentedList(errorOutput, 2) - ) - ) + "RESULTS OF STDERR:".followedByIndentedList(errorOutput, 2), + ), + ), ).isEqualTo(0) } @@ -111,12 +111,12 @@ abstract class BaseCLITest { fun assertErrorOutputIsEmpty() { assertThat(errorOutput.isEmpty()) .withFailMessage( - "Expected error output to be empty but was:".followedByIndentedList(errorOutput) + "Expected error output to be empty but was:".followedByIndentedList(errorOutput), ).isTrue } fun assertSourceFileWasFormatted( - filePathInProject: String + filePathInProject: String, ) { val originalFile = testProjectsPath.resolve(testProject.last()).resolve(filePathInProject) val newFile = testProject.resolve(filePathInProject) diff --git a/ktlint/src/test/kotlin/com/pinterest/ktlint/BaselineTests.kt b/ktlint/src/test/kotlin/com/pinterest/ktlint/BaselineTests.kt index 144470ecfe..fe6bee7751 100644 --- a/ktlint/src/test/kotlin/com/pinterest/ktlint/BaselineTests.kt +++ b/ktlint/src/test/kotlin/com/pinterest/ktlint/BaselineTests.kt @@ -10,18 +10,20 @@ import org.junit.jupiter.api.Test class BaselineTests { @BeforeEach internal fun setUp() { - System.setSecurityManager(object : SecurityManager() { - override fun checkPermission(perm: Permission?) { // allow anything. - } + System.setSecurityManager( + object : SecurityManager() { + override fun checkPermission(perm: Permission?) { // allow anything. + } - override fun checkPermission(perm: Permission?, context: Any?) { // allow anything. - } + override fun checkPermission(perm: Permission?, context: Any?) { // allow anything. + } - override fun checkExit(status: Int) { - super.checkExit(status) - throw ExitException() - } - }) + override fun checkExit(status: Int) { + super.checkExit(status) + throw ExitException() + } + }, + ) } @Test diff --git a/ktlint/src/test/kotlin/com/pinterest/ktlint/RuleSetsLoaderCLITest.kt b/ktlint/src/test/kotlin/com/pinterest/ktlint/RuleSetsLoaderCLITest.kt index 6823ba55f4..dc22ce413e 100644 --- a/ktlint/src/test/kotlin/com/pinterest/ktlint/RuleSetsLoaderCLITest.kt +++ b/ktlint/src/test/kotlin/com/pinterest/ktlint/RuleSetsLoaderCLITest.kt @@ -18,7 +18,7 @@ class RuleSetsLoaderCLITest : BaseCLITest() { val jarWithRulesetProviderV1 = "custom-ruleset/rule-set-provider-v1/ktlint-ruleset-template.jar" runKtLintCliProcess( "custom-ruleset", - listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithRulesetProviderV1") + listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithRulesetProviderV1"), ) { assertNormalExitCode() @@ -26,7 +26,7 @@ class RuleSetsLoaderCLITest : BaseCLITest() { assertThat(normalOutput) .anyMatch { it.matches( - Regex(".* WARN .* JAR .*$jarWithRulesetProviderV1, provided as command line argument, contains a custom ruleset provider which will \\*NOT\\*.* be compatible with the next KtLint version \\(0.48\\). Contact the maintainer of this ruleset. This JAR is not maintained by the KtLint project.*") + Regex(".* WARN .* JAR .*$jarWithRulesetProviderV1, provided as command line argument, contains a custom ruleset provider which will \\*NOT\\*.* be compatible with the next KtLint version \\(0.48\\). Contact the maintainer of this ruleset. This JAR is not maintained by the KtLint project.*"), ) } } @@ -37,14 +37,14 @@ class RuleSetsLoaderCLITest : BaseCLITest() { val jarWithoutRulesetProvider = "custom-ruleset/rule-set-provider-v1/ktlint-reporter-html.jar" runKtLintCliProcess( "custom-ruleset", - listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithoutRulesetProvider") + listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithoutRulesetProvider"), ) { assertNormalExitCode() assertThat(normalOutput) .anyMatch { it.matches( - Regex(".* WARN .* JAR .*$jarWithoutRulesetProvider, provided as command line argument, does not contain a custom ruleset provider.") + Regex(".* WARN .* JAR .*$jarWithoutRulesetProvider, provided as command line argument, does not contain a custom ruleset provider."), ) } } @@ -59,7 +59,7 @@ class RuleSetsLoaderCLITest : BaseCLITest() { val jarWithRulesetProviderV2 = "custom-ruleset/rule-set-provider-v2/ktlint-ruleset-template.jar" runKtLintCliProcess( "custom-ruleset", - listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithRulesetProviderV2") + listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithRulesetProviderV2"), ) { assertNormalExitCode() @@ -67,7 +67,7 @@ class RuleSetsLoaderCLITest : BaseCLITest() { assertThat(normalOutput) .noneMatch { it.matches( - Regex(".* WARN .* JAR .*$jarWithRulesetProviderV2, provided as command line argument, contains a custom ruleset provider which will \\*NOT\\*.* be compatible with the next KtLint version \\(0.48\\). Contact the maintainer of this ruleset. This JAR is not maintained by the KtLint project.*") + Regex(".* WARN .* JAR .*$jarWithRulesetProviderV2, provided as command line argument, contains a custom ruleset provider which will \\*NOT\\*.* be compatible with the next KtLint version \\(0.48\\). Contact the maintainer of this ruleset. This JAR is not maintained by the KtLint project.*"), ) } } @@ -78,14 +78,14 @@ class RuleSetsLoaderCLITest : BaseCLITest() { val jarWithoutRulesetProvider = "custom-ruleset/rule-set-provider-v2/ktlint-reporter-html.jar" runKtLintCliProcess( "custom-ruleset", - listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithoutRulesetProvider") + listOf("-R", "$BASE_DIR_PLACEHOLDER/$jarWithoutRulesetProvider"), ) { assertNormalExitCode() assertThat(normalOutput) .anyMatch { it.matches( - Regex(".* WARN .* JAR .*$jarWithoutRulesetProvider, provided as command line argument, does not contain a custom ruleset provider.") + Regex(".* WARN .* JAR .*$jarWithoutRulesetProvider, provided as command line argument, does not contain a custom ruleset provider."), ) } } diff --git a/ktlint/src/test/kotlin/com/pinterest/ktlint/SimpleCLITest.kt b/ktlint/src/test/kotlin/com/pinterest/ktlint/SimpleCLITest.kt index d7be6368d9..77bb3e65dd 100644 --- a/ktlint/src/test/kotlin/com/pinterest/ktlint/SimpleCLITest.kt +++ b/ktlint/src/test/kotlin/com/pinterest/ktlint/SimpleCLITest.kt @@ -13,7 +13,7 @@ class SimpleCLITest : BaseCLITest() { fun `Given CLI argument --help then return the help output`() { runKtLintCliProcess( "no-code-style-error", - listOf("--help") + listOf("--help"), ) { assertNormalExitCode() assertErrorOutputIsEmpty() @@ -28,7 +28,7 @@ class SimpleCLITest : BaseCLITest() { fun `Given CLI argument --version then return the version information output`() { runKtLintCliProcess( "no-code-style-error", - listOf("--version") + listOf("--version"), ) { assertNormalExitCode() assertErrorOutputIsEmpty() @@ -43,7 +43,7 @@ class SimpleCLITest : BaseCLITest() { @Test fun `Given some code without errors then return from lint with normal exit code and no error output`() { runKtLintCliProcess( - "no-code-style-error" + "no-code-style-error", ) { assertNormalExitCode() assertErrorOutputIsEmpty() @@ -53,7 +53,7 @@ class SimpleCLITest : BaseCLITest() { @Test fun `Given some code with an error then return from lint with the error exit code and error output`() { runKtLintCliProcess( - "too-many-empty-lines" + "too-many-empty-lines", ) { assertErrorExitCode() @@ -67,7 +67,7 @@ class SimpleCLITest : BaseCLITest() { fun `Given some code with an error but a glob which does not select the file`() { runKtLintCliProcess( "too-many-empty-lines", - listOf("SomeOtherFile.kt") + listOf("SomeOtherFile.kt"), ) { assertErrorExitCode() @@ -81,7 +81,7 @@ class SimpleCLITest : BaseCLITest() { fun `Given some code with an error which can be autocorrected then return from from with the normal exit code`() { runKtLintCliProcess( "too-many-empty-lines", - listOf("-F") + listOf("-F"), ) { assertNormalExitCode() // on JDK11+ contains warning about illegal reflective access operation @@ -95,13 +95,13 @@ class SimpleCLITest : BaseCLITest() { fun `Given some code which only contains errors for rules which are disabled via CLI argument --disabled_rules then return from lint with the normal exit code and without error output`() { runKtLintCliProcess( "too-many-empty-lines", - listOf("--disabled_rules=no-consecutive-blank-lines,no-empty-first-line-in-method-block") + listOf("--disabled_rules=no-consecutive-blank-lines,no-empty-first-line-in-method-block"), ) { assertNormalExitCode() assertThat(normalOutput).doesNotContain( "no-consecutive-blank-lines", - "no-empty-first-line-in-method-block" + "no-empty-first-line-in-method-block", ) } } diff --git a/ktlint/src/test/kotlin/com/pinterest/ktlint/internal/FileUtilsTest.kt b/ktlint/src/test/kotlin/com/pinterest/ktlint/internal/FileUtilsTest.kt index f78416afca..20ab8639da 100644 --- a/ktlint/src/test/kotlin/com/pinterest/ktlint/internal/FileUtilsTest.kt +++ b/ktlint/src/test/kotlin/com/pinterest/ktlint/internal/FileUtilsTest.kt @@ -75,11 +75,11 @@ internal class FileUtilsFileSequenceTest { ktsFileInProjectRootDirectory, ktFile1InProjectSubDirectory, ktFile2InProjectSubDirectory, - ktsFileInProjectSubDirectory + ktsFileInProjectSubDirectory, ).doesNotContain( javaFileInHiddenDirectory, ktFileInHiddenDirectory, - ktsFileInHiddenDirectory + ktsFileInHiddenDirectory, ) } @@ -88,19 +88,19 @@ internal class FileUtilsFileSequenceTest { val foundFiles = getFiles( patterns = listOf( "project1/**/*.kt".normalizeGlob(), - "project1/*.kt".normalizeGlob() - ) + "project1/*.kt".normalizeGlob(), + ), ) assertThat(foundFiles) .containsExactlyInAnyOrder( ktFileInProjectRootDirectory, ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ).doesNotContain( javaFileInHiddenDirectory, ktFileInHiddenDirectory, - ktsFileInHiddenDirectory + ktsFileInHiddenDirectory, ) } @@ -111,8 +111,8 @@ internal class FileUtilsFileSequenceTest { val foundFiles = getFiles( patterns = listOf( "project1/src/**/*.kt".normalizeGlob(), - "!project1/src/**/example/*.kt".normalizeGlob() - ) + "!project1/src/**/example/*.kt".normalizeGlob(), + ), ) assertThat(foundFiles) @@ -126,14 +126,14 @@ internal class FileUtilsFileSequenceTest { System .getProperty("os.name") .lowercase(Locale.getDefault()) - .startsWith("windows") + .startsWith("windows"), ) val foundFiles = getFiles( patterns = listOf( "project1\\src\\**\\*.kt".normalizeGlob(), - "!project1\\src\\**\\example\\*.kt".normalizeGlob() - ) + "!project1\\src\\**\\example\\*.kt".normalizeGlob(), + ), ) assertThat(foundFiles) @@ -146,14 +146,14 @@ internal class FileUtilsFileSequenceTest { fun `Given a pattern and a workdir then find all files in that workdir and all its sub directories that match the pattern`() { val foundFiles = getFiles( patterns = listOf( - "**/main/**/*.kt".normalizeGlob() + "**/main/**/*.kt".normalizeGlob(), ), - rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ) } @@ -161,11 +161,11 @@ internal class FileUtilsFileSequenceTest { fun `Given an (relative) file path from the workdir then find all files in that workdir and all its sub directories that match the pattern`() { val foundFiles = getFiles( patterns = listOf("src/main/kotlin/One.kt".normalizeGlob()), - rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( - ktFile1InProjectSubDirectory + ktFile1InProjectSubDirectory, ) } @@ -174,14 +174,14 @@ internal class FileUtilsFileSequenceTest { val foundFiles = getFiles( patterns = listOf( "src/main/kotlin/One.kt".normalizeGlob(), - ktFile2InProjectSubDirectory.normalizeGlob() + ktFile2InProjectSubDirectory.normalizeGlob(), ), - rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ) } @@ -189,14 +189,14 @@ internal class FileUtilsFileSequenceTest { fun `Given a glob containing an (absolute) file path and a workdir then find all files match the pattern`() { val foundFiles = getFiles( patterns = listOf( - "${rootDir}project1/src/**/*.kt".normalizeGlob() + "${rootDir}project1/src/**/*.kt".normalizeGlob(), ), - rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ) } @@ -209,18 +209,18 @@ internal class FileUtilsFileSequenceTest { "~/project/src/main/kotlin/*.kt", "~/project/src/main/kotlin/", "~/project/src/main/kotlin", - "~/project/src/main/**/*.kt" - ] + "~/project/src/main/**/*.kt", + ], ) fun `Given a non-Windows OS and a pattern that starts with a tilde then transform the globs to the user home directory`( - pattern: String + pattern: String, ) { val homeDir = System.getProperty("user.home") val filePath = "$homeDir/project/src/main/kotlin/One.kt".normalizePath() tempFileSystem.createFile(filePath) val foundFiles = getFiles( - patterns = listOf(pattern.normalizeGlob()) + patterns = listOf(pattern.normalizeGlob()), ) assertThat(foundFiles).containsExactlyInAnyOrder(filePath) @@ -230,14 +230,14 @@ internal class FileUtilsFileSequenceTest { fun `Given a pattern containing a double star and a workdir without subdirectories then find all files in that workdir`() { val foundFiles = getFiles( patterns = listOf( - "**/*.kt".normalizeGlob() + "**/*.kt".normalizeGlob(), ), - rootDir = tempFileSystem.getPath("${rootDir}project1/src/main/kotlin/".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1/src/main/kotlin/".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ) } @@ -247,14 +247,14 @@ internal class FileUtilsFileSequenceTest { fun `Given a (relative) directory path (but not a glob) from the workdir then find all files in that workdir and it subdirectories having the default kotlin extensions`() { val foundFiles = getFiles( patterns = listOf("src/main/kotlin".normalizeGlob()), - rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()) + rootDir = tempFileSystem.getPath("${rootDir}project1".normalizePath()), ) assertThat(foundFiles).containsExactlyInAnyOrder( ktFile1InProjectSubDirectory, - ktFile2InProjectSubDirectory + ktFile2InProjectSubDirectory, ).doesNotContain( - javaFileInProjectSubDirectory + javaFileInProjectSubDirectory, ) } @@ -264,14 +264,14 @@ internal class FileUtilsFileSequenceTest { System .getProperty("os.name") .lowercase(Locale.getDefault()) - .startsWith("windows") + .startsWith("windows"), ) val foundFiles = getFiles( patterns = listOf( "project1\\src\\**\\*.kt".normalizeGlob(), - "!project1\\src\\**\\example\\*.kt".normalizeGlob() - ) + "!project1\\src\\**\\example\\*.kt".normalizeGlob(), + ), ) assertThat(foundFiles) @@ -291,7 +291,7 @@ internal class FileUtilsFileSequenceTest { private fun getFiles( patterns: List = emptyList(), - rootDir: Path = tempFileSystem.rootDirectories.first() + rootDir: Path = tempFileSystem.rootDirectories.first(), ): List = tempFileSystem .fileSequence(patterns, rootDir) .map { it.toString() } diff --git a/settings.gradle.kts b/settings.gradle.kts index e6cb58a2f0..c6c871f1bd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -41,5 +41,5 @@ include( ":ktlint-ruleset-template", ":ktlint-ruleset-test", ":ktlint-test", - ":ktlint-test-logging" + ":ktlint-test-logging", )