Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'Missing newline before ")"' when no params #364

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.github.shyiko.ktlint.core.ast.ElementType.VALUE_PARAMETER_LIST
import com.github.shyiko.ktlint.core.ast.ElementType.WHITE_SPACE
import com.github.shyiko.ktlint.core.ast.children
import com.github.shyiko.ktlint.core.ast.isRoot
import com.github.shyiko.ktlint.core.ast.prevCodeLeaf
import com.github.shyiko.ktlint.core.ast.prevLeaf
import com.github.shyiko.ktlint.core.ast.visit
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
Expand Down Expand Up @@ -39,6 +38,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
) {
Expand Down Expand Up @@ -99,7 +100,7 @@ class ParameterListWrappingRule : Rule("parameter-list-wrapping") {
paramInnerIndentAdjustment = adjustedIndent.length - prevLeaf.getTextLength()
(prevLeaf as LeafPsiElement).rawReplaceWithText(adjustedIndent)
}
} else if (prevLeaf?.prevCodeLeaf()?.elementType != LPAR) {
} else {
emit(child.startOffset, errorMessage(child), true)
if (autoCorrect) {
paramInnerIndentAdjustment = intendedIndent.length - child.column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -137,8 +151,6 @@ class ParameterListWrappingRuleTest {
b: Any,
c: Any) {
}
fun f() {}
fun f(/**/) {}
""".trimIndent()
)
).isEqualTo(
Expand Down