Repository: analysis-dev/diktat (kotlin)

Issue:
CUSTOM_GETTERS_SETTERS false positive on the override of fields
```kotlin
interface A {
    val a: Int
}

object B: A {
    override a: int 
        get() = 0
}
```

In interface you should always use getters with backing-fields. SO if we see `override` modifier - we should not raise a warning

Pull request:
### What's done:
* added check for override getter

Closes #1504

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
index 496fd51a9f..2602bcf3a5 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt
@@ -7,6 +7,7 @@ import org.cqfn.diktat.ruleset.utils.*
 
 import com.pinterest.ktlint.core.ast.ElementType.GET_KEYWORD
 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.PRIVATE_KEYWORD
 import com.pinterest.ktlint.core.ast.ElementType.PROPERTY_ACCESSOR
 import com.pinterest.ktlint.core.ast.ElementType.SET_KEYWORD
@@ -30,6 +31,7 @@ class CustomGetterSetterRule(configRules: List<RulesConfig>) : DiktatRule(
         val getter = node.getFirstChildWithType(GET_KEYWORD)
         val setter = node.getFirstChildWithType(SET_KEYWORD)
         val isPrivateSetter = node.getFirstChildWithType(MODIFIER_LIST)?.hasAnyChildOfTypes(PRIVATE_KEYWORD) ?: false
+        val isOverrideGetter = node.treeParent.getFirstChildWithType(MODIFIER_LIST)?.hasAnyChildOfTypes(OVERRIDE_KEYWORD) ?: false
 
         setter?.let {
             // only private custom setters are allowed
@@ -39,7 +41,10 @@ class CustomGetterSetterRule(configRules: List<RulesConfig>) : DiktatRule(
         }
 
         getter?.let {
-            CUSTOM_GETTERS_SETTERS.warn(configRules, emitWarn, isFixMode, getter.text, getter.startOffset, node)
+            // only override getter are allowed
+            if (!isOverrideGetter) {
+                CUSTOM_GETTERS_SETTERS.warn(configRules, emitWarn, isFixMode, getter.text, getter.startOffset, node)
+            }
         }
     }
 


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt
index ef8b1db3fd..7e76dd583f 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt
@@ -49,6 +49,23 @@ class CustomGetterSetterWarnTest : LintTestBase(::CustomGetterSetterRule) {
         )
     }
 
+    @Test
+    @Tag(CUSTOM_GETTERS_SETTERS)
+    fun `override getter`() {
+        lintMethod(
+            """
+                    |interface A {
+                    |    val a: Int
+                    |}
+                    |
+                    |object B: A {
+                    |    override val a: int
+                    |        get() = 0
+                    |}
+            """.trimMargin(),
+        )
+    }
+
     @Test
     @Tag(CUSTOM_GETTERS_SETTERS)
     fun `exception case with private setter`() {