From 7398da60d35ded1c8e58e7c13ec5182f4b0a5d2f Mon Sep 17 00:00:00 2001 From: kentr0w Date: Thu, 14 Jan 2021 17:27:26 +0300 Subject: [PATCH 1/7] AsyncAndSyncRule ### What's done: Implemented rule, added tests and documentation --- diktat-analysis.yml | 3 ++ .../src/main/kotlin/generated/WarningNames.kt | 2 + .../cqfn/diktat/ruleset/constants/Warnings.kt | 1 + .../diktat/ruleset/rules/AsyncAndSyncRule.kt | 43 +++++++++++++++++ .../ruleset/rules/DiktatRuleSetProvider.kt | 1 + .../main/resources/diktat-analysis-huawei.yml | 3 ++ .../src/main/resources/diktat-analysis.yml | 3 ++ .../ruleset/chapter5/AsyncAndSyncRuleTest.kt | 48 +++++++++++++++++++ info/available-rules.md | 1 + info/guide/guide-chapter-5.md | 11 +++++ 10 files changed, 116 insertions(+) create mode 100644 diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt create mode 100644 diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt diff --git a/diktat-analysis.yml b/diktat-analysis.yml index 9ffbf8021f..21c0115b55 100644 --- a/diktat-analysis.yml +++ b/diktat-analysis.yml @@ -350,6 +350,9 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true +# Checks that using runBlocking inside async block code +- name: RUN_BLOCKING_INSIDE_ASYNC + enabled: true # Checks that property in constructor doesn't contains comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index 61bc1fad94..41cc893c31 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -199,6 +199,8 @@ public object WarningNames { public const val WRONG_OVERLOADING_FUNCTION_ARGUMENTS: String = "WRONG_OVERLOADING_FUNCTION_ARGUMENTS" + public const val RUN_BLOCKING_INSIDE_ASYNC: String = "RUN_BLOCKING_INSIDE_ASYNC" + public const val SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY: String = "SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY" diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt index 981b21b565..37ff4f7139 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt @@ -131,6 +131,7 @@ enum class Warnings( TOO_MANY_PARAMETERS(false, "5.2.2", "function has too many parameters"), NESTED_BLOCK(false, "5.1.2", "function has too many nested blocks and should be simplified"), WRONG_OVERLOADING_FUNCTION_ARGUMENTS(false, "5.2.3", "use default argument instead of function overloading"), + RUN_BLOCKING_INSIDE_ASYNC(false, "5.2.4", "avoid using runBlocking in asynchronous code"), // ======== chapter 6 ======== SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY(true, "6.1.1", "if a class has single constructor, it should be converted to a primary constructor"), diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt new file mode 100644 index 0000000000..23d0589e9b --- /dev/null +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -0,0 +1,43 @@ +package org.cqfn.diktat.ruleset.rules + +import org.cqfn.diktat.common.config.rules.RulesConfig +import org.cqfn.diktat.ruleset.constants.EmitType +import org.cqfn.diktat.ruleset.constants.Warnings.RUN_BLOCKING_INSIDE_ASYNC + +import com.pinterest.ktlint.core.Rule +import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION +import com.pinterest.ktlint.core.ast.ElementType.FUN +import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION +import com.pinterest.ktlint.core.ast.parent +import org.jetbrains.kotlin.com.intellij.lang.ASTNode +import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier + +class AsyncAndSyncRule(private val configRules: List) : Rule("sync-in-async") { + private var isFixMode: Boolean = false + private lateinit var emitWarn: EmitType + private val asyncList = listOf("async", "launch") + + override fun visit(node: ASTNode, + autoCorrect: Boolean, + emit: EmitType) { + emitWarn = emit + isFixMode = autoCorrect + + if (node.isRunBlocking()) + checkRunBlocking(node) + } + + private fun checkRunBlocking(node: ASTNode) { + if (node.parent({it.isAsync() || it.isSuspend()}) != null) { + RUN_BLOCKING_INSIDE_ASYNC.warn(configRules, emitWarn, isFixMode, node.text, node.startOffset, node) + } + } + + private fun ASTNode.isAsync() = this.elementType == CALL_EXPRESSION && this.findChildByType(REFERENCE_EXPRESSION)?.text in asyncList + + private fun ASTNode.isSuspend() = this.elementType == FUN && (this.psi as KtFunction).modifierList?.hasSuspendModifier() ?: false + + private fun ASTNode.isRunBlocking() = this.elementType == REFERENCE_EXPRESSION && this.text == "runBlocking" +} + diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt index 7640a6f678..f05a80f906 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt @@ -137,6 +137,7 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS ::FunctionArgumentsSize, ::BlankLinesRule, ::FileSize, + ::AsyncAndSyncRule, ::NullableTypeRule, ::NullChecksRule, ::ImmutableValNoVarRule, diff --git a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml index 3e7f60fdb6..e5076289b4 100644 --- a/diktat-rules/src/main/resources/diktat-analysis-huawei.yml +++ b/diktat-rules/src/main/resources/diktat-analysis-huawei.yml @@ -350,6 +350,9 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true +# Checks that using runBlocking inside async block code +- name: RUN_BLOCKING_INSIDE_ASYNC + enabled: true # Checks that property in constructor doesn't contains comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true diff --git a/diktat-rules/src/main/resources/diktat-analysis.yml b/diktat-rules/src/main/resources/diktat-analysis.yml index 0caa29ff1e..3601911677 100644 --- a/diktat-rules/src/main/resources/diktat-analysis.yml +++ b/diktat-rules/src/main/resources/diktat-analysis.yml @@ -347,6 +347,9 @@ # Checks that function use default values, instead overloading - name: WRONG_OVERLOADING_FUNCTION_ARGUMENTS enabled: true +# Checks that using runBlocking inside async block code +- name: RUN_BLOCKING_INSIDE_ASYNC + enabled: true # Checks that property in constructor doesn't contain comment - name: KDOC_NO_CONSTRUCTOR_PROPERTY enabled: true diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt new file mode 100644 index 0000000000..9d93c210c7 --- /dev/null +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt @@ -0,0 +1,48 @@ +package org.cqfn.diktat.ruleset.chapter5 + +import org.cqfn.diktat.ruleset.constants.Warnings.RUN_BLOCKING_INSIDE_ASYNC +import org.cqfn.diktat.ruleset.rules.AsyncAndSyncRule +import org.cqfn.diktat.ruleset.rules.DIKTAT_RULE_SET_ID +import org.cqfn.diktat.util.LintTestBase + +import com.pinterest.ktlint.core.LintError +import generated.WarningNames +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test + +class AsyncAndSyncRuleTest: LintTestBase(::AsyncAndSyncRule) { + private val ruleId = "$DIKTAT_RULE_SET_ID:sync-in-async" + + @Test + @Tag(WarningNames.RUN_BLOCKING_INSIDE_ASYNC) + fun `test wrong case`() { + lintMethod( + """ + |fun foo() { + | GlobalScope.launch { + | c.addAndGet(i) + | } + | + | GlobalScope.async { + | n + | } + | + | GlobalScope.async { + | runBlocking { + | + | } + | } + |} + | + |suspend fun foo() { + | runBlocking { + | delay(2000) + | } + |} + | + """.trimMargin(), + LintError(11,8, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false), + LintError(18,4, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false) + ) + } +} \ No newline at end of file diff --git a/info/available-rules.md b/info/available-rules.md index 6af0e09a05..c57f68da13 100644 --- a/info/available-rules.md +++ b/info/available-rules.md @@ -95,6 +95,7 @@ | 5 | 5.2.1 | LAMBDA_IS_NOT_LAST_PARAMETER | Checks that lambda inside function parameters isn't in the end | no | no | | 5 | 5.2.2 | TOO_MANY_PARAMETERS | Check: if function contains more parameters than allowed | no | maxParameterListSize | | 5 | 5.2.3 | WRONG_OVERLOADING_FUNCTION_ARGUMENTS | Check: function has overloading instead use default arguments | no | no | +| 5 | 5.2.4 | RUN_BLOCKING_INSIDE_ASYNC | Check: using runBlocking inside async block code | no | no | - | | 6 | 6.1.1 | SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY | Check: warns if there is only one secondary constructor in a class
Fix: converts it to a primary constructor | yes | no | Support more complicated logic of constructor conversion | | 6 | 6.1.2 | USE_DATA_CLASS | Check: if class can be made as data class | no | no | yes | | 6 | 6.1.3 | EMPTY_PRIMARY_CONSTRUCTOR | Check: if there is empty primary constructor | yes | no | yes | diff --git a/info/guide/guide-chapter-5.md b/info/guide/guide-chapter-5.md index 294418dce4..b750a8eef0 100644 --- a/info/guide/guide-chapter-5.md +++ b/info/guide/guide-chapter-5.md @@ -132,3 +132,14 @@ private fun foo() { // ... } ``` +#### 5.2.4 Synchronizing code inside asynchronous code +Try to avoid using runBlocking in asynchronous code + +**Example**: +```kotlin +GlobalScope.async { + runBlocking { + count++ + } +} +``` \ No newline at end of file From 361b4612139527e868c3963b9cdb0f7e46621c6e Mon Sep 17 00:00:00 2001 From: kentr0w Date: Thu, 14 Jan 2021 17:36:47 +0300 Subject: [PATCH 2/7] AsyncAndSyncRule ### What's done: Fixed according out code-style --- .../cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt | 1 - .../diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt index 23d0589e9b..5d792113c0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -40,4 +40,3 @@ class AsyncAndSyncRule(private val configRules: List) : Rule("sync- private fun ASTNode.isRunBlocking() = this.elementType == REFERENCE_EXPRESSION && this.text == "runBlocking" } - diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt index 9d93c210c7..bb87b857cd 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt @@ -10,14 +10,14 @@ import generated.WarningNames import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -class AsyncAndSyncRuleTest: LintTestBase(::AsyncAndSyncRule) { +class AsyncAndSyncRuleTest : LintTestBase(::AsyncAndSyncRule) { private val ruleId = "$DIKTAT_RULE_SET_ID:sync-in-async" @Test @Tag(WarningNames.RUN_BLOCKING_INSIDE_ASYNC) fun `test wrong case`() { lintMethod( - """ + """ |fun foo() { | GlobalScope.launch { | c.addAndGet(i) @@ -40,9 +40,9 @@ class AsyncAndSyncRuleTest: LintTestBase(::AsyncAndSyncRule) { | } |} | - """.trimMargin(), - LintError(11,8, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false), - LintError(18,4, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false) + """.trimMargin(), + LintError(11, 8, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false), + LintError(18, 4, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false) ) } -} \ No newline at end of file +} From 2d2121739d332aa4743151bee86dcf19ba474750 Mon Sep 17 00:00:00 2001 From: kentr0w Date: Thu, 14 Jan 2021 17:43:47 +0300 Subject: [PATCH 3/7] AsyncAndSyncRule ### What's done: Fixed according out code-style --- .../org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt index 5d792113c0..e7ac8c014b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -13,10 +13,13 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier +/** + * This rule finds if using runBlocking in asynchronous code + */ class AsyncAndSyncRule(private val configRules: List) : Rule("sync-in-async") { + private val asyncList = listOf("async", "launch") private var isFixMode: Boolean = false private lateinit var emitWarn: EmitType - private val asyncList = listOf("async", "launch") override fun visit(node: ASTNode, autoCorrect: Boolean, @@ -24,12 +27,13 @@ class AsyncAndSyncRule(private val configRules: List) : Rule("sync- emitWarn = emit isFixMode = autoCorrect - if (node.isRunBlocking()) + if (node.isRunBlocking()) { checkRunBlocking(node) + } } private fun checkRunBlocking(node: ASTNode) { - if (node.parent({it.isAsync() || it.isSuspend()}) != null) { + node.parent({it.isAsync() || it.isSuspend()})?.let { RUN_BLOCKING_INSIDE_ASYNC.warn(configRules, emitWarn, isFixMode, node.text, node.startOffset, node) } } From 2f6df59bcb8a4d04898f01efb99a4d4fd426f8d0 Mon Sep 17 00:00:00 2001 From: kentr0w Date: Fri, 15 Jan 2021 14:20:33 +0300 Subject: [PATCH 4/7] AsyncAndSyncRule ### What's done: Fixed after review --- .../diktat/ruleset/rules/AsyncAndSyncRule.kt | 9 ++++++- .../ruleset/chapter5/AsyncAndSyncRuleTest.kt | 26 +++++++++++++++++++ info/guide/guide-chapter-5.md | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt index e7ac8c014b..185df557bf 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -6,12 +6,19 @@ import org.cqfn.diktat.ruleset.constants.Warnings.RUN_BLOCKING_INSIDE_ASYNC import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION +import com.pinterest.ktlint.core.ast.ElementType.FILE import com.pinterest.ktlint.core.ast.ElementType.FUN +import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION import com.pinterest.ktlint.core.ast.parent +import org.cqfn.diktat.ruleset.utils.hasChildOfType +import org.cqfn.diktat.ruleset.utils.prettyPrint import org.jetbrains.kotlin.com.intellij.lang.ASTNode +import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.KtReferenceExpression import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier +import org.jetbrains.kotlin.psi.psiUtil.isLambdaOutsideParentheses /** * This rule finds if using runBlocking in asynchronous code @@ -42,5 +49,5 @@ class AsyncAndSyncRule(private val configRules: List) : Rule("sync- private fun ASTNode.isSuspend() = this.elementType == FUN && (this.psi as KtFunction).modifierList?.hasSuspendModifier() ?: false - private fun ASTNode.isRunBlocking() = this.elementType == REFERENCE_EXPRESSION && this.text == "runBlocking" + private fun ASTNode.isRunBlocking() = this.elementType == REFERENCE_EXPRESSION && this.text == "runBlocking" && this.treeParent.hasChildOfType(LAMBDA_ARGUMENT) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt index bb87b857cd..9b45ec8df2 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt @@ -45,4 +45,30 @@ class AsyncAndSyncRuleTest : LintTestBase(::AsyncAndSyncRule) { LintError(18, 4, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false) ) } + + @Test + @Tag(WarningNames.RUN_BLOCKING_INSIDE_ASYNC) + fun `test dot qualified expression case`() { + lintMethod( + """ + |fun foo() { + | GlobalScope.async { + | node.runBlocking() + | runBlocking { + | n++ + | } + | } + |} + | + |fun goo() { + | runBlocking { + | GlobalScope.async { + | n++ + | } + | } + |} + """.trimMargin(), + LintError(4, 8, ruleId, "${RUN_BLOCKING_INSIDE_ASYNC.warnText()} runBlocking", false) + ) + } } diff --git a/info/guide/guide-chapter-5.md b/info/guide/guide-chapter-5.md index b750a8eef0..6eef6ca3a7 100644 --- a/info/guide/guide-chapter-5.md +++ b/info/guide/guide-chapter-5.md @@ -135,7 +135,7 @@ private fun foo() { #### 5.2.4 Synchronizing code inside asynchronous code Try to avoid using runBlocking in asynchronous code -**Example**: +**Invalid example**: ```kotlin GlobalScope.async { runBlocking { From 0485ffbf8a351089f4e7dd1c4a8f7b9919aa7c11 Mon Sep 17 00:00:00 2001 From: kentr0w Date: Fri, 15 Jan 2021 14:25:12 +0300 Subject: [PATCH 5/7] AsyncAndSyncRule ### What's done: Fixed according our code style --- .../org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt index 9b45ec8df2..8d904c8ea1 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AsyncAndSyncRuleTest.kt @@ -50,7 +50,7 @@ class AsyncAndSyncRuleTest : LintTestBase(::AsyncAndSyncRule) { @Tag(WarningNames.RUN_BLOCKING_INSIDE_ASYNC) fun `test dot qualified expression case`() { lintMethod( - """ + """ |fun foo() { | GlobalScope.async { | node.runBlocking() From 8f046fbd281c86743a1954d93cf66f1c04c3209d Mon Sep 17 00:00:00 2001 From: kentr0w Date: Fri, 15 Jan 2021 14:30:07 +0300 Subject: [PATCH 6/7] AsyncAndSyncRule ### What's done: Fixed according our code style --- .../kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt index 185df557bf..410102d330 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -6,19 +6,14 @@ import org.cqfn.diktat.ruleset.constants.Warnings.RUN_BLOCKING_INSIDE_ASYNC import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION -import com.pinterest.ktlint.core.ast.ElementType.FILE import com.pinterest.ktlint.core.ast.ElementType.FUN import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION import com.pinterest.ktlint.core.ast.parent import org.cqfn.diktat.ruleset.utils.hasChildOfType -import org.cqfn.diktat.ruleset.utils.prettyPrint import org.jetbrains.kotlin.com.intellij.lang.ASTNode -import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtFunction -import org.jetbrains.kotlin.psi.KtReferenceExpression import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier -import org.jetbrains.kotlin.psi.psiUtil.isLambdaOutsideParentheses /** * This rule finds if using runBlocking in asynchronous code From 90d30af8253863968babc357b4dac67d7a486a6e Mon Sep 17 00:00:00 2001 From: kentr0w Date: Fri, 15 Jan 2021 14:39:52 +0300 Subject: [PATCH 7/7] AsyncAndSyncRule ### What's done: Fixed according our code style --- .../kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt index 410102d330..7f7f08f7c0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/AsyncAndSyncRule.kt @@ -3,6 +3,7 @@ package org.cqfn.diktat.ruleset.rules import org.cqfn.diktat.common.config.rules.RulesConfig import org.cqfn.diktat.ruleset.constants.EmitType import org.cqfn.diktat.ruleset.constants.Warnings.RUN_BLOCKING_INSIDE_ASYNC +import org.cqfn.diktat.ruleset.utils.hasChildOfType import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION @@ -10,7 +11,6 @@ import com.pinterest.ktlint.core.ast.ElementType.FUN import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION import com.pinterest.ktlint.core.ast.parent -import org.cqfn.diktat.ruleset.utils.hasChildOfType import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier