Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule 6.4.1: Avoid using utility classes/objects #508

Merged
merged 18 commits into from
Dec 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import com.pinterest.ktlint.core.ast.ElementType.PRIMARY_CONSTRUCTOR
import com.pinterest.ktlint.core.ast.ElementType.RBRACE
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.getCommonConfiguration
import org.cqfn.diktat.ruleset.constants.EmitType
import org.cqfn.diktat.ruleset.constants.Warnings.AVOID_USING_UTILITY_CLASS
import org.cqfn.diktat.ruleset.utils.hasChildOfType
import org.cqfn.diktat.ruleset.utils.*
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.psiUtil.children

Expand All @@ -36,8 +37,12 @@ class AvoidUtilityClass(private val configRules: List<RulesConfig>) : Rule("avoi
override fun visit(node: ASTNode, autoCorrect: Boolean, emit: EmitType) {
emitWarn = emit
isFixMode = autoCorrect
if (node.elementType == OBJECT_DECLARATION || node.elementType == CLASS ) {
checkClass(node)
val config = configRules.getCommonConfiguration().value
kentr0w marked this conversation as resolved.
Show resolved Hide resolved
val fileName = node.getRootNode().getFileName()
if (!(node.hasTestAnnotation() || isLocatedInTest(fileName.splitPathToDirs(), config.testAnchors))) {
kentr0w marked this conversation as resolved.
Show resolved Hide resolved
if (node.elementType == OBJECT_DECLARATION || node.elementType == CLASS) {
checkClass(node)
}
}
}

Expand Down