Remove deprecated methods which were marked for removal in Ktlint 2.0, and resolve TOOD's
diff --git a/ktlint-api-consumer/src/test/kotlin/com/pinterest/ktlint/api/consumer/KtLintRuleEngineTest.kt b/ktlint-api-consumer/src/test/kotlin/com/pinterest/ktlint/api/consumer/KtLintRuleEngineTest.kt index 6da08ae..ef20055 100644 --- a/ktlint-api-consumer/src/test/kotlin/com/pinterest/ktlint/api/consumer/KtLintRuleEngineTest.kt +++ b/ktlint-api-consumer/src/test/kotlin/com/pinterest/ktlint/api/consumer/KtLintRuleEngineTest.kt
@@ -158,104 +158,6 @@ } @Nested - inner class `Format (legacy) with KtLintRuleEngine` { - @Test - fun `Given a file that does not contain an error`( - @TempDir - tempDir: Path, - ) { - val filePath = "$tempDir/Code.kt" - FileWriter(filePath).use { - it.write( - """ - fun bar() { - // bar - } - """.trimIndent(), - ) - } - - val lintErrors = mutableListOf<LintError>() - val actual = - @Suppress("DEPRECATION") - ktLintRuleEngine.format( - code = Code.fromFile(File(filePath)), - ) { lintError, _ -> lintErrors.add(lintError) } - - assertThat(lintErrors).containsExactlyInAnyOrder( - LintError(2, 5, RULE_WITH_AUTOCORRECT_APPROVE_HANDLER, "Bar comment with autocorrect approve handler", true), - LintError(3, 1, INDENTATION_RULE_ID, "Unexpected indentation (4) (should be 0)", true), - ) - assertThat(actual).isEqualTo( - """ - fun bar() { - // BAR - } - """.trimIndent(), - ) - } - - @Test - fun `Given a kotlin code snippet that does contain an indentation error`() { - val lintErrors = mutableListOf<LintError>() - val actual = - @Suppress("DEPRECATION") - ktLintRuleEngine.format( - code = - Code.fromSnippet( - """ - fun bar() { - // bar - } - """.trimIndent(), - ), - ) { lintError, _ -> lintErrors.add(lintError) } - - assertThat(lintErrors).containsExactlyInAnyOrder( - LintError(2, 5, RULE_WITH_AUTOCORRECT_APPROVE_HANDLER, "Bar comment with autocorrect approve handler", true), - LintError(3, 1, INDENTATION_RULE_ID, "Unexpected indentation (4) (should be 0)", true), - ) - assertThat(actual).isEqualTo( - """ - fun bar() { - // BAR - } - """.trimIndent(), - ) - } - - @Test - fun `Given a kotlin script code snippet that does contain an indentation error`() { - val lintErrors = mutableListOf<LintError>() - val actual = - @Suppress("DEPRECATION") - ktLintRuleEngine.format( - code = - Code.fromSnippet( - """ - plugins { - // bar - } - """.trimIndent(), - script = true, - ), - ) { lintError, _ -> lintErrors.add(lintError) } - - assertThat(lintErrors).containsExactlyInAnyOrder( - LintError(2, 5, RULE_WITH_AUTOCORRECT_APPROVE_HANDLER, "Bar comment with autocorrect approve handler", true), - LintError(3, 1, INDENTATION_RULE_ID, "Unexpected indentation (4) (should be 0)", true), - ) - assertThat(actual).isEqualTo( - """ - plugins { - // BAR - } - """.trimIndent(), - ) - } - } - - @Nested inner class `Format with KtLintRuleEngine` { @Nested inner class `Given a file that containing some errors` {
diff --git a/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/Baseline.kt b/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/Baseline.kt index 939a3bc..e64b99f 100644 --- a/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/Baseline.kt +++ b/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/Baseline.kt
@@ -71,16 +71,6 @@ } /** - * Loads the [Baseline] from the file located on [path]. Exceptions are swallowed and log message is written. On error, the baseline file is - * deleted. - */ -@Deprecated( - message = "Marked for removal in Ktlint 2.0", - replaceWith = ReplaceWith("loadBaseline(path, BaselineErrorHandling.LOG)"), -) -public fun loadBaseline(path: String): Baseline = loadBaseline(path, BaselineErrorHandling.LOG) - -/** * Loads the [Baseline] from the file located on [path]. In case the baseline file can not be loaded successfully, it will be deleted. */ public fun loadBaseline( @@ -121,8 +111,6 @@ .toFile() .takeIf { it.exists() } - var ruleReferenceWithoutRuleSetIdPrefix = 0 - fun load(): Baseline { require(path.isNotBlank()) { "Path for loading baseline may not be blank or empty" } @@ -133,15 +121,7 @@ path = path, lintErrorsPerFile = baselineFile.inputStream().parseBaseline(), status = VALID, - ).also { - if (ruleReferenceWithoutRuleSetIdPrefix > 0) { - LOGGER.warn { - "Baseline file '$path' contains $ruleReferenceWithoutRuleSetIdPrefix reference(s) to rule ids without " + - "a rule set id. For those references the rule set id 'standard' is assumed. It is advised to " + - "regenerate this baseline file." - } - } - } + ) } catch (e: IOException) { throw BaselineLoaderException("Unable to parse baseline file: $path", e) } catch (e: ParserConfigurationException) { @@ -200,18 +180,7 @@ KtlintCliError( line = getAttribute("line").toInt(), col = getAttribute("column").toInt(), - ruleId = - getAttribute("source") - .let { ruleId -> - // Ensure backwards compatibility with baseline files in which the rule set id for standard rules is not saved - RuleId - .prefixWithStandardRuleSetIdWhenMissing(ruleId) - .also { prefixedRuleId -> - if (prefixedRuleId != ruleId) { - ruleReferenceWithoutRuleSetIdPrefix++ - } - } - }, + ruleId = getAttribute("source"), // Detail is not available in the baseline detail = "", status = BASELINE_IGNORED, @@ -238,9 +207,7 @@ public fun List<KtlintCliError>.containsLintError(ktlintCliError: KtlintCliError): Boolean = any { it.isSameAs(ktlintCliError) } private fun KtlintCliError.isSameAs(lintError: KtlintCliError) = - col == lintError.col && - line == lintError.line && - RuleId.prefixWithStandardRuleSetIdWhenMissing(ruleId) == RuleId.prefixWithStandardRuleSetIdWhenMissing(lintError.ruleId) + col == lintError.col && line == lintError.line && ruleId == lintError.ruleId /** * Checks if the list does not contain the given [KtlintCliError]. The [List.contains] function can not be used as [KtlintCliError.detail]
diff --git a/ktlint-cli-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineTest.kt b/ktlint-cli-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineTest.kt index d95348f..681df37 100644 --- a/ktlint-cli-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineTest.kt +++ b/ktlint-cli-reporter-baseline/src/test/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineTest.kt
@@ -121,21 +121,7 @@ @Nested inner class `Baseline has invalid xml structure` { @Test - fun `Given that the baseline is loaded with classic loader then the log contains an error message`( - @TempDir - tempDir: Path, - ) { - val path = "baseline-invalid.xml".copyResourceToFileIn(tempDir) - - val logCaptor = LogCaptor.forClass(Baseline::class.java) - - loadBaseline(path) - - assertThat(logCaptor.errorLogs).contains("Unable to parse baseline file: $path") - } - - @Test - fun `Given that the baseline is loaded with new loader then an exception is thrown on error`( + fun `Given that the baseline is loaded with BaselineErrorHandling EXCEPTION then on error an exception is thrown`( @TempDir tempDir: Path, ) { @@ -150,7 +136,7 @@ } @Test - fun `Given that the baseline is loaded with new loader then the log message is printed and no exception is thrown`( + fun `Given that the baseline is loaded with BaselineErrorHandling LOG then on error a the log message is printed and no exception is thrown`( @TempDir tempDir: Path, ) { @@ -158,7 +144,7 @@ val logCaptor = LogCaptor.forClass(Baseline::class.java) - loadBaseline(path) + loadBaseline(path, BaselineErrorHandling.LOG) assertThat(logCaptor.errorLogs).contains("Unable to parse baseline file: $path") }
diff --git a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt index fb0325a..a8763fd 100644 --- a/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt +++ b/ktlint-cli/src/main/kotlin/com/pinterest/ktlint/cli/internal/KtlintCommandLine.kt Binary files differ
diff --git a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt index d13e87b..4fd178f 100644 --- a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt +++ b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/SimpleCLITest.kt
@@ -505,24 +505,6 @@ } @Test - fun `Given that the deprecated parameter --code-style is specified, then return an error`( - @TempDir - tempDir: Path, - ) { - CommandLineTestRunner(tempDir) - .run( - testProjectName = "too-many-empty-lines", - arguments = listOf("--code-style=android_studio"), - expectExitCodeLoggedWhenKtlintIsFinished = false, - ) { - assertThat(errorOutput).containsLineMatching( - "Parameter '--code-style' is no longer valid. The code style should be defined as '.editorconfig' property " + - "'ktlint_code_style='", - ) - } - } - - @Test fun `Issue 3096 - Given some code containing unicode characters, the code is provided via stdin then write the formatted code to stdout in UTF-8 to preserve the unicode characters`( @TempDir tempDir: Path,
diff --git a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt index 7e30579..a905db5 100644 --- a/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt +++ b/ktlint-cli/src/test/kotlin/com/pinterest/ktlint/cli/api/BaselineCLITest.kt
@@ -61,12 +61,6 @@ .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) .doesNotContainLineMatching( Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*"), - ).containsLineMatching( - Regex( - ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. " + - "For those references the rule set id 'standard' is assumed. It is advised to regenerate " + - "this baseline file.*", - ), ).doesNotContainLineMatching( Regex( ".*Format was not able to resolve all violations which \\(theoretically\\) can be autocorrected in file.*", @@ -100,12 +94,6 @@ .doesNotContainLineMatching(Regex(".*/$projectName/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) .doesNotContainLineMatching( Regex(".*/$projectName/some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*"), - ).containsLineMatching( - Regex( - ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. " + - "For those references the rule set id 'standard' is assumed. It is advised to regenerate " + - "this baseline file.*", - ), ) }.assertAll() } @@ -133,14 +121,6 @@ assertThat(normalOutput) .doesNotContainLineMatching(Regex("^TestBaselineFile.kt.test:1:24: Unnecessary block.*")) .doesNotContainLineMatching(Regex("^some/path/to/TestBaselineFile.kt.test:1:24: Unnecessary block.*")) - .containsLineMatching( - Regex( - // Escape "\" in baseline path for Windows - ".*Baseline file '${baselinePath.replace("\\", "\\\\")}' contains 4 " + - "reference\\(s\\) to rule ids without a rule set id. For those references the rule set id " + - "'standard' is assumed. It is advised to regenerate this baseline file.*", - ), - ) }.assertAll() } } @@ -177,12 +157,6 @@ ".*/$projectName/some/path/to/TestBaselineExtraErrorFile.kt.test:1:1: Replace the block comment with " + "an EOL comment.*", ), - ).containsLineMatching( - Regex( - ".*Baseline file '$baselinePath' contains 4 reference\\(s\\) to rule ids without a rule set id. For " + - "those references the rule set id 'standard' is assumed. It is advised to regenerate this " + - "baseline file.*", - ), ) }.assertAll() }
diff --git a/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml b/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml index ec2b8a0..7d2009c 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml +++ b/ktlint-cli/src/test/resources/cli/baseline/config/test-baseline.xml
@@ -1,15 +1,15 @@ <?xml version="1.0" encoding="utf-8"?> <baseline version="1.0"> <file name="TestBaselineExtraErrorFile.kt.test"> - <error line="2" column="34" source="no-empty-class-body" /> + <error line="2" column="34" source="standard:no-empty-class-body" /> </file> <file name="TestBaselineFile.kt.test"> - <error line="1" column="24" source="no-empty-class-body" /> + <error line="1" column="24" source="standard:no-empty-class-body" /> </file> <file name="some/path/to/TestBaselineExtraErrorFile.kt.test"> - <error line="2" column="34" source="no-empty-class-body" /> + <error line="2" column="34" source="standard:no-empty-class-body" /> </file> <file name="some/path/to/TestBaselineFile.kt.test"> - <error line="1" column="24" source="no-empty-class-body" /> + <error line="1" column="24" source="standard:no-empty-class-body" /> </file> </baseline>
diff --git a/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml b/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml index ec2b8a0..7d2009c 100644 --- a/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml +++ b/ktlint-cli/src/test/resources/cli/baseline/test-baseline.xml
@@ -1,15 +1,15 @@ <?xml version="1.0" encoding="utf-8"?> <baseline version="1.0"> <file name="TestBaselineExtraErrorFile.kt.test"> - <error line="2" column="34" source="no-empty-class-body" /> + <error line="2" column="34" source="standard:no-empty-class-body" /> </file> <file name="TestBaselineFile.kt.test"> - <error line="1" column="24" source="no-empty-class-body" /> + <error line="1" column="24" source="standard:no-empty-class-body" /> </file> <file name="some/path/to/TestBaselineExtraErrorFile.kt.test"> - <error line="2" column="34" source="no-empty-class-body" /> + <error line="2" column="34" source="standard:no-empty-class-body" /> </file> <file name="some/path/to/TestBaselineFile.kt.test"> - <error line="1" column="24" source="no-empty-class-body" /> + <error line="1" column="24" source="standard:no-empty-class-body" /> </file> </baseline>
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtension.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtension.kt index e22a160..48f621d 100644 --- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtension.kt +++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtension.kt
@@ -9,9 +9,6 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.STRING_TEMPLATE import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST -import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAL_KEYWORD -import com.pinterest.ktlint.rule.engine.core.api.ElementType.VARARG_KEYWORD -import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAR_KEYWORD import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE import org.jetbrains.kotlin.KtNodeType import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -25,43 +22,13 @@ import org.jetbrains.kotlin.lexer.KtToken import org.jetbrains.kotlin.psi.KtAnnotated import org.jetbrains.kotlin.psi.KtElement -import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtLoopExpression import org.jetbrains.kotlin.psi.psiUtil.leaves import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.psi.stubs.elements.KtFileElementType import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementType import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets import org.jetbrains.kotlin.util.prefixIfNot -import org.jetbrains.kotlin.utils.addToStdlib.applyIf -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.contract -import kotlin.reflect.KClass - -/** - * In Ktlint 2.0 all ASTNode extensions functions will be replaced with property access where applicable. For now (ktlint 1.x) those - * property accessors are prefixed with `_` to avoid name clashes with the functions. You are encouraged to replace the deprecated - * functions with the accessors prefixed with `_` with use of the IntelliJ IDEA functionality. In Ktlint 2.0 the functions will be removed, - * and the prefix `_` will be removed from the accessors. - */ - -@Deprecated( - "Marked for removal in KtLint 2.0. Replace calls to 'nextLeaf()', 'nextLeaf(false)', and 'nextLeaf(false, false)' with " + - "property accessor 'nextLeaf'. For any situation, use 'nextLeaf((ASTNode) -> Boolean)'.", -) -public fun ASTNode.nextLeaf( - includeEmpty: Boolean = false, - skipSubtree: Boolean = false, -): ASTNode? { - var n = if (skipSubtree) lastChildLeafOrSelf20.nextLeafAny else this.nextLeafAny - if (!includeEmpty) { - while (n != null && n.textLength == 0) { - n = n.nextLeafAny - } - } - return n -} /** * The next leaf after [ASTNode], or null when no such leaf exists. @@ -99,20 +66,12 @@ } private val ASTNode.nextLeafStrict - get(): ASTNode? = nextSibling20?.firstChildLeafOrSelf20 ?: parent?.nextLeafStrict - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("firstChildLeafOrSelf20"), -) -public fun ASTNode.firstChildLeafOrSelf(): ASTNode = firstChildLeafOrSelf20 + get(): ASTNode? = nextSibling?.firstChildLeafOrSelf ?: parent?.nextLeafStrict /** * The first child leaf in [ASTNode], or [ASTNode] when it does not contain any children. */ -public val ASTNode.firstChildLeafOrSelf20: ASTNode +public val ASTNode.firstChildLeafOrSelf: ASTNode get(): ASTNode { var node = this while (node.firstChildNode != null) { @@ -121,21 +80,6 @@ return node } -@Deprecated( - "Marked for removal in KtLint 2.0. Replace calls to 'prevLeaf()', and 'prevLeaf(false)' with property accessor 'prevLeaf'. For any " + - "situation, use 'prevLeaf((ASTNode) -> Boolean)'.", - replaceWith = ReplaceWith("prevLeaf"), -) -public fun ASTNode.prevLeaf(includeEmpty: Boolean = false): ASTNode? { - var n = this.prevLeafAny - if (!includeEmpty) { - while (n != null && n.textLength == 0) { - n = n.prevLeafAny - } - } - return n -} - /** * The previous leaf before [ASTNode], or null when no such leaf exists. */ @@ -160,20 +104,12 @@ } private val ASTNode.prevLeafAny - get(): ASTNode? = prevSibling20?.lastChildLeafOrSelf20 ?: parent?.prevLeafAny - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("lastChildLeafOrSelf20"), -) -public fun ASTNode.lastChildLeafOrSelf(): ASTNode = lastChildLeafOrSelf20 + get(): ASTNode? = prevSibling?.lastChildLeafOrSelf ?: parent?.prevLeafAny /** * The last child leaf in [ASTNode], or [ASTNode] when it does not contain any children. */ -public val ASTNode.lastChildLeafOrSelf20: ASTNode +public val ASTNode.lastChildLeafOrSelf: ASTNode get(): ASTNode { var node = this while (node.lastChildNode != null) { @@ -186,19 +122,7 @@ * `true` when [ASTNode] is not a whitespace element, and is not part of a comment. */ public val ASTNode.isCode: Boolean - get(): Boolean = !isWhiteSpace20 && !isPartOfComment20 - -@Deprecated( - "Marked for removal in KtLint 2.0. Replace calls to 'prevCodeLeaf()', and 'prevCodeLeaf(false)' with property accessor " + - "'prevCodeLeaf'. For any other situation, use 'prevCodeLeaf((ASTNode) -> Boolean)'.", -) -public fun ASTNode.prevCodeLeaf(includeEmpty: Boolean = false): ASTNode? { - var n = prevLeaf(includeEmpty) - while (n != null && !n.isCode) { - n = n.prevLeaf(includeEmpty) - } - return n -} + get(): Boolean = !isWhiteSpace && !isPartOfComment /** * The previous code leaf before [ASTNode], or null when no such leaf exists. @@ -212,21 +136,6 @@ return node } -@Deprecated( - "Marked for removal in KtLint 2.0. Replace calls to 'nextCodeLeaf()', 'nextCodeLeaf(false)', and 'nextCodeLeaf(false, false)' with " + - "property accessor 'nextCodeLeaf'. For any other situation, use 'nextCodeLeaf((ASTNode) -> Boolean)'.", -) -public fun ASTNode.nextCodeLeaf( - includeEmpty: Boolean = false, - skipSubtree: Boolean = false, -): ASTNode? { - var n = nextLeaf - while (n != null && !n.isCode) { - n = n.nextLeaf - } - return n -} - /** * The next code leaf after [ASTNode], or null when no such leaf exists. */ @@ -239,18 +148,10 @@ return node } -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("prevCodeSibling20"), -) -public fun ASTNode.prevCodeSibling(): ASTNode? = prevCodeSibling20 - /** * The previous code sibling of [ASTNode], or null when no such sibling exists. */ -public val ASTNode.prevCodeSibling20: ASTNode? +public val ASTNode.prevCodeSibling: ASTNode? get(): ASTNode? = prevSibling { it.isCode } /** @@ -267,33 +168,16 @@ return null } -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("prevSibling20"), -) -public fun ASTNode.prevSibling(): ASTNode? = prevSibling20 - /** * The previous sibling of [ASTNode], or null when no such sibling exists. */ -public inline val ASTNode.prevSibling20: ASTNode? +public inline val ASTNode.prevSibling: ASTNode? get(): ASTNode? = treePrev -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("nextCodeSibling20"), -) -// TODO: In Ktlint 2.0 replace with accessor without temporary suffix "20" -public fun ASTNode.nextCodeSibling(): ASTNode? = nextCodeSibling20 - /** * The next code sibling of [ASTNode], or null when no such sibling exists. */ -public val ASTNode.nextCodeSibling20: ASTNode? +public val ASTNode.nextCodeSibling: ASTNode? get(): ASTNode? = nextSibling { it.isCode } /** @@ -310,18 +194,10 @@ return null } -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("nextSibling20"), -) -public fun ASTNode.nextSibling(): ASTNode? = nextSibling20 - /** * The next sibling of [ASTNode], or null when no such sibling exists. */ -public inline val ASTNode.nextSibling20: ASTNode? +public inline val ASTNode.nextSibling: ASTNode? get(): ASTNode? = treeNext /** @@ -331,33 +207,6 @@ get(): ASTNode? = treeParent /** - * @param elementType [ElementType].* - */ -@Deprecated( - "Marked for removal in Ktlint 2.0", - replaceWith = ReplaceWith("findParentByType(elementType)"), -) -public fun ASTNode.parent( - elementType: IElementType, - strict: Boolean = true, -): ASTNode? { - var n: ASTNode? = if (strict) this.parent else this - while (n != null) { - if (n.elementType == elementType) { - return n - } - n = n.parent - } - return null -} - -@Deprecated( - message = "Marked for removal in Ktlint 2.0", - replaceWith = ReplaceWith("findParentByType(elementType)"), -) -public fun ASTNode.parent(elementType: IElementType): ASTNode? = findParentByType(elementType) - -/** * Find the first parent from [ASTNode] with [elementType]. */ public fun ASTNode.findParentByType(elementType: IElementType): ASTNode? { @@ -371,21 +220,6 @@ return null } -@Deprecated("Marked for removal in Ktlint 2.0") -public fun ASTNode.parent( - strict: Boolean = true, - predicate: (ASTNode) -> Boolean, -): ASTNode? { - var n: ASTNode? = if (strict) this.parent else this - while (n != null) { - if (predicate(n)) { - return n - } - n = n.parent - } - return null -} - /** * Find the first parent from [ASTNode] matching [predicate]. */ @@ -407,176 +241,64 @@ */ public fun ASTNode.isPartOf(elementType: IElementType): Boolean = this.elementType == elementType || findParentByType(elementType) != null -@Deprecated( - "Marked for removal in Ktlint 2.x. Replace with ASTNode.isPartOf(elementType: IElementType) or ASTNode.isPartOf(tokenSet: TokenSet). " + - "This method might cause performance issues, see https://github.com/pinterest/ktlint/pull/2901", - replaceWith = ReplaceWith("this.isPartOf(elementTypeOrTokenSet)"), -) -public fun ASTNode.isPartOf(klass: KClass<out PsiElement>): Boolean { - var node: ASTNode? = this - while (node != null) { - if (klass.java.isInstance(node.psi)) { - return true - } - node = node.parent - } - return false -} - -@Deprecated("Marked for removal in KtLint 2.0") -public fun ASTNode.isPartOfCompositeElementOfType(iElementType: IElementType): Boolean = - iElementType == findCompositeParentElementOfType(iElementType)?.elementType - -@Deprecated("Marked for removal in KtLint 2.0") -public fun ASTNode.findCompositeParentElementOfType(iElementType: IElementType): ASTNode? = - parent { it.elementType == iElementType || it !is CompositeElement } - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isPartOfString20"), -) -public fun ASTNode.isPartOfString(): Boolean = isPartOfString20 - /** * `true` when [ASTNode] is part of a string template */ -public val ASTNode.isPartOfString20: Boolean +public val ASTNode.isPartOfString: Boolean get(): Boolean = findParentByType(STRING_TEMPLATE) != null -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isWhiteSpace20"), -) -@OptIn(ExperimentalContracts::class) -public fun ASTNode?.isWhiteSpace(): Boolean { - contract { - returns(true) implies (this@isWhiteSpace != null) - } - return isWhiteSpace20 -} - /** * `true` when [ASTNode] is a whitespace element */ -public val ASTNode?.isWhiteSpace20: Boolean +public val ASTNode?.isWhiteSpace: Boolean get() = this != null && elementType == WHITE_SPACE -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isWhiteSpaceWithNewline20"), -) -public fun ASTNode?.isWhiteSpaceWithNewline(): Boolean = isWhiteSpaceWithNewline20 - /** * `true` when [ASTNode] is a whitespace element that contains a newline */ -public val ASTNode?.isWhiteSpaceWithNewline20: Boolean - get(): Boolean = this != null && isWhiteSpace20 && textContains('\n') - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isWhiteSpaceWithoutNewline20"), -) -public fun ASTNode?.isWhiteSpaceWithoutNewline(): Boolean = isWhiteSpaceWithoutNewline20 +public val ASTNode?.isWhiteSpaceWithNewline: Boolean + get(): Boolean = this != null && isWhiteSpace && textContains('\n') /** * `true` when [ASTNode] is a whitespace element not containing a newline */ -public val ASTNode?.isWhiteSpaceWithoutNewline20: Boolean - get(): Boolean = this != null && isWhiteSpace20 && !textContains('\n') +public val ASTNode?.isWhiteSpaceWithoutNewline: Boolean + get(): Boolean = this != null && isWhiteSpace && !textContains('\n') /** * `true` when [ASTNode] is null, or when [ASTNode] is a whitespace element not containing a newline */ public val ASTNode?.isWhiteSpaceWithoutNewlineOrNull: Boolean - get(): Boolean = this == null || isWhiteSpaceWithoutNewline20 - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isRoot20"), -) -public fun ASTNode.isRoot(): Boolean = isRoot20 + get(): Boolean = this == null || isWhiteSpaceWithoutNewline /** * `true` when [ASTNode] is the root (e.g. FILE) element type */ -public val ASTNode.isRoot20: Boolean +public val ASTNode.isRoot: Boolean get(): Boolean = elementType == FILE -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isLeaf20"), -) -public fun ASTNode.isLeaf(): Boolean = isLeaf20 - /** * `true` when [ASTNode] is a leaf element type */ -public val ASTNode.isLeaf20: Boolean +public val ASTNode.isLeaf: Boolean get(): Boolean = firstChildNode == null /** - * Check if the given [ASTNode] is a code leaf. E.g. it must be a leaf and may not be a whitespace or be part of a - * comment. - */ -@Deprecated("Marked for removal in Ktlint 2.0. Use `isLeaf20 && isCode` instead") -public fun ASTNode.isCodeLeaf(): Boolean = isLeaf20 && isCode - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isPartOfComment20"), -) -public fun ASTNode.isPartOfComment(): Boolean = isPartOfComment20 - -/** * `true` when [ASTNode] is part of a comment */ -public val ASTNode.isPartOfComment20: Boolean +public val ASTNode.isPartOfComment: Boolean get(): Boolean = isPartOf(TokenSets.COMMENTS) -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("children20"), -) -public fun ASTNode.children(): Sequence<ASTNode> = children20 - /** * A sequence of the children of [ASTNode] */ -public val ASTNode.children20: Sequence<ASTNode> - get(): Sequence<ASTNode> = generateSequence(firstChildNode) { node -> node.nextSibling20 } - -@Deprecated("Marked for removal in Ktlint 2.0") -public fun ASTNode.recursiveChildren(includeSelf: Boolean = false): Sequence<ASTNode> = recursiveChildrenInternal(includeSelf) - -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("recursiveChildren20"), -) -public fun ASTNode.recursiveChildren(): Sequence<ASTNode> = recursiveChildren20 +public val ASTNode.children: Sequence<ASTNode> + get(): Sequence<ASTNode> = generateSequence(firstChildNode) { node -> node.nextSibling } /** * A sequence of the children of [ASTNode] recursively iterated */ -public val ASTNode.recursiveChildren20: Sequence<ASTNode> +public val ASTNode.recursiveChildren: Sequence<ASTNode> get(): Sequence<ASTNode> = recursiveChildrenInternal(false) private fun ASTNode.recursiveChildrenInternal(includeSelf: Boolean = false): Sequence<ASTNode> = @@ -584,7 +306,7 @@ if (includeSelf) { yield(this@recursiveChildrenInternal) } - this@recursiveChildrenInternal.children20.forEach { yieldAll(it.recursiveChildrenInternal(includeSelf = true)) } + this@recursiveChildrenInternal.children.forEach { yieldAll(it.recursiveChildrenInternal(includeSelf = true)) } } /** @@ -593,13 +315,13 @@ * added after the previous leaf node. */ public fun ASTNode.upsertWhitespaceBeforeMe(text: String) { - if (isLeaf20) { - if (isWhiteSpace20) { + if (isLeaf) { + if (isWhiteSpace) { return replaceTextWith(text) } - val previous = prevSibling20 ?: this.prevLeaf + val previous = prevSibling ?: this.prevLeaf when { - previous != null && previous.isWhiteSpace20 -> { + previous != null && previous.isWhiteSpace -> { previous.replaceTextWith(text) } @@ -615,7 +337,7 @@ } } } else { - when (val prevSibling = prevSibling20) { + when (val prevSibling = prevSibling) { null -> { // Never insert a whitespace element as first child node in a composite node. Instead, upsert just before the composite node parent?.upsertWhitespaceBeforeMe(text) @@ -650,13 +372,13 @@ * added after the last child leaf. */ public fun ASTNode.upsertWhitespaceAfterMe(text: String) { - if (isLeaf20) { - if (isWhiteSpace20) { + if (isLeaf) { + if (isWhiteSpace) { return replaceTextWith(text) } - val next = nextSibling20 ?: nextLeaf + val next = nextSibling ?: nextLeaf when { - next != null && next.isWhiteSpace20 -> { + next != null && next.isWhiteSpace -> { next.replaceTextWith(text) } @@ -672,7 +394,7 @@ } } } else { - when (val nextSibling = nextSibling20) { + when (val nextSibling = nextSibling) { null -> { // Never insert a whitespace element as last child node in a composite node. Instead, upsert just after the composite node parent?.upsertWhitespaceAfterMe(text) @@ -700,7 +422,7 @@ var leaf = prevLeaf var offsetToTheLeft = 0 while (leaf != null) { - if (leaf.isWhiteSpaceWithNewline20) { + if (leaf.isWhiteSpaceWithNewline) { offsetToTheLeft += leaf.textLength - 1 - leaf.text.lastIndexOf('\n') break } @@ -711,26 +433,9 @@ } /** - * Get the current indentation of the line containing the [ASTNode]. By default, this indentation starts with a newline (\n) character. - */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "one of the temporary property accessor. Calls to `indent()` or `indent(true)` should be replaced with `indent20()`. Calls " + - "to `indent(false)` should be replaced with `indentWithoutNewlinePrefix()` In 2.0 the temporary accessors will be replaced " + - "the final property accessors.", - replaceWith = ReplaceWith("indent20 or indentWithoutNewlinePrefix"), -) -public fun ASTNode.indent(includeNewline: Boolean = true): String = - if (includeNewline) { - indent20 - } else { - indentWithoutNewlinePrefix - } - -/** * The indentation of [ASTNode] including the newline prefix */ -public val ASTNode.indent20: String +public val ASTNode.indent: String get(): String = indentInternal().prefixIfNot("\n") /** @@ -744,30 +449,12 @@ */ private fun ASTNode.indentInternal(): String = leaves(forward = false) - .firstOrNull { it.isWhiteSpaceWithNewline20 } + .firstOrNull { it.isWhiteSpaceWithNewline } ?.text ?.substringAfterLast('\n') .orEmpty() // Fallback if node is not preceded by any newline character /** - * Print content of a node and the element type of the node, its parent and its direct children. Utility is meant to - * be used during development only. Please do not remove. - */ -@Suppress("unused") -@Deprecated("Marked for removal in Ktlint 2.0. Use PsiViewer plugin instead") -public fun ASTNode.logStructure(): ASTNode = - also { - println("Processing ${text.replaceTabAndNewline()} : Type $elementType with parent ${parent?.elementType} ") - children20 - .toList() - .map { - println(" ${it.text.replaceTabAndNewline()} : Type ${it.elementType}") - } - } - -private fun String.replaceTabAndNewline(): String = replace("\t", "\\t").replace("\n", "\\n") - -/** * Verifies that a leaf containing a newline exist in the closed range [from] - [to]. Also, returns true in case any of * the boundary nodes [from] or [to] contains a newline. */ @@ -808,7 +495,7 @@ ): Sequence<ASTNode> = from .leaves() - .takeWhile { it != to && it != to.lastChildLeafOrSelf20 } + .takeWhile { it != to && it != to.lastChildLeafOrSelf } /** * Creates a sequence of leaf nodes in the closed range [from] - [to]. This means that the boundary nodes are included from the range in @@ -822,32 +509,14 @@ ): Sequence<ASTNode> { val stopAtLeaf = to - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .nextLeaf return from - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leavesForwardsIncludingSelf .takeWhile { it != stopAtLeaf } } -@Deprecated("Marked for removal in Ktlint 2.0") -public fun ASTNode.isValOrVarKeyword(): Boolean = elementType == VAL_KEYWORD || elementType == VAR_KEYWORD || elementType == VARARG_KEYWORD - -/** - * Creates a sequences of leaves including the [ASTNode] in case it is a [LeafElement] itself. By default, the leaves are traversed in - * forward order. Setting [forward] to `false` changes this to traversal in backward direction. - */ -@Deprecated("Marked for removal in Ktlint 2.0. Use `leavesForwardsIncludingSelf` or `leavesBackwardsIncludingSelf` instead") -public fun ASTNode.leavesIncludingSelf(forward: Boolean = true): Sequence<ASTNode> { - val sequence = - if (isLeaf20) { - sequenceOf(this) - } else { - emptySequence() - } - return sequence.plus(leaves(forward)) -} - /** * Creates a forward sequence of leaves including the [ASTNode] in case it is a [LeafElement] itself. Otherwise, an empty sequence is * returned. @@ -865,7 +534,7 @@ private val ASTNode.sequenceOfLeafOrEmpty get(): Sequence<ASTNode> { val sequence = - if (isLeaf20) { + if (isLeaf) { sequenceOf(this) } else { emptySequence() @@ -874,21 +543,9 @@ } /** - * Get all leaves on the same line as the given node including the whitespace indentation. Note that the whitespace indentation may start - * with zero or more newline characters. - */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("leavesOnLine20"), -) -public fun ASTNode.leavesOnLine(): Sequence<ASTNode> = leavesOnLine20 - -/** * A sequence of all leaves on the same line at which the [ASTNode] starts */ -public val ASTNode.leavesOnLine20: Sequence<ASTNode> +public val ASTNode.leavesOnLine: Sequence<ASTNode> get(): Sequence<ASTNode> { val takeAll = lastLeafOnLineOrNull == null return firstLeafOnLineOrSelf @@ -897,74 +554,24 @@ } /** - * Get all leaves on the same line as the given node including the whitespace indentation. Note that the whitespace indentation may start - * with zero or more newline characters. - */ -@Deprecated( - "Marked for removal in Ktlint 2.0. Use 'leavesOnLine20.dropTrailingEolComment()' to get all leaves on the line without the " + - "trailing EOL comment", -) -public fun ASTNode.leavesOnLine(excludeEolComment: Boolean): Sequence<ASTNode> = - leavesOnLine20.applyIf(excludeEolComment) { dropTrailingEolComment() } - -/** * Take all nodes preceding the whitespace before the EOL comment */ public fun Sequence<ASTNode>.dropTrailingEolComment(): Sequence<ASTNode> = takeWhile { - !(it.isWhiteSpaceWithoutNewline20 && it.nextLeaf?.elementType == EOL_COMMENT) && + !(it.isWhiteSpaceWithoutNewline && it.nextLeaf?.elementType == EOL_COMMENT) && // But if EOL-comment not preceded by whitespace than take all nodes before the EOL comment it.elementType != EOL_COMMENT } internal val ASTNode.firstLeafOnLineOrSelf get() = - prevLeaf { (it.textContains('\n') && !it.isPartOfComment20) || it.prevLeaf == null } + prevLeaf { (it.textContains('\n') && !it.isPartOfComment) || it.prevLeaf == null } ?: this internal val ASTNode.lastLeafOnLineOrNull get() = nextLeaf { it.textContains('\n') }?.prevLeaf /** - * Get the total length of all leaves on the same line as the given node including the whitespace indentation but excluding all leading - * newline characters in the whitespace indentation. Note that EOL-comments are included in the line length calculation. This can lead to - * rules modifying the code before the EOL-comment in case the EOL-comment causes the max_line_length to be exceeded. It should be - * preferred to prevent this by excluding the EOL-comment from the calculation (use [lineLength]), and let max-line-length rule report the - * violation. - */ -@Deprecated( - message = - "Marked for removal in Ktlint 2.x. Rules should not modify code in case the EOL comment causes the max_line_length to be exceeded.", - replaceWith = ReplaceWith("lineLength(excludeEolComment = false)"), -) -public fun ASTNode.lineLengthWithoutNewlinePrefix(): Int = leavesOnLine20.lineLength - -/** - * Get the total length of all leaves on the same line as the given node including the whitespace indentation but excluding all leading - * newline characters in the whitespace indentation. Use [excludeEolComment] to exclude the EOL-comment (and preceding whitespace) from this - * calculation. Note that rules should not modify code in case the EOL comment causes the max_line_length to be exceeded. Instead, let the - * max-line-length rule report this violation so that the developer can choose whether the comment can be shortened or that it can be placed - * on a separate line. - */ -@Deprecated( - "Marked for removal in Ktlint 2.0. Use `leavesOnLine20.dropTrailingEolComment().lineLength` instead to get the length of the line " + - "without the trailing EOL comment.`", -) -public fun ASTNode.lineLength(excludeEolComment: Boolean = false): Int = leavesOnLine(excludeEolComment).lineLength - -/** - * Get the total length of all leaves in the sequence including the whitespace indentation but excluding all leading newline characters in - * the whitespace indentation. The first leaf node in the sequence must be a white space starting with at least one newline. - */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("lineLength"), -) -public fun Sequence<ASTNode>.lineLengthWithoutNewlinePrefix(): Int = lineLength - -/** * The length of the first non-empty line in the [Sequence] of [ASTNode]'s */ public val Sequence<ASTNode>.lineLength: Int @@ -1007,7 +614,7 @@ */ public fun ASTNode.hasModifier(iElementType: IElementType): Boolean = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children .orEmpty() .any { it.elementType == iElementType } @@ -1028,40 +635,14 @@ /** * Searches the receiver [ASTNode] recursively, returning the first child with type [elementType]. If none are found, returns `null`. - * If [includeSelf] is `true`, includes the receiver in the search. The receiver would then be the first element searched, so it is - * guaranteed to be returned if it has type [elementType]. - */ -@Deprecated("Marked for removal in KtLint 2.0") -public fun ASTNode.findChildByTypeRecursively( - elementType: IElementType, - includeSelf: Boolean, -): ASTNode? = - recursiveChildren(includeSelf).firstOrNull { - it.elementType == - elementType - } - -/** - * Searches the receiver [ASTNode] recursively, returning the first child with type [elementType]. If none are found, returns `null`. */ public fun ASTNode.findChildByTypeRecursively(elementType: IElementType): ASTNode? = - recursiveChildren20.firstOrNull { it.elementType == elementType } + recursiveChildren.firstOrNull { it.elementType == elementType } /** * Returns the end offset of the text of this [ASTNode] */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("endOffset20"), -) -public fun ASTNode.endOffset(): Int = endOffset20 - -/** - * Returns the end offset of the text of this [ASTNode] - */ -public val ASTNode.endOffset20: Int // TODO: In Ktlint 2.0 replace with accessor without temporary suffix "20" +public val ASTNode.endOffset: Int get(): Int = textRange.endOffset private val elementTypeCache = hashMapOf<IElementType, PsiElement>() @@ -1070,27 +651,9 @@ * Checks if the [AstNode] extends the [KtAnnotated] interface. Using this function to check the interface is more performant than checking * whether `psi is KtAnnotated` as the psi does not need to be derived from [ASTNode]. */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isKtAnnotated20"), -) -public fun ASTNode.isKtAnnotated(): Boolean = isKtAnnotated20 - -/** - * Checks if the [AstNode] extends the [KtAnnotated] interface. Using this function to check the interface is more performant than checking - * whether `psi is KtAnnotated` as the psi does not need to be derived from [ASTNode]. - */ -public val ASTNode.isKtAnnotated20: Boolean +public val ASTNode.isKtAnnotated: Boolean get(): Boolean = psiType { it is KtAnnotated } -@Deprecated("Marked for removal in KtLint 2.0") -public fun ASTNode.isKtExpression(): Boolean = psiType { it is KtExpression } - -@Deprecated("Marked for removal in KtLint 2.0") -public fun ASTNode.isKtLoopExpression(): Boolean = psiType { it is KtLoopExpression } - private inline fun ASTNode.psiType(predicate: (psiElement: PsiElement) -> Boolean): Boolean = predicate(dummyPsiElement()) /** @@ -1125,20 +688,9 @@ private fun createDummyKtFile(): KtFile = KtlintKotlinCompiler.createPsiFileFromText("File.kt", "") as KtFile /** - * Returns true if the receiver is not null, and it represents a declaration - */ -@Deprecated( - "In Ktlint 2.0, it will be replaced with a property accessor. For easy migration replace current function call with " + - "the temporary property accessor. In 2.0 it can be replaced the final property accessor which will be the same as the " + - "current function name.", - replaceWith = ReplaceWith("isDeclaration20"), -) -public fun ASTNode?.isDeclaration(): Boolean = isDeclaration20 - -/** * `true` if [ASTNode] is a declaration */ -public val ASTNode?.isDeclaration20: Boolean +public val ASTNode?.isDeclaration: Boolean get(): Boolean = this != null && elementType in KtTokenSets.DECLARATION_TYPES /** @@ -1151,12 +703,12 @@ private fun ASTNode.isAnnotatedWithMaxLineLengthSuppression(): Boolean = (elementType == ANNOTATED_EXPRESSION && containsMaxLineLengthSuppression()) || findChildByType(MODIFIER_LIST).containsMaxLineLengthSuppression() || - (isRoot20 && findChildByType(FILE_ANNOTATION_LIST)?.containsMaxLineLengthSuppression() == true) + (isRoot && findChildByType(FILE_ANNOTATION_LIST)?.containsMaxLineLengthSuppression() == true) private fun ASTNode?.containsMaxLineLengthSuppression(): Boolean = this ?.findChildByType(ANNOTATION_ENTRY) ?.findChildByType(VALUE_ARGUMENT_LIST) - ?.children20 + ?.children ?.any { it.elementType == VALUE_ARGUMENT && it.text == "\"ktlint:standard:max-line-length\"" } ?: false
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt index 2d90adf..30e9b73 100644 --- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt +++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt
@@ -85,7 +85,7 @@ /** * Get the indentation including the newline character for a node at the next indent level compared to the given node. */ - public fun childIndentOf(node: ASTNode): String = node.indent20.plus(indent) + public fun childIndentOf(node: ASTNode): String = node.indent.plus(indent) /** * Get the indentation including the newline character for a node at the same indent level as the given node. @@ -95,7 +95,7 @@ /** * Get the indentation including the newline character for a node at the same indent level as the parent of the given node. */ - public fun parentIndentOf(node: ASTNode): String = node.parent!!.indent20 + public fun parentIndentOf(node: ASTNode): String = node.parent!!.indent /** * Converts [text] to a normalized indent. If [text] contains a new line, then only text after the last new line
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt index a8a86e4..695e3e2 100644 --- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt +++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt
@@ -20,14 +20,6 @@ public companion object { private const val DELIMITER = ":" - // TODO: Remove in 1.0 version when backward compatibility of rule id references can be dropped. - public fun prefixWithStandardRuleSetIdWhenMissing(id: String): String = - if (id.contains(DELIMITER)) { - id - } else { - "${RuleSetId.STANDARD.value}$DELIMITER$id" - } - public fun isValid(value: String): Boolean = IdNamingPolicy.isValidRuleId(value) } } @@ -232,7 +224,7 @@ } @Deprecated( - message = "Only use for backward compatibility of custom ruleset JARs with Ktlint 2.x", + message = "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. Use RuleV2 when possible.", replaceWith = ReplaceWith("RuleV2"), ) public open class Rule( @@ -363,7 +355,7 @@ */ @Poko @Deprecated( - message = "Only use for backward compatibility of custom ruleset JARs with Ktlint 2.x", + message = "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. Use RuleV2.about when possible.", replaceWith = ReplaceWith("RuleV2.About"), ) public class About( @@ -383,8 +375,8 @@ @Deprecated( message = - "Only used for backward compatibility of custom ruleset JARs with Ktlint 2.x. VisitorModifier is not used in Ktlint 2.x as " + - "due to the way that rules are executed, modifying the order in which rules are visited is not needed anymore.", + "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. VisitorModifiers are ignored by Ktlint 2.x " + + "as due to the way that rules are executed, modifying the order in which rules are visited is not needed anymore.", ) public sealed class VisitorModifier { /** @@ -394,8 +386,9 @@ @Poko @Deprecated( message = - "Only used for backward compatibility of custom ruleset JARs with Ktlint 2.x. VisitorModifier is not used in Ktlint 2.x " + - "as due to the way that rules are executed, modifying the order in which rules are visited is not needed anymore.", + "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. The RunAfterRule VisitorModifier is " + + "ignored by Ktlint 2.x as due to the way that rules are executed, modifying the order in which rules are visited is " + + "not needed anymore.", ) public class RunAfterRule( /** @@ -427,8 +420,9 @@ @Deprecated( message = - "Only used for backward compatibility of custom ruleset JARs with Ktlint 2.x. VisitorModifier is not used in Ktlint 2.x " + - "as due to the way that rules are executed, modifying the order in which rules are visited is not needed anymore.", + "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. The RunAsLateAsPossible VisitorModifier " + + "is ignored by Ktlint 2.x as due to the way that rules are executed, modifying the order in which rules are visited " + + "is not needed anymore.", ) public object RunAsLateAsPossible : VisitorModifier() } @@ -438,6 +432,9 @@ * '.editorconfig' allows this rule specifically or all experimental rules. This interface is used by Ktlint internally but is also * explicitly meant to be used by custom rule providers. */ + @Deprecated( + message = "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. Use RuleV2.Experimental when possible", + ) public interface Experimental /** @@ -445,6 +442,10 @@ * '.editorconfig' contains property "code_style = ktlint_official" or when enabled explicitly. This interface is intended to be used * in Ktlint internally only. It may be subject to change at any time without providing any backward compatibility. */ + @Deprecated( + message = + "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. Use RuleV2.OfficialCodeStyle when possible", + ) public interface OfficialCodeStyle /** @@ -452,5 +453,10 @@ * deprecated, or when a rule is not applicable for general use. * This interface should not be used on a rule that is also marked with [Experimental], or [OfficialCodeStyle]. */ + @Deprecated( + message = + "Provides backwards compatibility of custom ruleset JARs created for Ktlint 1.x. Use RuleV2.OnlyWhenEnabledInEditorconfig " + + "when possible", + ) public interface OnlyWhenEnabledInEditorconfig }
diff --git a/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtensionTest.kt b/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtensionTest.kt index f52cb36..0d5de46 100644 --- a/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtensionTest.kt +++ b/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/ASTNodeExtensionTest.kt
@@ -176,7 +176,7 @@ val actual = hasNewLineInClosedRange( - enumClass.first { it.isWhiteSpaceWithNewline20 }, + enumClass.first { it.isWhiteSpaceWithNewline }, enumClass.last(), ) @@ -212,7 +212,7 @@ val actual = hasNewLineInClosedRange( enumBodyClass.first(), - enumBodyClass.last { it.isWhiteSpaceWithNewline20 }, + enumBodyClass.last { it.isWhiteSpaceWithNewline }, ) assertThat(actual).isTrue @@ -456,7 +456,7 @@ ?.findChildByType(VALUE_PARAMETER) ?.findChildByType(MODIFIER_LIST) ?.findChildByType(ANNOTATION_ENTRY) - ?.nextSibling20 + ?.nextSibling ?.upsertWhitespaceBeforeMe(" ") }.text @@ -481,8 +481,8 @@ ?.upsertWhitespaceBeforeMe(" ") }.findChildByType(CLASS) ?.findChildByType(CLASS_BODY) - ?.prevSibling20 - ?.let { it.isWhiteSpace20 && it.text == " " } + ?.prevSibling + ?.let { it.isWhiteSpace && it.text == " " } ?: false assertThat(actual).isTrue() @@ -653,8 +653,8 @@ ?.upsertWhitespaceAfterMe(" ") }.findChildByType(FUN) ?.findChildByType(VALUE_PARAMETER_LIST) - ?.nextSibling20 - ?.let { it.isWhiteSpace20 && it.text == " " } + ?.nextSibling + ?.let { it.isWhiteSpace && it.text == " " } ?: false assertThat(actual).isTrue() @@ -676,11 +676,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { it.text to it.indent20 } - .toMap() + .associate { it.text to it.indent } assertThat(actual).contains( entry("Foo1", "\n"), @@ -706,12 +705,12 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } .map { identifier -> identifier - .leavesOnLine20 + .leavesOnLine .joinToString(separator = "") { it.text } }.toList() @@ -741,10 +740,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { identifier -> identifier.leavesOnLine20.lineLength } + .map { identifier -> identifier.leavesOnLine.lineLength } .toList() assertThat(actual).contains( @@ -771,10 +770,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { identifier -> identifier.leavesOnLine20.lineLength } + .map { identifier -> identifier.leavesOnLine.lineLength } .toList() assertThat(actual).contains( @@ -801,12 +800,12 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } .map { identifier -> identifier - .leavesOnLine20 + .leavesOnLine .takeWhile { it.prevLeaf != identifier } .lineLength }.toList() @@ -831,12 +830,12 @@ assertThatNoException() .isThrownBy { transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } .map { identifier -> identifier - .leavesOnLine20 + .leavesOnLine .takeWhile { it.prevLeaf != identifier } .lineLength }.toList() @@ -861,10 +860,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { identifier -> identifier.leavesOnLine20.lineLength } + .map { identifier -> identifier.leavesOnLine.lineLength } .toList() assertThat(actual).contains( @@ -890,10 +889,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { identifier -> identifier.leavesOnLine20.lineLength } + .map { identifier -> identifier.leavesOnLine.lineLength } .toList() assertThat(actual).contains( @@ -919,10 +918,10 @@ val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leaves() .filter { it.elementType == IDENTIFIER } - .map { identifier -> identifier.leavesOnLine20.dropTrailingEolComment().lineLength } + .map { identifier -> identifier.leavesOnLine.dropTrailingEolComment().lineLength } .toList() assertThat(actual).contains( @@ -943,10 +942,10 @@ """.trimIndent() val actual = transformCodeToAST(code) - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leavesForwardsIncludingSelf .first { it.elementType == EOL_COMMENT } - .leavesOnLine20 + .leavesOnLine .dropTrailingEolComment() .lineLength @@ -1041,7 +1040,7 @@ val actual = transformCodeToAST(code) - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .firstLeafOnLineOrSelf .text @@ -1107,7 +1106,7 @@ """.trimIndent() val result = transformCodeToAST(code) - .findChildByTypeRecursively(FUN, includeSelf = false) + .findChildByTypeRecursively(FUN) assertThat(result).isNotNull() } @@ -1121,7 +1120,7 @@ """.trimIndent() val result = transformCodeToAST(code) - .findChildByTypeRecursively(FUN, includeSelf = false) + .findChildByTypeRecursively(FUN) assertThat(result).isNull() } } @@ -1135,9 +1134,9 @@ val actual = transformCodeToAST(code).findChildByType(CLASS)!! - assertThat(actual.isKtAnnotated20).isTrue() - assertThat(actual.findChildByType(CLASS_KEYWORD)!!.isKtAnnotated20).isFalse() - assertThat(actual.findChildByType(IDENTIFIER)!!.isKtAnnotated20).isFalse() + assertThat(actual.isKtAnnotated).isTrue() + assertThat(actual.findChildByType(CLASS_KEYWORD)!!.isKtAnnotated).isFalse() + assertThat(actual.findChildByType(IDENTIFIER)!!.isKtAnnotated).isFalse() assertThat(actual.isPsiType<KtAnnotated>()).isTrue() assertThat(actual.findChildByType(CLASS_KEYWORD)!!.isPsiType<KtAnnotated>()).isFalse() @@ -1287,13 +1286,13 @@ fileASTNode .findChildByType(CLASS) ?.findChildByType(CLASS_BODY) - ?.children20 + ?.children .orEmpty() private fun toEnumClassSequence(fileASTNode: FileASTNode) = fileASTNode .findChildByType(CLASS) - ?.children20 + ?.children .orEmpty() /**
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine.kt index 4c96a51..32fde86 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine.kt
@@ -11,7 +11,6 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue import com.pinterest.ktlint.rule.engine.core.api.propertyTypes import com.pinterest.ktlint.rule.engine.core.util.safeAs -import com.pinterest.ktlint.rule.engine.internal.AllAutocorrectHandler import com.pinterest.ktlint.rule.engine.internal.CodeFormatter import com.pinterest.ktlint.rule.engine.internal.EditorConfigFinder import com.pinterest.ktlint.rule.engine.internal.EditorConfigGenerator @@ -96,25 +95,6 @@ } /** - * Fix all style violations in [code] for lint errors when possible. If [code] is passed as file reference then the '.editorconfig' - * files on the path are taken into account. For each lint violation found, the [callback] is invoked. - * - * If [code] contains lint errors which have been autocorrected, then the resulting code is formatted again (up until - * [MAX_FORMAT_RUNS_PER_FILE] times) in order to fix lint errors that might result from the previous formatting run. - * - * [callback] is invoked once for each [LintError] found during any runs. As of that the [callback] might be invoked multiple times for - * the same [LintError]. - * - * @throws KtLintParseException if text is not a valid Kotlin code - * @throws KtLintRuleException in case of internal failure caused by a bug in rule implementation - */ - @Deprecated(message = "Marked for removal in Ktlint 2.0") - public fun format( - code: Code, - callback: (LintError, Boolean) -> Unit = { _, _ -> }, - ): String = codeFormatter.format(code, AllAutocorrectHandler, callback, MAX_FORMAT_RUNS_PER_FILE) - - /** * Formats style violations in [code]. Whenever a [LintError] is found the [callback] is invoked. If the [LintError] can be * autocorrected, the API Consumer determines whether that [LintError] is to autocorrected, or not. * @@ -138,7 +118,7 @@ ): String = codeFormatter.format( code = code, - autocorrectHandler = LintErrorAutocorrectHandler(defaultAutocorrect, callback), + autocorrectHandler = LintErrorAutocorrectHandler(callback), maxFormatRunsPerFile = if (rerunAfterAutocorrect) { MAX_FORMAT_RUNS_PER_FILE
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtlintRuleEngineSuppression.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtlintRuleEngineSuppression.kt index ba8ce4b..e7a926b 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtlintRuleEngineSuppression.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/KtlintRuleEngineSuppression.kt
@@ -1,7 +1,7 @@ package com.pinterest.ktlint.rule.engine.api import com.pinterest.ktlint.rule.engine.core.api.RuleId -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.internal.RuleExecutionContext import com.pinterest.ktlint.rule.engine.internal.insertKtlintRuleSuppression @@ -43,7 +43,7 @@ is KtlintSuppressionAtOffset -> { findLeafElementAt(suppression.offsetFromStartOf(text)) ?.let { - if (it.isWhiteSpace20) { + if (it.isWhiteSpace) { // A suppression can not be added at a whitespace element. Insert it at the parent instead it.parent } else {
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/AutocorrectHandler.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/AutocorrectHandler.kt index 3a14e16..b6e1cca 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/AutocorrectHandler.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/AutocorrectHandler.kt
@@ -2,7 +2,6 @@ import com.pinterest.ktlint.rule.engine.api.LintError import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision -import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision.ALLOW_AUTOCORRECT import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision.NO_AUTOCORRECT /** @@ -19,16 +18,7 @@ override fun autocorrectDecision(lintError: LintError) = NO_AUTOCORRECT } -/** - * Autocorrect all [LintError]s - */ -internal data object AllAutocorrectHandler : AutocorrectHandler { - override fun autocorrectDecision(lintError: LintError) = ALLOW_AUTOCORRECT -} - internal class LintErrorAutocorrectHandler( - // TODO: remove unused variable autocorrectRuleWithoutAutocorrectApproveHandler - val autocorrectRuleWithoutAutocorrectApproveHandler: Boolean, private val callback: (LintError) -> AutocorrectDecision, ) : AutocorrectHandler { override fun autocorrectDecision(lintError: LintError) = callback(lintError)
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/KtlintSuppression.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/KtlintSuppression.kt index 21a1378..9cba95d 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/KtlintSuppression.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/KtlintSuppression.kt
@@ -26,13 +26,13 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_PARAMETER_LIST import com.pinterest.ktlint.rule.engine.core.api.KtlintKotlinCompiler import com.pinterest.ktlint.rule.engine.core.api.findChildByTypeRecursively -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isRoot +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.replaceWith import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -159,8 +159,8 @@ // moved to the next list element. When no such element is found, it will be moved to the parent of the list type targetPsiElement .node - .nextCodeSibling20 - ?.firstChildLeafOrSelf20 + .nextCodeSibling + ?.firstChildLeafOrSelf ?.psi } @@ -178,7 +178,7 @@ private fun PsiElement.isIgnorableListElement() = node .takeIf { it.parent?.elementType in listTypeTokenSet } - ?.let { it.elementType == COMMA || it.isWhiteSpace20 || it.isPartOfComment20 } + ?.let { it.elementType == COMMA || it.isWhiteSpace || it.isPartOfComment } ?: false /** @@ -220,7 +220,7 @@ } private fun ASTNode.findSuppressionAnnotations(): Map<SuppressAnnotationType, ASTNode> = - if (isRoot20) { + if (isRoot) { findChildByType(FILE_ANNOTATION_LIST) ?.toMapOfSuppressionAnnotations() .orEmpty() @@ -288,7 +288,7 @@ } is KtClass, is KtFunction, is KtProperty, is KtPropertyAccessor -> { - this.addChild(PsiWhiteSpaceImpl(indent20), this.firstChildNode) + this.addChild(PsiWhiteSpaceImpl(indent), this.firstChildNode) val modifierListWithAnnotation = createModifierListWithAnnotationEntry(suppressType, suppressions) this.addChild(modifierListWithAnnotation, this.firstChildNode) } @@ -303,7 +303,7 @@ } else { val modifierListWithAnnotation = createModifierListWithAnnotationEntry(suppressType, suppressions) parent!!.addChild(modifierListWithAnnotation.findChildByType(ANNOTATION_ENTRY)!!, this) - parent!!.addChild(PsiWhiteSpaceImpl(indent20), this) + parent!!.addChild(PsiWhiteSpaceImpl(indent), this) } } } @@ -326,7 +326,7 @@ } private fun ASTNode.createFileAnnotationList(annotation: ASTNode) { - require(isRoot20) { "File annotation list can only be created for root node" } + require(isRoot) { "File annotation list can only be created for root node" } // Should always be inserted into the first (root) code child regardless in which root node the ktlint directive // was actually found findChildByType(PACKAGE_DIRECTIVE) @@ -336,7 +336,7 @@ ?.addChild(annotation, packageDirective) packageDirective .parent - ?.addChild(PsiWhiteSpaceImpl("\n" + indent20), packageDirective) + ?.addChild(PsiWhiteSpaceImpl("\n" + indent), packageDirective) } }
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/RuleExecutionContext.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/RuleExecutionContext.kt index b1217cd..43f52cb 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/RuleExecutionContext.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/RuleExecutionContext.kt
@@ -187,18 +187,6 @@ } } - // Simplify the emitAndApprove to an emit only lambda which can be used in the legacy (deprecated) functions - @Deprecated(message = "Remove in Ktlint 2.0") - private fun ((offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision).onlyEmit() = - { - offset: Int, - errorMessage: String, - canBeAutoCorrected: Boolean, - -> - this(offset, errorMessage, canBeAutoCorrected) - Unit - } - companion object { internal fun createRuleExecutionContext( ktLintRuleEngine: KtLintRuleEngine, @@ -233,12 +221,6 @@ ktLintRuleEngine .editorConfigLoader .load(code.filePath) - .also { - // TODO: Remove warning below in KtLint 0.52 or later as some users skips multiple versions - it.warnIfPropertyIsObsolete("disabled_rules", "0.49") - // TODO: Remove warning below in KtLint 0.52 or later as some users skips multiple versions - it.warnIfPropertyIsObsolete("ktlint_disabled_rules", "0.49") - } val ruleProviders = ktLintRuleEngine @@ -277,18 +259,6 @@ } } -private fun EditorConfig.warnIfPropertyIsObsolete( - propertyName: String, - ktlintVersion: String, -) { - if (this.contains(propertyName)) { - LOGGER.warn { - "Editorconfig property '$propertyName' is obsolete and is not used by KtLint starting from version $ktlintVersion. Remove " + - "the property from all '.editorconfig' files." - } - } -} - private class RuleExecutionException( val rule: RuleV2, val line: Int,
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt index 58afde2..6fcc59f 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocator.kt
@@ -10,10 +10,10 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleV2 import com.pinterest.ktlint.rule.engine.core.api.TokenSets import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig -import com.pinterest.ktlint.rule.engine.core.api.isKtAnnotated20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isKtAnnotated +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.recursiveChildren20 +import com.pinterest.ktlint.rule.engine.core.api.recursiveChildren import com.pinterest.ktlint.rule.engine.internal.SuppressionLocator.CommentSuppressionHint.Type.BLOCK_END import com.pinterest.ktlint.rule.engine.internal.SuppressionLocator.CommentSuppressionHint.Type.BLOCK_START import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -59,7 +59,7 @@ private fun findSuppressionHints(rootNode: ASTNode): List<SuppressionHint> { val suppressionHints = ArrayList<SuppressionHint>() val commentSuppressionsHints = mutableListOf<CommentSuppressionHint>() - rootNode.recursiveChildren20.forEach { node -> + rootNode.recursiveChildren.forEach { node -> when (node.elementType) { in TokenSets.COMMENTS -> { node @@ -142,7 +142,7 @@ if (rbraceOfContainingBlock == null) { // Apply suppression on next sibling only, when the outer element does not end with a RBRACE it.node - .nextSibling20 + .nextSibling .let { nextSibling -> SuppressionHint( IntRange( @@ -178,7 +178,7 @@ private fun ASTNode.createSuppressionHintFromAnnotations(): SuppressionHint? { val suppressedRuleIds = - recursiveChildren20 + recursiveChildren .filter { it.elementType == VALUE_ARGUMENT } .flatMapTo(mutableListOf()) { it.text.removeSurrounding("\"").findRuleSuppressionIds() @@ -186,7 +186,7 @@ if (suppressedRuleIds.isEmpty()) return null - val owner = parent { it.isKtAnnotated20 } ?: return null + val owner = parent { it.isKtAnnotated } ?: return null val textRange = owner.textRange @@ -211,8 +211,7 @@ // Disable specific rule. For backwards compatibility prefix rules without rule set id with the "standard" rule set // id. Note that the KtlintSuppressionRule will emit a lint violation on the id. So this fix is only applicable for // code bases in which the rule and suppression id's have not yet been fixed. - removePrefix("ktlint:") - .let { listOf(RuleId.prefixWithStandardRuleSetIdWhenMissing(it)) } + listOf(removePrefix("ktlint:")) } else -> {
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/rules/KtlintSuppressionRule.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/rules/KtlintSuppressionRule.kt index 62e115b..17ba917 100644 --- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/rules/KtlintSuppressionRule.kt +++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/internal/rules/KtlintSuppressionRule.kt
@@ -25,8 +25,8 @@ import com.pinterest.ktlint.rule.engine.core.api.findChildByTypeRecursively import com.pinterest.ktlint.rule.engine.core.api.findParentByType import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent @@ -130,7 +130,7 @@ private fun ASTNode.removePrecedingWhitespace() { prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.remove() } @@ -148,7 +148,7 @@ ) { when (ktlintDirectiveType) { KTLINT_DISABLE -> { - if (node.elementType == EOL_COMMENT && node.prevLeaf.isWhiteSpaceWithNewline20) { + if (node.elementType == EOL_COMMENT && node.prevLeaf.isWhiteSpaceWithNewline) { removeDanglingEolCommentWithKtlintDisableDirective(emit) } else { visitKtlintDisableDirective(emit) @@ -208,7 +208,7 @@ if (node.elementType == EOL_COMMENT) { node.removePrecedingWhitespace() } else { - if (node.nextLeaf.isWhiteSpaceWithNewline20) { + if (node.nextLeaf.isWhiteSpaceWithNewline) { node .nextLeaf ?.remove() @@ -282,7 +282,7 @@ matchingKtlintEnabledDirective != node .parent - ?.nextSibling { !it.isWhiteSpace20 } + ?.nextSibling { !it.isWhiteSpace } } ?: false }
diff --git a/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintTest.kt b/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintTest.kt index 1b1b48d..e12dcb9 100644 --- a/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintTest.kt +++ b/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/api/KtLintTest.kt
@@ -25,7 +25,7 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.END_OF_LINE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 +import com.pinterest.ktlint.rule.engine.core.api.isRoot import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import org.assertj.core.api.Assertions.assertThat import org.ec4j.core.model.PropertyType @@ -50,7 +50,7 @@ setOf( RuleV2InstanceProvider { DummyRule { node -> - if (node.isRoot20) { + if (node.isRoot) { numberOfRootNodesVisited++ } } @@ -116,7 +116,7 @@ setOf( RuleV2InstanceProvider { DummyRule { node -> - if (node.isRoot20) { + if (node.isRoot) { numberOfRootNodesVisited++ } } @@ -562,7 +562,7 @@ private val ASTNode.visitNodeType: RuleExecutionCall.VisitNodeType get() = - if (isRoot20) { + if (isRoot) { ROOT } else { CHILD
diff --git a/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocatorTest.kt b/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocatorTest.kt index dc4d1a2..7d0e747 100644 --- a/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocatorTest.kt +++ b/ktlint-rule-engine/src/test/kotlin/com/pinterest/ktlint/rule/engine/internal/SuppressionLocatorTest.kt
@@ -70,7 +70,7 @@ fun `Given that a NoFooIdentifierRule violation is suppressed with @Suppress at statement level for a specific rule then do not find a violation for that rule`() { val code = """ - @Suppress("ktlint:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") + @Suppress("ktlint:standard:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") val fooNotReported = "foo" val fooReported = "foo" @@ -85,7 +85,7 @@ fun `Given that a NoFooIdentifierRule violation is suppressed with @Suppress at function level then do not find a violation for that rule in that function`() { val code = """ - @Suppress("ktlint:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") + @Suppress("ktlint:standard:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") fun foo() { val fooNotReported = "foo" } @@ -119,7 +119,7 @@ fun `Given that a NoFooIdentifierRule violation is suppressed with @Suppress at class level then do not find a violation for that rule in that class`() { val code = """ - @Suppress("ktlint:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") + @Suppress("ktlint:standard:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") class Foo { fun foo() { val fooNotReported = "foo" @@ -151,7 +151,7 @@ fun `Given that the NoFooIdentifierRule is suppressed in the entire file with @file-colon-Suppress then do not find any NoFooIdentifierRule violation`() { val code = """ - @file:Suppress("ktlint:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") + @file:Suppress("ktlint:standard:no-foo-identifier-standard", "ktlint:$NON_STANDARD_RULE_SET_ID:no-foo-identifier") class Foo { fun foo() { @@ -341,7 +341,15 @@ val actual = lint(code = code, ignoreKtlintSuppressionRule = false) @Suppress("ktlint:standard:max-line-length") assertThat(actual) - .containsExactly(LintError(1, 17, KTLINT_SUPPRESSION_RULE_ID, "Ktlint rule with id 'ktlint:internal:ktlint-suppression' is unknown or not loaded", false)) + .containsExactly( + LintError( + 1, + 17, + KTLINT_SUPPRESSION_RULE_ID, + "Ktlint rule with id 'ktlint:internal:ktlint-suppression' is unknown or not loaded", + false, + ), + ) } @Test @@ -353,8 +361,20 @@ val actual = lint(code = code, ignoreKtlintSuppressionRule = false) @Suppress("ktlint:standard:max-line-length") assertThat(actual).containsExactly( - LintError(1, 4, KTLINT_SUPPRESSION_RULE_ID, "Directive 'ktlint-disable' is deprecated. Replace with @Suppress annotation", true), - LintError(1, 19, KTLINT_SUPPRESSION_RULE_ID, "Ktlint rule with id 'internal:ktlint-suppression' is unknown or not loaded", false), + LintError( + 1, + 4, + KTLINT_SUPPRESSION_RULE_ID, + "Directive 'ktlint-disable' is deprecated. Replace with @Suppress annotation", + true, + ), + LintError( + 1, + 19, + KTLINT_SUPPRESSION_RULE_ID, + "Ktlint rule with id 'internal:ktlint-suppression' is unknown or not loaded", + false, + ), ) } @@ -370,8 +390,20 @@ .containsExactly( lintError(1, 5, "standard:no-foo-identifier-standard"), lintError(1, 5, "$NON_STANDARD_RULE_SET_ID:no-foo-identifier"), - LintError(1, 20, KTLINT_SUPPRESSION_RULE_ID, "Directive 'ktlint-disable' is deprecated. Replace with @Suppress annotation", true), - LintError(1, 35, KTLINT_SUPPRESSION_RULE_ID, "Ktlint rule with id 'internal:ktlint-suppression' is unknown or not loaded", false), + LintError( + 1, + 20, + KTLINT_SUPPRESSION_RULE_ID, + "Directive 'ktlint-disable' is deprecated. Replace with @Suppress annotation", + true, + ), + LintError( + 1, + 35, + KTLINT_SUPPRESSION_RULE_ID, + "Ktlint rule with id 'internal:ktlint-suppression' is unknown or not loaded", + false, + ), ) } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt index bc53894..40fa5e4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationRule.kt
@@ -27,7 +27,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CommaSeparatedListValueParser @@ -35,20 +35,20 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -173,7 +173,7 @@ } node - .children20 + .children .filter { it.elementType == ANNOTATION_ENTRY } .filter { it.isAnnotationEntryWithValueArgumentListThatShouldBeWrapped() || @@ -190,7 +190,7 @@ index == 0 && codeStyle == CodeStyleValue.ktlint_official && it.annotationOnSameLineAsClosingParenthesisOfClassParameterList() - }?.takeUnless { it.isWhiteSpaceWithNewline20 } + }?.takeUnless { it.isWhiteSpaceWithNewline } ?.let { prevLeaf -> emit(prevLeaf.startOffset, "Expected newline before annotation", true) .ifAutocorrectAllowed { @@ -207,12 +207,12 @@ } node - .children20 + .children .lastOrNull { it.elementType == ANNOTATION_ENTRY } - ?.lastChildLeafOrSelf20 + ?.lastChildLeafOrSelf ?.nextCodeLeaf ?.prevLeaf - ?.takeUnless { it.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.isWhiteSpaceWithNewline } ?.let { prevLeaf -> // Let the indentation rule determine the exact indentation and only report and fix when the line needs to be wrapped emit(prevLeaf.startOffset, "Expected newline after last annotation", true) @@ -223,16 +223,16 @@ node .takeIf { it.elementType == ANNOTATED_EXPRESSION } - ?.takeUnless { it.nextCodeSibling20?.elementType == OPERATION_REFERENCE } - ?.lastChildLeafOrSelf20 + ?.takeUnless { it.nextCodeSibling?.elementType == OPERATION_REFERENCE } + ?.lastChildLeafOrSelf ?.nextCodeLeaf ?.prevLeaf - ?.takeUnless { it.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.isWhiteSpaceWithNewline } ?.let { leaf -> // Let the indentation rule determine the exact indentation and only report and fix when the line needs to be wrapped emit(leaf.startOffset, "Expected newline", true) .ifAutocorrectAllowed { - leaf.upsertWhitespaceBeforeMe(node.indent20) + leaf.upsertWhitespaceBeforeMe(node.indent) } } } @@ -245,7 +245,7 @@ private fun ASTNode.hasAnnotationWithParameter(): Boolean { require(elementType in ANNOTATION_CONTAINER) - return children20 + return children .any { it.isAnnotationEntryWithValueArgumentListThatShouldBeWrapped() && it.parent?.parent?.elementType != VALUE_PARAMETER && @@ -256,7 +256,7 @@ private fun ASTNode.hasMultipleAnnotationsOnSameLine(): Boolean { require(elementType in ANNOTATION_CONTAINER) - return children20 + return children .any { it.parent?.elementType != ANNOTATION && it.parent?.parent?.elementType != VALUE_PARAMETER && @@ -274,16 +274,16 @@ private fun ASTNode.hasAnnotationBeforeConstructor() = codeStyle == CodeStyleValue.ktlint_official && hasAnnotationEntry() && - nextCodeSibling20?.elementType == CONSTRUCTOR_KEYWORD + nextCodeSibling?.elementType == CONSTRUCTOR_KEYWORD - private fun ASTNode.hasAnnotationEntry() = children20.any { it.elementType == ANNOTATION_ENTRY } + private fun ASTNode.hasAnnotationEntry() = children.any { it.elementType == ANNOTATION_ENTRY } private fun visitTypeArgumentList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == TYPE_PROJECTION } .mapNotNull { it.findChildByType(TYPE_REFERENCE) } .filter { it.elementType == TYPE_REFERENCE } @@ -298,11 +298,11 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == TYPE_PROJECTION } .forEach { typeProjection -> - val prevLeaf = typeProjection.prevLeaf.takeIf { it.isWhiteSpace20 } - if (prevLeaf == null || prevLeaf.isWhiteSpaceWithoutNewline20) { + val prevLeaf = typeProjection.prevLeaf.takeIf { it.isWhiteSpace } + if (prevLeaf == null || prevLeaf.isWhiteSpaceWithoutNewline) { emit(typeProjection.startOffset - 1, "Expected newline", true) .ifAutocorrectAllowed { typeProjection.upsertWhitespaceBeforeMe(indentConfig.childIndentOf(node)) @@ -313,8 +313,8 @@ node .findChildByType(GT) ?.let { gt -> - val prevLeaf = gt.prevLeaf.takeIf { it.isWhiteSpace20 } - if (prevLeaf == null || prevLeaf.isWhiteSpaceWithoutNewline20) { + val prevLeaf = gt.prevLeaf.takeIf { it.isWhiteSpace } + if (prevLeaf == null || prevLeaf.isWhiteSpaceWithoutNewline) { emit(gt.startOffset, "Expected newline", true) .ifAutocorrectAllowed { gt.upsertWhitespaceBeforeMe(indentConfig.childIndentOf(node)) @@ -339,7 +339,7 @@ true, ).ifAutocorrectAllowed { node - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .upsertWhitespaceBeforeMe(getNewlineWithIndent(node.parent!!)) } } @@ -349,7 +349,7 @@ val firstAnnotation = parent?.findChildByType(ANNOTATION_ENTRY) return siblings(forward = false) .takeWhile { it != firstAnnotation } - .any { it.isWhiteSpaceWithNewline20 } + .any { it.isWhiteSpaceWithNewline } } private fun ASTNode.isNotReceiverTargetAnnotation() = getAnnotationUseSiteTarget() != AnnotationUseSiteTarget.RECEIVER @@ -393,17 +393,17 @@ private fun ASTNode.isLastAnnotationEntry() = this == parent - ?.children20 + ?.children ?.lastOrNull { it.elementType == ANNOTATION_ENTRY } private fun ASTNode.isPrecededByOtherAnnotationEntryWithoutParametersOnTheSameLine() = siblings(forward = false) - .takeWhile { !it.isWhiteSpaceWithNewline20 && !it.isAnnotationEntryWithValueArgumentListThatShouldBeWrapped() } + .takeWhile { !it.isWhiteSpaceWithNewline && !it.isAnnotationEntryWithValueArgumentListThatShouldBeWrapped() } .any { it.elementType == ANNOTATION_ENTRY && !it.isAnnotationEntryWithValueArgumentListThatShouldBeWrapped() } private fun ASTNode.isPrecededByOtherAnnotationEntryOnTheSameLine() = siblings(forward = false) - .takeWhile { !it.isWhiteSpaceWithNewline20 } + .takeWhile { !it.isWhiteSpaceWithNewline } .any { it.elementType == ANNOTATION_ENTRY } private fun ASTNode.isPrecededByOtherAnnotationEntry() = @@ -413,7 +413,7 @@ private fun ASTNode.isOnSameLineAsPreviousAnnotationEntry() = siblings(forward = false) .takeWhile { it.elementType != ANNOTATION_ENTRY } - .none { it.isWhiteSpaceWithNewline20 } + .none { it.isWhiteSpaceWithNewline } private fun ASTNode.isFollowedByOtherAnnotationEntry() = siblings(forward = true).any { it.elementType == ANNOTATION_ENTRY } @@ -425,28 +425,28 @@ // FooBar() this ?.takeIf { it.parent?.elementType == CLASS } - ?.prevCodeSibling20 + ?.prevCodeSibling ?.takeIf { it.elementType == COLON } ?.prevCodeLeaf ?.takeIf { it.elementType == RPAR } ?.prevLeaf - ?.isWhiteSpaceWithNewline20 + ?.isWhiteSpaceWithNewline ?: false private fun ASTNode.isOnSameLineAsNextAnnotationEntry() = siblings(forward = true) .takeWhile { it.elementType != ANNOTATION_ENTRY } - .none { it.isWhiteSpaceWithNewline20 } + .none { it.isWhiteSpaceWithNewline } private fun visitFileAnnotationList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .nextCodeLeaf ?.let { codeLeaf -> - val whitespaceBefore = codeLeaf.prevLeaf { it.isWhiteSpace20 } + val whitespaceBefore = codeLeaf.prevLeaf { it.isWhiteSpace } if (whitespaceBefore == null || whitespaceBefore.text != "\n\n") { emit( @@ -484,7 +484,7 @@ val nodeBeforeAnnotations = modifierListRoot .parent - ?.prevSibling20 + ?.prevSibling // Make sure we only insert a single newline val indentWithoutNewline = nodeBeforeAnnotations
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt index ab57479..b7188d7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/AnnotationSpacingRule.kt
@@ -8,16 +8,15 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.endOffset20 +import com.pinterest.ktlint.rule.engine.core.api.endOffset import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove @@ -67,50 +66,50 @@ // val s: Any // val whiteSpaces = - (annotations.asSequence().map { it.nextSibling20 } + node.nextSibling20) + (annotations.asSequence().map { it.nextSibling } + node.nextSibling) .filterNotNull() - .filter { it.isWhiteSpace20 } + .filter { it.isWhiteSpace } .take(annotations.size) .toList() val next = node.nextSiblingWithAtLeastOneOf( { - !it.isWhiteSpace20 && + !it.isWhiteSpace && it.textLength > 0 && !it.isPartOf(FILE_ANNOTATION_LIST) && !it.isCommentOnSameLineAsPrevLeaf() }, { // Disallow multiple white spaces as well as comments - if (it.isWhiteSpace20) { + if (it.isWhiteSpace) { val s = it.text // Ensure at least one occurrence of two line breaks s.indexOf("\n") != s.lastIndexOf("\n") } else { - it.isPartOfComment20 && !it.isCommentOnSameLineAsPrevLeaf() + it.isPartOfComment && !it.isCommentOnSameLineAsPrevLeaf() } }, ) if (next != null) { - if (node.elementType != FILE_ANNOTATION_LIST && next.isPartOfComment20) { - emit(node.endOffset20, ERROR_MESSAGE, true) + if (node.elementType != FILE_ANNOTATION_LIST && next.isPartOfComment) { + emit(node.endOffset, ERROR_MESSAGE, true) .ifAutocorrectAllowed { // Special-case autocorrection when the annotation is separated from the annotated construct // by a comment: we need to swap the order of the comment and the annotation // Remove the annotation and the following whitespace val eolComment = node.nextSibling { it.isCommentOnSameLineAsPrevLeaf() } if (eolComment != null) { - eolComment.prevSibling { it.isWhiteSpace20 }?.remove() - eolComment.nextSibling { it.isWhiteSpace20 }?.remove() + eolComment.prevSibling { it.isWhiteSpace }?.remove() + eolComment.nextSibling { it.isWhiteSpace }?.remove() eolComment.remove() } else { - node.nextSibling { it.isWhiteSpace20 }?.remove() + node.nextSibling { it.isWhiteSpace }?.remove() } node.remove() // Insert the annotation prior to the annotated construct - val beforeAnchor = next.nextCodeSibling20 + val beforeAnchor = next.nextCodeSibling next .parent!! .apply { @@ -125,7 +124,7 @@ } } if (node.elementType != FILE_ANNOTATION_LIST && whiteSpaces.any { it.containsMultipleNewlines() }) { - emit(node.endOffset20, ERROR_MESSAGE, true) + emit(node.endOffset, ERROR_MESSAGE, true) .ifAutocorrectAllowed { removeIntraLineBreaks(node, annotations.last()) removeExtraLineBreaks(node) @@ -139,7 +138,7 @@ p: (ASTNode) -> Boolean, needsToOccur: (ASTNode) -> Boolean, ): ASTNode? { - var node = this.nextSibling20 + var node = this.nextSibling var occurrenceCount = 0 while (node != null) { if (needsToOccur(node)) { @@ -152,7 +151,7 @@ null } } - node = node.nextSibling20 + node = node.nextSibling } return null } @@ -160,7 +159,7 @@ private fun removeExtraLineBreaks(node: ASTNode) { val next = node.nextSibling { - it.isWhiteSpaceWithNewline20 + it.isWhiteSpaceWithNewline } as? LeafPsiElement if (next != null) { rawReplaceExtraLineBreaks(next) @@ -184,7 +183,7 @@ ) { // Pull the next before raw replace, or it will blow up val nextLeaf = fromNode.nextLeaf - if (fromNode.isWhiteSpace20) { + if (fromNode.isWhiteSpace) { if (fromNode.text.toCharArray().count { it == '\n' } > 1) { rawReplaceExtraLineBreaks(fromNode) } @@ -196,7 +195,7 @@ } private fun ASTNode.isCommentOnSameLineAsPrevLeaf() = - isPartOfComment20 && leaves(forward = false).takeWhile { it.isWhiteSpace20 }.none { "\n" in it.text } + isPartOfComment && leaves(forward = false).takeWhile { it.isWhiteSpace }.none { "\n" in it.text } } public val ANNOTATION_SPACING_RULE_ID: RuleId = AnnotationSpacingRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt index 78c7068..f16ae1a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ArgumentListWrappingRule.kt
@@ -22,16 +22,16 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith @@ -96,7 +96,7 @@ private fun needToWrapArgumentList(node: ASTNode) = if ( // skip when there are no arguments - node.firstChildNode?.nextSibling20?.elementType != RPAR && + node.firstChildNode?.nextSibling?.elementType != RPAR && // skip lambda arguments node.parent?.elementType != FUNCTION_LITERAL && // skip if number of arguments is big @@ -114,9 +114,9 @@ private fun ASTNode.exceedsMaxLineLength(): Boolean { if (textContains('\n')) return false require(this.elementType == VALUE_ARGUMENT_LIST) - val stopAtLeaf = findChildByType(RPAR)?.firstChildLeafOrSelf20 + val stopAtLeaf = findChildByType(RPAR)?.firstChildLeafOrSelf return hasNoMaxLineLengthSuppression() && - maxLineLength < leavesOnLine20.takeWhile { it.prevLeaf != stopAtLeaf }.lineLength + maxLineLength < leavesOnLine.takeWhile { it.prevLeaf != stopAtLeaf }.lineLength } private fun intendedIndent(child: ASTNode): String = @@ -181,7 +181,7 @@ child .prevLeaf ?.let { prevLeaf -> - if (prevLeaf.isWhiteSpaceWithNewline20) { + if (prevLeaf.isWhiteSpaceWithNewline) { emit(child.startOffset, errorMessage(child), true) .ifAutocorrectAllowed { prevLeaf.psi.delete() @@ -200,13 +200,13 @@ val intendedIndent = intendedIndent(child) val prevLeaf = child.prevWhiteSpaceWithNewLine() ?: child.prevLeaf when { - prevLeaf.isWhiteSpaceWithNewline20 -> { + prevLeaf.isWhiteSpaceWithNewline -> { // The current child is already wrapped to a new line. Checking and fixing the // correct size of the indent is the responsibility of the IndentationRule. return } - prevLeaf.isWhiteSpace20 -> { + prevLeaf.isWhiteSpace -> { // The current child needs to be wrapped to a newline. emit(child.startOffset, errorMessage(child), true) .ifAutocorrectAllowed { @@ -246,7 +246,7 @@ child.isValueArgumentContaining(char) } - private fun ASTNode.isWhitespaceContaining(char: Char) = isWhiteSpace20 && textContains(char) + private fun ASTNode.isWhitespaceContaining(char: Char) = isWhiteSpace && textContains(char) private fun ASTNode.isCollectionLiteralContaining(char: Char) = elementType == COLLECTION_LITERAL_EXPRESSION && textContains(char) @@ -257,7 +257,7 @@ parent ?.findChildByType(TYPE_ARGUMENT_LIST) ?.children() - ?.any { it.isWhiteSpaceWithNewline20 } == true + ?.any { it.isWhiteSpaceWithNewline } == true private fun ASTNode.isPartOfDotQualifiedAssignmentExpression(): Boolean = parent @@ -271,8 +271,8 @@ private fun ASTNode.prevWhiteSpaceWithNewLine(): ASTNode? { var prev = prevLeaf - while (prev != null && (prev.isWhiteSpace20 || prev.isPartOfComment20)) { - if (prev.isWhiteSpaceWithNewline20) { + while (prev != null && (prev.isWhiteSpace || prev.isPartOfComment)) { + if (prev.isWhiteSpaceWithNewline) { return prev } prev = prev.prevLeaf @@ -283,7 +283,7 @@ private fun ASTNode.isOnSameLineAsControlFlowKeyword(): Boolean { var prevLeaf = prevLeaf ?: return false while (prevLeaf.elementType !in TokenSets.CONTROL_FLOW_KEYWORDS) { - if (prevLeaf.isWhiteSpaceWithNewline20) return false + if (prevLeaf.isWhiteSpaceWithNewline) return false prevLeaf = prevLeaf.prevLeaf ?: return false } return true
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt index 43d9c50..17131f3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BackingPropertyNamingRule.kt
@@ -18,7 +18,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.android_studio import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -130,7 +130,7 @@ } private fun ASTNode.findPropertyWithName(name: String) = - children20 + children .filter { it.elementType == PROPERTY } .mapNotNull { it.findChildByType(IDENTIFIER) } .firstOrNull { it.text == name } @@ -140,7 +140,7 @@ parent ?.takeIf { it.elementType == OBJECT_DECLARATION } ?.findChildByType(MODIFIER_LIST) - ?.children20 + ?.children ?.firstOrNull { it.elementType == COMPANION_KEYWORD } private fun ASTNode.findCorrelatedFunction(): ASTNode? { @@ -158,7 +158,7 @@ } private fun ASTNode.findFunctionWithName(name: String) = - children20 + children .filter { it.elementType == FUN } .filter { it.hasNonEmptyParameterList() } .mapNotNull { it.findChildByType(IDENTIFIER) } @@ -167,7 +167,7 @@ private fun ASTNode.hasNonEmptyParameterList() = findChildByType(VALUE_PARAMETER_LIST) - ?.children20 + ?.children ?.none { it.elementType == VALUE_PARAMETER } ?: false
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt index 44cda4e..34351ce 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BinaryExpressionWrappingRule.kt
@@ -21,24 +21,24 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.dropTrailingEolComment import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isLeaf20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isLeaf +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.noNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -98,7 +98,7 @@ ?.takeIf { binaryExpression -> binaryExpression .prevSibling { it.elementType == EQ } - ?.let { noNewLineInClosedRange(it, binaryExpression.firstChildLeafOrSelf20) } + ?.let { noNewLineInClosedRange(it, binaryExpression.firstChildLeafOrSelf) } ?: false }?.takeIf { it.isOnLineExceedingMaxLineLength() } ?.let { expression -> @@ -127,7 +127,7 @@ // "tooLongToFitOnSingleLine" + // "bar", // ) - node.prevLeaf.isWhiteSpaceWithNewline20 + node.prevLeaf.isWhiteSpaceWithNewline }?.takeIf { it.causesMaxLineLengthToBeExceeded() } ?.let { expression -> emit( @@ -141,8 +141,8 @@ // When left hand side is a call expression which causes the max line length to be exceeded then first wrap that expression node - .children20 - .firstOrNull { !it.isLeaf20 || !it.isCode } + .children + .firstOrNull { !it.isLeaf || !it.isCode } ?.takeIf { it.elementType == CALL_EXPRESSION } ?.takeIf { it.causesMaxLineLengthToBeExceeded() } ?.let { callExpression -> visitCallExpression(callExpression, emit) } @@ -161,8 +161,8 @@ // if (leftHandSideExpression && rightHandSideExpression) { parent ?.takeIf { it.elementType == CONDITION } - ?.lastChildLeafOrSelf20 - ?.nextLeaf { it.isWhiteSpaceWithNewline20 } + ?.lastChildLeafOrSelf + ?.nextLeaf { it.isWhiteSpaceWithNewline } ?.prevLeaf ?.causesMaxLineLengthToBeExceeded() ?: false @@ -211,7 +211,7 @@ // Allow: // val foo = "string too long to fit on the line" + // "more text" - it.nextSibling20.isWhiteSpaceWithNewline20 + it.nextSibling.isWhiteSpaceWithNewline }?.takeIf { it.parent?.elementType == BINARY_EXPRESSION } ?.takeIf { binaryExpression -> // Ignore binary expression inside raw string literals. Raw string literals are allowed to exceed max-line-length. Wrapping @@ -220,8 +220,8 @@ }?.let { operationReference -> if (operationReference.firstChildNode.elementType == ELVIS) { operationReference - .prevLeaf { it.isWhiteSpace20 } - .takeUnless { it.isWhiteSpaceWithNewline20 } + .prevLeaf { it.isWhiteSpace } + .takeUnless { it.isWhiteSpaceWithNewline } ?.let { // Wrapping after the elvis operator leads to violating the 'chain-wrapping' rule, so it must wrapped itself emit(operationReference.startOffset, "Line is exceeding max line length. Break line before '?:'", true) @@ -231,7 +231,7 @@ } } else { operationReference - .nextSibling20 + .nextSibling ?.let { nextSibling -> emit( nextSibling.startOffset, @@ -246,13 +246,13 @@ } private fun ASTNode.isOnLineExceedingMaxLineLength() = - hasNoMaxLineLengthSuppression() && maxLineLength < leavesOnLine20.dropTrailingEolComment().lineLength + hasNoMaxLineLengthSuppression() && maxLineLength < leavesOnLine.dropTrailingEolComment().lineLength private fun ASTNode.causesMaxLineLengthToBeExceeded() = hasNoMaxLineLengthSuppression() && - lastChildLeafOrSelf20 + lastChildLeafOrSelf .let { lastChildLeaf -> - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != lastChildLeaf } .lineLength
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt index b816ef0..5956d4d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt
@@ -21,14 +21,14 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isDeclaration20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isDeclaration +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -122,7 +122,7 @@ } if (node.elementType == FUN && - (node.prevCodeSibling20?.elementType == EQ || node.prevCodeSibling20?.elementType == RETURN_KEYWORD) + (node.prevCodeSibling?.elementType == EQ || node.prevCodeSibling?.elementType == RETURN_KEYWORD) ) { // Allow: // val foo = @@ -148,12 +148,12 @@ } node - .takeIf { it.isDeclaration20 } + .takeIf { it.isDeclaration } ?.takeUnless { it.prevLeaf.isBlankLine() } ?.let { insertBeforeNode -> emit(insertBeforeNode.startOffset, "Expected a blank line for this declaration", true) .ifAutocorrectAllowed { - insertBeforeNode.upsertWhitespaceBeforeMe("\n".plus(node.indent20)) + insertBeforeNode.upsertWhitespaceBeforeMe("\n".plus(node.indent)) } } } @@ -165,14 +165,14 @@ parent ?.takeIf { it.elementType == CLASS_BODY } ?.findChildByType(LBRACE) - ?.nextCodeSibling20 + ?.nextCodeSibling private fun ASTNode.isFirstCodeSiblingInBlock() = this == parent ?.takeIf { it.elementType == BLOCK } ?.findChildByType(LBRACE) - ?.nextCodeSibling20 + ?.nextCodeSibling private fun ASTNode.isFirstCodeSiblingInBodyOfFunctionLiteral() = this == @@ -181,12 +181,12 @@ ?.parent ?.takeIf { it.elementType == FUNCTION_LITERAL } ?.findChildByType(BLOCK) - ?.children20 + ?.children ?.firstOrNull { isCode } private fun ASTNode.isConsecutiveProperty() = takeIf { it.propertyRelated() } - ?.prevCodeSibling20 + ?.prevCodeSibling ?.let { it.propertyRelated() || it.parent!!.propertyRelated() } ?: false
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt index 979a0d7..7d4c4bf 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBetweenWhenConditions.kt
@@ -7,20 +7,20 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -74,7 +74,7 @@ emitAndApprove: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == WHEN_ENTRY } // Blank lines should only be added *between* when-conditions, so first when-condition is to be skipped .drop(1) @@ -82,7 +82,7 @@ whenEntry .prevCodeLeaf ?.leavesForwardsIncludingSelf - ?.takeWhile { !it.isWhiteSpaceWithNewline20 } + ?.takeWhile { !it.isWhiteSpaceWithNewline } ?.last() ?.nextLeaf ?.takeUnless { it.containsBlankLine() } @@ -92,39 +92,39 @@ "Add a blank line between all when-conditions in case at least one multiline when-condition is found in the statement", true, ).ifAutocorrectAllowed { - whitespaceBeforeWhenEntry.upsertWhitespaceBeforeMe("\n${whenEntry.indent20}") + whitespaceBeforeWhenEntry.upsertWhitespaceBeforeMe("\n${whenEntry.indent}") } } } } - private fun ASTNode.containsBlankLine(): Boolean = isWhiteSpace20 && text.count { it == '\n' } > 1 + private fun ASTNode.containsBlankLine(): Boolean = isWhiteSpace && text.count { it == '\n' } > 1 private fun ASTNode.hasAnyMultilineWhenCondition() = - children20 + children .any { it.elementType == WHEN_ENTRY && (it.textContains('\n') || it.isPrecededByComment()) } private fun ASTNode.isPrecededByComment(): Boolean { // Check if this when-entry is preceded by a comment on its own line - not a trailing comment on the previous when-entry - val prevNonWhitespace = prevSibling { !it.isWhiteSpace20 } - if (prevNonWhitespace?.isPartOfComment20 != true) return false + val prevNonWhitespace = prevSibling { !it.isWhiteSpace } + if (prevNonWhitespace?.isPartOfComment != true) return false // Found a comment before this when-entry, so check whether it's on its own line - val whitespaceBeforeComment = prevNonWhitespace.prevSibling { it.isWhiteSpace20 } + val whitespaceBeforeComment = prevNonWhitespace.prevSibling { it.isWhiteSpace } return whitespaceBeforeComment?.text?.contains('\n') == true } private fun ASTNode.findWhitespaceAfterPreviousCodeSibling() = - prevCodeSibling20 - ?.lastChildLeafOrSelf20 - ?.nextLeaf { it.isWhiteSpace20 } + prevCodeSibling + ?.lastChildLeafOrSelf + ?.nextLeaf { it.isWhiteSpace } private fun removeBlankLinesBetweenWhenConditions( node: ASTNode, emitAndApprove: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == WHEN_ENTRY } // Blank lines should only be removed *between* when-conditions, so first when-condition is to be skipped .drop(1)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CallExpressionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CallExpressionWrappingRule.kt index 89543a9..9c6097a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CallExpressionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CallExpressionWrappingRule.kt
@@ -1,7 +1,6 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision -import com.pinterest.ktlint.rule.engine.core.api.ElementType.ANNOTATION_ENTRY import com.pinterest.ktlint.rule.engine.core.api.ElementType.ARROW import com.pinterest.ktlint.rule.engine.core.api.ElementType.CALL_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.ElementType.FUNCTION_LITERAL @@ -9,18 +8,15 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.LAMBDA_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.ElementType.LBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.LPAR -import com.pinterest.ktlint.rule.engine.core.api.ElementType.MODIFIER_LIST import com.pinterest.ktlint.rule.engine.core.api.ElementType.RBRACE import com.pinterest.ktlint.rule.engine.core.api.ElementType.REFERENCE_EXPRESSION import com.pinterest.ktlint.rule.engine.core.api.ElementType.RPAR -import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.VALUE_ARGUMENT_LIST import com.pinterest.ktlint.rule.engine.core.api.IndentConfig import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.Companion.DEFAULT_INDENT_CONFIG import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.RuleV2 import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.children20 import com.pinterest.ktlint.rule.engine.core.api.dropTrailingEolComment import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY @@ -28,20 +24,17 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode -import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace -import org.jetbrains.kotlin.psi.psiUtil.parents @SinceKtlint("2.0", SinceKtlint.Status.EXPERIMENTAL) public class CallExpressionWrappingRule : @@ -94,17 +87,17 @@ emit: (Int, String, Boolean) -> AutocorrectDecision, ) { require(node.elementType == VALUE_ARGUMENT_LIST) - if (node.textContains('\n') || node.exceedsMaxLineLength(node.lastChildLeafOrSelf20)) { + if (node.textContains('\n') || node.exceedsMaxLineLength(node.lastChildLeafOrSelf)) { node .findChildByType(LPAR) - ?.takeUnless { it.nextSibling20.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.nextSibling.isWhiteSpaceWithNewline } ?.let { lpar -> emit(lpar.startOffset, "Expected new line after '('", true) .ifAutocorrectAllowed { lpar.upsertWhitespaceAfterMe(indentConfig.siblingIndentOf(lpar)) } } node .findChildByType(RPAR) - ?.takeUnless { it.prevSibling20.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.prevSibling.isWhiteSpaceWithNewline } ?.let { rbrace -> emit(rbrace.startOffset, "Expected new line before ')'", true) .ifAutocorrectAllowed { @@ -119,24 +112,24 @@ emit: (Int, String, Boolean) -> AutocorrectDecision, ) { require(node.elementType == LAMBDA_ARGUMENT) - if (node.textContains('\n') || node.exceedsMaxLineLength(node.lastChildLeafOrSelf20)) { + if (node.textContains('\n') || node.exceedsMaxLineLength(node.lastChildLeafOrSelf)) { val functionLiteral = node .findChildByType(LAMBDA_EXPRESSION) ?.findChildByType(FUNCTION_LITERAL) val arrow = functionLiteral?.findChildByType(ARROW) - if (arrow == null || node.exceedsMaxLineLength(arrow.lastChildLeafOrSelf20)) { + if (arrow == null || node.exceedsMaxLineLength(arrow.lastChildLeafOrSelf)) { // Arrow not found, or does not fit on the line. Wrap after brace functionLiteral ?.findChildByType(LBRACE) - .takeUnless { it?.nextSibling20.isWhiteSpaceWithNewline20 } + .takeUnless { it?.nextSibling.isWhiteSpaceWithNewline } ?.let { lbrace -> emit(lbrace.startOffset, "Expected new line after '{'", true) .ifAutocorrectAllowed { lbrace.upsertWhitespaceAfterMe(indentConfig.siblingIndentOf(lbrace)) } } } else { arrow - .takeUnless { it.nextSibling20.isWhiteSpaceWithNewline20 } + .takeUnless { it.nextSibling.isWhiteSpaceWithNewline } ?.let { emit(arrow.startOffset + 1, "Expected new line after '->'", true) .ifAutocorrectAllowed { arrow.upsertWhitespaceAfterMe(indentConfig.siblingIndentOf(arrow)) } @@ -144,7 +137,7 @@ } functionLiteral ?.findChildByType(RBRACE) - ?.takeUnless { it.prevSibling20.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.prevSibling.isWhiteSpaceWithNewline } ?.let { rbrace -> emit(rbrace.startOffset, "Expected new line before '}'", true) .ifAutocorrectAllowed { @@ -157,7 +150,7 @@ private fun ASTNode.exceedsMaxLineLength(stopAtLeaf: ASTNode): Boolean = hasNoMaxLineLengthSuppression() && maxLineLength < - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != stopAtLeaf } .lineLength
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt index 3d7e516..06b5fac 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainMethodContinuationRule.kt
@@ -30,7 +30,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.dropTrailingEolComment import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -38,22 +38,22 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove @@ -160,18 +160,18 @@ private fun ASTNode.isJavaClassReferenceExpression() = parent?.elementType == DOT_QUALIFIED_EXPRESSION && - prevCodeSibling20?.elementType == CLASS_LITERAL_EXPRESSION && - nextCodeSibling20?.elementType == REFERENCE_EXPRESSION && - nextCodeSibling20?.firstChildLeafOrSelf20?.text == "java" + prevCodeSibling?.elementType == CLASS_LITERAL_EXPRESSION && + nextCodeSibling?.elementType == REFERENCE_EXPRESSION && + nextCodeSibling?.firstChildLeafOrSelf?.text == "java" private fun ASTNode.isReferenceExpression(): Boolean = parent?.isNestedReferenceExpression() ?: false private fun ASTNode.isNestedReferenceExpression(): Boolean = elementType == DOT_QUALIFIED_EXPRESSION && - children20.first().let { it.elementType == REFERENCE_EXPRESSION || it.hasRightHandSideReferenceExpression() } && + children.first().let { it.elementType == REFERENCE_EXPRESSION || it.hasRightHandSideReferenceExpression() } && hasRightHandSideReferenceExpression() - private fun ASTNode.hasRightHandSideReferenceExpression() = children20.last().elementType == REFERENCE_EXPRESSION + private fun ASTNode.hasRightHandSideReferenceExpression() = children.last().elementType == REFERENCE_EXPRESSION private fun ChainedExpression.wrapBeforeChainOperator() = when { @@ -219,7 +219,7 @@ STRING_TEMPLATE == chainOperators .first() - .prevCodeSibling20 + .prevCodeSibling ?.elementType private fun ChainedExpression.exceedsMaxLineLength() = @@ -245,9 +245,9 @@ chainOperators .last() .startOfLambdaArgumentInCallExpressionOrNull() - ?: lastChildLeafOrSelf20.nextLeaf + ?: lastChildLeafOrSelf.nextLeaf hasNoMaxLineLengthSuppression() && - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != stopAtLeaf } .lineLength > maxLineLength @@ -256,7 +256,7 @@ private fun ASTNode.startOfLambdaArgumentInCallExpressionOrNull(): ASTNode? { require(elementType in chainOperatorTokenSet) - return nextCodeSibling20 + return nextCodeSibling ?.takeIf { it.elementType == CALL_EXPRESSION } ?.findChildByType(LAMBDA_ARGUMENT) ?.findChildByType(LAMBDA_EXPRESSION) @@ -264,7 +264,7 @@ ?.findChildByType(LBRACE) } - private fun ASTNode.isPrecededByComment() = parent?.children20?.any { it.isPartOfComment20 } ?: false + private fun ASTNode.isPrecededByComment() = parent?.children?.any { it.isPartOfComment } ?: false private fun insertWhiteSpaceBeforeChainOperator( chainOperator: ASTNode, @@ -275,7 +275,7 @@ .takeUnless { it?.isCode == true } .let { whiteSpaceOrComment -> when { - whiteSpaceOrComment?.isPartOfComment20 == true -> { + whiteSpaceOrComment?.isPartOfComment == true -> { // In a chained method containing comments before each method in the chain starts on a newline // Disallow: // fooBar @@ -286,7 +286,7 @@ } } - whiteSpaceOrComment == null || whiteSpaceOrComment.isWhiteSpaceWithoutNewline20 -> { + whiteSpaceOrComment == null || whiteSpaceOrComment.isWhiteSpaceWithoutNewline -> { // In a multiline chained method each method in the chain starts on a newline // Disallow: // fooBar @@ -301,7 +301,7 @@ } private fun ASTNode.shouldBeOnSameLineAsClosingElementOfPreviousExpressionInMethodChain() = - prevLeaf { !it.isWhiteSpace20 } + prevLeaf { !it.isWhiteSpace } ?.takeIf { it.elementType in groupClosingElementType } ?.let { closingElement -> closingElement.isPrecededByNewline() || @@ -311,13 +311,13 @@ private fun ASTNode.isPrecededByNewline() = prevLeaf - ?.isWhiteSpaceWithNewline20 + ?.isWhiteSpaceWithNewline ?: false private fun ASTNode.isPartOfMultilineStringTemplate() = parent ?.takeIf { it.elementType == STRING_TEMPLATE } - ?.children20 + ?.children ?.any { it.text == "\n" } ?: false @@ -327,7 +327,7 @@ ) { chainOperator .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } .let { whiteSpaceOrComment -> // Disallow: // bar { @@ -339,7 +339,7 @@ // some text // """ // .trimIndent() - if (whiteSpaceOrComment.isWhiteSpaceWithNewline20) { + if (whiteSpaceOrComment.isWhiteSpaceWithNewline) { emit(chainOperator.startOffset, "Unexpected newline before '${chainOperator.text}'", true) .ifAutocorrectAllowed { whiteSpaceOrComment?.remove() } } @@ -354,8 +354,8 @@ .chainOperators .forEach { chainOperator -> chainOperator - .nextSibling { !it.isWhiteSpace20 } - ?.takeIf { it.isPartOfComment20 } + .nextSibling { !it.isWhiteSpace } + ?.takeIf { it.isPartOfComment } ?.let { emit(it.startOffset, "No comment expected at this location in method chain", false) } } } @@ -369,7 +369,7 @@ .forEach { chainOperator -> chainOperator .nextLeaf - .takeIf { it.isWhiteSpaceWithNewline20 } + .takeIf { it.isWhiteSpaceWithNewline } ?.let { whiteSpace -> emit(whiteSpace.startOffset - 1, "Unexpected newline after '${chainOperator.text}'", true) .ifAutocorrectAllowed { whiteSpace.remove() } @@ -409,7 +409,7 @@ private fun ASTNode.toChainedExpression(): ChainedExpression? = when (elementType) { DOT_QUALIFIED_EXPRESSION, SAFE_ACCESS_EXPRESSION -> { - children20 + children .find { it.elementType in chainOperatorTokenSet } ?.let { chainOperator -> createBaseChainedExpression(chainOperator).let { chainedExpression -> @@ -423,7 +423,7 @@ } CALL_EXPRESSION, ARRAY_ACCESS_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION -> { - children20 + children .mapNotNull { it.toChainedExpression() } .singleOrNull() } @@ -434,12 +434,12 @@ } private fun ASTNode.createBaseChainedExpression(chainOperator: ASTNode): ChainedExpression { - val chainBefore = chainOperator.prevCodeSibling20?.toChainedExpression() - val chainAfter = chainOperator.nextCodeSibling20?.toChainedExpression() + val chainBefore = chainOperator.prevCodeSibling?.toChainedExpression() + val chainAfter = chainOperator.nextCodeSibling?.toChainedExpression() val newlineAfter = chainAfter.containsNewline() || - chainOperator.nextCodeSibling20!!.textContains('\n') || - chainOperator.nextSibling { it.isWhiteSpaceWithNewline20 } != null + chainOperator.nextCodeSibling!!.textContains('\n') || + chainOperator.nextSibling { it.isWhiteSpaceWithNewline } != null val chainOperators = mutableListOf<ASTNode>() .plus(chainBefore?.chainOperators.orEmpty()) @@ -461,7 +461,7 @@ private fun ChainedExpression.modifyForFirstOperator(chainOperator: ASTNode): ChainedExpression = copy( hasNewlineBeforeFirstChainOperator = - chainOperator.prevCodeSibling20!!.textContains('\n') || chainOperator.isPrecededByNewlineSibling(), + chainOperator.prevCodeSibling!!.textContains('\n') || chainOperator.isPrecededByNewlineSibling(), hasNewlineBetweenFirstAndLastChainOperator = false, ) @@ -478,7 +478,7 @@ copy(hasNewlineBetweenFirstAndLastChainOperator = chainOperators.first().isPrecededByNewlineSibling()) } - private fun ASTNode.isPrecededByNewlineSibling() = prevSibling { it.isWhiteSpaceWithNewline20 } != null + private fun ASTNode.isPrecededByNewlineSibling() = prevSibling { it.isWhiteSpaceWithNewline } != null private fun ChainedExpression?.containsNewline() = if (this == null) {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt index 9119a9c..952ba0e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ChainWrappingRule.kt
@@ -26,15 +26,15 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -76,11 +76,11 @@ ) { val elementType = node.elementType if (nextLineTokens.contains(elementType)) { - if (node.isPartOfComment20) { + if (node.isPartOfComment) { return } val nextLeaf = node.nextCodeLeaf?.prevLeaf - if (nextLeaf.isWhiteSpaceWithNewline20 && !node.isElvisOperatorAndComment()) { + if (nextLeaf.isWhiteSpaceWithNewline && !node.isElvisOperatorAndComment()) { emit(node.startOffset, "Line must not end with \"${node.text}\"", true) .ifAutocorrectAllowed { // rewriting @@ -99,7 +99,7 @@ } } } else if (sameLineTokens.contains(elementType) || prefixTokens.contains(elementType)) { - if (node.isPartOfComment20) { + if (node.isPartOfComment) { return } val prevLeaf = node.prevLeaf @@ -118,7 +118,7 @@ return } - if (prevLeaf != null && prevLeaf.isWhiteSpaceWithNewline20) { + if (prevLeaf != null && prevLeaf.isWhiteSpaceWithNewline) { emit(node.startOffset, "Line must not begin with \"${node.text}\"", true) .ifAutocorrectAllowed { // rewriting @@ -130,13 +130,13 @@ val nextLeaf = node.nextLeaf val whiteSpaceToBeDeleted = when { - nextLeaf.isWhiteSpaceWithNewline20 -> { + nextLeaf.isWhiteSpaceWithNewline -> { // Node is preceded and followed by whitespace. Prefer to remove the whitespace before the node as this will // change the indent of the next line prevLeaf } - nextLeaf.isWhiteSpaceWithoutNewline20 -> { + nextLeaf.isWhiteSpaceWithoutNewline -> { nextLeaf } @@ -149,8 +149,8 @@ if (parent?.elementType == OPERATION_REFERENCE) { val insertBeforeSibling = parent - .prevCodeSibling20 - ?.nextSibling20 + .prevCodeSibling + ?.nextSibling parent.remove() insertBeforeSibling?.parent?.addChild(parent, insertBeforeSibling) parent.upsertWhitespaceBeforeMe(" ") @@ -182,7 +182,7 @@ private fun ASTNode.isElvisOperatorAndComment(): Boolean = elementType == ELVIS && - leaves().takeWhile { it.isWhiteSpaceWithoutNewline20 || it.isPartOfComment20 }.any() + leaves().takeWhile { it.isWhiteSpaceWithoutNewline || it.isPartOfComment }.any() } public val CHAIN_WRAPPING_RULE_ID: RuleId = ChainWrappingRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt index a738e46..1624301 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRule.kt
@@ -27,7 +27,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.ktlint_official import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -39,21 +39,20 @@ import com.pinterest.ktlint.rule.engine.core.api.hasModifier import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isLeaf20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isLeaf +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewlineOrNull import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -128,7 +127,7 @@ private fun ASTNode.superTypes() = findChildByType(SUPER_TYPE_LIST) - ?.children20 + ?.children ?.filter { it.isCode && it.elementType != COMMA } private fun ASTNode.hasMultilineSuperTypeList() = findChildByType(SUPER_TYPE_LIST)?.textContains('\n') == true @@ -136,7 +135,7 @@ private fun ASTNode.getFirstChildInSignature(): ASTNode? { findChildByType(MODIFIER_LIST) ?.let { modifierList -> - val iterator = modifierList.children20.iterator() + val iterator = modifierList.children.iterator() var currentNode: ASTNode while (iterator.hasNext()) { currentNode = iterator.next() @@ -148,7 +147,7 @@ return currentNode } } - return modifierList.nextCodeSibling20 + return modifierList.nextCodeSibling } return nextCodeLeaf } @@ -177,7 +176,7 @@ private fun ASTNode.containsEolComment() = getPrimaryConstructorParameterListOrNull() - ?.children20 + ?.children ?.any { it.elementType == EOL_COMMENT } ?: false @@ -198,7 +197,7 @@ private fun ASTNode.classSignatureExcludingSuperTypesIsMultiline() = classSignatureNodes(excludeSuperTypes = true) - .any { it.isWhiteSpaceWithNewline20 } + .any { it.isWhiteSpaceWithNewline } private fun ASTNode.getClassSignatureLength(excludeSuperTypes: Boolean) = indentWithoutNewlinePrefix.length + getClassSignatureNodesLength(excludeSuperTypes) @@ -210,21 +209,21 @@ private fun ASTNode.containsMultilineParameter(): Boolean = getPrimaryConstructorParameterListOrNull() - ?.children20 + ?.children .orEmpty() .filter { it.elementType == VALUE_PARAMETER } .any { it.textContains('\n') } private fun ASTNode.containsAnnotatedParameter(): Boolean = getPrimaryConstructorParameterListOrNull() - ?.children20 + ?.children .orEmpty() .filter { it.elementType == VALUE_PARAMETER } .any { it.isAnnotated() } private fun ASTNode.isAnnotated() = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children .orEmpty() .any { it.elementType == ANNOTATION_ENTRY } @@ -239,7 +238,7 @@ val primaryConstructorParameterList = node.getPrimaryConstructorParameterListOrNull() val hasNoValueParameters = primaryConstructorParameterList - ?.children20 + ?.children .orEmpty() .none { it.elementType == VALUE_PARAMETER } @@ -271,7 +270,7 @@ ?.takeUnless { // Allow: // class Foo constructor() { ... } - it.prevCodeSibling20?.elementType == CONSTRUCTOR_KEYWORD + it.prevCodeSibling?.elementType == CONSTRUCTOR_KEYWORD }?.takeUnless { // Allow // class Foo() { @@ -297,7 +296,7 @@ return whiteSpaceCorrection } - private fun ASTNode.containsComment() = children20.any { it.isPartOfComment20 } + private fun ASTNode.containsComment() = children.any { it.isPartOfComment } private fun fixWhiteSpacesBeforeFirstParameterInValueParameterList( node: ASTNode, @@ -310,14 +309,14 @@ val valueParameterList = node.getPrimaryConstructorParameterListOrNull() val firstParameterInList = valueParameterList - ?.children20 + ?.children ?.first { it.elementType == VALUE_PARAMETER } ?: return 0 val firstParameter = firstParameterInList.firstChildNode firstParameter ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (multiline) { if (whiteSpaceBeforeIdentifier.isWhiteSpaceWithoutNewlineOrNull) { @@ -361,19 +360,19 @@ val valueParameterList = node.getPrimaryConstructorParameterListOrNull() val firstParameterInList = valueParameterList - ?.children20 + ?.children ?.first { it.elementType == VALUE_PARAMETER } ?: return 0 valueParameterList - .children20 + .children .filter { it.elementType == VALUE_PARAMETER } .filter { it != firstParameterInList } .forEach { valueParameter -> val firstChildNodeInValueParameter = valueParameter.firstChildNode firstChildNodeInValueParameter ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (multiline) { if (whiteSpaceBeforeIdentifier.isWhiteSpaceWithoutNewlineOrNull) { @@ -419,13 +418,13 @@ .getPrimaryConstructorParameterListOrNull() ?.findChildByType(RPAR) closingParenthesisPrimaryConstructor - ?.prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + ?.prevSibling + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeClosingParenthesis -> if (multiline) { if (whiteSpaceBeforeClosingParenthesis.isWhiteSpaceWithoutNewlineOrNull) { // Let IndentationRule determine the exact indent - val expectedParameterIndent = node.indent20 + val expectedParameterIndent = node.indent if (!dryRun) { emit(closingParenthesisPrimaryConstructor!!.startOffset, "Newline expected before closing parenthesis", true) .ifAutocorrectAllowed { @@ -475,8 +474,8 @@ // Remove the whitespace before the super type call and do not insert a new whitespace as it will be fixed later superTypeCallEntry - .prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + .prevSibling + ?.takeIf { it.isWhiteSpace } ?.remove() superTypeList.addChild(superTypeCallEntry, superTypes.first()) @@ -499,8 +498,8 @@ .let { firstSuperType -> firstSuperType .prevLeaf - .takeIf { it.isWhiteSpaceWithNewline20 } - ?.takeUnless { it.prevSibling20?.elementType == EOL_COMMENT } + .takeIf { it.isWhiteSpaceWithNewline } + ?.takeUnless { it.prevSibling?.elementType == EOL_COMMENT } ?.let { whiteSpaceBeforeSuperType -> val expectedWhitespace = " " if (whiteSpaceBeforeSuperType.text != expectedWhitespace) { @@ -518,7 +517,7 @@ ?.let { superTypeFirstChildNode -> superTypeFirstChildNode .prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (node.hasMultilineSuperTypeList() || classSignaturesIncludingFirstSuperTypeExceedsMaxLineLength(node, emit) @@ -550,7 +549,7 @@ val firstChildNodeInSuperType = superType.firstChildNode firstChildNodeInSuperType ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (index == 0 && node.hasMultilinePrimaryConstructor()) { val expectedWhitespace = " " @@ -610,8 +609,8 @@ findChildByType(PRIMARY_CONSTRUCTOR) ?.findChildByType(VALUE_PARAMETER_LIST) ?.findChildByType(RPAR) - ?.prevLeaf { !it.isPartOfComment20 } - .isWhiteSpaceWithNewline20 + ?.prevLeaf { !it.isPartOfComment } + .isWhiteSpaceWithNewline private fun fixClassBody( node: ASTNode, @@ -636,10 +635,10 @@ private fun List<ASTNode>.collectLeavesRecursively(): List<ASTNode> = flatMap { it.collectLeavesRecursively() } private fun ASTNode.collectLeavesRecursively(): List<ASTNode> = - if (isLeaf20) { + if (isLeaf) { listOf(this) } else { - children20 + children .flatMap { it.collectLeavesRecursively() } .toList() } @@ -677,7 +676,7 @@ private fun ASTNode.countParameters() = getPrimaryConstructorParameterListOrNull() - ?.children20 + ?.children .orEmpty() .count { it.elementType == VALUE_PARAMETER }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt index bc21db3..7a42872 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentSpacingRule.kt
@@ -5,7 +5,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -21,7 +21,7 @@ ) { if (node.elementType == EOL_COMMENT) { val prevLeaf = node.prevLeaf - if (!prevLeaf.isWhiteSpace20 && prevLeaf is LeafPsiElement) { + if (!prevLeaf.isWhiteSpace && prevLeaf is LeafPsiElement) { emit(node.startOffset, "Missing space before //", true) .ifAutocorrectAllowed { node.upsertWhitespaceBeforeMe(" ")
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt index 6227f8a..4253847 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/CommentWrappingRule.kt
@@ -10,13 +10,13 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -46,15 +46,15 @@ val beforeBlockComment = node .leaves(false) - .takeWhile { it.isWhiteSpaceWithoutNewline20 } + .takeWhile { it.isWhiteSpaceWithoutNewline } .firstOrNull() - ?: node.firstChildLeafOrSelf20 + ?: node.firstChildLeafOrSelf val afterBlockComment = node .leaves() - .takeWhile { it.isWhiteSpaceWithoutNewline20 } + .takeWhile { it.isWhiteSpaceWithoutNewline } .firstOrNull() - ?: node.lastChildLeafOrSelf20 + ?: node.lastChildLeafOrSelf if (!beforeBlockComment.prevLeaf.isWhitespaceWithNewlineOrNull() && !afterBlockComment.nextLeaf.isWhitespaceWithNewlineOrNull() @@ -107,13 +107,13 @@ "A block comment may not be followed by any other element on that same line", true, ).ifAutocorrectAllowed { - nextLeaf.upsertWhitespaceBeforeMe(node.indent20) + nextLeaf.upsertWhitespaceBeforeMe(node.indent) } } } } - private fun ASTNode?.isWhitespaceWithNewlineOrNull() = this == null || this.isWhiteSpaceWithNewline20 + private fun ASTNode?.isWhitespaceWithNewlineOrNull() = this == null || this.isWhiteSpaceWithNewline } public val COMMENT_WRAPPING_RULE_ID: RuleId = CommentWrappingRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverListWrappingRule.kt index 5c2063b..f119ebf 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverListWrappingRule.kt
@@ -17,21 +17,21 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -93,14 +93,14 @@ // Context receiver must be followed by new line or comment unless it is a type reference of a parameter node .takeUnless { it.isTypeReferenceParameterInFunction() } - ?.lastChildLeafOrSelf20 - ?.nextLeaf { !it.isWhiteSpaceWithoutNewline20 && !it.isPartOfComment20 } - ?.takeIf { !it.isWhiteSpaceWithNewline20 } + ?.lastChildLeafOrSelf + ?.nextLeaf { !it.isWhiteSpaceWithoutNewline && !it.isPartOfComment } + ?.takeIf { !it.isWhiteSpaceWithNewline } ?.let { nodeAfterContextReceiver -> emit(nodeAfterContextReceiver.startOffset, "Expected a newline after the context parameter", true) .ifAutocorrectAllowed { nodeAfterContextReceiver - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .upsertWhitespaceBeforeMe(indentConfig.parentIndentOf(node)) } } @@ -111,7 +111,7 @@ node.indentWithoutNewlinePrefix.length + node.textLength > maxLineLength ) { node - .children20 + .children .filter { it.elementType == VALUE_PARAMETER } .forEach { emit( @@ -132,7 +132,7 @@ "Newline expected before closing parenthesis as max line length is violated", true, ).ifAutocorrectAllowed { - rpar.upsertWhitespaceBeforeMe(node.indent20) + rpar.upsertWhitespaceBeforeMe(node.indent) } } } @@ -164,7 +164,7 @@ node.indentWithoutNewlinePrefix.length + contextReceiverText.length > maxLineLength ) { node - .children20 + .children .filter { it.elementType == TYPE_PROJECTION } .forEach { emit(
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt index ffa39db..2721184 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ContextReceiverWrappingRule.kt
@@ -17,21 +17,21 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -94,14 +94,14 @@ // Context receiver must be followed by new line or comment unless it is a type reference of a parameter node .takeUnless { it.isFunctionTypeReferenceInValueParameterList() } - ?.lastChildLeafOrSelf20 - ?.nextLeaf { !it.isWhiteSpaceWithoutNewline20 && !it.isPartOfComment20 } - ?.takeIf { !it.isWhiteSpaceWithNewline20 } + ?.lastChildLeafOrSelf + ?.nextLeaf { !it.isWhiteSpaceWithoutNewline && !it.isPartOfComment } + ?.takeIf { !it.isWhiteSpaceWithNewline } ?.let { nodeAfterContextReceiver -> emit(nodeAfterContextReceiver.startOffset, "Expected a newline after the context receiver", true) .ifAutocorrectAllowed { nodeAfterContextReceiver - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .upsertWhitespaceBeforeMe(indentConfig.parentIndentOf(node)) } } @@ -112,7 +112,7 @@ node.indentWithoutNewlinePrefix.length + node.textLength > maxLineLength ) { node - .children20 + .children .filter { it.elementType == CONTEXT_RECEIVER } .forEach { emit( @@ -133,7 +133,7 @@ "Newline expected before closing parenthesis as max line length is violated", true, ).ifAutocorrectAllowed { - rpar.upsertWhitespaceBeforeMe(node.indent20) + rpar.upsertWhitespaceBeforeMe(node.indent) } } } @@ -163,7 +163,7 @@ node.indentWithoutNewlinePrefix.length + contextReceiverText.length > maxLineLength ) { node - .children20 + .children .filter { it.elementType == TYPE_PROJECTION } .forEach { emit(
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt index d1d8cc3..c7ef248 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/EnumWrappingRule.kt
@@ -13,18 +13,18 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasModifier import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -87,13 +87,13 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ): Boolean { - val firstEnumEntry = node.findChildByType(ENUM_ENTRY)?.firstChildLeafOrSelf20 + val firstEnumEntry = node.findChildByType(ENUM_ENTRY)?.firstChildLeafOrSelf if (firstEnumEntry != null) { node - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leavesForwardsIncludingSelf .takeWhile { it != firstEnumEntry } - .firstOrNull { it.isPartOfComment20 } + .firstOrNull { it.isPartOfComment } ?.let { commentBeforeFirstEnumEntry -> val expectedIndent = indentConfig.childIndentOf(node) if (commentBeforeFirstEnumEntry.prevLeaf?.text != expectedIndent) { @@ -111,26 +111,26 @@ private fun ASTNode.isMultiline() = text.contains('\n') private fun ASTNode.hasAnnotatedEnumEntry() = - children20 + children .filter { it.elementType == ENUM_ENTRY } .any { it.isAnnotated() } private fun ASTNode.isAnnotated(): Boolean = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children .orEmpty() .any { it.elementType == ANNOTATION_ENTRY } - private fun ASTNode.hasCommentedEnumEntry() = children20.any { it.containsCommentInEnumEntry() } + private fun ASTNode.hasCommentedEnumEntry() = children.any { it.containsCommentInEnumEntry() } - private fun ASTNode.containsCommentInEnumEntry() = children20.any { it.isPartOfComment20 } + private fun ASTNode.containsCommentInEnumEntry() = children.any { it.isPartOfComment } private fun wrapEnumEntries( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == ENUM_ENTRY } .forEach { enumEntry -> wrapEnumEntry(enumEntry, emit) @@ -142,8 +142,8 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .prevLeaf { !it.isPartOfComment20 && !it.isWhiteSpaceWithoutNewline20 } - ?.takeUnless { it.isWhiteSpaceWithNewline20 } + .prevLeaf { !it.isPartOfComment && !it.isWhiteSpaceWithoutNewline } + ?.takeUnless { it.isWhiteSpaceWithNewline } ?.let { prevLeaf -> emit(node.startOffset, "Enum entry should start on a separate line", true) .ifAutocorrectAllowed { @@ -175,10 +175,10 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .lastOrNull { it.elementType == ENUM_ENTRY } - ?.nextSibling { !it.isPartOfComment20 } - ?.takeUnless { it.nextCodeSibling20?.elementType == RBRACE } + ?.nextSibling { !it.isPartOfComment } + ?.takeUnless { it.nextCodeSibling?.elementType == RBRACE } ?.let { nextSibling -> val expectedIndent = "\n".plus(indentConfig.siblingIndentOf(node)) if (nextSibling.text != expectedIndent) {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ExpressionOperandWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ExpressionOperandWrappingRule.kt index 8f6a1e3..678e77a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ExpressionOperandWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ExpressionOperandWrappingRule.kt
@@ -10,19 +10,19 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleV2 import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesInClosedRange -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -91,17 +91,17 @@ ) { node .findChildByType(OPERATION_REFERENCE) - ?.takeUnless { it.nextSibling20.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.nextSibling.isWhiteSpaceWithNewline } ?.takeUnless { - it.nextSibling20.isWhiteSpaceWithoutNewline20 && - it.nextSibling20?.nextSibling20?.elementType == EOL_COMMENT + it.nextSibling.isWhiteSpaceWithoutNewline && + it.nextSibling?.nextSibling?.elementType == EOL_COMMENT }?.let { operationReference -> val startOffset = with(operationReference) { startOffset + textLength } .plus( operationReference - .nextSibling20 - ?.takeIf { it.isWhiteSpace20 } + .nextSibling + ?.takeIf { it.isWhiteSpace } ?.textLength ?: 0, ) @@ -120,13 +120,13 @@ } return anyParentBinaryExpression { parent -> - parent.children20.any { it.isWhiteSpaceWithNewline20 } + parent.children.any { it.isWhiteSpaceWithNewline } } } - private fun ASTNode.leftHandSide() = children20.firstOrNull { it.isCode } + private fun ASTNode.leftHandSide() = children.firstOrNull { it.isCode } - private fun ASTNode.rightHandSide() = children20.lastOrNull { it.isCode } + private fun ASTNode.rightHandSide() = children.lastOrNull { it.isCode } private fun ASTNode?.isMultilineOperand() = when { @@ -135,8 +135,8 @@ } else -> { - leavesInClosedRange(this.firstChildLeafOrSelf20, this.lastChildLeafOrSelf20) - .any { it.isWhiteSpaceWithNewline20 } + leavesInClosedRange(this.firstChildLeafOrSelf, this.lastChildLeafOrSelf) + .any { it.isWhiteSpaceWithNewline } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt index 0434a9a..4063433 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FilenameRule.kt
@@ -11,8 +11,8 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.TYPE_REFERENCE import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint -import com.pinterest.ktlint.rule.engine.core.api.children20 -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 +import com.pinterest.ktlint.rule.engine.core.api.children +import com.pinterest.ktlint.rule.engine.core.api.isRoot import com.pinterest.ktlint.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -49,7 +49,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isRoot20) { + if (node.isRoot) { node as FileASTNode? ?: error("node is not ${FileASTNode::class} but ${node::class}") val filePath = (node.psi as? KtFile)?.virtualFilePath @@ -99,7 +99,7 @@ } private fun ASTNode.topLevelDeclarations(elementType: IElementType? = null): List<TopLevelDeclaration> = - children20 + children .filter { elementType == null || it.elementType == elementType } .filter { it.doesNotHavePrivateModifier() } .mapNotNull { it.toTopLevelDeclaration() } @@ -108,12 +108,12 @@ private fun ASTNode.doesNotHavePrivateModifier(): Boolean = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children ?.none { it.text == "private" } ?: true private fun ASTNode.hasTopLevelDeclarationNotExtending(className: String) = - children20 + children .filter { it.doesNotHavePrivateModifier() } .any { it.isNotClassRelatedTopLevelDeclaration() || it.isFunctionNotExtending(className) }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt index 2d2991f..9327c59 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FinalNewlineRule.kt
@@ -7,10 +7,10 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INSERT_FINAL_NEWLINE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isRoot +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -32,21 +32,21 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isRoot20) { + if (node.isRoot) { if (node.textLength == 0) { stopTraversalOfAST() return } val lastNode = lastChildNodeOf(node) when { - insertFinalNewline && (!lastNode.isWhiteSpace20 || lastNode.isWhiteSpaceWithoutNewline20) -> { + insertFinalNewline && (!lastNode.isWhiteSpace || lastNode.isWhiteSpaceWithoutNewline) -> { emit(node.textLength - 1, "File must end with a newline (\\n)", true) .ifAutocorrectAllowed { node.addChild(PsiWhiteSpaceImpl("\n"), null) } } - !insertFinalNewline && lastNode != null && lastNode.isWhiteSpaceWithNewline20 -> { + !insertFinalNewline && lastNode != null && lastNode.isWhiteSpaceWithNewline -> { emit(lastNode.startOffset, "Redundant newline (\\n) at the end of file", true) .ifAutocorrectAllowed { lastNode.remove() } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt index e4ab229..41a9db0 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionExpressionBodyRule.kt
@@ -17,19 +17,19 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesInClosedRange import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -107,7 +107,7 @@ ?.takeUnless { it.countReturnKeywords() > 1 } ?.findChildByType(RETURN) ?.findChildByType(RETURN_KEYWORD) - ?.nextSibling { !it.isWhiteSpace20 } + ?.nextSibling { !it.isWhiteSpace } ?.let { codeSibling -> emit(block.startOffset, "Function body should be replaced with body expression", true) .ifAutocorrectAllowed { @@ -129,8 +129,8 @@ with(block.parent!!) { // Remove whitespace before block block - .prevSibling20 - .takeIf { it.isWhiteSpace20 } + .prevSibling + .takeIf { it.isWhiteSpace } ?.remove() if (findChildByType(TYPE_REFERENCE) == null) { // Insert Unit as return type as otherwise a compilation error results @@ -150,13 +150,13 @@ private fun ASTNode.containingOnly(iElementType: IElementType) = iElementType == - children20 - .filterNot { it.elementType == LBRACE || it.elementType == RBRACE || it.isWhiteSpace20 } + children + .filterNot { it.elementType == LBRACE || it.elementType == RBRACE || it.isWhiteSpace } .singleOrNull() ?.elementType private fun ASTNode.countReturnKeywords() = - leavesInClosedRange(firstChildLeafOrSelf20, lastChildLeafOrSelf20) + leavesInClosedRange(firstChildLeafOrSelf, lastChildLeafOrSelf) .count { it.elementType == RETURN_KEYWORD } private fun createUnitTypeReference() =
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt index 24c7c20..8074325 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionLiteralRule.kt
@@ -19,7 +19,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.dropTrailingEolComment import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -27,24 +27,23 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.findParentByType -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewlineOrNull -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove @@ -132,7 +131,7 @@ ) { val valueParameters = parameterList - .children20 + .children .filter { it.elementType == VALUE_PARAMETER } if (valueParameters.count() > 1 || parameterList.wrapFirstParameterToNewline()) { if (parameterList.textContains('\n') || parameterList.doesNotFitOnSameLineAsStartOfFunctionLiteral()) { @@ -179,7 +178,7 @@ require(elementType == VALUE_PARAMETER_LIST && parent?.elementType == FUNCTION_LITERAL) val lbrace = parent?.findChildByType(LBRACE)!! return lbrace - .leavesOnLine20 + .leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != lbrace } .lineLength @@ -187,12 +186,12 @@ private fun ASTNode.lengthOfParameterListWhenOnSingleLine(): Int { require(elementType == VALUE_PARAMETER_LIST) - val stopAtLeaf = lastChildLeafOrSelf20.nextLeaf - return firstChildLeafOrSelf20 + val stopAtLeaf = lastChildLeafOrSelf.nextLeaf + return firstChildLeafOrSelf .leavesForwardsIncludingSelf .takeWhile { it != stopAtLeaf } .joinToString(separator = "") { - if (it.isWhiteSpace20) { + if (it.isWhiteSpace) { // Eliminate newlines and redundant spaces " " } else { @@ -206,7 +205,7 @@ val stopAtLeaf = nextSibling { it.elementType == RBRACE } return hasNoMaxLineLengthSuppression() && maxLineLength < - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != stopAtLeaf } .lineLength @@ -219,11 +218,11 @@ // bar() // } val stopAtLeaf = - children20 + children .first { it.elementType == VALUE_PARAMETER } - .lastChildLeafOrSelf20 - .nextLeaf { !it.isWhiteSpaceWithoutNewline20 && !it.isPartOfComment20 } - leavesOnLine20 + .lastChildLeafOrSelf + .nextLeaf { !it.isWhiteSpaceWithoutNewline && !it.isPartOfComment } + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != stopAtLeaf } .lineLength @@ -248,7 +247,7 @@ ) { require(parameterList.elementType == VALUE_PARAMETER_LIST) parameterList - .children20 + .children .filter { it.elementType == VALUE_PARAMETER } .forEach { wrapValueParameter(it, emit) } parameterList @@ -266,7 +265,7 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { require(valueParameter.elementType == VALUE_PARAMETER) - if (valueParameter.prevLeaf.isWhiteSpaceWithoutNewline20) { + if (valueParameter.prevLeaf.isWhiteSpaceWithoutNewline) { emit(valueParameter.startOffset, "Newline expected before parameter", true) .ifAutocorrectAllowed { valueParameter.upsertWhitespaceBeforeMe( @@ -291,7 +290,7 @@ require(arrow.elementType == ARROW) arrow .prevLeaf - .takeIf { it.isWhiteSpaceWithoutNewline20 } + .takeIf { it.isWhiteSpaceWithoutNewline } ?.let { emit(arrow.startOffset, "Newline expected before arrow", true) .ifAutocorrectAllowed { @@ -339,7 +338,7 @@ require(parameterList.elementType == VALUE_PARAMETER_LIST) parameterList .takeUnless { it.isPrecededByComment() } - ?.prevSibling { it.isWhiteSpaceWithNewline20 } + ?.prevSibling { it.isWhiteSpaceWithNewline } ?.let { whitespaceBeforeParameterList -> emit(parameterList.startOffset, "No newline expected before parameter", true) .ifAutocorrectAllowed { @@ -347,8 +346,8 @@ } } parameterList - .nextSibling { it.isWhiteSpace20 } - ?.takeIf { it.isWhiteSpaceWithNewline20 } + .nextSibling { it.isWhiteSpace } + ?.takeIf { it.isWhiteSpaceWithNewline } ?.let { whitespaceAfterParameterList -> emit(parameterList.startOffset + parameterList.textLength, "No newline expected after parameter", true) .ifAutocorrectAllowed { @@ -357,7 +356,7 @@ } } - private fun ASTNode.isPrecededByComment() = siblings(forward = false).any { it.isPartOfComment20 } + private fun ASTNode.isPrecededByComment() = siblings(forward = false).any { it.isPartOfComment } private fun visitArrow( arrow: ASTNode, @@ -373,8 +372,8 @@ emit(arrow.startOffset, "Arrow is redundant when parameter list is empty", true) .ifAutocorrectAllowed { arrow - .nextSibling20 - .takeIf { it.isWhiteSpace20 } + .nextSibling + .takeIf { it.isWhiteSpace } ?.remove() arrow.remove() } @@ -416,7 +415,7 @@ require(block.elementType == BLOCK) if (block.textContains('\n') || block.exceedsMaxLineLength()) { block - .prevCodeSibling20 + .prevCodeSibling ?.let { prevCodeSibling -> when (prevCodeSibling.elementType) { ARROW -> wrapAfterArrow(prevCodeSibling, emit) @@ -426,7 +425,7 @@ } block - .nextCodeSibling20 + .nextCodeSibling ?.takeIf { it.elementType == RBRACE } ?.let { rbrace -> wrapBeforeRbrace(rbrace, emit) } } @@ -439,7 +438,7 @@ require(lbrace.elementType == LBRACE) lbrace .nextLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } .let { whitespaceAfterLbrace -> if (whitespaceAfterLbrace.isWhiteSpaceWithoutNewlineOrNull) { emit(lbrace.startOffset, "Newline expected after opening brace", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt index 82bc0c3..87955a2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionNamingRule.kt
@@ -19,11 +19,11 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CommaSeparatedListValueParser import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.ec4j.core.model.PropertyType @@ -129,7 +129,7 @@ private fun ASTNode.isAnonymousFunction() = VALUE_PARAMETER_LIST == findChildByType(FUN_KEYWORD) - ?.nextCodeSibling20 + ?.nextCodeSibling ?.elementType /* @@ -139,7 +139,7 @@ */ private fun ASTNode.isOverrideFunction() = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children .orEmpty() .any { it.elementType == OVERRIDE_KEYWORD } @@ -148,7 +148,7 @@ private fun ASTNode?.containsAnnotationEntryWithIdentifierIn(excludeWhenAnnotatedWith: Set<String>): Boolean = this - ?.children20 + ?.children ?.any { when (it.elementType) { ANNOTATION -> {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt index 603d5ac..a00d7ea 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionReturnTypeSpacingRule.kt
@@ -10,8 +10,8 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove @@ -54,7 +54,7 @@ require(node.elementType == COLON) node .prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { whitespaceBeforeColonNode -> emit(whitespaceBeforeColonNode.startOffset, "Unexpected whitespace", true) .ifAutocorrectAllowed { whitespaceBeforeColonNode.remove() } @@ -68,7 +68,7 @@ require(node.elementType == COLON) node .nextLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceAfterColon -> if (whiteSpaceAfterColon?.text != " ") { // In case the whitespace contains a newline than replacing it with a single space results in merging the lines to a @@ -100,7 +100,7 @@ 0 } else { leaves(forward = forward) - .takeWhile { !it.isWhiteSpaceWithNewline20 } + .takeWhile { !it.isWhiteSpaceWithNewline } .sumOf { it.textLength } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt index 0c94138..3b8eb5d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt
@@ -25,7 +25,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue.ktlint_official import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig @@ -34,23 +34,23 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY_OFF -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isLeaf20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isLeaf +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewlineOrNull -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -123,7 +123,7 @@ // fun foo(bar: String) { // or // fun foo(bar: String) = - val firstCodeChild = getFirstCodeChild()?.firstChildLeafOrSelf20 + val firstCodeChild = getFirstCodeChild()?.firstChildLeafOrSelf val startOfBodyBlock = this .findChildByType(BLOCK) @@ -146,16 +146,16 @@ funNode ?.findChildByType(MODIFIER_LIST) ?.let { modifierList -> - val iterator = modifierList.children20.iterator() + val iterator = modifierList.children.iterator() var currentNode: ASTNode while (iterator.hasNext()) { currentNode = iterator.next() if (currentNode.elementType == CONTEXT_RECEIVER_LIST) { return currentNode - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .nextLeaf .let { leafAfterCompositeContextReceiverList -> - if (leafAfterCompositeContextReceiverList.isWhiteSpaceWithNewline20) { + if (leafAfterCompositeContextReceiverList.isWhiteSpaceWithNewline) { // Ignore context receiver when followed by newline or EOL comment. Also, ignore that newline or EOL // comment. // context(Foo) @@ -176,7 +176,7 @@ return currentNode } } - return modifierList.nextCodeSibling20 + return modifierList.nextCodeSibling } return funNode?.nextCodeLeaf @@ -259,21 +259,21 @@ private fun ASTNode.containsMultilineParameter(): Boolean = findChildByType(VALUE_PARAMETER_LIST) - ?.children20 + ?.children .orEmpty() .filter { it.elementType == VALUE_PARAMETER } .any { it.textContains('\n') } private fun ASTNode.containsAnnotatedParameter(): Boolean = findChildByType(VALUE_PARAMETER_LIST) - ?.children20 + ?.children .orEmpty() .filter { it.elementType == VALUE_PARAMETER } .any { it.isAnnotated() } private fun ASTNode.isAnnotated() = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children .orEmpty() .any { it.elementType == ANNOTATION_ENTRY } @@ -313,7 +313,7 @@ val valueParameterList = requireNotNull(node.findChildByType(VALUE_PARAMETER_LIST)) val firstParameterInList = valueParameterList - .children20 + .children .firstOrNull { it.elementType == VALUE_PARAMETER } whiteSpaceCorrection += @@ -339,7 +339,7 @@ val valueParameterList = requireNotNull(node.findChildByType(VALUE_PARAMETER_LIST)) valueParameterList - .children20 + .children .filter { it.elementType != LPAR && it.elementType != RPAR } .also { elementsInValueParameterList -> // Functions with comments in the value parameter list are excluded from processing before. So an "empty" value @@ -372,13 +372,13 @@ val valueParameterList = requireNotNull(node.findChildByType(VALUE_PARAMETER_LIST)) val firstParameterInList = valueParameterList - .children20 + .children .first { it.elementType == VALUE_PARAMETER } val firstParameter = firstParameterInList.firstChildNode firstParameter ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (multiline) { val expectedParameterIndent = indentConfig.childIndentOf(node) @@ -426,18 +426,18 @@ val valueParameterList = requireNotNull(node.findChildByType(VALUE_PARAMETER_LIST)) val firstParameterInList = valueParameterList - .children20 + .children .first { it.elementType == VALUE_PARAMETER } valueParameterList - .children20 + .children .filter { it.elementType == VALUE_PARAMETER } .filter { it != firstParameterInList } .forEach { valueParameter -> val firstChildNodeInValueParameter = valueParameter.firstChildNode firstChildNodeInValueParameter ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeIdentifier -> if (multiline) { val expectedParameterIndent = indentConfig.childIndentOf(node) @@ -485,13 +485,13 @@ ): Int { var whiteSpaceCorrection = 0 - val newlineAndIndent = node.indent20 + val newlineAndIndent = node.indent val valueParameterList = requireNotNull(node.findChildByType(VALUE_PARAMETER_LIST)) val closingParenthesis = valueParameterList.findChildByType(RPAR) closingParenthesis - ?.prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + ?.prevSibling + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeClosingParenthesis -> if (multiline) { if (whiteSpaceBeforeClosingParenthesis == null || @@ -540,7 +540,7 @@ ?: return val bodyNodes = node.getFunctionBody(lastNodeOfFunctionSignatureWithBodyExpression) val whiteSpaceBeforeFunctionBodyExpression = bodyNodes.getStartingWhitespaceOrNull() - val functionBodyExpressionNodes = bodyNodes.dropWhile { it.isWhiteSpace20 } + val functionBodyExpressionNodes = bodyNodes.dropWhile { it.isWhiteSpace } val functionBodyExpressionLines = functionBodyExpressionNodes @@ -549,9 +549,9 @@ functionBodyExpressionLines .firstOrNull() ?.also { firstLineOfBodyExpression -> - if (whiteSpaceBeforeFunctionBodyExpression.isWhiteSpaceWithNewline20) { + if (whiteSpaceBeforeFunctionBodyExpression.isWhiteSpaceWithNewline) { lastNodeOfFunctionSignatureWithBodyExpression - .nextCodeSibling20 + .nextCodeSibling .takeIf { it?.elementType == ANNOTATED_EXPRESSION } ?.let { // Never merge an annotated expression body with function signature as this conflicts with the Annotation rule @@ -657,7 +657,7 @@ ?.let { block -> block .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } .let { whiteSpaceBeforeBlock -> if (whiteSpaceBeforeBlock == null || whiteSpaceBeforeBlock.text != " ") { if (!dryRun) { @@ -689,17 +689,17 @@ private fun List<ASTNode>.getStartingWhitespaceOrNull() = this .firstOrNull() - ?.takeIf { first -> first.isWhiteSpace20 } + ?.takeIf { first -> first.isWhiteSpace } private fun isMaxLineLengthSet() = maxLineLength != MAX_LINE_LENGTH_PROPERTY_OFF private fun List<ASTNode>.collectLeavesRecursively(): List<ASTNode> = flatMap { it.collectLeavesRecursively() } private fun ASTNode.collectLeavesRecursively(): List<ASTNode> = - if (isLeaf20) { + if (isLeaf) { listOf(this) } else { - children20 + children .flatMap { it.collectLeavesRecursively() } .toList() } @@ -739,7 +739,7 @@ private fun ASTNode.countParameters(): Int { val valueParameterList = requireNotNull(findChildByType(VALUE_PARAMETER_LIST)) return valueParameterList - .children20 + .children .count { it.elementType == VALUE_PARAMETER } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt index 05bbe97..5d7e7ee 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionStartOfBodySpacingRule.kt
@@ -10,7 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -88,7 +88,7 @@ .nextLeaf ?.takeIf { it.elementType == WHITE_SPACE } .let { whiteSpaceAfterAssignment -> - if (whiteSpaceAfterAssignment?.text != " " && !whiteSpaceAfterAssignment.isWhiteSpaceWithNewline20) { + if (whiteSpaceAfterAssignment?.text != " " && !whiteSpaceAfterAssignment.isWhiteSpaceWithNewline) { emit( assignmentExpression.startOffset, "Expected a single white space between assignment and expression body on same line",
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt index 0c0772b..767f86e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeModifierSpacingRule.kt
@@ -8,9 +8,9 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -27,7 +27,7 @@ ) { node .takeIf { it.elementType == MODIFIER_LIST } - ?.nextCodeSibling20 + ?.nextCodeSibling ?.takeIf { it.elementType == FUNCTION_TYPE } ?.takeUnless { it.isPrecededBySingleSpace() } ?.let { functionTypeNode -> @@ -39,8 +39,8 @@ } private fun ASTNode.isPrecededBySingleSpace(): Boolean = - prevSibling20 - ?.let { it.isWhiteSpace20 && it.text == " " } + prevSibling + ?.let { it.isWhiteSpace && it.text == " " } ?: false }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt index 1eeb6c9..e65d127 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionTypeReferenceSpacingRule.kt
@@ -10,8 +10,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -48,7 +48,7 @@ if (currentNode.elementType == TYPE_REFERENCE) { return currentNode } - currentNode = currentNode.nextSibling20 + currentNode = currentNode.nextSibling } return null } @@ -59,7 +59,7 @@ ) { var currentNode: ASTNode? = node while (currentNode != null && currentNode.elementType != VALUE_PARAMETER_LIST) { - val nextNode = currentNode.nextSibling20 + val nextNode = currentNode.nextSibling removeIfNonEmptyWhiteSpace(currentNode, emit) currentNode = nextNode } @@ -69,7 +69,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpace20 && node.text.isNotEmpty()) { + if (node.isWhiteSpace && node.text.isNotEmpty()) { emit(node.startOffset, "Unexpected whitespace", true) .ifAutocorrectAllowed { node.remove() } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt index d2c8035..663d3ed 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseBracingRule.kt
@@ -19,10 +19,10 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith @@ -144,13 +144,13 @@ val nextLeaves = node .leaves(forward = true) - .takeWhile { it.isWhiteSpaceWithoutNewline20 || it.isPartOfComment20 } + .takeWhile { it.isWhiteSpaceWithoutNewline || it.isPartOfComment } .toList() - .dropLastWhile { it.isWhiteSpaceWithoutNewline20 } + .dropLastWhile { it.isWhiteSpaceWithoutNewline } prevLeaves .firstOrNull() - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.replaceTextWith(" ") KtBlockExpression(null).apply { val previousChild = node.firstChildNode @@ -164,7 +164,7 @@ addChild(PsiWhiteSpaceImpl(indentConfig.childIndentOf(node))) } prevLeaves - .dropWhile { it.isWhiteSpace20 } + .dropWhile { it.isWhiteSpace } .takeIf { it.isNotEmpty() } ?.forEach(::addChild) if (previousChild != null) { @@ -172,7 +172,7 @@ } nextLeaves.forEach(::addChild) if (previousChild != null) { - addChild(PsiWhiteSpaceImpl(node.indent20)) + addChild(PsiWhiteSpaceImpl(node.indent)) } addChild(LeafPsiElement(RBRACE, "}")) } @@ -180,7 +180,7 @@ // Make sure else starts on same line as newly inserted right brace if (node.elementType == THEN) { node - .nextSibling { !it.isPartOfComment20 } + .nextSibling { !it.isPartOfComment } ?.upsertWhitespaceBeforeMe(" ") } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt index f864a5c..4943a11 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IfElseWrappingRule.kt
@@ -17,18 +17,18 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.betweenCodeSiblings -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -70,7 +70,7 @@ ) { when { node.elementType == IF -> visitIf(node, emit) - node.isPartOfComment20 && node.parent?.elementType == IF -> visitComment(node, emit) + node.isPartOfComment && node.parent?.elementType == IF -> visitComment(node, emit) } } @@ -146,14 +146,14 @@ with(node.findFirstNodeInBlockToBeIndented() ?: node) { val expectedIndent = - if (nextSibling20?.elementType == RBRACE) { - node.indent20 + if (nextSibling?.elementType == RBRACE) { + node.indent } else { indentConfig.siblingIndentOf(node) } applyIf(elementType == THEN || elementType == ELSE || elementType == ELSE_KEYWORD) { prevLeaf!! } - .takeUnless { it.isWhiteSpaceWithNewline20 } + .takeUnless { it.isWhiteSpaceWithNewline } ?.let { // Expected a newline with indent. Leave it up to the IndentationRule to determine exact indent emit(startOffset, "Expected a newline", true) @@ -173,14 +173,14 @@ private fun ASTNode.findFirstNodeInBlockToBeIndented(): ASTNode? = findChildByType(BLOCK) - ?.children20 + ?.children ?.first { it.elementType != LBRACE && !it.isWhitespaceBeforeComment() && - !it.isPartOfComment20 + !it.isPartOfComment } - private fun ASTNode.isWhitespaceBeforeComment() = isWhiteSpaceWithoutNewline20 && nextLeaf?.isPartOfComment20 == true + private fun ASTNode.isWhitespaceBeforeComment() = isWhiteSpaceWithoutNewline && nextLeaf?.isPartOfComment == true private fun ASTNode.outerIf(): ASTNode { require(this.elementType == IF) @@ -200,7 +200,7 @@ comment: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - require(comment.isPartOfComment20) + require(comment.isPartOfComment) if (comment.betweenCodeSiblings(RPAR, THEN) || comment.betweenCodeSiblings(THEN, ELSE_KEYWORD) || comment.betweenCodeSiblings(ELSE_KEYWORD, ELSE)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt index 9662362..eed7aa4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ImportOrderingRule.kt
@@ -12,9 +12,9 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.ImportOrderingRule.Companion.ASCII_PATTERN import com.pinterest.ktlint.ruleset.standard.rules.ImportOrderingRule.Companion.IDEA_PATTERN @@ -124,10 +124,10 @@ ).ifAutocorrectAllowed { autocorrect = true } } if (autocorrect) { - node.removeRange(node.firstChildNode, node.lastChildNode.nextSibling20) + node.removeRange(node.firstChildNode, node.lastChildNode.nextSibling) sortedImportsWithSpaces.reduce { current, next -> node.addChild(current, null) - if (!current.isWhiteSpace20 && !next.isWhiteSpace20) { + if (!current.isWhiteSpace && !next.isWhiteSpace) { node.addChild(PsiWhiteSpaceImpl("\n"), null) } return@reduce next @@ -149,7 +149,7 @@ children.forEach { current -> when { - current.isWhiteSpace20 && current.text.count { it == '\n' } > 1 -> { + current.isWhiteSpace && current.text.count { it == '\n' } > 1 -> { imports += current } @@ -175,7 +175,7 @@ val combined = actual.zip(expected) return combined.all { (first, second) -> - if (first.isWhiteSpace20 && second.isWhiteSpace20) { + if (first.isWhiteSpace && second.isWhiteSpace) { return@all (first as PsiWhiteSpace).text == (second as PsiWhiteSpace).text } return@all first == second @@ -184,7 +184,7 @@ private fun isCustomLayout() = importsLayout != IDEA_PATTERN && importsLayout != ASCII_PATTERN - private fun hasTooMuchWhitespace(nodes: Array<ASTNode>): Boolean = nodes.any { it.isWhiteSpaceWithoutNewline20 } + private fun hasTooMuchWhitespace(nodes: Array<ASTNode>): Boolean = nodes.any { it.isWhiteSpaceWithoutNewline } public companion object { /**
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt index 91f9826..996795b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/IndentationRule.kt
@@ -88,7 +88,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.TokenSets -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.column import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue @@ -98,24 +98,24 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.findParentByType -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix import com.pinterest.ktlint.rule.engine.core.api.isCode import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isRoot +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove @@ -172,11 +172,11 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isRoot20) { + if (node.isRoot) { // File should not start with a whitespace node .nextLeaf - ?.takeIf { it.isWhiteSpaceWithoutNewline20 } + ?.takeIf { it.isWhiteSpaceWithoutNewline } ?.let { whitespaceWithoutNewline -> emit(node.startOffset, "Unexpected indentation", true) .ifAutocorrectAllowed { whitespaceWithoutNewline.remove() } @@ -185,7 +185,7 @@ } when { - node.isWhiteSpaceWithNewline20 -> { + node.isWhiteSpaceWithNewline -> { line++ if (indentContextStack.peekLast()?.activated == false) { val lastIndentContext = indentContextStack.removeLast() @@ -207,10 +207,10 @@ } (node.elementType == SUPER_TYPE_LIST && !node.isPrecededByComment()) || - (node.isPartOfComment20 && node.nextCodeSibling20?.elementType == SUPER_TYPE_LIST) -> { + (node.isPartOfComment && node.nextCodeSibling?.elementType == SUPER_TYPE_LIST) -> { if (codeStyle == ktlint_official) { val superTypeList = - if (node.isPartOfComment20) { + if (node.isPartOfComment) { node.nextCodeLeaf!! } else { node @@ -304,7 +304,7 @@ } node.elementType == LPAR && - node.nextCodeSibling20?.elementType == CONDITION -> { + node.nextCodeSibling?.elementType == CONDITION -> { visitLparBeforeCondition(node) } @@ -341,9 +341,9 @@ // } startIndentContext( fromAstNode = node.parent!!, - toAstNode = node.parent!!.parent!!.lastChildLeafOrSelf20, + toAstNode = node.parent!!.parent!!.lastChildLeafOrSelf, ) - } else if (node.prevCodeSibling20.isElvisOperator()) { + } else if (node.prevCodeSibling.isElvisOperator()) { startIndentContext(node) } else if (node.parent?.elementType in CHAINABLE_EXPRESSION) { // Multiple dot qualified expressions and/or safe expression on the same line should not increase the indent level @@ -358,7 +358,7 @@ } node.elementType == LITERAL_STRING_TEMPLATE_ENTRY && - node.nextCodeSibling20?.elementType == CLOSING_QUOTE -> { + node.nextCodeSibling?.elementType == CLOSING_QUOTE -> { visitWhiteSpaceBeforeClosingQuote(node, emit) } @@ -371,7 +371,7 @@ } node.elementType == WHERE_KEYWORD && - node.nextCodeSibling20?.elementType == TYPE_CONSTRAINT_LIST -> { + node.nextCodeSibling?.elementType == TYPE_CONSTRAINT_LIST -> { visitWhereKeywordBeforeTypeConstraintList(node) } @@ -455,7 +455,7 @@ } private fun visitIf(node: ASTNode) { - var nextToAstNode = node.lastChildLeafOrSelf20 + var nextToAstNode = node.lastChildLeafOrSelf node .findChildByType(ELSE) ?.let { fromAstNode -> @@ -468,7 +468,7 @@ node .findChildByType(THEN) - ?.lastChildLeafOrSelf20 + ?.lastChildLeafOrSelf ?.nextLeaf ?.let { nodeAfterThenBlock -> nextToAstNode = @@ -565,7 +565,7 @@ .takeIf { it.isPartOf(CALL_EXPRESSION) } ?.parent ?.leaves(false) - ?.takeWhile { !it.isWhiteSpaceWithNewline20 } + ?.takeWhile { !it.isWhiteSpaceWithNewline } ?.sumOf { it.textLength } ?.plus(2) // need to add spaces to compensate for "{ " ?.let { length -> " ".repeat(length) } @@ -582,7 +582,7 @@ // Allow to pickup whitespace before condition fromAstNode = requireNotNull(node.nextLeaf), // Ignore whitespace after condition but before rpar - toAstNode = requireNotNull(node.nextCodeSibling20).lastChildLeafOrSelf20, + toAstNode = requireNotNull(node.nextCodeSibling).lastChildLeafOrSelf, nodeIndent = currentIndent() + indentConfig.indent, childIndent = "", ) @@ -590,7 +590,7 @@ private fun visitValueParameter(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode: ASTNode = node.lastChildLeafOrSelf20 + var nextToAstNode: ASTNode = node.lastChildLeafOrSelf node .findChildByType(EQ) ?.let { fromAstNode -> @@ -621,13 +621,13 @@ // Leading annotations and comments should be indented at same level as constructor itself val fromAstNode = node.skipLeadingWhitespaceCommentsAndAnnotations() if (fromAstNode != node.firstChildNode && - node.prevSibling { it.isWhiteSpaceWithNewline20 } == null && + node.prevSibling { it.isWhiteSpaceWithNewline } == null && node == node.parent?.findChildByType(VALUE_PARAMETER) ) { startIndentContext( fromAstNode = fromAstNode, toAstNode = nextToAstNode, - ).fromASTNode.prevLeaf { !it.isWhiteSpace20 }!! + ).fromASTNode.prevLeaf { !it.isWhiteSpace }!! } else { startIndentContext( fromAstNode = node, @@ -639,7 +639,7 @@ private fun visitFun(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode: ASTNode = node.lastChildLeafOrSelf20 + var nextToAstNode: ASTNode = node.lastChildLeafOrSelf val eqOrBlock = node.findChildByType(EQ) ?: node.findChildByType(BLOCK) @@ -656,7 +656,7 @@ ?.let { where -> val typeConstraintList = requireNotNull( - where.nextCodeSibling20, + where.nextCodeSibling, ) { "Can not find code sibling after WHERE in FUN" } require(typeConstraintList.elementType == TYPE_CONSTRAINT_LIST) { "Code sibling after WHERE in CLASS is not a TYPE_CONSTRAINT_LIST" @@ -664,7 +664,7 @@ nextToAstNode = startIndentContext( fromAstNode = where.getPrecedingLeadingCommentsAndWhitespaces(), - toAstNode = typeConstraintList.lastChildLeafOrSelf20, + toAstNode = typeConstraintList.lastChildLeafOrSelf, childIndent = " ".repeat( maxOf(0, where.column - 1 - node.indentWithoutNewlinePrefix.length), @@ -692,13 +692,13 @@ private fun visitClass(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode: ASTNode = node.lastChildLeafOrSelf20 + var nextToAstNode: ASTNode = node.lastChildLeafOrSelf node .findChildByType(WHERE_KEYWORD) ?.let { where -> val typeConstraintList = requireNotNull( - where.nextCodeSibling20, + where.nextCodeSibling, ) { "Can not find code sibling after WHERE in CLASS" } require(typeConstraintList.elementType == TYPE_CONSTRAINT_LIST) { "Code sibling after WHERE in CLASS is not a TYPE_CONSTRAINT_LIST" @@ -706,7 +706,7 @@ nextToAstNode = startIndentContext( fromAstNode = where.getPrecedingLeadingCommentsAndWhitespaces(), - toAstNode = typeConstraintList.lastChildLeafOrSelf20, + toAstNode = typeConstraintList.lastChildLeafOrSelf, ).prevCodeLeaf() } @@ -726,7 +726,7 @@ nextToAstNode = startIndentContext( fromAstNode = superTypeList.getPrecedingLeadingCommentsAndWhitespaces(), - toAstNode = superTypeList.lastChildLeafOrSelf20, + toAstNode = superTypeList.lastChildLeafOrSelf, ).prevCodeLeaf() } } @@ -741,14 +741,14 @@ private fun visitObjectDeclaration(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode: ASTNode = node.lastChildLeafOrSelf20 + var nextToAstNode: ASTNode = node.lastChildLeafOrSelf node .findChildByType(SUPER_TYPE_LIST) ?.let { superTypeList -> nextToAstNode = startIndentContext( fromAstNode = superTypeList.getPrecedingLeadingCommentsAndWhitespaces(), - toAstNode = superTypeList.lastChildLeafOrSelf20, + toAstNode = superTypeList.lastChildLeafOrSelf, ).prevCodeLeaf() } @@ -769,7 +769,7 @@ // Create new indent context for the remainder (operator and right-hand side) of the binary expression startIndentContext( fromAstNode = node.findChildByType(OPERATION_REFERENCE)!!, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, nodeIndent = conditionIndentContext.nodeIndent, childIndent = conditionIndentContext.childIndent, ) @@ -784,12 +784,12 @@ private fun visitIdentifierInProperty(node: ASTNode) { startIndentContext( fromAstNode = node, - toAstNode = node.parent!!.lastChildLeafOrSelf20, + toAstNode = node.parent!!.lastChildLeafOrSelf, ) } private fun visitWhen(node: ASTNode) { - var nextToASTNode = node.lastChildLeafOrSelf20 + var nextToASTNode = node.lastChildLeafOrSelf node .findChildByType(LPAR) ?.let { lpar -> @@ -811,10 +811,10 @@ .findChildByType(ARROW) ?.let { arrow -> arrow - .prevSibling { !it.isPartOfComment20 } + .prevSibling { !it.isPartOfComment } .let { prevSibling -> - if (indentWhenArrowOnNewLine && prevSibling != null && prevSibling.isWhiteSpaceWithNewline20) { - if (arrow.nextCodeSibling20?.elementType == BLOCK && codeStyle != ktlint_official) { + if (indentWhenArrowOnNewLine && prevSibling != null && prevSibling.isWhiteSpaceWithNewline) { + if (arrow.nextCodeSibling?.elementType == BLOCK && codeStyle != ktlint_official) { // Uglify the indentation to below to keep compatible with default formatting Intellij IDEA // val foo = // when (bar()) { @@ -825,7 +825,7 @@ // } startIndentContext( fromAstNode = prevSibling, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, firstChildIndent = indentConfig.indent, childIndent = "", ) @@ -841,7 +841,7 @@ // } startIndentContext( fromAstNode = arrow.nextLeaf!!, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, ) startIndentContext( fromAstNode = node, @@ -852,7 +852,7 @@ } else { startIndentContext( fromAstNode = arrow.nextLeaf!!, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, ) startIndentContext( fromAstNode = node, @@ -867,7 +867,7 @@ private fun visitWhereKeywordBeforeTypeConstraintList(node: ASTNode) { node .prevLeaf - .takeUnless { it.isWhiteSpaceWithNewline20 } + .takeUnless { it.isWhiteSpaceWithNewline } ?.takeIf { !indentContextStack.peekLast().activated } ?.let { val lastIndentContext = indentContextStack.removeLast() @@ -878,7 +878,7 @@ startIndentContext( fromAstNode = node, - toAstNode = node.nextCodeSibling20?.lastChildLeafOrSelf20!!, + toAstNode = node.nextCodeSibling?.lastChildLeafOrSelf!!, childIndent = TYPE_CONSTRAINT_CONTINUATION_INDENT, ) } @@ -890,21 +890,21 @@ ?.let { fromAstNode -> startIndentContext( fromAstNode = fromAstNode, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, childIndent = KDOC_CONTINUATION_INDENT, ) } } private fun visitPropertyAccessor(node: ASTNode) { - var nextToASTNode = node.lastChildLeafOrSelf20 + var nextToASTNode = node.lastChildLeafOrSelf node .findChildByType(EQ) ?.let { fromAstNode -> nextToASTNode = startIndentContext( fromAstNode = fromAstNode, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, ).prevCodeLeaf() } // No indent on preceding annotations and comments @@ -923,7 +923,7 @@ ?.let { rpar -> startIndentContext( fromAstNode = rpar, - toAstNode = node.lastChildLeafOrSelf20, + toAstNode = node.lastChildLeafOrSelf, ) } node @@ -953,7 +953,7 @@ private fun visitNullableType(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode = node.lastChildLeafOrSelf20 + var nextToAstNode = node.lastChildLeafOrSelf node .findChildByType(RPAR) ?.let { fromAstNode -> @@ -972,7 +972,7 @@ private fun visitDestructuringDeclaration(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode = node.lastChildLeafOrSelf20 + var nextToAstNode = node.lastChildLeafOrSelf node .findChildByType(EQ) ?.let { eq -> @@ -996,7 +996,7 @@ private fun visitTryCatchFinally(node: ASTNode) { // Inner indent contexts in reversed order - var nextToAstNode = node.lastChildLeafOrSelf20 + var nextToAstNode = node.lastChildLeafOrSelf node .findChildByType(FINALLY) ?.let { finally -> @@ -1031,18 +1031,18 @@ return findChildByType(MODIFIER_LIST) ?.let { modifierList -> modifierList - .children20 + .children .firstOrNull { it.isCode && it.elementType != ANNOTATION_ENTRY } - ?: modifierList.nextCodeSibling20 + ?: modifierList.nextCodeSibling } - ?: children20.firstOrNull { it.isCode } + ?: children.firstOrNull { it.isCode } ?: this } private fun ASTNode.getPrecedingLeadingCommentsAndWhitespaces(): ASTNode { var fromAstNode: ASTNode? = this while (fromAstNode?.prevLeaf != null && - (fromAstNode.prevLeaf.isWhiteSpace20 || fromAstNode.prevLeaf?.isPartOfComment20 == true) + (fromAstNode.prevLeaf.isWhiteSpace || fromAstNode.prevLeaf?.isPartOfComment == true) ) { fromAstNode = fromAstNode.prevLeaf } @@ -1063,7 +1063,7 @@ private fun startIndentContext( fromAstNode: ASTNode, - toAstNode: ASTNode = fromAstNode.lastChildLeafOrSelf20, + toAstNode: ASTNode = fromAstNode.lastChildLeafOrSelf, nodeIndent: String = currentIndent(), childIndent: String = indentConfig.indent, firstChildIndent: String = childIndent, @@ -1201,8 +1201,8 @@ val nextLeaf = nextLeaf val adjustedChildIndent = when { - this == lastIndexContext.fromASTNode.firstChildLeafOrSelf20 || - nextLeaf == lastIndexContext.fromASTNode.firstChildLeafOrSelf20 -> { + this == lastIndexContext.fromASTNode.firstChildLeafOrSelf || + nextLeaf == lastIndexContext.fromASTNode.firstChildLeafOrSelf -> { lastIndexContext.firstChildIndent } @@ -1274,7 +1274,7 @@ firstChildNode?.elementType == ELVIS private fun ASTNode.acceptableTrailingSpaces(): String { - require(isWhiteSpace20) + require(isWhiteSpace) val acceptableTrailingSpaces = when (nextLeaf?.elementType) { KDOC_LEADING_ASTERISK, KDOC_END -> { @@ -1312,7 +1312,7 @@ activated = true, ) - private fun ASTNode.isPrecededByComment() = prevSibling { !it.isWhiteSpace20 }?.isPartOfComment20 == true + private fun ASTNode.isPrecededByComment() = prevSibling { !it.isWhiteSpace }?.isPartOfComment == true public companion object { private const val KDOC_CONTINUATION_INDENT = " " @@ -1344,7 +1344,7 @@ * The node at which the indent context ends. If null, then the context ends at the last child leaf of the node * on which the indent context starts. */ - val toASTNode: ASTNode = fromASTNode.lastChildLeafOrSelf20, + val toASTNode: ASTNode = fromASTNode.lastChildLeafOrSelf, /** * Cumulative indentation for the node. Normally this should be equal to a multiple of the * 'indentConfig.indentStyle' to ensure a consistent indentation style. @@ -1469,7 +1469,7 @@ expectedIndent } node - .children20 + .children .filter { it.isIndentBeforeClosingQuote() } .forEach { if (it.prevLeaf?.text == "\n") { @@ -1495,7 +1495,7 @@ } private fun ASTNode.isRawStringLiteralFunctionBodyExpression() = - (!prevLeaf.isWhiteSpace20 || prevLeaf?.text == " ") && + (!prevLeaf.isWhiteSpace || prevLeaf?.text == " ") && FUN == prevCodeLeaf .takeIf { it?.elementType == EQ } @@ -1515,7 +1515,7 @@ .let { it?.elementType == CALL_EXPRESSION && it.text == callExpressionName } private fun ASTNode.isMultiLine(): Boolean = - children20 + children .filter { it.elementType == LITERAL_STRING_TEMPLATE_ENTRY } .any { it.text == "\n" } @@ -1540,7 +1540,7 @@ } private fun ASTNode.isIndentBeforeClosingQuote() = - elementType == CLOSING_QUOTE || (text.isBlank() && nextCodeSibling20?.elementType == CLOSING_QUOTE) + elementType == CLOSING_QUOTE || (text.isBlank() && nextCodeSibling?.elementType == CLOSING_QUOTE) private fun String.indentLength() = indexOfFirst { !it.isWhitespace() }.let { if (it == -1) length else it }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt index 88b8ad9..da585b2 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/KdocWrappingRule.kt
@@ -11,8 +11,8 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -41,7 +41,7 @@ node .findChildByType(KDOC_START) ?.prevLeaf - ?.takeIf { !it.isWhiteSpaceWithNewline20 } + ?.takeIf { !it.isWhiteSpaceWithNewline } ?.let { // It cannot be autocorrected as it might depend on the situation and code style what is // preferred. @@ -55,11 +55,11 @@ node .findChildByType(KDOC_END) ?.nextLeaf - ?.takeIf { !it.isWhiteSpaceWithNewline20 } + ?.takeIf { !it.isWhiteSpaceWithNewline } ?.let { nextLeaf -> emit(nextLeaf.startOffset, "A KDoc comment may not be followed by any other element on that same line", true) .ifAutocorrectAllowed { - node.upsertWhitespaceAfterMe(node.indent20) + node.upsertWhitespaceAfterMe(node.indent) } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt index 824eeb7..80963aa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MaxLineLengthRule.kt
@@ -19,10 +19,10 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.ktLintRuleExecutionPropertyName import com.pinterest.ktlint.rule.engine.core.api.findParentByType import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent @@ -57,12 +57,12 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpace20) { + if (node.isWhiteSpace) { return } node .takeIf { it is LeafPsiElement } - ?.takeIf { it.nextLeaf == null || it.nextLeaf.isWhiteSpaceWithNewline20 } + ?.takeIf { it.nextLeaf == null || it.nextLeaf.isWhiteSpaceWithNewline } ?.takeIf { it.lineLength() > maxLineLength } ?.takeUnless { it.isPartOf(PACKAGE_DIRECTIVE) } ?.takeUnless { it.isPartOf(IMPORT_DIRECTIVE) } @@ -75,7 +75,7 @@ // Calculate the offset at the last possible position at which the newline should be inserted on the line val offset = node - .leavesOnLine20 + .leavesOnLine .first() .startOffset .plus(maxLineLength + 1) @@ -88,7 +88,7 @@ } private fun ASTNode.lineLength() = - leavesOnLine20 + leavesOnLine .filterNot { ignoreBackTickedIdentifier && it.elementType == IDENTIFIER && @@ -107,14 +107,14 @@ stringTemplate .prevLeaf .let { leafBeforeStringTemplate -> - leafBeforeStringTemplate == null || leafBeforeStringTemplate.isWhiteSpaceWithNewline20 + leafBeforeStringTemplate == null || leafBeforeStringTemplate.isWhiteSpaceWithNewline } } ?: false private fun ASTNode.isLineOnlyContainingComment() = - isPartOfComment20 && - (prevLeaf == null || prevLeaf.isWhiteSpaceWithNewline20) + isPartOfComment && + (prevLeaf == null || prevLeaf.isWhiteSpaceWithNewline) public companion object { public val IGNORE_BACKTICKED_IDENTIFIER_PROPERTY: EditorConfigProperty<Boolean> =
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt index 834b05a..039ffac 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ModifierListSpacingRule.kt
@@ -11,13 +11,13 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -55,7 +55,7 @@ ) { if (node.elementType == MODIFIER_LIST) { node - .children20 + .children .forEach { visitModifierChild(it, emit) } // The whitespace of the last entry of the modifier list is actually placed outside the modifier list visitModifierChild(node, emit) @@ -66,14 +66,14 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpace20) { + if (node.isWhiteSpace) { return } node - .nextSibling { it.isWhiteSpace20 && it.nextLeaf?.isPartOfComment20 != true } + .nextSibling { it.isWhiteSpace && it.nextLeaf?.isPartOfComment != true } ?.takeUnless { // A single newline after a comment is always ok and does not need further checking. - it.text.trim(' ', '\t').contains('\n') && it.prevLeaf?.isPartOfComment20 == true + it.text.trim(' ', '\t').contains('\n') && it.prevLeaf?.isPartOfComment == true }?.let { whitespace -> when { node.isAnnotation() -> {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt index 12bc556..aef410e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultiLineIfElseRule.kt
@@ -19,13 +19,13 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -101,7 +101,7 @@ return } - if (!node.prevSibling20!!.textContains('\n')) { + if (!node.prevSibling!!.textContains('\n')) { if (node.firstChildNode == null) { // if block with an empty 'then' block return @@ -140,13 +140,13 @@ val nextLeaves = node .leaves(forward = true) - .takeWhile { it.isWhiteSpaceWithoutNewline20 || it.isPartOfComment20 } + .takeWhile { it.isWhiteSpaceWithoutNewline || it.isPartOfComment } .toList() - .dropLastWhile { it.isWhiteSpaceWithoutNewline20 } + .dropLastWhile { it.isWhiteSpaceWithoutNewline } prevLeaves .firstOrNull() - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.replaceTextWith(" ") KtBlockExpression(null).apply { val previousChild = node.firstChildNode @@ -154,18 +154,18 @@ addChild(LeafPsiElement(LBRACE, "{")) addChild(PsiWhiteSpaceImpl(indentConfig.childIndentOf(node))) prevLeaves - .dropWhile { it.isWhiteSpace20 } + .dropWhile { it.isWhiteSpace } .forEach(::addChild) addChild(previousChild) nextLeaves.forEach(::addChild) - addChild(PsiWhiteSpaceImpl(node.indent20)) + addChild(PsiWhiteSpaceImpl(node.indent)) addChild(LeafPsiElement(RBRACE, "}")) } // Make sure else starts on same line as newly inserted right brace if (node.elementType == THEN) { node - .nextSibling { !it.isPartOfComment20 } + .nextSibling { !it.isPartOfComment } ?.upsertWhitespaceBeforeMe(" ") } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt index b4890c9..478919a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineExpressionWrappingRule.kt
@@ -40,17 +40,17 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -113,17 +113,17 @@ ) { if (node.containsWhitespaceWithNewline() && node.needToWrapMultilineExpression()) { node - .prevLeaf { !it.isPartOfComment20 } - .takeUnless { it.isWhiteSpaceWithNewline20 } + .prevLeaf { !it.isPartOfComment } + .takeUnless { it.isWhiteSpaceWithNewline } ?.let { prevLeaf -> emit(node.startOffset, "A multiline expression should start on a new line", true) .ifAutocorrectAllowed { node.upsertWhitespaceBeforeMe(indentConfig.siblingIndentOf(node)) val leafOnSameLineAfterMultilineExpression = node - .lastChildLeafOrSelf20 - .nextLeaf { !it.isWhiteSpaceWithoutNewline20 && !it.isPartOfComment20 } - ?.takeIf { !it.isWhiteSpaceWithNewline20 } + .lastChildLeafOrSelf + .nextLeaf { !it.isWhiteSpaceWithoutNewline && !it.isPartOfComment } + ?.takeIf { !it.isWhiteSpaceWithNewline } when { leafOnSameLineAfterMultilineExpression == null -> { Unit @@ -161,11 +161,11 @@ } private fun ASTNode.containsWhitespaceWithNewline(): Boolean { - val lastLeaf = lastChildLeafOrSelf20 - return firstChildLeafOrSelf20 + val lastLeaf = lastChildLeafOrSelf + return firstChildLeafOrSelf .leavesForwardsIncludingSelf .takeWhile { it != lastLeaf } - .any { it.isWhiteSpaceWithNewline20 || it.isRegularStringPartWithNewline() } + .any { it.isWhiteSpaceWithNewline || it.isRegularStringPartWithNewline() } } private fun ASTNode.isRegularStringPartWithNewline() = @@ -180,7 +180,7 @@ private fun ASTNode.isValueInAnAssignment() = null != - prevCodeSibling20 + prevCodeSibling ?.takeIf { it.elementType == EQ || it.elementType == OPERATION_REFERENCE } ?.takeUnless { functionBodyExpressionWrapping == default && it.parent?.elementType == FUN } ?.takeUnless { it.isElvisOperator() } @@ -188,7 +188,7 @@ it .closingParenthesisOfFunctionOrNull() ?.prevLeaf - .isWhiteSpaceWithNewline20 + .isWhiteSpaceWithNewline } private fun ASTNode?.isElvisOperator() = @@ -220,7 +220,7 @@ private fun ASTNode.isRightHandSideOfBinaryExpression() = null != takeIf { it.parent?.elementType == BINARY_EXPRESSION } - .takeIf { it?.prevCodeSibling20?.elementType == OPERATION_REFERENCE } + .takeIf { it?.prevCodeSibling?.elementType == OPERATION_REFERENCE } private companion object { // Based on https://kotlinlang.org/spec/expressions.html#expressions
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt index c4b5cb8..7d5fe3c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/MultilineLoopRule.kt
@@ -16,10 +16,10 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith @@ -89,13 +89,13 @@ val nextLeaves = node .leaves(forward = true) - .takeWhile { it.isWhiteSpaceWithoutNewline20 || it.isPartOfComment20 } + .takeWhile { it.isWhiteSpaceWithoutNewline || it.isPartOfComment } .toList() - .dropLastWhile { it.isWhiteSpaceWithoutNewline20 } + .dropLastWhile { it.isWhiteSpaceWithoutNewline } prevLeaves .firstOrNull() - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.replaceTextWith(" ") KtBlockExpression(null).apply { val previousChild = node.firstChildNode @@ -103,16 +103,16 @@ addChild(LeafPsiElement(LBRACE, "{")) addChild(PsiWhiteSpaceImpl(indentConfig.childIndentOf(node))) prevLeaves - .dropWhile { it.isWhiteSpace20 } + .dropWhile { it.isWhiteSpace } .forEach(::addChild) addChild(previousChild) nextLeaves.forEach(::addChild) - addChild(PsiWhiteSpaceImpl(node.indent20)) + addChild(PsiWhiteSpaceImpl(node.indent)) addChild(LeafPsiElement(RBRACE, "}")) } node - .nextSibling { !it.isPartOfComment20 } + .nextSibling { !it.isPartOfComment } ?.upsertWhitespaceBeforeMe(" ") } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt index 20f654e..d3cf613 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineBeforeRbraceRule.kt
@@ -6,7 +6,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -18,7 +18,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpaceWithNewline20 && + if (node.isWhiteSpaceWithNewline && node.nextLeaf?.elementType == RBRACE ) { val split = node.getText().split("\n")
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt index b2cf452..0e5996d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLineInListRule.kt
@@ -14,10 +14,10 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -32,7 +32,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (!node.isWhiteSpace20) { + if (!node.isWhiteSpace) { return } @@ -50,7 +50,7 @@ // the SUPER_TYPE_LIST of a CLASS the whitespaces before the first super type is a child of the CLASS. The whitespace after the last // SUPER_TYPE is part of the class only when the class has a body. node - .nextSibling20 + .nextSibling ?.elementType ?.takeIf { it in LIST_TYPES } ?.let { treeParentElementType -> @@ -68,7 +68,7 @@ // the SUPER_TYPE_LIST of a CLASS the whitespaces before the first super type is a child of the CLASS. The whitespace after the last // SUPER_TYPE is part of the class only when the class has a body. node - .prevSibling20 + .prevSibling ?.elementType ?.takeIf { it in LIST_TYPES } ?.let { treeParentElementType -> @@ -76,7 +76,7 @@ node = node, emit = emit, partOfElementType = treeParentElementType, - replaceWithSingeSpace = node.nextSibling20?.elementType == CLASS_BODY, + replaceWithSingeSpace = node.nextSibling?.elementType == CLASS_BODY, ) } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt index 610d39e..6f5a6ec 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoBlankLinesInChainedMethodCallsRule.kt
@@ -5,7 +5,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -17,7 +17,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - val isBlankLine = node.isWhiteSpace20 && node.text.contains("\n\n") + val isBlankLine = node.isWhiteSpace && node.text.contains("\n\n") if (isBlankLine && node.parent?.elementType == DOT_QUALIFIED_EXPRESSION) { emit(node.startOffset + 1, "Needless blank line(s)", true) .ifAutocorrectAllowed {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt index bcfc1ec..d907769 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveBlankLinesRule.kt
@@ -8,12 +8,12 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -24,7 +24,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpace20 && node.prevSibling20 != null) { + if (node.isWhiteSpace && node.prevSibling != null) { val text = node.getText() val newLineCount = text.count { it == '\n' } if (newLineCount < 2) { @@ -67,7 +67,7 @@ ?.let { prevNode -> prevNode.elementType == IDENTIFIER && prevNode.parent?.elementType == CLASS && - this.nextSibling20?.elementType == PRIMARY_CONSTRUCTOR + this.nextSibling?.elementType == PRIMARY_CONSTRUCTOR } ?: false }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt index 569b8c5..009c4ff 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoConsecutiveCommentsRule.kt
@@ -10,7 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -34,7 +34,7 @@ ) { node .takeIf { it.isStartOfComment() } - ?.prevLeaf { !it.isWhiteSpace20 } + ?.prevLeaf { !it.isWhiteSpace } ?.takeIf { previousNonWhiteSpace -> previousNonWhiteSpace.isEndOfComment() } ?.let { previousComment -> when { @@ -103,7 +103,7 @@ previousComment.elementType != node.elementType && node .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.text .orEmpty() .count { it == '\n' } > 1 -> {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt index eb99735..dfa7021 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyClassBodyRule.kt
@@ -8,13 +8,13 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -33,7 +33,7 @@ emit(node.startOffset, "Unnecessary block (\"{}\")", true) .ifAutocorrectAllowed { // remove space between declaration and block - node.prevSibling20.takeIf { it.isWhiteSpace20 }?.remove() + node.prevSibling.takeIf { it.isWhiteSpace }?.remove() // remove block node.remove() } @@ -43,13 +43,13 @@ private fun ASTNode.isEmptyBlockBody(): Boolean = firstChildNode != null && firstChildNode.elementType == LBRACE && - firstChildNode.nextLeaf { !it.isWhiteSpace20 }?.elementType == RBRACE + firstChildNode.nextLeaf { !it.isWhiteSpace }?.elementType == RBRACE private fun isNotCompanion(node: ASTNode): Boolean = node .parent ?.firstChildNode - ?.children20 + ?.children .orEmpty() .none { it.text == "companion" } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt index e978fd0..ccf76be 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFileRule.kt
@@ -8,9 +8,9 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 +import com.pinterest.ktlint.rule.engine.core.api.isRoot import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -22,7 +22,7 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .takeIf { it.isRoot20 } + .takeIf { it.isRoot } ?.takeIf { it.isEmptyFile() } ?.let { emit(0, "File '${node.getFileName()}' should not be empty", false) } } @@ -37,7 +37,7 @@ private fun ASTNode.isEmptyFile(): Boolean = null == - children20 + children .firstOrNull { it.isCode && it.elementType != PACKAGE_DIRECTIVE &&
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt index fa9577b..e3c5b18 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInClassBodyRule.kt
@@ -12,7 +12,7 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -48,7 +48,7 @@ node .firstChildNode // LBRACE .nextLeaf - .takeIf { it.isWhiteSpaceWithNewline20 } + .takeIf { it.isWhiteSpaceWithNewline } ?.let { whitespace -> val countNewlines = whitespace
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt index af596c6..e302a56 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoEmptyFirstLineInMethodBlockRule.kt
@@ -10,7 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith @@ -24,7 +24,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpaceWithNewline20 && + if (node.isWhiteSpaceWithNewline && node.prevLeaf?.elementType == LBRACE && node.isPartOf(FUN) && // Allow:
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt index 1a55cc6..25d83b9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakAfterElseRule.kt
@@ -8,7 +8,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith @@ -21,7 +21,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isWhiteSpaceWithNewline20 && + if (node.isWhiteSpaceWithNewline && node.prevLeaf?.elementType == ELSE_KEYWORD && node.nextLeaf?.elementType.let { it == IF_KEYWORD || it == LBRACE } ) {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt index 0cdb443..2706e8f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoLineBreakBeforeAssignmentRule.kt
@@ -7,11 +7,11 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -35,8 +35,8 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { assignmentNode - .prevSibling20 - .takeIf { it.isWhiteSpaceWithNewline20 } + .prevSibling + .takeIf { it.isWhiteSpaceWithNewline } ?.let { unexpectedNewlineBeforeAssignment -> emit(unexpectedNewlineBeforeAssignment.startOffset, "Line break before assignment is not allowed", true) .ifAutocorrectAllowed { @@ -47,18 +47,18 @@ .takeWhile { !it.isCode } .last() .let { before -> - if (!before.prevSibling20.isWhiteSpace20) { + if (!before.prevSibling.isWhiteSpace) { parent.addChild(PsiWhiteSpaceImpl(" "), before) } parent.addChild(LeafPsiElement(EQ, "="), before) - if (!before.isWhiteSpace20) { + if (!before.isWhiteSpace) { parent.addChild(PsiWhiteSpaceImpl(" "), before) } } // Cleanup old assignment and whitespace after it. The indent before the old assignment is kept unchanged assignmentNode - .nextSibling20 - .takeIf { it.isWhiteSpace20 } + .nextSibling + .takeIf { it.isWhiteSpace } ?.remove() assignmentNode.remove() }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt index bb5fdbe..142c38e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoMultipleSpacesRule.kt
@@ -7,9 +7,9 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -21,7 +21,7 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .takeIf { node.isWhiteSpace20 } + .takeIf { node.isWhiteSpace } .takeUnless { node.isPossibleAlignmentOfKdocTag() } ?.let { val beforeIndentation = node.removeIndentation() @@ -40,7 +40,7 @@ // allow multiple spaces in KDoc in case of KDOC_TAG for alignment, e.g. // @param foo stuff // @param foobar stuff2 - private fun ASTNode.isPossibleAlignmentOfKdocTag() = prevSibling20?.elementType == KDOC_MARKDOWN_LINK && parent?.elementType == KDOC_TAG + private fun ASTNode.isPossibleAlignmentOfKdocTag() = prevSibling?.elementType == KDOC_MARKDOWN_LINK && parent?.elementType == KDOC_TAG } public val NO_MULTIPLE_SPACES_RULE_ID: RuleId = NoMultipleSpacesRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt index b9fb8a9..4ab73bb 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSemicolonsRule.kt
@@ -21,10 +21,10 @@ import com.pinterest.ktlint.rule.engine.core.api.hasModifier import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf @@ -53,14 +53,14 @@ .ifAutocorrectAllowed { val prevLeaf = node.prevLeaf node.remove() - if ((prevLeaf != null && prevLeaf.isWhiteSpace20) && - (nextLeaf == null || nextLeaf.isWhiteSpace20) + if ((prevLeaf != null && prevLeaf.isWhiteSpace) && + (nextLeaf == null || nextLeaf.isWhiteSpace) ) { prevLeaf.remove() } } - } else if (!nextLeaf.isWhiteSpace20) { - if (node.prevLeaf.isWhiteSpaceWithNewline20) { + } else if (!nextLeaf.isWhiteSpace) { + if (node.prevLeaf.isWhiteSpaceWithNewline) { return } // todo: move to a separate rule @@ -77,7 +77,7 @@ true } - this.isWhiteSpace20 -> { + this.isWhiteSpace -> { nextLeaf { it.isCode && it.findParentByType(KDOC) == null && @@ -135,14 +135,14 @@ private fun ASTNode?.getLastCodeLeafBeforeClosingOfClassBody() = this ?.findParentByType(CLASS_BODY) - ?.lastChildLeafOrSelf20 + ?.lastChildLeafOrSelf ?.prevCodeLeaf private fun ASTNode?.isEnumClassWithoutValues() = this ?.takeIf { !it.isLastCodeLeafBeforeClosingOfClassBody() } ?.findParentByType(CLASS_BODY) - ?.takeIf { this == it.firstChildNode.nextCodeSibling20 } + ?.takeIf { this == it.firstChildNode.nextCodeSibling } ?.findParentByType(CLASS) ?.hasModifier(ENUM_KEYWORD) ?: false
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt index 3cdb308..60b1547 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoSingleLineBlockCommentRule.kt
@@ -10,11 +10,11 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -47,9 +47,9 @@ val afterBlockComment = node .leaves() - .takeWhile { it.isWhiteSpaceWithoutNewline20 } + .takeWhile { it.isWhiteSpaceWithoutNewline } .firstOrNull() - ?: node.lastChildLeafOrSelf20 + ?: node.lastChildLeafOrSelf if (!node.textContains('\n') && afterBlockComment.nextLeaf.isWhitespaceWithNewlineOrNull() @@ -59,9 +59,9 @@ val beforeBlockComment = node .leaves(false) - .takeWhile { it.isWhiteSpaceWithoutNewline20 } + .takeWhile { it.isWhiteSpaceWithoutNewline } .firstOrNull() - ?: node.firstChildLeafOrSelf20 + ?: node.firstChildLeafOrSelf beforeBlockComment .prevLeaf .takeIf { !it.isWhitespaceWithNewlineOrNull() } @@ -81,7 +81,7 @@ rawRemove() } - private fun ASTNode?.isWhitespaceWithNewlineOrNull() = this == null || this.isWhiteSpaceWithNewline20 + private fun ASTNode?.isWhitespaceWithNewlineOrNull() = this == null || this.isWhiteSpaceWithNewline } public val NO_SINGLE_LINE_BLOCK_COMMENT_RULE_ID: RuleId = NoSingleLineBlockCommentRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt index d8fad2b..06efb67 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoTrailingSpacesRule.kt
@@ -1,22 +1,19 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision -import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.EOL_COMMENT import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_END import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_LEADING_ASTERISK import com.pinterest.ktlint.rule.engine.core.api.ElementType.KDOC_TEXT -import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -28,7 +25,7 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { if (node.isPartOfKDoc()) { - if (node.isWhiteSpace20 && node.hasTrailingSpacesBeforeNewline()) { + if (node.isWhiteSpace && node.hasTrailingSpacesBeforeNewline()) { val offsetOfSpaceBeforeNewlineInText = node.text.indexOf(" \n") val offsetOfFirstSpaceBeforeNewlineInText = node
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt index 46b43be..0f3aa58 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnitReturnRule.kt
@@ -9,8 +9,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -27,7 +27,7 @@ if (node.elementType == TYPE_REFERENCE && node.text == "Unit" && node.parent?.elementType == FUN && - node.nextCodeSibling20?.firstChildNode?.elementType == LBRACE + node.nextCodeSibling?.firstChildNode?.elementType == LBRACE ) { emit(node.startOffset, "Unnecessary \"Unit\" return type", true) .ifAutocorrectAllowed { @@ -38,14 +38,14 @@ // Remove space after colon when not followed by Unit node node .nextLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.takeIf { it.nextLeaf != node } ?.remove() colonNode.remove() } node .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.takeIf { it.prevLeaf?.elementType != COLON } ?.remove() node.remove()
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt index 4f83089..6bc17e4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NoUnusedImportsRule.kt
@@ -17,14 +17,14 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isRoot20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isRoot +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -59,7 +59,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isRoot20) { + if (node.isRoot) { rootNode = node } when (node.elementType) { @@ -169,13 +169,13 @@ ) { emit(node.startOffset, "Unused import", true) .ifAutocorrectAllowed { - val nextSibling = node.nextSibling20 + val nextSibling = node.nextSibling if (nextSibling == null) { // Last import node - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .nextLeaf - ?.takeIf { it.isWhiteSpaceWithNewline20 } + ?.takeIf { it.isWhiteSpaceWithNewline } ?.let { whitespace -> if (node.prevLeaf == null) { // Also it was the first import, and it is not preceded by any other node containing some text. So @@ -193,7 +193,7 @@ } } else { nextSibling - .takeIf { it.isWhiteSpaceWithNewline20 } + .takeIf { it.isWhiteSpaceWithNewline } ?.remove() } importDirective.delete() @@ -215,20 +215,20 @@ require(this.elementType == IMPORT_DIRECTIVE) when { parent?.firstChildNode == this -> { - nextSibling20 - ?.takeIf { it.isWhiteSpaceWithNewline20 } + nextSibling + ?.takeIf { it.isWhiteSpaceWithNewline } ?.remove() } parent?.lastChildNode == this -> { - prevSibling20 - ?.takeIf { it.isWhiteSpaceWithNewline20 } + prevSibling + ?.takeIf { it.isWhiteSpaceWithNewline } ?.remove() } else -> { nextLeaf - ?.takeIf { it.isWhiteSpaceWithNewline20 } + ?.takeIf { it.isWhiteSpaceWithNewline } ?.remove() } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt index 7aa918b..f6d861e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/NullableTypeSpacingRule.kt
@@ -7,7 +7,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -23,7 +23,7 @@ node .takeIf { node.elementType == QUEST } ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { whiteSpaceBeforeQuest -> emit(whiteSpaceBeforeQuest.startOffset, "Unexpected whitespace", true) .ifAutocorrectAllowed {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt index 7a0a36a..e4aa65f 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PackageNameRule.kt
@@ -7,7 +7,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import com.pinterest.ktlint.ruleset.standard.rules.internal.regExIgnoringDiacriticsAndStrokesOnLetters import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -24,7 +24,7 @@ node .takeIf { node.elementType == PACKAGE_DIRECTIVE } ?.firstChildNode - ?.nextCodeSibling20 + ?.nextCodeSibling ?.takeIf { it.elementType == DOT_QUALIFIED_EXPRESSION || it.elementType == REFERENCE_EXPRESSION } ?.let { expression -> if (expression.text.contains('_')) {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt index bf7c132..0d09d81 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListSpacingRule.kt
@@ -14,21 +14,21 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.dropTrailingEolComment import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.lineLength -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -71,12 +71,12 @@ require(node.elementType == VALUE_PARAMETER_LIST) val countValueParameters = node - .children20 + .children .count { it.elementType == VALUE_PARAMETER } var valueParameterCount = 0 val iterator = node - .children20 + .children // Store elements in list before changing them as otherwise only one element is being changed .toList() .iterator() @@ -102,11 +102,11 @@ // Avoid conflict with comment spacing rule which requires a whitespace before the // EOL-comment } - } else if (el.nextCodeSibling20?.elementType == COMMA) { + } else if (el.nextCodeSibling?.elementType == COMMA) { // No whitespace between parameter name and comma allowed removeUnexpectedWhiteSpace(el, emit) - } else if (el.isWhiteSpace20 && el.isNotIndent() && el.isNotSingleSpace()) { - require(el.prevCodeSibling20?.elementType == COMMA) + } else if (el.isWhiteSpace && el.isNotIndent() && el.isNotSingleSpace()) { + require(el.prevCodeSibling?.elementType == COMMA) replaceWithSingleSpace(el, emit) } } @@ -115,7 +115,7 @@ // Comma, except when it is the trailing comma, must be followed by whitespace el .nextLeaf - ?.takeUnless { it.isWhiteSpace20 || it.elementType == RPAR } + ?.takeUnless { it.isWhiteSpace || it.elementType == RPAR } ?.let { addMissingWhiteSpaceAfterMe(el, emit) } } @@ -127,7 +127,7 @@ } } - private fun ASTNode.containsNoComments() = children20.none { it.isPartOfComment20 } + private fun ASTNode.containsNoComments() = children.none { it.isPartOfComment } private fun visitValueParameter( node: ASTNode, @@ -153,8 +153,8 @@ ) { require(node.elementType == MODIFIER_LIST) node - .children20 - .filter { it.isWhiteSpace20 } + .children + .filter { it.isWhiteSpace } // Store elements in the list before changing them as otherwise only the first whitespace is being changed .toList() .forEach { visitWhiteSpaceAfterModifier(it, emit) } @@ -178,8 +178,8 @@ ) { require(node.elementType == MODIFIER_LIST) node - .nextSibling20 - ?.takeIf { it.isWhiteSpace20 } + .nextSibling + ?.takeIf { it.isWhiteSpace } ?.let { visitWhiteSpaceAfterModifier(it, emit) } } @@ -190,7 +190,7 @@ node .findChildByType(COLON) ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { whiteSpaceBeforeColon -> removeUnexpectedWhiteSpace(whiteSpaceBeforeColon, emit) } @@ -203,7 +203,7 @@ val colonNode = node.findChildByType(COLON) ?: return colonNode .nextLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } .let { whiteSpaceAfterColon -> if (whiteSpaceAfterColon == null) { addMissingWhiteSpaceAfterMe(colonNode, emit) @@ -243,10 +243,10 @@ private fun ASTNode.isNotIndent(): Boolean = !isIndent() - private fun ASTNode.isIndent(): Boolean = isWhiteSpaceWithNewline20 + private fun ASTNode.isIndent(): Boolean = isWhiteSpaceWithNewline private fun ASTNode.isNotSingleSpace(): Boolean { - require(isWhiteSpace20) + require(isWhiteSpace) return text != " " } @@ -269,7 +269,7 @@ } private fun ASTNode.getPrecedingModifier(): ASTNode? = - prevCodeSibling20 + prevCodeSibling ?.let { prevCodeSibling -> if (prevCodeSibling.elementType == MODIFIER_LIST) { prevCodeSibling.lastChildNode @@ -286,13 +286,13 @@ ?.findChildByType(MODIFIER_LIST) private fun ASTNode.hasTypeReferenceWhichDoesNotFitOnSameLineAsColon() = - takeIf { it.isWhiteSpaceWithNewline20 } - ?.nextCodeSibling20 + takeIf { it.isWhiteSpaceWithNewline } + ?.nextCodeSibling ?.takeIf { it.elementType == TYPE_REFERENCE } ?.let { typeReference -> val length = // length of the previous line - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .lineLength + // single space before type reference @@ -301,7 +301,7 @@ this.text.substringAfterLast("\n").length + // length of line containing typeReference typeReference - .leavesOnLine20 + .leavesOnLine .dropTrailingEolComment() .lineLength length > maxLineLength
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt index 27f518e..0cc32c3 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterListWrappingRule.kt
@@ -26,16 +26,16 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.leavesOnLine import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -98,12 +98,12 @@ .takeUnless { // skip when max line length is not exceeded (node.column - 1 + node.textLength) <= maxLineLength - }?.takeUnless { it.isWhiteSpaceWithNewline20 } + }?.takeUnless { it.isWhiteSpaceWithNewline } ?.takeIf { it.isFunctionTypeWithNonEmptyValueParameterList() } ?.let { nullableType -> nullableType .findChildByType(LPAR) - ?.takeUnless { it.nextLeaf?.isWhiteSpaceWithNewline20 == true } + ?.takeUnless { it.nextLeaf?.isWhiteSpaceWithNewline == true } ?.let { lpar -> emit( lpar.startOffset + 1, @@ -115,7 +115,7 @@ } nullableType .findChildByType(RPAR) - ?.takeUnless { it.prevLeaf?.isWhiteSpaceWithNewline20 == true } + ?.takeUnless { it.prevLeaf?.isWhiteSpaceWithNewline == true } ?.let { rpar -> emit( rpar.startOffset, @@ -168,7 +168,7 @@ private fun ASTNode.hasNoParameters(): Boolean { require(elementType == VALUE_PARAMETER_LIST) - return firstChildNode?.nextSibling20?.elementType == RPAR + return firstChildNode?.nextSibling?.elementType == RPAR } private fun ASTNode.isPartOfFunctionLiteralInNonKtlintOfficialCodeStyle(): Boolean { @@ -178,7 +178,7 @@ private fun ASTNode.isPartOfFunctionLiteralStartingOnSameLineAsClosingParenthesisOfPrecedingReferenceExpression(): Boolean { require(elementType == VALUE_PARAMETER_LIST) - return firstChildLeafOrSelf20 + return firstChildLeafOrSelf .let { startOfFunctionLiteral -> parent ?.takeIf { it.elementType == FUNCTION_LITERAL } @@ -187,7 +187,7 @@ ?.takeIf { it.parent?.parent?.elementType == CALL_EXPRESSION } ?.leaves() ?.takeWhile { it != startOfFunctionLiteral } - ?.none { it.isWhiteSpaceWithNewline20 } + ?.none { it.isWhiteSpaceWithNewline } ?: false } } @@ -221,9 +221,9 @@ private fun isPrecededByComment(node: ASTNode) = node - .prevLeaf { !it.isWhiteSpace20 } + .prevLeaf { !it.isWhiteSpace } ?.prevLeaf - ?.isPartOfComment20 + ?.isPartOfComment ?: false private fun intendedIndent(child: ASTNode): String = @@ -269,7 +269,7 @@ .parent ?.takeUnless { it.isValueParameterListInFunctionType() } ?.prevLeaf - ?.takeIf { it.isWhiteSpaceWithNewline20 } + ?.takeIf { it.isWhiteSpaceWithNewline } ?.let { whitespace -> emit(child.startOffset, errorMessage(child), true) .ifAutocorrectAllowed { whitespace.remove() } @@ -286,13 +286,13 @@ val intendedIndent = intendedIndent(child) val prevLeaf = child.prevLeaf when { - prevLeaf.isWhiteSpaceWithNewline20 -> { + prevLeaf.isWhiteSpaceWithNewline -> { // The current child is already wrapped to a new line. Checking and fixing the // correct size of the indent is the responsibility of the IndentationRule. return } - prevLeaf.isWhiteSpace20 -> { + prevLeaf.isWhiteSpace -> { // The current child needs to be wrapped to a newline. emit(child.startOffset, errorMessage(child), true) .ifAutocorrectAllowed { @@ -325,9 +325,9 @@ private fun ASTNode.isOnLineExceedingMaxLineLength(): Boolean = if (hasNoMaxLineLengthSuppression()) { - val stopLeaf = nextLeaf { it.isWhiteSpaceWithNewline20 }?.nextLeaf + val stopLeaf = nextLeaf { it.isWhiteSpaceWithNewline }?.nextLeaf val lineContent = - leavesOnLine20 + leavesOnLine .dropTrailingEolComment() .takeWhile { it.prevLeaf != stopLeaf } .joinToString(separator = "") { it.text } @@ -351,7 +351,7 @@ ?.takeIf { elementType == FUN } ?.findChildByType(TYPE_PARAMETER_LIST) ?.children() - ?.any { it.isWhiteSpaceWithNewline20 } + ?.any { it.isWhiteSpaceWithNewline } ?: false }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt index 29c4040..579a074 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ParameterWrappingRule.kt
@@ -19,13 +19,13 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesBackwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf @@ -90,12 +90,12 @@ val baseIndentLength = node.indentWithoutNewlinePrefix.length // Find the first node after the indenting whitespace on the same line as the identifier - val nodeFirstChildLeafOrSelf = node.firstChildLeafOrSelf20 + val nodeFirstChildLeafOrSelf = node.firstChildLeafOrSelf val fromNode = node .findChildByType(IDENTIFIER) ?.leavesBackwardsIncludingSelf - ?.firstOrNull { it.prevLeaf.isWhiteSpaceWithNewline20 || it == nodeFirstChildLeafOrSelf } + ?.firstOrNull { it.prevLeaf.isWhiteSpaceWithNewline || it == nodeFirstChildLeafOrSelf } ?: node node @@ -143,15 +143,15 @@ } private fun ASTNode.orTrailingComma() = - lastChildLeafOrSelf20 + lastChildLeafOrSelf .nextCodeLeaf ?.takeIf { it.elementType == COMMA } ?: this private fun ASTNode.sumOfTextLengthUntil(astNode: ASTNode): Int { - val stopAtLeaf = astNode.lastChildLeafOrSelf20 + val stopAtLeaf = astNode.lastChildLeafOrSelf return leavesForwardsIncludingSelf - .takeWhile { !it.isWhiteSpaceWithNewline20 && it.prevLeaf != stopAtLeaf } + .takeWhile { !it.isWhiteSpaceWithNewline && it.prevLeaf != stopAtLeaf } .sumOf { it.textLength } } @@ -168,7 +168,7 @@ "$line: ${if (autocorrectDecision == NO_AUTOCORRECT) "would have" else ""} inserted newline before ${node.text}" } }.ifAutocorrectAllowed { - node.upsertWhitespaceBeforeMe(node.indent20) + node.upsertWhitespaceBeforeMe(node.indent) } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt index 07cf0a8..c6b170a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyNamingRule.kt
@@ -15,7 +15,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.editorconfig.SafeEnumValueParser @@ -121,7 +121,7 @@ private fun ASTNode.isTopLevelValue() = parent?.elementType == FILE && containsValKeyword() - private fun ASTNode.containsValKeyword() = children20.any { it.elementType == VAL_KEYWORD } + private fun ASTNode.containsValKeyword() = children.any { it.elementType == VAL_KEYWORD } private fun ASTNode.isObjectValue() = parent?.elementType == CLASS_BODY &&
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt index 8a29166..126febb 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt
@@ -17,12 +17,12 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.indentWithoutNewlinePrefix -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesBackwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -86,12 +86,12 @@ val baseIndentLength = node.indentWithoutNewlinePrefix.length // Find the first node after the indenting whitespace on the same line as the identifier - val nodeFirstChildLeafOrSelf = node.firstChildLeafOrSelf20 + val nodeFirstChildLeafOrSelf = node.firstChildLeafOrSelf val fromNode = node .findChildByType(IDENTIFIER) ?.leavesBackwardsIncludingSelf - ?.firstOrNull { it.prevLeaf.isWhiteSpaceWithNewline20 || it == nodeFirstChildLeafOrSelf } + ?.firstOrNull { it.prevLeaf.isWhiteSpaceWithNewline || it == nodeFirstChildLeafOrSelf } ?: node node @@ -139,9 +139,9 @@ } private fun ASTNode.sumOfTextLengthUntil(astNode: ASTNode): Int { - val stopAtLeaf = astNode.lastChildLeafOrSelf20 + val stopAtLeaf = astNode.lastChildLeafOrSelf return leavesForwardsIncludingSelf - .takeWhile { !it.isWhiteSpaceWithNewline20 && it.prevLeaf != stopAtLeaf } + .takeWhile { !it.isWhiteSpaceWithNewline && it.prevLeaf != stopAtLeaf } .sumOf { it.textLength } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt index 2e2575d..4411289 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundAngleBracketsRule.kt
@@ -10,8 +10,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove @@ -34,7 +34,7 @@ // Check for rogue spacing before an opening bracket, e.g. Map <String, Int> openingBracket .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.let { beforeLeftAngle -> // Ignore when the whitespace is preceded by certain keywords, e.g. fun <T> func(arg: T) {} if (!ELEMENT_TYPES_ALLOWING_PRECEDING_WHITESPACE.contains(beforeLeftAngle.prevLeaf?.elementType)) { @@ -46,9 +46,9 @@ // Check for rogue spacing after an opening bracket openingBracket .nextLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.let { afterLeftAngle -> - if (afterLeftAngle.isWhiteSpaceWithoutNewline20) { + if (afterLeftAngle.isWhiteSpaceWithoutNewline) { emit(afterLeftAngle.startOffset, "Unexpected spacing after \"<\"", true) .ifAutocorrectAllowed { // when spacing does not include any new lines, e.g. Map< String, Int> @@ -74,10 +74,10 @@ val closingBracket = node.lastChildNode closingBracket ?.prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { beforeRightAngle -> // Check for rogue spacing before a closing bracket - if (beforeRightAngle.isWhiteSpaceWithoutNewline20) { + if (beforeRightAngle.isWhiteSpaceWithoutNewline) { emit(beforeRightAngle.startOffset, "Unexpected spacing before \">\"", true) .ifAutocorrectAllowed { // when spacing does not include any new lines, e.g. Map<String, Int >
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt index d5e8571..12fcfe4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundColonRule.kt
@@ -18,15 +18,15 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe @@ -54,7 +54,7 @@ ) { node .prevLeaf - ?.takeIf { it.isWhiteSpaceWithNewline20 } + ?.takeIf { it.isWhiteSpaceWithNewline } ?.let { prevLeaf -> emit(prevLeaf.startOffset, "Unexpected newline before \":\"", true) .ifAutocorrectAllowed { @@ -70,12 +70,12 @@ node .siblings(forward = true) .firstOrNull { it.elementType == EQ } - ?.nextSibling20 + ?.nextSibling ?.let { nextSibling -> prevNonCodeElements.forEach { node.parent?.addChild(it, nextSibling) } - if (nextSibling.isWhiteSpace20) { + if (nextSibling.isWhiteSpace) { nextSibling.remove() } Unit @@ -88,14 +88,14 @@ val before = blockElement .firstChildNode - .nextSibling20 + .nextSibling prevNonCodeElements .let { - if (it.first().isWhiteSpace20) { + if (it.first().isWhiteSpace) { it.first().remove() it.drop(1) } - if (it.last().isWhiteSpaceWithNewline20) { + if (it.last().isWhiteSpaceWithNewline) { it.last().remove() it.dropLast(1) } else { @@ -107,12 +107,12 @@ } } - prevLeaf.prevLeaf?.isPartOfComment20 == true -> { + prevLeaf.prevLeaf?.isPartOfComment == true -> { val nextLeaf = node.nextLeaf prevNonCodeElements.forEach { node.parent?.addChild(it, nextLeaf) } - if (nextLeaf != null && nextLeaf.isWhiteSpace20) { + if (nextLeaf != null && nextLeaf.isWhiteSpace) { nextLeaf.remove() } } @@ -135,19 +135,19 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.prevSibling20.isWhiteSpaceWithoutNewline20 && node.noSpacingBefore) { + if (node.prevSibling.isWhiteSpaceWithoutNewline && node.noSpacingBefore) { emit(node.startOffset, "Unexpected spacing before \":\"", true) .ifAutocorrectAllowed { node - .prevSibling20 + .prevSibling ?.remove() } } - if (node.nextSibling20.isWhiteSpaceWithoutNewline20 && node.spacingAfter) { + if (node.nextSibling.isWhiteSpaceWithoutNewline && node.spacingAfter) { emit(node.startOffset, "Unexpected spacing after \":\"", true) .ifAutocorrectAllowed { node - .nextSibling20 + .nextSibling ?.remove() } } @@ -157,8 +157,8 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - val missingSpacingBefore = !node.prevSibling20.isWhiteSpace20 && node.spacingBefore - val missingSpacingAfter = !node.nextSibling20.isWhiteSpace20 && node.noSpacingAfter + val missingSpacingBefore = !node.prevSibling.isWhiteSpace && node.spacingBefore + val missingSpacingAfter = !node.nextSibling.isWhiteSpace && node.noSpacingAfter when { missingSpacingBefore && missingSpacingAfter -> { emit(node.startOffset, "Missing spacing around \":\"", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt index 50d6274..dcb68f1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCommaRule.kt
@@ -8,12 +8,12 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfString20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isPartOfString +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -32,24 +32,24 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node is LeafPsiElement && node.textMatches(",") && !node.isPartOfString20) { + if (node is LeafPsiElement && node.textMatches(",") && !node.isPartOfString) { node .prevLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.let { prevLeaf -> emit(prevLeaf.startOffset, "Unexpected spacing before \"${node.text}\"", true) .ifAutocorrectAllowed { val isPrecededByComment = prevLeaf - .prevLeaf { !it.isWhiteSpace20 } - ?.isPartOfComment20 + .prevLeaf { !it.isWhiteSpace } + ?.isPartOfComment ?: false - if (isPrecededByComment && prevLeaf.isWhiteSpaceWithNewline20) { + if (isPrecededByComment && prevLeaf.isWhiteSpaceWithNewline) { // If comma is on new line and preceded by a comment, it should be moved before this comment // https://github.com/pinterest/ktlint/issues/367 val previousStatement = node.prevCodeLeaf!! - previousStatement.parent?.addChild(node.clone(), previousStatement.nextSibling20) - node.nextLeaf.takeIf { it.isWhiteSpace20 }?.remove() + previousStatement.parent?.addChild(node.clone(), previousStatement.nextSibling) + node.nextLeaf.takeIf { it.isWhiteSpace }?.remove() node.remove() } else { prevLeaf.remove() @@ -58,7 +58,7 @@ } node .nextLeaf - .takeUnless { it.isWhiteSpace20 } + .takeUnless { it.isWhiteSpace } ?.takeUnless { it.elementType in rTokenSet } ?.let { emit(node.startOffset + 1, "Missing spacing after \"${node.text}\"", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt index a8b9069..66f0cac 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundCurlyRule.kt
@@ -29,15 +29,15 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isLeaf20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isPartOfString20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isLeaf +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isPartOfString +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.leavesBackwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove @@ -77,7 +77,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isLeaf20 && !node.isPartOfString20) { + if (node.isLeaf && !node.isPartOfString) { val prevLeaf = node.prevLeaf val nextLeaf = node.nextLeaf val spacingBefore: Boolean @@ -85,7 +85,7 @@ when (node.elementType) { LBRACE -> { spacingBefore = - prevLeaf.isWhiteSpace20 || + prevLeaf.isWhiteSpace || prevLeaf?.elementType == AT || ( (prevLeaf?.elementType == LPAR || prevLeaf?.elementType == LBRACKET) && @@ -94,8 +94,8 @@ node.parent?.parent?.elementType == LAMBDA_EXPRESSION ) ) - spacingAfter = nextLeaf.isWhiteSpace20 || nextLeaf?.elementType == RBRACE - if (prevLeaf.isWhiteSpaceWithoutNewline20 && + spacingAfter = nextLeaf.isWhiteSpace || nextLeaf?.elementType == RBRACE + if (prevLeaf.isWhiteSpaceWithoutNewline && prevLeaf!!.isPrecededBy { it.elementType == LPAR || it.elementType == AT } ) { emit(node.startOffset, "Unexpected space before \"${node.text}\"", true) @@ -118,7 +118,7 @@ node.parent?.addChildren( leavesToMoveAfterCurly.first(), leavesToMoveAfterCurly.last(), - node.nextSibling20, + node.nextSibling, ) } } @@ -129,10 +129,10 @@ } RBRACE -> { - spacingBefore = prevLeaf.isWhiteSpace20 || prevLeaf?.elementType == LBRACE - spacingAfter = nextLeaf == null || nextLeaf.isWhiteSpace20 || shouldNotToBeSeparatedBySpace(nextLeaf) + spacingBefore = prevLeaf.isWhiteSpace || prevLeaf?.elementType == LBRACE + spacingAfter = nextLeaf == null || nextLeaf.isWhiteSpace || shouldNotToBeSeparatedBySpace(nextLeaf) nextLeaf - .takeIf { it.isWhiteSpaceWithoutNewline20 } + .takeIf { it.isWhiteSpaceWithoutNewline } ?.takeIf { shouldNotToBeSeparatedBySpace(it.nextLeaf) } ?.let { leaf -> emit(node.startOffset, "Unexpected space after \"${node.text}\"", true) @@ -172,7 +172,7 @@ private fun ASTNode.hasUnexpectedNewlineBeforeLbrace(): Boolean = also { require(it.elementType == LBRACE) } - .takeIf { prevLeaf.isWhiteSpaceWithNewline20 } + .takeIf { prevLeaf.isWhiteSpaceWithNewline } ?.let { parent?.elementType == CLASS_BODY || parent?.elementType == BLOCK } ?: false @@ -183,7 +183,7 @@ private fun ASTNode.isPrecededByEolComment() = prevLeaf - ?.isPartOfComment20 + ?.isPartOfComment ?: false private fun shouldNotToBeSeparatedBySpace(leaf: ASTNode?): Boolean {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt index 569be0d..ba76838 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDotRule.kt
@@ -6,8 +6,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove @@ -24,13 +24,13 @@ if (node is LeafPsiElement && node.isCode && node.textMatches(".")) { node .prevLeaf - .takeIf { it.isWhiteSpaceWithoutNewline20 } + .takeIf { it.isWhiteSpaceWithoutNewline } ?.let { prevLeaf -> emit(prevLeaf.startOffset, "Unexpected spacing before \"${node.text}\"", true) .ifAutocorrectAllowed { prevLeaf.remove() } } node.nextLeaf - .takeIf { it.isWhiteSpace20 } + .takeIf { it.isWhiteSpace } ?.let { nextLeaf -> emit(nextLeaf.startOffset, "Unexpected spacing after \"${node.text}\"", true) .ifAutocorrectAllowed { nextLeaf.remove() }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt index 36a54dc..4841404 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundDoubleColonRule.kt
@@ -9,11 +9,11 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -32,21 +32,21 @@ var removeSingleWhiteSpace = false val spacingBefore = when { - node.isPartOf(CLASS_LITERAL_EXPRESSION) && prevLeaf.isWhiteSpace20 -> { + node.isPartOf(CLASS_LITERAL_EXPRESSION) && prevLeaf.isWhiteSpace -> { true } // Clazz::class - node.isPartOf(CALLABLE_REFERENCE_EXPRESSION) && prevLeaf.isWhiteSpace20 -> { + node.isPartOf(CALLABLE_REFERENCE_EXPRESSION) && prevLeaf.isWhiteSpace -> { // String::length, ::isOdd - if (node.prevSibling20 == null) { // compose(length, ::isOdd), val predicate = ::isOdd + if (node.prevSibling == null) { // compose(length, ::isOdd), val predicate = ::isOdd removeSingleWhiteSpace = true prevLeaf - .takeIf { it.isWhiteSpaceWithoutNewline20 } + .takeIf { it.isWhiteSpaceWithoutNewline } ?.let { it.textLength > 1 } ?: false } else { // String::length, List<String>::isEmpty - prevLeaf.isWhiteSpaceWithoutNewline20 + prevLeaf.isWhiteSpaceWithoutNewline } } @@ -54,7 +54,7 @@ false } } - val spacingAfter = nextLeaf.isWhiteSpace20 + val spacingAfter = nextLeaf.isWhiteSpace when { spacingBefore && spacingAfter -> { emit(node.startOffset, "Unexpected spacing around \"${node.text}\"", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt index 5392924..f7681ec 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundKeywordRule.kt
@@ -22,8 +22,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -56,7 +56,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.elementType in tokenSet && node.parent?.elementType != KDOC_NAME && !node.nextLeaf.isWhiteSpace20) { + if (node.elementType in tokenSet && node.parent?.elementType != KDOC_NAME && !node.nextLeaf.isWhiteSpace) { emit(node.startOffset + node.text.length, "Missing spacing after \"${node.text}\"", true) .ifAutocorrectAllowed { node.upsertWhitespaceAfterMe(" ") } } @@ -64,7 +64,7 @@ .takeIf { keywordsWithoutSpaces.contains(it.elementType) } .takeIf { node.isPropertyAccessorWithValueParameterList() } ?.nextLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.also { nextLeaf -> emit(node.startOffset, "Unexpected spacing after \"${node.text}\"", true) .ifAutocorrectAllowed { nextLeaf.remove() } @@ -72,7 +72,7 @@ if (noLFBeforeSet.contains(node.elementType)) { val prevLeaf = node.prevLeaf val isElseKeyword = node.elementType == ELSE_KEYWORD - if (prevLeaf.isWhiteSpaceWithNewline20 && + if (prevLeaf.isWhiteSpaceWithNewline && (!isElseKeyword || node.parent?.elementType != WHEN_ENTRY) ) { val rBrace = prevLeaf?.prevLeaf?.takeIf { it.elementType == RBRACE }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt index 86c1626..e5684d9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundOperatorsRule.kt
@@ -34,7 +34,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -81,8 +81,8 @@ if (node.elementType in OPERATORS || (node.elementType == IDENTIFIER && node.parent?.elementType == OPERATION_REFERENCE) ) { - val spacingBefore = node.prevLeaf.isWhiteSpace20 - val spacingAfter = node.nextLeaf.isWhiteSpace20 + val spacingBefore = node.prevLeaf.isWhiteSpace + val spacingAfter = node.nextLeaf.isWhiteSpace when { !spacingBefore && !spacingAfter -> { emit(node.startOffset, "Missing spacing around \"${node.text}\"", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt index e17309c..8183648 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundParensRule.kt
@@ -18,14 +18,14 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -56,11 +56,11 @@ private fun ASTNode.isUnexpectedSpacingBeforeParenthesis(): Boolean = when { - prevLeaf.isWhiteSpaceWithNewline20 && hasNoNewlineAfterLpar() -> { + prevLeaf.isWhiteSpaceWithNewline && hasNoNewlineAfterLpar() -> { true } - !prevLeaf.isWhiteSpaceWithoutNewline20 -> { + !prevLeaf.isWhiteSpaceWithoutNewline -> { false } @@ -78,7 +78,7 @@ // Disallow: // val foo = fn("foo" ) // val foo = fn( ) - prevLeaf?.prevSibling20?.elementType != LPAR + prevLeaf?.prevSibling?.elementType != LPAR } else -> { @@ -88,7 +88,7 @@ private fun ASTNode.isUnexpectedSpacingBetweenIdentifierAndElementList() = prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.takeIf { // Disallow: // fun foo () {} @@ -105,7 +105,7 @@ private fun ASTNode.isUnexpectedSpacingInCallToSuper() = prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { // Disallow: // class Foo : Bar { @@ -117,7 +117,7 @@ private fun ASTNode.isUnexpectedSpacingInExplicitConstructor() = prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { // Disallow: // class Foo constructor () @@ -127,19 +127,19 @@ private fun ASTNode.isUnexpectedSpacingInSuperTypeCallEntry() = prevLeaf - ?.takeIf { it.isWhiteSpace20 } + ?.takeIf { it.isWhiteSpace } ?.let { // Disallow: // class Foo : Bar ("test") // class Foo : Bar<String> ("test") parent?.parent?.elementType == SUPER_TYPE_CALL_ENTRY && - it.prevSibling20?.elementType == CONSTRUCTOR_CALLEE + it.prevSibling?.elementType == CONSTRUCTOR_CALLEE } ?: false private fun ASTNode.isUnexpectedSpacingAfterParenthesis(): Boolean = when { - elementType == LPAR && nextSibling20.isWhiteSpaceWithNewline20 && hasNoOtherNewlineBeforeRpar() -> { + elementType == LPAR && nextSibling.isWhiteSpaceWithNewline && hasNoOtherNewlineBeforeRpar() -> { true } @@ -160,28 +160,28 @@ // val foo = fn( ) // val foo = fn( "bar") // val foo = ( (1 + 2) / 3) - isWhiteSpaceWithoutNewline20 + isWhiteSpaceWithoutNewline private fun ASTNode.isUnexpectedNewlineAfterLpar() = // Disallow: // val foo = fn( // ) - isWhiteSpaceWithNewline20 && nextLeaf?.elementType == RPAR + isWhiteSpaceWithNewline && nextLeaf?.elementType == RPAR private fun ASTNode.hasNoOtherNewlineBeforeRpar() = - nextSibling20 - .takeIf { it.isWhiteSpaceWithNewline20 } + nextSibling + .takeIf { it.isWhiteSpaceWithNewline } ?.siblings() ?.takeWhile { it.elementType != RPAR } - ?.none { it.isWhiteSpaceWithNewline20 } + ?.none { it.isWhiteSpaceWithNewline } ?: false private fun ASTNode.isNextLeafAComment(): Boolean = nextLeaf?.elementType in commentTypes private fun ASTNode.hasNoNewlineAfterLpar() = - prevSibling20 - .takeIf { it.isWhiteSpaceWithNewline20 } - ?.takeUnless { it.prevSibling20?.elementType == LPAR } + prevSibling + .takeIf { it.isWhiteSpaceWithNewline } + ?.takeUnless { it.prevSibling?.elementType == LPAR } ?.siblings(false) ?.takeWhile { it.elementType != LPAR } ?.none { it.textContains('\n') || it.elementType == EOL_COMMENT }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt index 87b9e19..a5ab0f9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundRangeOperatorRule.kt
@@ -7,7 +7,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove @@ -25,7 +25,7 @@ val prevLeaf = node.prevLeaf val nextLeaf = node.nextLeaf when { - prevLeaf.isWhiteSpace20 && nextLeaf.isWhiteSpace20 -> { + prevLeaf.isWhiteSpace && nextLeaf.isWhiteSpace -> { emit(node.startOffset, "Unexpected spacing around \"${node.elementTypeDescription()}\"", true) .ifAutocorrectAllowed { prevLeaf?.remove() @@ -33,12 +33,12 @@ } } - prevLeaf != null && prevLeaf.isWhiteSpace20 -> { + prevLeaf != null && prevLeaf.isWhiteSpace -> { emit(prevLeaf.startOffset, "Unexpected spacing before \"${node.elementTypeDescription()}\"", true) .ifAutocorrectAllowed { prevLeaf.remove() } } - nextLeaf != null && nextLeaf.isWhiteSpace20 -> { + nextLeaf != null && nextLeaf.isWhiteSpace -> { emit(nextLeaf.startOffset, "Unexpected spacing after \"${node.elementTypeDescription()}\"", true) .ifAutocorrectAllowed { nextLeaf.remove() } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt index a64cf26..1e4fc3e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundSquareBracketsRule.kt
@@ -10,7 +10,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -53,11 +53,11 @@ // ] // Disallow: // @Foo(fooBar = ["foo", "bar" ]) - node.elementType == RBRACKET && prevLeaf.isWhiteSpaceWithoutNewline20 + node.elementType == RBRACKET && prevLeaf.isWhiteSpaceWithoutNewline } else -> { - prevLeaf.isWhiteSpaceWithoutNewline20 + prevLeaf.isWhiteSpaceWithoutNewline } } val spacingAfter = @@ -74,7 +74,7 @@ // ] // Disallow: // @Foo(fooBar = [ "foo", "bar"]) - node.elementType == LBRACKET && nextLeaf.isWhiteSpaceWithoutNewline20 + node.elementType == LBRACKET && nextLeaf.isWhiteSpaceWithoutNewline when { spacingBefore && spacingAfter -> { emit(node.startOffset, "Unexpected spacing around '${node.text}'", true)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt index 743e8aa..14317aa 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingAroundUnaryOperatorRule.kt
@@ -7,10 +7,10 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -28,15 +28,15 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { if (node.elementType == PREFIX_EXPRESSION || node.elementType == POSTFIX_EXPRESSION) { - val children = node.children20.toList() + val children = node.children.toList() // ignore: var a = + /* comment */ 1 - if (children.any { it.isPartOfComment20 }) { + if (children.any { it.isPartOfComment }) { return } children - .firstOrNull { it.isWhiteSpace20 } + .firstOrNull { it.isWhiteSpace } ?.let { whiteSpace -> emit(whiteSpace.startOffset, "Unexpected spacing in ${node.text.replace("\n", "\\n")}", true) .ifAutocorrectAllowed { whiteSpace.remove() }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt index 7f8fa89..9d12697 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithAnnotationsRule.kt
@@ -8,15 +8,15 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isDeclaration20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isDeclaration +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -37,31 +37,31 @@ } } - private fun ASTNode.isDeclarationOrPropertyAccessor() = isDeclaration20 || elementType == PROPERTY_ACCESSOR + private fun ASTNode.isDeclarationOrPropertyAccessor() = isDeclaration || elementType == PROPERTY_ACCESSOR private fun visitDeclaration( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .prevCodeSibling20 + .prevCodeSibling ?.takeIf { it.isDeclarationOrPropertyAccessor() } ?.takeIf { prevDeclaration -> hasNoBlankLineBetweenDeclarations(node, prevDeclaration) } ?.let { - val prevLeaf = node.prevCodeLeaf?.nextLeaf { it.isWhiteSpace20 }!! + val prevLeaf = node.prevCodeLeaf?.nextLeaf { it.isWhiteSpace }!! emit( prevLeaf.startOffset + 1, "Declarations and declarations with annotations should have an empty space between.", true, ).ifAutocorrectAllowed { - prevLeaf.upsertWhitespaceBeforeMe("\n".plus(node.indent20)) + prevLeaf.upsertWhitespaceBeforeMe("\n".plus(node.indent)) } } } private fun ASTNode.isAnnotated(): Boolean = findChildByType(MODIFIER_LIST) - ?.children20 + ?.children ?.any { it.elementType == ANNOTATION_ENTRY } ?: false @@ -74,7 +74,7 @@ .takeWhile { it != prevDeclaration } .none { it.isBlankLine() } - private fun ASTNode.isBlankLine() = isWhiteSpace20 && text.count { it == '\n' } > 1 + private fun ASTNode.isBlankLine() = isWhiteSpace && text.count { it == '\n' } > 1 } public val SPACING_BETWEEN_DECLARATIONS_WITH_ANNOTATIONS_RULE_ID: RuleId = SpacingBetweenDeclarationsWithAnnotationsRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt index 436c927..4bbc22e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt
@@ -7,12 +7,12 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.TokenSets import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isDeclaration20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 +import com.pinterest.ktlint.rule.engine.core.api.isDeclaration +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -31,8 +31,8 @@ .takeIf { it.elementType in TokenSets.COMMENTS } ?.takeUnless { it.isTailComment() } ?.parent - ?.takeIf { it.isDeclaration20 } - ?.takeIf { it.prevCodeSibling20.isDeclaration20 } + ?.takeIf { it.isDeclaration } + ?.takeIf { it.prevCodeSibling.isDeclaration } ?.let { visitCommentedDeclaration(it, emit) } } @@ -43,7 +43,7 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .prevSibling20 + .prevSibling ?.takeUnless { it.isBlankLine() } ?.let { prevSibling -> emit(node.startOffset, "Declarations and declarations with comments should have an empty space between.", true) @@ -59,7 +59,7 @@ } } - private fun ASTNode.isBlankLine() = isWhiteSpace20 && text.startsWith("\n\n") + private fun ASTNode.isBlankLine() = isWhiteSpace && text.startsWith("\n\n") } public val SPACING_BETWEEN_DECLARATIONS_WITH_COMMENTS_RULE_ID: RuleId = SpacingBetweenDeclarationsWithCommentsRule().ruleId
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt index b172cd6..3466dc1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenFunctionNameAndOpeningParenthesisRule.kt
@@ -8,8 +8,8 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -24,8 +24,8 @@ node .takeIf { node.elementType == FUN } ?.findChildByType(IDENTIFIER) - ?.nextSibling20 - ?.takeIf { it.isWhiteSpace20 } + ?.nextSibling + ?.takeIf { it.isWhiteSpace } ?.let { whiteSpace -> emit(whiteSpace.startOffset, "Unexpected whitespace", true) .ifAutocorrectAllowed { whiteSpace.remove() }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt index af49fdf..50a297e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StatementWrappingRule.kt
@@ -20,16 +20,16 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasModifier import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.indent +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.noNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.parent @@ -158,7 +158,7 @@ takeIf { elementType == FUNCTION_LITERAL } ?.takeUnless { it.textContains('\n') } ?.findChildByType(BLOCK) - ?.children20 + ?.children ?.count { it.elementType != VALUE_PARAMETER_LIST && it.elementType != ARROW } ?.let { count -> count <= 1 } ?: false @@ -166,7 +166,7 @@ private inline val ASTNode.isEnumClassOnSingleLine: Boolean get() = if (isEnumClass) { - val lastChildLeaf = lastChildLeafOrSelf20 + val lastChildLeaf = lastChildLeafOrSelf // Ignore the leading comment noNewLineInClosedRange(firstCodeLeafOrNull!!, lastChildLeaf) } else { @@ -177,31 +177,31 @@ get() = // Skip the comment on top of the node by getting modifier list findChildByType(MODIFIER_LIST) - ?.children20 + ?.children ?.dropWhile { // Ignore annotations placed on separate lines above the node - it.elementType == ANNOTATION_ENTRY || it.isWhiteSpace20 + it.elementType == ANNOTATION_ENTRY || it.isWhiteSpace }?.firstOrNull() - ?.firstChildLeafOrSelf20 + ?.firstChildLeafOrSelf private inline val ASTNode.isEnumClass: Boolean get() = elementType == CLASS && hasModifier(ENUM_KEYWORD) private inline val ASTNode.indentAsChild: String - get() = indent20.plus(indentConfig.indent) + get() = indent.plus(indentConfig.indent) private inline val ASTNode.indentAsSibling: String - get() = parent!!.indent20.plus(indentConfig.indent) + get() = parent!!.indent.plus(indentConfig.indent) private inline val ASTNode.indentAsParent: String - get() = parent!!.indent20 + get() = parent!!.indent private fun visitSemiColon( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - val previousCodeLeaf = node.prevCodeLeaf?.lastChildLeafOrSelf20 ?: return - val nextCodeLeaf = node.nextCodeLeaf?.firstChildLeafOrSelf20 ?: return + val previousCodeLeaf = node.prevCodeLeaf?.lastChildLeafOrSelf ?: return + val nextCodeLeaf = node.nextCodeLeaf?.firstChildLeafOrSelf ?: return if (previousCodeLeaf.parent?.elementType == ENUM_ENTRY && nextCodeLeaf.elementType == RBRACE) { // Allow // enum class INDEX2 { ONE, TWO, THREE; } @@ -210,7 +210,7 @@ if (noNewLineInClosedRange(previousCodeLeaf, nextCodeLeaf)) { emit(node.startOffset + 1, """Missing newline after '${node.text}'""", true) .ifAutocorrectAllowed { - node.upsertWhitespaceAfterMe(previousCodeLeaf.indent20) + node.upsertWhitespaceAfterMe(previousCodeLeaf.indent) } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt index c16e862..ca56ec6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateIndentRule.kt
@@ -22,18 +22,17 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -104,10 +103,10 @@ } stringTemplate .getFirstLeafAfterTrimIndent() - ?.takeUnless { it.isWhiteSpaceWithNewline20 } + ?.takeUnless { it.isWhiteSpaceWithNewline } ?.takeUnless { it.elementType == COMMA } ?.takeUnless { it.parent?.elementType == DOT_QUALIFIED_EXPRESSION } - ?.takeUnless { it.parent?.elementType == BINARY_EXPRESSION && it.nextSibling20?.elementType == OPERATION_REFERENCE } + ?.takeUnless { it.parent?.elementType == BINARY_EXPRESSION && it.nextSibling?.elementType == OPERATION_REFERENCE } ?.let { nextLeaf -> emit(nextLeaf.startOffset, "Expected newline after multiline string template", true) .ifAutocorrectAllowed { @@ -137,10 +136,10 @@ takeIf { it.elementType == STRING_TEMPLATE } ?.takeIf { it.isFollowedByTrimIndent() } ?.parent - ?.lastChildLeafOrSelf20 + ?.lastChildLeafOrSelf ?.nextLeaf - private fun ASTNode.isPrecededByWhitespaceWithNewline() = prevLeaf.isWhiteSpaceWithNewline20 + private fun ASTNode.isPrecededByWhitespaceWithNewline() = prevLeaf.isWhiteSpaceWithNewline private fun ASTNode.isPrecededByReturnKeyword() = // Allow below as otherwise it results in compilation failure: @@ -154,7 +153,7 @@ ?.takeIf { it.elementType == EQ } ?.closingParenthesisOfFunctionOrNull() ?.prevLeaf - ?.isWhiteSpaceWithNewline20 + ?.isWhiteSpaceWithNewline ?: false private fun ASTNode.closingParenthesisOfFunctionOrNull() = @@ -167,7 +166,7 @@ // is out of scope of this rule as it is owned by the indentation rule. Therefore, the indentation of the line at which the // string template is found, is assumed to be correct and is used to indent all lines of the string template. The indent will be // fixed once the indent rule is run as well. - val firstWhiteSpaceLeafOnSameLine = this.prevLeaf { it.isWhiteSpaceWithNewline20 } + val firstWhiteSpaceLeafOnSameLine = this.prevLeaf { it.isWhiteSpaceWithNewline } return if (prevLeaf == firstWhiteSpaceLeafOnSameLine) { // The string template already is on a separate new line. Keep the current indent. firstWhiteSpaceLeafOnSameLine.getTextAfterLastNewline() @@ -238,7 +237,7 @@ checkAndFixNewLineAfterOpeningQuotes(node, newIndent, emit) node - .children20 + .children .filterNot { it.elementType == OPEN_QUOTE } .filterNot { // Blank lines inside the string template should not be indented @@ -335,7 +334,7 @@ LeafPsiElement(REGULAR_STRING_PART, newIndent), ) } else { - node.firstChildLeafOrSelf20.replaceTextWith(newIndent + newContent) + node.firstChildLeafOrSelf.replaceTextWith(newIndent + newContent) } } } @@ -361,7 +360,7 @@ private fun ASTNode.containsLiteralStringTemplateEntryWithNewline(): Boolean { require(elementType == STRING_TEMPLATE) - return children20 + return children .any { it.elementType == LITERAL_STRING_TEMPLATE_ENTRY && it.text == "\n" } } @@ -399,7 +398,7 @@ ) } - private fun ASTNode.isIndentBeforeClosingQuote() = text.isBlank() && nextCodeSibling20?.elementType == CLOSING_QUOTE + private fun ASTNode.isIndentBeforeClosingQuote() = text.isBlank() && nextCodeSibling?.elementType == CLOSING_QUOTE private companion object { const val RAW_STRING_LITERAL_QUOTES = "\"\"\""
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt index 684f669..cca7a84 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/StringTemplateRule.kt
@@ -18,12 +18,12 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -78,7 +78,7 @@ private fun ASTNode.splitCodeChildren(): Triple<ASTNode, ASTNode, ASTNode> { require(elementType == DOT_QUALIFIED_EXPRESSION) - return children20 + return children .filter { it.isCode } .toList() .also { require(it.size == 3) } @@ -89,11 +89,11 @@ emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { takeIf { it.isStringTemplate() } - ?.children20 + ?.children ?.firstOrNull { it.elementType != LONG_TEMPLATE_ENTRY_START } ?.takeIf { it.elementType == REFERENCE_EXPRESSION || it.elementType == THIS_EXPRESSION } ?.let { - nextSibling20 + nextSibling ?.takeIf { nextSibling -> nextSibling.elementType == CLOSING_QUOTE || ( @@ -101,7 +101,7 @@ !nextSibling.text.substring(0, 1).isPartOfIdentifier() ) }?.let { - emit(prevSibling20!!.startOffset + 2, "Redundant curly braces", true) + emit(prevSibling!!.startOffset + 2, "Redundant curly braces", true) .ifAutocorrectAllowed { removeCurlyBracesIfRedundant() } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ThenSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ThenSpacingRule.kt index 78f171f..d50174d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ThenSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ThenSpacingRule.kt
@@ -5,13 +5,13 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.endOffset20 +import com.pinterest.ktlint.rule.engine.core.api.endOffset import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -35,18 +35,18 @@ emit: (Int, String, Boolean) -> AutocorrectDecision, ) { node - .takeUnless { it.prevSibling20.isWhiteSpace20 } + .takeUnless { it.prevSibling.isWhiteSpace } ?.let { emit(node.startOffset, "Expected a whitespace before 'then' block", true) .ifAutocorrectAllowed { node.prevLeaf?.upsertWhitespaceAfterMe(" ") } } node - .takeUnless { it.nextSibling20 == null || it.nextSibling20.isWhiteSpace20 } + .takeUnless { it.nextSibling == null || it.nextSibling.isWhiteSpace } ?.let { node - .lastChildLeafOrSelf20 + .lastChildLeafOrSelf .let { lastLeafInThen -> - emit(lastLeafInThen.endOffset20, "Expected a whitespace after 'then' block", true) + emit(lastLeafInThen.endOffset, "Expected a whitespace after 'then' block", true) .ifAutocorrectAllowed { lastLeafInThen.upsertWhitespaceAfterMe(" ") } } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt index 43f9b05..de043cb 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnCallSiteRule.kt
@@ -15,17 +15,16 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -74,7 +73,7 @@ ) { val inspectNode = node - .children20 + .children .last { it.elementType == RBRACKET } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -91,7 +90,7 @@ ) { val inspectNode = node - .children20 + .children .last { it.elementType == RBRACKET } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -106,7 +105,7 @@ ) { if (node.parent?.elementType != FUNCTION_LITERAL) { node - .children20 + .children .lastOrNull { it.elementType == RPAR } ?.let { inspectNode -> node.reportAndCorrectTrailingCommaNodeBefore( @@ -124,7 +123,7 @@ ) { val inspectNode = node - .children20 + .children .first { it.elementType == GT } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -165,8 +164,8 @@ true, ).ifAutocorrectAllowed { inspectNode - .prevCodeSibling20 - ?.nextSibling20 + .prevCodeSibling + ?.nextSibling ?.let { before -> before.parent?.addChild(LeafPsiElement(COMMA, ","), before) } @@ -201,9 +200,9 @@ private fun ASTNode.findValueArgumentFollowedByWhiteSpaceWithNewline() = this .findChildByType(VALUE_ARGUMENT) - ?.nextSibling { it.isWhiteSpaceWithNewline20 } + ?.nextSibling { it.isWhiteSpaceWithNewline } - private fun ASTNode.hasAtLeastOneArgument() = children20.any { it.elementType == VALUE_ARGUMENT } + private fun ASTNode.hasAtLeastOneArgument() = children.any { it.elementType == VALUE_ARGUMENT } private fun ASTNode.findPreviousTrailingCommaNodeOrNull(): ASTNode? { val codeLeaf =
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt index 68f5927..b493dc4 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TrailingCommaOnDeclarationSiteRule.kt
@@ -27,16 +27,16 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty import com.pinterest.ktlint.rule.engine.core.api.hasModifier import com.pinterest.ktlint.rule.engine.core.api.hasNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.isCode -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.noNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.parent @@ -99,7 +99,7 @@ ) { val inspectNode = node - .children20 + .children .last { it.elementType == RPAR } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -116,7 +116,7 @@ ) { val inspectNode = node - .children20 + .children .lastOrNull { it.elementType == ARROW } ?: // lambda w/o an arrow -> no arguments -> no commas return @@ -133,7 +133,7 @@ ) { if (node.parent?.elementType != FUNCTION_LITERAL) { node - .children20 + .children .lastOrNull { it.elementType == RPAR } ?.let { inspectNode -> node.reportAndCorrectTrailingCommaNodeBefore( @@ -151,7 +151,7 @@ ) { val inspectNode = node - .children20 + .children .first { it.elementType == GT } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -173,7 +173,7 @@ val inspectNode = node - .children20 + .children .first { it.elementType == ARROW } node.reportAndCorrectTrailingCommaNodeBefore( inspectNode = inspectNode, @@ -217,11 +217,12 @@ } } - private fun ASTNode.noEnumEntries() = children20.none { it.elementType == ENUM_ENTRY } + private fun ASTNode.noEnumEntries() = children.none { it.elementType == ENUM_ENTRY } private fun ASTNode.lastTwoEnumEntriesAreOnSameLine(): Boolean { val lastTwoEnumEntries = - children20 + this@lastTwoEnumEntriesAreOnSameLine + .children .filter { it.elementType == ENUM_ENTRY } .toList() .takeLast(2) @@ -236,9 +237,9 @@ * last element of the class. */ private fun ASTNode.findNodeAfterLastEnumEntry() = - children20 + children .lastOrNull { it.elementType == ENUM_ENTRY } - ?.children20 + ?.children ?.singleOrNull { it.elementType == SEMICOLON } ?: lastChildNode @@ -273,13 +274,13 @@ ?.findChildByType(ARROW) ?.prevLeaf ?.let { lastNodeBeforeArrow -> - if (!lastNodeBeforeArrow.isWhiteSpaceWithNewline20) { + if (!lastNodeBeforeArrow.isWhiteSpaceWithNewline) { emit( trailingCommaNode!!.startOffset, "Expected a newline between the trailing comma and \"${inspectNode.text}\"", true, ).ifAutocorrectAllowed { - lastNodeBeforeArrow.upsertWhitespaceAfterMe(inspectNode.parent!!.indent20) + lastNodeBeforeArrow.upsertWhitespaceAfterMe(inspectNode.parent!!.indent) } } } @@ -295,7 +296,7 @@ TrailingCommaState.MISSING -> { if (isTrailingCommaAllowed) { val leafBeforeArrowOrNull = leafBeforeArrowOrNull() - val addNewLine = !(leafBeforeArrowOrNull?.isWhiteSpaceWithNewline20 ?: true) + val addNewLine = !(leafBeforeArrowOrNull?.isWhiteSpaceWithNewline ?: true) val prevNode = inspectNode.prevCodeLeaf!! if (addNewLine) { emit( @@ -311,8 +312,8 @@ ) }.ifAutocorrectAllowed { if (addNewLine) { - val indent = prevNode.parent!!.indent20 - if (leafBeforeArrowOrNull.isWhiteSpace20) { + val indent = prevNode.parent!!.indent + if (leafBeforeArrowOrNull.isWhiteSpace) { leafBeforeArrowOrNull.replaceTextWith(indent) } else { inspectNode @@ -326,8 +327,8 @@ if (inspectNode.parent?.elementType == ENUM_ENTRY) { val parentIndent = - (prevNode.parent?.prevLeaf?.takeIf { it.isWhiteSpace20 })?.text - ?: prevNode.indent20 + (prevNode.parent?.prevLeaf?.takeIf { it.isWhiteSpace })?.text + ?: prevNode.indent inspectNode .parent ?.apply { @@ -416,7 +417,7 @@ private fun ASTNode.hasWhenEntryGuard() = elementType == WHEN_ENTRY && hasWhenEntryGuardKotlin21() - private fun ASTNode.hasWhenEntryGuardKotlin21(): Boolean = children20.any { it.elementType == WHEN_ENTRY_GUARD } + private fun ASTNode.hasWhenEntryGuardKotlin21(): Boolean = children.any { it.elementType == WHEN_ENTRY_GUARD } private enum class TrailingCommaState { /**
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt index 70e1489..a11c2de 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TryCatchFinallySpacingRule.kt
@@ -18,7 +18,7 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf @@ -58,7 +58,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isPartOfComment20 && node.parent?.elementType in TRY_CATCH_FINALLY_TOKEN_SET) { + if (node.isPartOfComment && node.parent?.elementType in TRY_CATCH_FINALLY_TOKEN_SET) { emit(node.startOffset, "No comment expected at this location", false) return } @@ -84,7 +84,7 @@ node .findChildByType(LBRACE)!! .let { lbrace -> - val nextSibling = lbrace.nextSibling { !it.isPartOfComment20 }!! + val nextSibling = lbrace.nextSibling { !it.isPartOfComment }!! if (!nextSibling.text.startsWith("\n")) { emit(lbrace.startOffset + 1, "Expected a newline after '{'", true) .ifAutocorrectAllowed { @@ -96,7 +96,7 @@ node .findChildByType(RBRACE)!! .let { rbrace -> - val prevSibling = rbrace.prevSibling { !it.isPartOfComment20 }!! + val prevSibling = rbrace.prevSibling { !it.isPartOfComment }!! if (!prevSibling.text.startsWith("\n")) { emit(rbrace.startOffset, "Expected a newline before '}'", true) .ifAutocorrectAllowed { @@ -110,7 +110,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - val prevLeaf = node.prevLeaf { !it.isPartOfComment20 }!! + val prevLeaf = node.prevLeaf { !it.isPartOfComment }!! if (prevLeaf.text != " ") { emit(node.startOffset, "A single space is required before '${node.elementTypeName()}'", true) .ifAutocorrectAllowed {
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentCommentRule.kt index cc8c073..3328e02 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentCommentRule.kt
@@ -8,8 +8,8 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -29,7 +29,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isPartOfComment20 && node.parent?.elementType in typeArgumentTokenSet) { + if (node.isPartOfComment && node.parent?.elementType in typeArgumentTokenSet) { when (node.elementType) { EOL_COMMENT, BLOCK_COMMENT -> { if (node.parent?.elementType == TYPE_PROJECTION) { @@ -44,7 +44,7 @@ false, ) } else if (node.parent?.elementType == TYPE_ARGUMENT_LIST) { - if (node.prevLeaf.isWhiteSpaceWithNewline20) { + if (node.prevLeaf.isWhiteSpaceWithNewline) { // Allow: // fun Foo< // /* some comment */
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt index 59df90d..0107295 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeArgumentListSpacingRule.kt
@@ -21,12 +21,12 @@ import com.pinterest.ktlint.rule.engine.core.api.findParentByType import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -116,11 +116,11 @@ node .findChildByType(LT) - ?.nextSibling20 + ?.nextSibling ?.let { nextSibling -> if (multiline) { if (nextSibling.text != expectedIndent) { - if (nextSibling.isWhiteSpaceWithoutNewline20) { + if (nextSibling.isWhiteSpaceWithoutNewline) { emit(nextSibling.startOffset, "Expected newline", true) .ifAutocorrectAllowed { nextSibling.upsertWhitespaceAfterMe(expectedIndent) @@ -130,7 +130,7 @@ } } } else { - if (nextSibling.isWhiteSpace20) { + if (nextSibling.isWhiteSpace) { // Disallow // val list = listOf< String>() noWhitespaceExpected(nextSibling, emit) @@ -140,11 +140,11 @@ node .findChildByType(GT) - ?.prevSibling20 + ?.prevSibling ?.let { prevSibling -> if (multiline) { if (prevSibling.text != expectedIndent) { - if (prevSibling.isWhiteSpaceWithoutNewline20) { + if (prevSibling.isWhiteSpaceWithoutNewline) { emit(prevSibling.startOffset, "Expected newline", true) .ifAutocorrectAllowed { prevSibling.upsertWhitespaceBeforeMe(expectedIndent) @@ -154,7 +154,7 @@ } } } else { - if (prevSibling.isWhiteSpace20) { + if (prevSibling.isWhiteSpace) { // Disallow // val list = listOf<String >() noWhitespaceExpected(prevSibling, emit)
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterCommentRule.kt index c704c2a..2e5c044 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterCommentRule.kt
@@ -8,8 +8,8 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -29,7 +29,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isPartOfComment20 && node.parent?.elementType in typeParameterTokenSet) { + if (node.isPartOfComment && node.parent?.elementType in typeParameterTokenSet) { when (node.elementType) { EOL_COMMENT, BLOCK_COMMENT -> { if (node.parent?.elementType == TYPE_PARAMETER) { @@ -44,7 +44,7 @@ false, ) } else if (node.parent?.elementType == TYPE_PARAMETER_LIST) { - if (node.prevLeaf.isWhiteSpaceWithNewline20) { + if (node.prevLeaf.isWhiteSpaceWithNewline) { // Allow // class Foo< // /* some comment */
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt index 8ebc8cf..917b568 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/TypeParameterListSpacingRule.kt
@@ -20,15 +20,15 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextSibling import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.rule.engine.core.api.replaceTextWith import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe @@ -82,19 +82,19 @@ // No white space expected between class name and parameter list // class Bar <T> node - .prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + .prevSibling + ?.takeIf { it.isWhiteSpace } ?.let { visitWhitespace(it, emit) } // No white space expected between parameter type list and the constructor except when followed by compound // constructor // class Bar<T> (...) node - .nextSibling20 - ?.takeIf { it.isWhiteSpace20 && it.nextCodeSibling20?.elementType == PRIMARY_CONSTRUCTOR } + .nextSibling + ?.takeIf { it.isWhiteSpace && it.nextCodeSibling?.elementType == PRIMARY_CONSTRUCTOR } ?.let { whiteSpace -> - if (whiteSpace.nextCodeSibling20?.findChildByType(CONSTRUCTOR_KEYWORD) != null) { - if (whiteSpace.isWhiteSpaceWithNewline20) { + if (whiteSpace.nextCodeSibling?.findChildByType(CONSTRUCTOR_KEYWORD) != null) { + if (whiteSpace.isWhiteSpaceWithNewline) { // Newline is acceptable before (modifier list of) constructor // class Bar<T> // constructor(...) @@ -132,8 +132,8 @@ // No white space expected between parameter type list and class body when constructor is missing // class Bar<T> { node - .nextSibling20 - ?.takeIf { it.isWhiteSpace20 && it.nextCodeSibling20?.elementType == CLASS_BODY } + .nextSibling + ?.takeIf { it.isWhiteSpace && it.nextCodeSibling?.elementType == CLASS_BODY } ?.let { singleSpaceExpected(it, emit) } } @@ -144,15 +144,15 @@ // No white space expected between typealias keyword name and parameter list // typealias Bar <T> node - .prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + .prevSibling + ?.takeIf { it.isWhiteSpace } ?.let { visitWhitespace(it, emit) } // No white space expected between parameter type list and equals sign // typealias Bar<T> = ... node - .nextSibling20 - ?.takeIf { it.isWhiteSpace20 && it.nextCodeSibling20?.elementType == EQ } + .nextSibling + ?.takeIf { it.isWhiteSpace && it.nextCodeSibling?.elementType == EQ } ?.let { singleSpaceExpected(it, emit) } } @@ -165,7 +165,7 @@ node .prevLeaf ?.let { prevLeaf -> - if (prevLeaf.isWhiteSpace20) { + if (prevLeaf.isWhiteSpace) { singleSpaceExpected(prevLeaf, emit) } else { singleSpaceExpected(node.firstChildNode, emit) @@ -189,8 +189,8 @@ ) { node .findChildByType(LT) - ?.nextSibling20 - ?.takeIf { it.isWhiteSpace20 } + ?.nextSibling + ?.takeIf { it.isWhiteSpace } ?.let { val expectedWhitespace = if (node.textContains('\n')) { @@ -203,8 +203,8 @@ node .findChildByType(GT) - ?.prevSibling20 - ?.takeIf { it.isWhiteSpace20 } + ?.prevSibling + ?.takeIf { it.isWhiteSpace } ?.let { val expectedWhitespace = if (node.textContains('\n')) { @@ -231,7 +231,7 @@ .ifAutocorrectAllowed { node.remove() } } - node.isWhiteSpaceWithoutNewline20 && expectedWhitespace.startsWith("\n") -> { + node.isWhiteSpaceWithoutNewline && expectedWhitespace.startsWith("\n") -> { emit(node.startOffset, "Expected a newline", true) .ifAutocorrectAllowed { node.replaceTextWith(expectedWhitespace) } } @@ -252,7 +252,7 @@ Unit } - node.isWhiteSpaceWithNewline20 -> { + node.isWhiteSpaceWithNewline -> { emit(node.startOffset, "Expected a single space instead of newline", true) .ifAutocorrectAllowed { node.replaceTextWith(" ") } }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt index 3a26a5e..5bbc57a 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt
@@ -12,11 +12,11 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.remove import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -34,8 +34,8 @@ if (node.isEmptyArgumentList() && node.isPartOf(CALL_EXPRESSION) && node.isNotPrecededByCallExpressionEndingWithLambdaArgument() && - node.nextCodeSibling20?.elementType == LAMBDA_ARGUMENT && - node.prevCodeSibling20?.elementType != CALL_EXPRESSION + node.nextCodeSibling?.elementType == LAMBDA_ARGUMENT && + node.prevCodeSibling?.elementType != CALL_EXPRESSION ) { emit( node.startOffset, @@ -47,12 +47,12 @@ private fun ASTNode.isEmptyArgumentList(): Boolean = elementType == VALUE_ARGUMENT_LIST && - children20 + children .filterNot { it.elementType == LPAR || it.elementType == RPAR } .none() private fun ASTNode.isNotPrecededByCallExpressionEndingWithLambdaArgument() = - prevCodeSibling20 + prevCodeSibling ?.takeIf { it.elementType == CALL_EXPRESSION } ?.lastChildNode ?.takeIf { it.elementType == LAMBDA_ARGUMENT }
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueArgumentCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueArgumentCommentRule.kt index 9f2617c..9e6be44 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueArgumentCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueArgumentCommentRule.kt
@@ -5,7 +5,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -23,7 +23,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isPartOfComment20 && node.parent?.elementType == VALUE_ARGUMENT) { + if (node.isPartOfComment && node.parent?.elementType == VALUE_ARGUMENT) { // Disallow: // val foo = foo( // bar /* some comment */ = "bar"
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueParameterCommentRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueParameterCommentRule.kt index cc96ef4..e1f482e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueParameterCommentRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ValueParameterCommentRule.kt
@@ -6,7 +6,7 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -24,7 +24,7 @@ node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - if (node.isPartOfComment20 && node.parent?.elementType == VALUE_PARAMETER) { + if (node.isPartOfComment && node.parent?.elementType == VALUE_PARAMETER) { if (node.elementType == KDOC && node.parent?.firstChildNode == node) { // Allow KDoc to be the first element of a value parameter. EOL and block comments directly before a value parameter are // a child of the value parameter list, and as of that will never be the first child of the value.
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WhenEntryBracing.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WhenEntryBracing.kt index cef94a0..115c702 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WhenEntryBracing.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WhenEntryBracing.kt
@@ -12,19 +12,18 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.EXPERIMENTAL import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling +import com.pinterest.ktlint.rule.engine.core.api.prevSibling import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.psiUtil.leaves @@ -77,7 +76,7 @@ } } - private fun ASTNode.hasAnyWhenEntryWithBlockAfterArrow() = children20.any { it.elementType == WHEN_ENTRY && it.hasBlockAfterArrow() } + private fun ASTNode.hasAnyWhenEntryWithBlockAfterArrow() = children.any { it.elementType == WHEN_ENTRY && it.hasBlockAfterArrow() } private fun ASTNode.hasBlockAfterArrow(): Boolean { require(elementType == WHEN_ENTRY) @@ -87,14 +86,14 @@ .any { it.elementType == BLOCK } } - private fun ASTNode.hasAnyWhenEntryWithMultilineBody() = children20.any { it.elementType == WHEN_ENTRY && it.hasMultilineBody() } + private fun ASTNode.hasAnyWhenEntryWithMultilineBody() = children.any { it.elementType == WHEN_ENTRY && it.hasMultilineBody() } private fun ASTNode.hasMultilineBody(): Boolean { require(elementType == WHEN_ENTRY) return findChildByType(ARROW) ?.siblings() .orEmpty() - .any { it.isWhiteSpaceWithNewline20 } + .any { it.isWhiteSpaceWithNewline } } private fun addBracesToWhenEntry( @@ -102,14 +101,14 @@ emitAndApprove: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { node - .children20 + .children .filter { it.elementType == WHEN_ENTRY } .filter { !it.hasBlockAfterArrow() } .forEach { whenEntry -> whenEntry .findChildByType(ARROW) ?.let { arrow -> - val nonWhiteSpaceSibling = arrow.nextSibling { !it.isWhiteSpace20 } ?: arrow + val nonWhiteSpaceSibling = arrow.nextSibling { !it.isWhiteSpace } ?: arrow emitAndApprove( nonWhiteSpaceSibling.startOffset, "Body of when entry should be surrounded by braces if any when entry body is surrounded by braces " + @@ -129,23 +128,23 @@ val whenEntryIndent = indentConfig.parentIndentOf(this).removePrefix("\n") val whenEntry = parent!! // Find the anchor node, e.g. the last node before the current when-entry which is not altered - val siblingBeforeWhenEntry = whenEntry.prevSibling20!! + val siblingBeforeWhenEntry = whenEntry.prevSibling!! // Find the first leaf after the when-entry (including the EOL comment after it) that not has to be enclosed within the braces val stopLeaf = siblingBeforeWhenEntry .siblings() - .takeWhile { !it.isWhiteSpaceWithNewline20 } + .takeWhile { !it.isWhiteSpaceWithNewline } .last() - .nextSibling20!! - .firstChildLeafOrSelf20 + .nextSibling!! + .firstChildLeafOrSelf val whenEntryNode = createWhenEntryNode( - "${whenEntryIndent}${prevCodeSibling20!!.text} -> {" + + "${whenEntryIndent}${prevCodeSibling!!.text} -> {" + // Replace the whitespaces (possibly this could be a proper indent) at the beginning of the body with an indent. In case // the body was already a multiline statement, then the second and following lines should already be properly indented. indentConfig.childIndentOf(this) + leaves() - .dropWhile { it.isWhiteSpace20 } + .dropWhile { it.isWhiteSpace } .takeWhile { it != stopLeaf } .joinToString(separator = "") { it.text } + "\n$whenEntryIndent}",
diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt index 2366341..97ad5cc 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/WrappingRule.kt
@@ -48,35 +48,33 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.TokenSets -import com.pinterest.ktlint.rule.engine.core.api.children20 +import com.pinterest.ktlint.rule.engine.core.api.children import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MAX_LINE_LENGTH_PROPERTY_OFF -import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.firstChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.hasNewLineInClosedRange import com.pinterest.ktlint.rule.engine.core.api.hasNoMaxLineLengthSuppression import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed -import com.pinterest.ktlint.rule.engine.core.api.indent20 +import com.pinterest.ktlint.rule.engine.core.api.indent import com.pinterest.ktlint.rule.engine.core.api.isPartOf -import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline20 -import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline20 -import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf20 +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline +import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithoutNewline +import com.pinterest.ktlint.rule.engine.core.api.lastChildLeafOrSelf import com.pinterest.ktlint.rule.engine.core.api.leavesForwardsIncludingSelf import com.pinterest.ktlint.rule.engine.core.api.nextCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.nextLeaf import com.pinterest.ktlint.rule.engine.core.api.nextSibling -import com.pinterest.ktlint.rule.engine.core.api.nextSibling20 import com.pinterest.ktlint.rule.engine.core.api.parent import com.pinterest.ktlint.rule.engine.core.api.prevCodeLeaf -import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling20 +import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.prevSibling -import com.pinterest.ktlint.rule.engine.core.api.prevSibling20 import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceAfterMe import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe import com.pinterest.ktlint.ruleset.standard.StandardRule @@ -162,7 +160,7 @@ } node - .takeUnless { it.firstChildLeafOrSelf20.elementType == EOL_COMMENT } + .takeUnless { it.firstChildLeafOrSelf.elementType == EOL_COMMENT } ?.getEndOfBlock() ?.takeIf { it.elementType == RBRACE } ?.let { rbrace -> @@ -175,13 +173,13 @@ val lengthUntilBeginOfLine = node .leaves(false) - .takeWhile { !it.isWhiteSpaceWithNewline20 } + .takeWhile { !it.isWhiteSpaceWithNewline } .sumOf { it.textLength } val lengthUntilEndOfLine = node - .firstChildLeafOrSelf20 + .firstChildLeafOrSelf .leavesForwardsIncludingSelf - .takeWhile { !it.isWhiteSpaceWithNewline20 } + .takeWhile { !it.isWhiteSpaceWithNewline } .sumOf { it.textLength } if (lengthUntilBeginOfLine + lengthUntilEndOfLine > maxLineLength) { requireNewlineAfterLeaf(lbrace, emit) @@ -192,13 +190,13 @@ private fun ASTNode.followedByEolComment() = null != leaves() - .takeWhile { it.isWhiteSpaceWithoutNewline20 || it.elementType == EOL_COMMENT } + .takeWhile { it.isWhiteSpaceWithoutNewline || it.elementType == EOL_COMMENT } .firstOrNull { it.elementType == EOL_COMMENT } private fun ASTNode.followedByFunctionLiteralParameterList() = VALUE_PARAMETER_LIST == takeIf { parent?.elementType == FUNCTION_LITERAL } - ?.nextCodeSibling20 + ?.nextCodeSibling ?.elementType private fun rearrangeBlock( @@ -260,10 +258,10 @@ .nextCodeLeaf ?.prevLeaf { // Skip comments, whitespace, and empty nodes - !it.isPartOfComment20 && - !it.isWhiteSpaceWithoutNewline20 && + !it.isPartOfComment && + !it.isWhiteSpaceWithoutNewline && it.textLength > 0 - }.isWhiteSpaceWithNewline20 && + }.isWhiteSpaceWithNewline && // IDEA quirk: // if (true && // true @@ -275,11 +273,11 @@ // true // ) { // } - node.nextSibling20?.elementType != CONDITION + node.nextSibling?.elementType != CONDITION ) { requireNewlineAfterLeaf(node, emit) } - if (!closingElement.prevLeaf.isWhiteSpaceWithNewline20) { + if (!closingElement.prevLeaf.isWhiteSpaceWithNewline) { requireNewlineBeforeLeaf(closingElement, emit, indentConfig.parentIndentOf(node)) } } @@ -310,25 +308,25 @@ ) ) { // put space after : - if (!node.prevLeaf.isWhiteSpaceWithNewline20) { + if (!node.prevLeaf.isWhiteSpaceWithNewline) { val colon = node.prevCodeLeaf!! if ( - !colon.prevLeaf.isWhiteSpaceWithNewline20 && - colon.prevCodeLeaf.let { it?.elementType != RPAR || !it.prevLeaf.isWhiteSpaceWithNewline20 } + !colon.prevLeaf.isWhiteSpaceWithNewline && + colon.prevCodeLeaf.let { it?.elementType != RPAR || !it.prevLeaf.isWhiteSpaceWithNewline } ) { requireNewlineAfterLeaf(colon, emit) } } // put entries on separate lines - for (c in node.children20) { + for (c in node.children) { if (c.elementType == COMMA && - !c.nextSibling20.isWhiteSpaceWithNewline20 && + !c.nextSibling.isWhiteSpaceWithNewline && !c.isFollowedByCommentOnSameLine() ) { requireNewlineAfterLeaf( nodeAfterWhichNewlineIsRequired = c, emit = emit, - indent = node.indent20, + indent = node.indent, ) } } @@ -336,14 +334,14 @@ } private fun ASTNode.isFollowedByCommentOnSameLine() = - nextLeaf { !it.isWhiteSpaceWithoutNewline20 } - ?.isPartOfComment20 == true + nextLeaf { !it.isWhiteSpaceWithoutNewline } + ?.isPartOfComment == true private fun rearrangeValueList( node: ASTNode, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> AutocorrectDecision, ) { - for (c in node.children20) { + for (c in node.children) { val hasLineBreak = when (c.elementType) { VALUE_ARGUMENT -> c.hasLineBreak(LAMBDA_EXPRESSION, FUN) @@ -364,25 +362,25 @@ // c, d // insert \n in front of multi-line value - val prevSibling = c.prevSibling { !it.isWhiteSpace20 } + val prevSibling = c.prevSibling { !it.isWhiteSpace } if ( prevSibling?.elementType == COMMA && - !prevSibling.nextSibling20.isWhiteSpaceWithNewline20 + !prevSibling.nextSibling.isWhiteSpaceWithNewline ) { requireNewlineAfterLeaf(prevSibling, emit) } // insert \n after multi-line value - val nextSibling = c.nextSibling { !it.isWhiteSpace20 } + val nextSibling = c.nextSibling { !it.isWhiteSpace } val hasDestructuringDeclarationAsLastValueParameter = c.isLastValueParameter() && c.firstChildNode.elementType == DESTRUCTURING_DECLARATION if ( nextSibling?.elementType == COMMA && !hasDestructuringDeclarationAsLastValueParameter && - !nextSibling.nextSibling20.isWhiteSpaceWithNewline20 && + !nextSibling.nextSibling.isWhiteSpaceWithNewline && // value( // ), // a comment // c, d - nextSibling.nextSibling20?.nextSibling20?.let { !TokenSets.COMMENTS.contains(it.elementType) } != false + nextSibling.nextSibling?.nextSibling?.let { !TokenSets.COMMENTS.contains(it.elementType) } != false ) { requireNewlineAfterLeaf(nextSibling, emit) } @@ -401,13 +399,13 @@ if (node.textContains('\n')) { // Each type projection must be preceded with a whitespace containing a newline node - .children20 + .children .filter { it.elementType == TYPE_PROJECTION || it.elementType == TYPE_PARAMETER } .forEach { typeProjection -> typeProjection - .prevSibling { !it.isPartOfComment20 } + .prevSibling { !it.isPartOfComment } .let { prevSibling -> - if (prevSibling?.elementType == LT || prevSibling.isWhiteSpaceWithoutNewline20) { + if (prevSibling?.elementType == LT || prevSibling.isWhiteSpaceWithoutNewline) { emit(typeProjection.startOffset, "A newline was expected before '${typeProjection.text}'", true) .ifAutocorrectAllowed { typeProjection.upsertWhitespaceBeforeMe(indentConfig.siblingIndentOf(node)) @@ -420,8 +418,8 @@ node .findChildByType(GT) ?.let { closingAngle -> - val prevSibling = closingAngle.prevSibling { !it.isPartOfComment20 } - if (!prevSibling.isWhiteSpaceWithNewline20) { + val prevSibling = closingAngle.prevSibling { !it.isPartOfComment } + if (!prevSibling.isWhiteSpaceWithNewline) { emit(closingAngle.startOffset, "A newline was expected before '${closingAngle.text}'", true) .ifAutocorrectAllowed { closingAngle.upsertWhitespaceBeforeMe(indentConfig.siblingIndentOf(node)) @@ -441,7 +439,7 @@ ?.let { it.psi as KtStringTemplateExpression } ?.takeIf { it.isMultiLine() } ?.takeIf { it.isFollowedByTrimIndent() || it.isFollowedByTrimMargin() } - ?.takeUnless { node.prevSibling20?.text.isNullOrBlank() } + ?.takeUnless { node.prevSibling?.text.isNullOrBlank() } ?.let { // rewriting // """ @@ -473,8 +471,8 @@ // find matching rToken // return true if there is no newline after the rToken // return false - val nextCodeSibling = node.nextCodeSibling20 // e.g. BINARY_EXPRESSION - var lToken = nextCodeSibling?.nextLeaf { it.isWhiteSpaceWithNewline20 }?.prevCodeLeaf + val nextCodeSibling = node.nextCodeSibling // e.g. BINARY_EXPRESSION + var lToken = nextCodeSibling?.nextLeaf { it.isWhiteSpaceWithNewline }?.prevCodeLeaf if (lToken != null && lToken.elementType !in LTOKEN_SET) { // special cases: // x = y.f({ z -> @@ -517,16 +515,16 @@ // 0x200D // Zero-width Joiner // -> true // } - (parent.elementType == WHEN_ENTRY && node.prevLeaf.isWhiteSpaceWithNewline20) + (parent.elementType == WHEN_ENTRY && node.prevLeaf.isWhiteSpaceWithNewline) ) { return } - if (!node.nextCodeLeaf?.prevLeaf.isWhiteSpaceWithNewline20) { + if (!node.nextCodeLeaf?.prevLeaf.isWhiteSpaceWithNewline) { requireNewlineAfterLeaf(node, emit) } val r = node.nextSibling { it.elementType == RBRACE } ?: return - if (!r.prevLeaf.isWhiteSpaceWithNewline20) { - requireNewlineBeforeLeaf(r, emit, node.indent20) + if (!r.prevLeaf.isWhiteSpaceWithNewline) { + requireNewlineBeforeLeaf(r, emit, node.indent) } } @@ -569,7 +567,7 @@ } private fun KtStringTemplateExpression.isMultiLine(): Boolean { - for (child in node.children20) { + for (child in node.children) { if (child.elementType == LITERAL_STRING_TEMPLATE_ENTRY) { val v = child.text if (v == "\n") { @@ -581,12 +579,12 @@ } private fun ASTNode.hasLineBreak(vararg ignoreElementTypes: IElementType): Boolean { - if (isWhiteSpaceWithNewline20) return true + if (isWhiteSpaceWithNewline) return true return if (ignoreElementTypes.isEmpty()) { textContains('\n') } else { elementType !in ignoreElementTypes && - children20.any { c -> c.textContains('\n') && c.elementType !in ignoreElementTypes } + children.any { c -> c.textContains('\n') && c.elementType !in ignoreElementTypes } } } @@ -627,10 +625,10 @@ var node: ASTNode? = this while (node != null && node.elementType != RPAR) { - if (node.isWhiteSpaceWithNewline20) { + if (node.isWhiteSpaceWithNewline) { return false } - node = node.nextSibling20 + node = node.nextSibling } return true } @@ -661,22 +659,22 @@ } } - private fun ASTNode.followedByNewline() = nextLeaf.isWhiteSpaceWithNewline20 + private fun ASTNode.followedByNewline() = nextLeaf.isWhiteSpaceWithNewline - private fun ASTNode.isPrecededByNewline() = prevLeaf.isWhiteSpaceWithNewline20 + private fun ASTNode.isPrecededByNewline() = prevLeaf.isWhiteSpaceWithNewline private fun ASTNode.getStartOfBlock() = if (parent?.elementType == FUNCTION_LITERAL) { parent!!.findChildByType(LBRACE) } else { - firstChildLeafOrSelf20 + firstChildLeafOrSelf .let { node -> if (node.elementType == LBRACE) { // WHEN-entry block have LBRACE and RBRACE as first and last elements node } else { // Other blocks have LBRACE and RBRACE as siblings of the block - node.prevCodeSibling20 + node.prevCodeSibling } } } @@ -685,14 +683,14 @@ if (parent?.elementType == FUNCTION_LITERAL) { parent!!.findChildByType(RBRACE) } else { - lastChildLeafOrSelf20 + lastChildLeafOrSelf .let { node -> if (node.elementType == RBRACE) { // WHEN-entry block have LBRACE and RBRACE as first and last elements node } else { // Other blocks have LBRACE and RBRACE as siblings of the block - node.nextCodeSibling20 + node.nextCodeSibling } } }
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 459cfb0..49d7aa4 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
@@ -340,31 +340,6 @@ ) /** - * Creates an assertThat assertion function for the rule provided by [provider]. This assertion function has extensions specifically - * for testing KtLint rules. The rules provided via [additionalRuleProviders] are only executed during the format phase of the test. - * This means that the unit test only has to check the lint violations thrown by the rule for which the assertThat is created. But - * the code is formatted by both the rule and the rules provided by [additionalRuleProviders] in the order as defined by the rule - * definitions. - * - * Use function [assertThatRule] to create a default assertThat assertion function. In case a more specialized assertion function is - * needed, then use [assertThatRuleBuilder]. - */ - @Deprecated(message = "Marked for removal in Ktlint 2.0. See KDOC for alternative") - public fun assertThatRule( - provider: () -> RuleV2, - additionalRuleProviders: Set<RuleV2InstanceProvider> = emptySet(), - editorConfigProperties: Set<Pair<EditorConfigProperty<*>, *>> = emptySet(), - ): (String) -> KtLintAssertThat = - { code -> - KtLintAssertThat( - ruleProvider = RuleV2InstanceProvider { provider() }, - code = code, - additionalRuleProviders = additionalRuleProviders.toMutableSet(), - editorConfigProperties = editorConfigProperties.toMutableSet(), - ) - } - - /** * See [setMaxLineLength] for intended usage. */ public const val MAX_LINE_LENGTH_MARKER: String = "Max line length marker:"