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.addInstanceCreationExpression((node) {
    final constructorName = node.constructorName.type;
    if (constructorName.element case final typeElement?) {
      // is it something we want to complain about?
      final match =
          _complain.firstWhereOrNull((e) => e.$2.isExactly(typeElement));
      if (match == null) {
        return;
      }

      // does it have a children argument?
      var children = node.argumentList.arguments.firstWhereOrNull(
        (e) => e.staticParameterElement?.name == match.$1,
      );
      if (children == null) {
        return;
      } else if (children is NamedExpression) {
        children = children.expression;
      }

      _checkInstanceCreation(constructorName, children, reporter);
    }
  });
}