Skip to content

Commit

Permalink
bugfix/newlinesrule(#748)
Browse files Browse the repository at this point in the history
### What's done:
  * Fixed bugs
  • Loading branch information
aktsay6 committed Feb 9, 2021
1 parent 0d8431e commit 67d6d0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.pinterest.ktlint.core.ast.ElementType.PLUS
import com.pinterest.ktlint.core.ast.ElementType.PLUSEQ
import com.pinterest.ktlint.core.ast.ElementType.POSTFIX_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.PRIMARY_CONSTRUCTOR
import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.RETURN
import com.pinterest.ktlint.core.ast.ElementType.RETURN_KEYWORD
import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS
Expand Down Expand Up @@ -310,7 +311,7 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
return
}

if (node.elementType == VALUE_ARGUMENT_LIST && !node.hasParent(SUPER_TYPE_LIST)) {
if (node.elementType == VALUE_ARGUMENT_LIST && node.treePrev != null && node.treePrev.elementType == REFERENCE_EXPRESSION) {
// check that it is not function invocation, but only supertype constructor calls
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
LintError(3, 10, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of <Foo>", true),
LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} first parameter should be placed on a separate line or all other parameters " +
"should be aligned with it in declaration of <Foo>", true),
LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of <Foo>", true)
LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of <Foo>", true),
LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (arg1) should be placed on the new line or all other parameters should be aligned with it", true),
LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true)
)
}

Expand Down Expand Up @@ -657,6 +659,20 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
)
}

@Test
@Tag(WarningNames.WRONG_NEWLINES)
fun `should not raise warning on list params`() {
lintMethod(
"""
|class SomeRule(configRules: List<Int>) : Rule("id",
|configRules,
|listOf("foo", "baz", "triple", "bar")) {
|
|}
""".trimMargin()
)
}

@Test
@Tag(WarningNames.WRONG_NEWLINES)
fun `should raise warning on value arguments`() {
Expand Down

0 comments on commit 67d6d0c

Please sign in to comment.