run method

  1. @override
void run(
  1. CustomLintResolver resolver,
  2. ErrorReporter reporter,
  3. CustomLintContext context
)

Emits lints for a given file.

run will only be invoked with files respecting filesToAnalyze

Implementation

@override
void run(
  CustomLintResolver resolver,
  ErrorReporter reporter,
  CustomLintContext context,
) {
  context.registry.addExtendsClause((node) {
    final superClass = node.superclass;
    TypeAnnotation? stateNode;

    if (superClass.element?.name == BlocLintConstants.cubitClass) {
      stateNode = superClass.typeArguments?.arguments[0];
    } else if (superClass.element?.name == BlocLintConstants.blocClass) {
      stateNode = superClass.typeArguments?.arguments[1];
    }
    if (stateNode == null) {
      return;
    }
    final stateType = stateNode.type as InterfaceType?;
    if (stateType == null || _ignoredType.contains(stateType.element.name)) {
      return;
    }

    if (stateType.element.name.endsWith('State') == false) {
      reporter.atNode(stateNode, code);
    }
  });
}