From 6b3637b62f7b374e62c70d1c6dbf31962919088b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mart=C3=ADn?= Date: Sat, 30 Mar 2019 23:55:19 +0100 Subject: [PATCH] Fix 'Missing newline before ")"' when no params Avoid checking "parameter-list-wrapping" rule when the element doesn't have parameters. Fixes #327 --- .../ruleset/standard/ParameterListWrappingRule.kt | 2 ++ .../standard/ParameterListWrappingRuleTest.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRule.kt index 3b0e681dd8..a6a6bf5afe 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRule.kt @@ -39,6 +39,8 @@ class ParameterListWrappingRule : Rule("parameter-list-wrapping") { return } if (node.elementType == VALUE_PARAMETER_LIST && + // skip when there are no parameters + node.firstChildNode.treeNext.elementType != RPAR && // skip lambda parameters node.treeParent?.elementType != FUNCTION_LITERAL ) { diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt index 4636ad118a..f10db3dd0f 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRuleTest.kt @@ -62,6 +62,20 @@ class ParameterListWrappingRuleTest { ) } + @Test + fun testLintClassParameterListWhenMaxLineLengthExceededAndNoParameters() { + assertThat( + ParameterListWrappingRule().lint( + """ + class ClassAWithALongName() + """.trimIndent(), + userData = mapOf("max_line_length" to "10") + ) + ).doesNotContain( + LintError(1, 27, "parameter-list-wrapping", """Missing newline before ")"""") + ) + } + @Test fun testLintClassParameterListValid() { assertThat(