diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt index 26873cb5ca..e661476607 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt @@ -85,6 +85,20 @@ class IdentifierNaming(private val configRules: List) : Rule("ident private var isFixMode: Boolean = false private lateinit var emitWarn: EmitType + val configuration by lazy { + BooleanFunctionsConfiguration( + this.configRules.getRuleConfig(FUNCTION_BOOLEAN_PREFIX)?.configuration ?: emptyMap() + ) + } + + private val allMethodPrefixes by lazy { + if (configuration.allowedBooleanPrefixes.isNullOrEmpty()) { + booleanMethodPrefixes + } else { + booleanMethodPrefixes + configuration.allowedBooleanPrefixes.filter { it.isNotEmpty() } + } + } + override fun visit( node: ASTNode, autoCorrect: Boolean, @@ -359,18 +373,6 @@ class IdentifierNaming(private val configRules: List) : Rule("ident if (!node.isOverridden()) { // if function has Boolean return type in 99% of cases it is much better to name it with isXXX or hasXXX prefix if (functionReturnType != null && functionReturnType == PrimitiveType.BOOLEAN.typeName.asString()) { - val configuration by lazy { - BooleanFunctionsConfiguration( - this.configRules.getRuleConfig(FUNCTION_BOOLEAN_PREFIX)?.configuration ?: emptyMap() - ) - } - val allMethodPrefixes by lazy { - if (configuration.allowedBooleanPrefixes.isNullOrEmpty()) { - booleanMethodPrefixes - } else { - booleanMethodPrefixes + configuration.allowedBooleanPrefixes.filter { it.isNotEmpty() } - } - } if (allMethodPrefixes.none { functionName.text.startsWith(it) }) { FUNCTION_BOOLEAN_PREFIX.warnAndFix(configRules, emitWarn, isFixMode, functionName.text, functionName.startOffset, functionName) { // FixMe: add agressive autofix for this diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt index bd2499cc52..7be9e7c55f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt @@ -150,7 +150,6 @@ class PackageNaming(private val configRules: List) : Rule("package- /** * only letters, digits and underscore are allowed */ - @Suppress("FUNCTION_BOOLEAN_PREFIX") private fun areCorrectSymbolsUsed(word: String): Boolean { // underscores are allowed in some cases - see "exceptionForUnderscore" val wordFromPackage = word.replace("_", "") diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/classes/DataClassesRule.kt index 1baefc23d9..38ad64dde7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/classes/DataClassesRule.kt @@ -94,7 +94,6 @@ class DataClassesRule(private val configRule: List) : Rule("data-cl /** * Checks if any property with accessor contains logic in accessor */ - @Suppress("FUNCTION_BOOLEAN_PREFIX") private fun areGoodProps(node: ASTNode): Boolean { val propertiesWithAccessors = node.getAllChildrenWithType(PROPERTY).filter { it.hasChildOfType(PROPERTY_ACCESSOR) } @@ -109,7 +108,7 @@ class DataClassesRule(private val configRule: List) : Rule("data-cl return true } - @Suppress("UnsafeCallOnNullableType", "FUNCTION_BOOLEAN_PREFIX") + @Suppress("UnsafeCallOnNullableType") private fun areGoodAccessors(accessors: List): Boolean { accessors.forEach { if (it.hasChildOfType(BLOCK)) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt index a9fc830025..9acba46866 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt @@ -626,7 +626,6 @@ fun ASTNode.isChildBeforeGroup(child: ASTNode, group: List): Boolean = * * @return boolean result */ -@Suppress("FUNCTION_BOOLEAN_PREFIX") fun ASTNode.areChildrenBeforeChild(children: List, beforeChild: ASTNode): Boolean = areChildrenBeforeGroup(children, listOf(beforeChild)) @@ -635,7 +634,7 @@ fun ASTNode.areChildrenBeforeChild(children: List, beforeChild: ASTNode * * @return boolean result */ -@Suppress("UnsafeCallOnNullableType", "FUNCTION_BOOLEAN_PREFIX") +@Suppress("UnsafeCallOnNullableType") fun ASTNode.areChildrenBeforeGroup(children: List, group: List): Boolean { require(children.isNotEmpty() && group.isNotEmpty()) { "no sense to operate on empty lists" } return children.map { getChildren(null).indexOf(it) }.max()!! < group.map { getChildren(null).indexOf(it) }.min()!!