Repository: cqfn/diKTat
Pull request #567 (2020-11-25 00:36:51)

override functions excluded from FUNCTION_BOOLEAN_PREFIX
We don't need to ask subclasses to rename superclass methods

codecov[bot]: # [Codecov](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=h1) Report
> Merging [#567](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=desc) (8d9e32a) into [master](https://codecov.io/gh/cqfn/diKTat/commit/052bd9de61a0f4e371805dde0c5e8af0f0064eaf?el=desc) (052bd9d) will **decrease** coverage by `0.86%`.
> The diff coverage is `93.42%`.

[![Impacted file tree graph](https://codecov.io/gh/cqfn/diKTat/pull/567/graphs/tree.svg?width=650&height=150&src=pr&token=P2quRDffpt)](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##             master     #567      +/-   ##
============================================
- Coverage     81.68%   80.82%   -0.87%     
- Complexity     1641     1712      +71     
============================================
  Files            79       87       +8     
  Lines          4139     4385     +246     
  Branches       1307     1351      +44     
============================================
+ Hits           3381     3544     +163     
- Misses          229      298      +69     
- Partials        529      543      +14     
```

| Flag | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| unittests | `80.82% <93.42%> (-0.87%)` | `0.00 <43.00> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...at-rules/src/main/kotlin/generated/WarningNames.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9nZW5lcmF0ZWQvV2FybmluZ05hbWVzLmt0) | `0.00% <ø> (ø)` | `0.00 <0.00> (ø)` | |
| [...tlin/org/cqfn/diktat/ruleset/utils/ASTConstants.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC91dGlscy9BU1RDb25zdGFudHMua3Q=) | `100.00% <ø> (ø)` | `0.00 <0.00> (ø)` | |
| [...lin/org/cqfn/diktat/ruleset/rules/PackageNaming.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9QYWNrYWdlTmFtaW5nLmt0) | `93.82% <50.00%> (-1.11%)` | `32.00 <0.00> (ø)` | |
| [...ktat/ruleset/rules/AvoidEmptyPrimaryConstructor.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9Bdm9pZEVtcHR5UHJpbWFyeUNvbnN0cnVjdG9yLmt0) | `90.00% <90.00%> (ø)` | `8.00 <8.00> (?)` | |
| [...iktat/ruleset/rules/ImplicitBackingPropertyRule.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9JbXBsaWNpdEJhY2tpbmdQcm9wZXJ0eVJ1bGUua3Q=) | `93.75% <93.75%> (ø)` | `23.00 <23.00> (?)` | |
| [...tlin/org/cqfn/diktat/ruleset/constants/Warnings.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9jb25zdGFudHMvV2FybmluZ3Mua3Q=) | `98.34% <100.00%> (+0.02%)` | `10.00 <0.00> (ø)` | |
| [...cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9EaWt0YXRSdWxlU2V0UHJvdmlkZXIua3Q=) | `97.64% <100.00%> (+0.38%)` | `9.00 <0.00> (+1.00)` | |
| [...kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9FbXB0eUJsb2NrLmt0) | `66.66% <100.00%> (ø)` | `9.00 <5.00> (-1.00)` | |
| [.../org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9JZGVudGlmaWVyTmFtaW5nLmt0) | `83.33% <100.00%> (+0.12%)` | `78.00 <0.00> (+1.00)` | |
| [...qfn/diktat/ruleset/rules/classes/SingleInitRule.kt](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree#diff-ZGlrdGF0LXJ1bGVzL3NyYy9tYWluL2tvdGxpbi9vcmcvY3Fmbi9kaWt0YXQvcnVsZXNldC9ydWxlcy9jbGFzc2VzL1NpbmdsZUluaXRSdWxlLmt0) | `78.46% <100.00%> (+0.68%)` | `16.00 <0.00> (+6.00)` | |
| ... and [27 more](https://codecov.io/gh/cqfn/diKTat/pull/567/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=footer). Last update [0bc75c8...8d9e32a](https://codecov.io/gh/cqfn/diKTat/pull/567?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt
index 405a0318..eb997c81 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/EmptyBlock.kt
@@ -1,8 +1,6 @@
 package org.cqfn.diktat.ruleset.rules
 
 import com.pinterest.ktlint.core.Rule
-import com.pinterest.ktlint.core.ast.ElementType.MODIFIER_LIST
-import com.pinterest.ktlint.core.ast.ElementType.OVERRIDE_KEYWORD
 import com.pinterest.ktlint.core.ast.ElementType.RBRACE
 import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
 import org.cqfn.diktat.common.config.rules.RuleConfiguration
@@ -11,6 +9,7 @@ import org.cqfn.diktat.common.config.rules.getRuleConfig
 import org.cqfn.diktat.ruleset.constants.Warnings.EMPTY_BLOCK_STRUCTURE_ERROR
 import org.cqfn.diktat.ruleset.utils.findLBrace
 import org.cqfn.diktat.ruleset.utils.isBlockEmpty
+import org.cqfn.diktat.ruleset.utils.isOverriden
 import org.jetbrains.kotlin.com.intellij.lang.ASTNode
 import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
 import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
@@ -38,7 +37,7 @@ class EmptyBlock(private val configRules: List<RulesConfig>) : Rule("empty-block
 
     @Suppress("UnsafeCallOnNullableType")
     private fun checkEmptyBlock(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
-        if (node.treeParent.findChildByType(MODIFIER_LIST)?.findChildByType(OVERRIDE_KEYWORD) != null) return
+        if (node.treeParent.isOverriden()) return
         if (node.isBlockEmpty()) {
             if (!configuration.emptyBlockExist) {
                 EMPTY_BLOCK_STRUCTURE_ERROR.warn(configRules, emitWarn, isFixMode, "empty blocks are forbidden unless it is function with override keyword",
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 1deebbc2..8e5293f1 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
@@ -43,6 +43,7 @@ import org.cqfn.diktat.ruleset.utils.hasTestAnnotation
 import org.cqfn.diktat.ruleset.utils.isConstant
 import org.cqfn.diktat.ruleset.utils.isDigits
 import org.cqfn.diktat.ruleset.utils.isLowerCamelCase
+import org.cqfn.diktat.ruleset.utils.isOverriden
 import org.cqfn.diktat.ruleset.utils.isPascalCase
 import org.cqfn.diktat.ruleset.utils.isUpperSnakeCase
 import org.cqfn.diktat.ruleset.utils.removePrefix
@@ -347,11 +348,14 @@ class IdentifierNaming(private val configRules: List<RulesConfig>) : Rule("ident
         // check for methods that return Boolean
         val functionReturnType = node.findChildAfter(VALUE_PARAMETER_LIST, TYPE_REFERENCE)?.text
 
-        // 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()) {
-            if (BOOLEAN_METHOD_PREFIXES.none { functionName.text.startsWith(it) }) {
-                FUNCTION_BOOLEAN_PREFIX.warnAndFix(configRules, emitWarn, isFixMode, functionName.text, functionName.startOffset, functionName) {
-                    // FixMe: add agressive autofix for this
+        // We don't need to ask subclasses to rename superclass methods
+        if (!node.isOverriden()) {
+            // 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()) {
+                if (BOOLEAN_METHOD_PREFIXES.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/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
index e2cc290b..95176ced 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
@@ -9,6 +9,7 @@ import com.pinterest.ktlint.core.ast.ElementType.FILE_ANNOTATION_LIST
 import com.pinterest.ktlint.core.ast.ElementType.INTERNAL_KEYWORD
 import com.pinterest.ktlint.core.ast.ElementType.LBRACE
 import com.pinterest.ktlint.core.ast.ElementType.MODIFIER_LIST
+import com.pinterest.ktlint.core.ast.ElementType.OVERRIDE_KEYWORD
 import com.pinterest.ktlint.core.ast.ElementType.OPERATION_REFERENCE
 import com.pinterest.ktlint.core.ast.ElementType.PRIVATE_KEYWORD
 import com.pinterest.ktlint.core.ast.ElementType.PROTECTED_KEYWORD
@@ -351,6 +352,11 @@ fun ASTNode.hasSuppress(warningName: String): Boolean {
     }, strict = false) != null
 }
 
+/**
+ * Checks node has `override` modifier
+ */
+fun ASTNode.isOverriden(): Boolean =
+    findChildByType(MODIFIER_LIST)?.findChildByType(OVERRIDE_KEYWORD) != null
 /**
  * creation of operation reference in a node
  */


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
index bc304e0d..46ee71af 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt
@@ -369,6 +369,8 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) {
                     fun hasEmptyLineAfter(): Boolean { }    
                     fun ASTNode.isEmpty(): Boolean { }    
                     fun isEmpty(): Boolean { }    
+                    override fun empty(): Boolean { }
+                    override fun ASTNode.empty(): Boolean { }
                 """.trimIndent()
         )
     }