run method

  1. @override
void run(
  1. CustomLintResolver resolver,
  2. DiagnosticReporter 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,
  DiagnosticReporter reporter,
  CustomLintContext context,
) {
  if (isGeneratedFile(resolver.path)) return;

  final config = RigidConfig.forFile(resolver.path);
  if (!config.isEnabled(code.name)) return;

  final extraAllowed = config.allowedMagicNumbers;

  context.registry.addNamedExpression((node) {
    if (!_layoutParams.contains(node.name.label.name)) return;

    // Skip numbers inside private widget constructors — these are
    // implementation details, not design decisions.
    if (isInsidePrivateConstructor(node)) return;

    final expr = node.expression;
    if (expr is IntegerLiteral) {
      final v = expr.value;
      if (_allowedIntegers.contains(v)) return;
      if (extraAllowed.contains(v)) return;
      reporter.atNode(expr, code);
    } else if (expr is DoubleLiteral) {
      final v = expr.value;
      if (_allowedDoubles.contains(v)) return;
      if (extraAllowed.contains(v)) return;
      reporter.atNode(expr, code);
    }
  });
}