check method

  1. @override
void check(
  1. DcqRegistry registry
)

Implementation

@override
void check(
  DcqRegistry registry,
) {
  registry.addMethodInvocation((node) {
    if (node.methodName.name != 'toString') return;

    final target = node.target;
    if (target != null && target is! ThisExpression) return;

    final enclosingMethod = _findEnclosingMethod(node);
    if (enclosingMethod == null) return;
    if (enclosingMethod.name.lexeme != 'toString') return;

    reportAtNode(node);
  });

  registry.addStringInterpolation((node) {
    final enclosingMethod = _findEnclosingMethod(node);
    if (enclosingMethod == null) return;
    if (enclosingMethod.name.lexeme != 'toString') return;

    for (final element in node.elements) {
      if (element is InterpolationExpression &&
          element.expression is ThisExpression) {
        reportAtNode(element);
      }
    }
  });
}