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 1635d5c1b9..381f96ad3d 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 @@ -149,7 +149,8 @@ public class ClassSignatureRule : currentNode = iterator.next() if (currentNode.elementType != ANNOTATION && currentNode.elementType != ANNOTATION_ENTRY && - currentNode.elementType != WHITE_SPACE + currentNode.elementType != WHITE_SPACE && + currentNode.elementType != EOL_COMMENT ) { return currentNode } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRuleTest.kt index a0de8fdce4..4bb734041c 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/ClassSignatureRuleTest.kt @@ -1849,6 +1849,20 @@ class ClassSignatureRuleTest { classSignatureWrappingRuleAssertThat(code).hasNoLintViolations() } + @Test + fun `Issue 2755 - Given a class preceded by an annotation, and EOL comment, and another class modifier then ignore the EOL comment in determination of class signature length`() { + val code = + """ + // $MAX_LINE_LENGTH_MARKER $EOL_CHAR + @Suppress("UnnecessaryAbstractClass") // some comment + abstract class Bar(val baz1: String, val baz2: String) + """.trimIndent() + classSignatureWrappingRuleAssertThat(code) + .setMaxLineLength() + .withEditorConfigOverride(FORCE_MULTILINE_WHEN_PARAMETER_COUNT_GREATER_OR_EQUAL_THAN_PROPERTY to "unset") + .hasNoLintViolations() + } + private companion object { const val UNEXPECTED_SPACES = " " const val NO_SPACE = ""