From c16fbfee4ff0397f1d76f4ff0e38480c863912e0 Mon Sep 17 00:00:00 2001 From: Cheshiriks Date: Fri, 10 Sep 2021 18:31:04 +0300 Subject: [PATCH 1/5] NPE in NewlinesRule: ### What's done: * fixed bug in NewlinesRule Closes #1047 --- .../ruleset/rules/chapter3/files/NewlinesRule.kt | 3 ++- .../ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 9344ffd263..7de5d18eb0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -22,6 +22,7 @@ import org.cqfn.diktat.ruleset.utils.isSingleLineIfElse import org.cqfn.diktat.ruleset.utils.leaveOnlyOneNewLine import com.pinterest.ktlint.core.ast.ElementType.ANDAND +import com.pinterest.ktlint.core.ast.ElementType.ARRAY_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.ARROW import com.pinterest.ktlint.core.ast.ElementType.BINARY_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.BLOCK @@ -461,7 +462,7 @@ class NewlinesRule(configRules: List) : DiktatRule( if (psi.children.isNotEmpty() && !psi.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) && !psi.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { - val firstChild = psi.firstChild + val firstChild = if (psi.isFirstChildElementType(ARRAY_ACCESS_EXPRESSION)) psi.firstChild.firstChild else psi.firstChild if (firstChild.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) || firstChild.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { getOrderedCallExpressions(firstChild.firstChild, result) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 95a505b829..bece38b5b9 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -527,6 +527,18 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { ) } + @Test + @Tag(WarningNames.WRONG_NEWLINES) + fun `should warn for array access expression`() { + lintMethod( + """ + |fun bar(): String { + | val a = it.responseBody!!.name + |} + """.trimMargin() + ) + } + @Test @Tag(WarningNames.WRONG_NEWLINES) fun `long argument list should be split into several lines - positive example`() { From 847dd89bc89936ad641e7e51e9f11345242c2fb5 Mon Sep 17 00:00:00 2001 From: Cheshiriks Date: Sat, 11 Sep 2021 15:27:10 +0300 Subject: [PATCH 2/5] NPE in NewlinesRule: ### What's done: * fixed bug in NewlinesRule Closes #1047 --- .../cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 3 --- .../cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 7de5d18eb0..9e30f3e7c0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -467,9 +467,6 @@ class NewlinesRule(configRules: List) : DiktatRule( firstChild.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { getOrderedCallExpressions(firstChild.firstChild, result) } - if (firstChild.isFirstChildElementType(POSTFIX_EXPRESSION)) { - result.add(firstChild.node) - } result.add(firstChild.node .siblings(true) .dropWhile { it.elementType in dropChainValues } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index bece38b5b9..564f535116 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -533,7 +533,7 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { lintMethod( """ |fun bar(): String { - | val a = it.responseBody!!.name + | val a = it.responseBody!![0].name |} """.trimMargin() ) From 23f76da94744b5f60a94d1ec72c0f865cc534a27 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Tue, 14 Sep 2021 19:36:56 +0300 Subject: [PATCH 3/5] Kdoc fixer: not ask @return on simple delegating getters: ### What's done: * fixed bug in WRONG_NEWLINES * now don't ask @return on function with name same last reference Expression Closes #965 --- .../diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 2 +- .../diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 9e30f3e7c0..0909e60cd7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -462,7 +462,7 @@ class NewlinesRule(configRules: List) : DiktatRule( if (psi.children.isNotEmpty() && !psi.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) && !psi.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { - val firstChild = if (psi.isFirstChildElementType(ARRAY_ACCESS_EXPRESSION)) psi.firstChild.firstChild else psi.firstChild + val firstChild = psi.firstChild if (firstChild.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) || firstChild.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { getOrderedCallExpressions(firstChild.firstChild, result) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 564f535116..25880d8bef 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -533,9 +533,11 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { lintMethod( """ |fun bar(): String { - | val a = it.responseBody!![0].name + | val a = list.responseBody!![0]. + | name |} - """.trimMargin() + """.trimMargin(), + LintError(2, 35, ruleId, "$shouldBreakBefore .", true) ) } From 32b0037537a84d16cb62eb578b1ca0fae87c6c50 Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Fri, 17 Sep 2021 18:13:39 +0300 Subject: [PATCH 4/5] Kdoc fixer: not ask @return on simple delegating getters: ### What's done: * fixed bug in WRONG_NEWLINES * now don't ask @return on function with name same last reference Expression Closes #965 --- .../test/paragraph3/newlines/FunctionalStyleExpected.kt | 3 +++ .../resources/test/paragraph3/newlines/FunctionalStyleTest.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt index 6d0f90b556..a9cba895f8 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt @@ -28,6 +28,9 @@ fun goo() { .map() .filter() .hre() + + t.responseBody!![0] +.name } fun foo() { diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt index 16e8490f85..a21af042f6 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt @@ -22,6 +22,9 @@ fun goo() { x .map() .filter().hre() + + t.responseBody!![0]. + name } fun foo() { From f68ac3566f16d0b4274c76430138618e0d6117d7 Mon Sep 17 00:00:00 2001 From: Cheshiriks Date: Wed, 22 Sep 2021 15:56:14 +0300 Subject: [PATCH 5/5] NPE in NewlinesRule: ### What's done: * fixed bug in NewlinesRule Closes #1047 --- .../org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 0909e60cd7..fd62a17688 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -22,7 +22,6 @@ import org.cqfn.diktat.ruleset.utils.isSingleLineIfElse import org.cqfn.diktat.ruleset.utils.leaveOnlyOneNewLine import com.pinterest.ktlint.core.ast.ElementType.ANDAND -import com.pinterest.ktlint.core.ast.ElementType.ARRAY_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.ARROW import com.pinterest.ktlint.core.ast.ElementType.BINARY_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.BLOCK