I want to write a custom lint rule to ban calling function states.accept() in all classes that extends BaseViewModel where states is a BehaviorRelay object.
how can I achieve something like this.
I’ve written the check using visitMethodCall but this only can check the function name and if it’s member of BehaviorRelay,
the missing part is how to check if this function is being called in children’s of BaseViewModel.
below is the part that works: using visitMethodCall but detecting the function in whole code.
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
val evaluator = context.evaluator
if (evaluator.isMemberInClass(method, BEHAVIOR_RELAY)) {
if (method.name == ACCEPT_FUNCTION) {
context.report(
Incident(
issue = ISSUE,
scope = node,
location = context.getNameLocation(node),
message = "View Models implements `BaseViewModel` must not update `states`"
)
)
}
}
}