check method

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

Implementation

@override
void check(DcqRegistry registry) {
  final patternStr = effectiveString('name-pattern', '');
  if (patternStr.isEmpty) return;
  final pattern = RegExp(patternStr);

  registry.addClassDeclaration((node) {
    final className = node.namePart.typeName.lexeme;
    if (!pattern.hasMatch(className)) return;

    // Check superclass.
    final superclass = node.extendsClause?.superclass.type;
    if (superclass is InterfaceType &&
        superclass.element.name == 'Equatable') {
      return;
    }

    // Check mixins.
    final withClause = node.withClause;
    if (withClause != null) {
      for (final mixin in withClause.mixinTypes) {
        if (mixin.name.lexeme == 'EquatableMixin') return;
      }
    }

    // Check superclass chain for Equatable.
    if (superclass is InterfaceType) {
      InterfaceType? current = superclass;
      while (current != null) {
        if (current.element.name == 'Equatable') return;
        current = current.element.supertype;
      }
    }

    reportAtToken(node.namePart.typeName);
  });
}