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 @@ -55,6 +55,6 @@ class AvoidUtilityClass(private val configRules: List<RulesConfig>) : Rule("avoi
?.filter { it.elementType == FUN }
kentr0w marked this conversation as resolved.
Show resolved Hide resolved
?.ifEmpty { return }
?: return
AVOID_USING_UTILITY_CLASS.warn(configRules, emitWarn, isFixMode, node.findChildByType(IDENTIFIER)!!.text, node.startOffset, node)
AVOID_USING_UTILITY_CLASS.warn(configRules, emitWarn, isFixMode, node.findChildByType(IDENTIFIER)?.text ?: node.text, node.startOffset, node)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,21 @@ class AvoidUtilityClassWarnTest: LintTestBase(::AvoidUtilityClass) {
LintError(2,1, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} StringUtils")
)
}

@Test
@Tag(WarningNames.AVOID_USING_UTILITY_CLASS)
fun `test with class without identifier`() {
lintMethod(
"""
fun foo() {
window.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) { /*...*/ }

override fun mouseEntered(e: MouseEvent) { /*...*/ }
})
}
""".trimMargin(),
LintError(2,45, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} object : MouseAdapter() {...")
kentr0w marked this conversation as resolved.
Show resolved Hide resolved
)
}
}