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,
) {
  // Track the depth of the widget tree to determine complexity
  int treeDepth = 0;
  Map<String, int> widgetCounts = {};

  // Check for widgets with conditional rebuilds (common performance issue)
  context.registry.addIfStatement((node) {
    _analyzeIfStatement(node, reporter);
  });

  // Check for deep widget hierarchies (can exacerbate missing key issues)
  context.registry.addInstanceCreationExpression((node) {
    final type = node.constructorName.type.type;
    if (type == null) return;

    final String typeName = type.toString();
    if (_isWidget(typeName)) {
      widgetCounts[typeName] = (widgetCounts[typeName] ?? 0) + 1;
      treeDepth++; // This is simplified - in reality we'd need to track actual tree depth

      // Check for potential performance issues
      _analyzePotentialIssue(node, reporter, treeDepth, widgetCounts);

      treeDepth--; // Exit the level after processing
    }
  });
}