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;
  if (!RigidConfig.forFile(resolver.path).isEnabled(code.name)) return;

  context.registry.addInstanceCreationExpression((node) {
    final type = node.staticType;
    if (type == null) return;

    // Is this an Expanded or Flexible?
    if (!FlutterTypes.expanded.isExactlyType(type) &&
        !FlutterTypes.flexible.isExactlyType(type)) {
      return;
    }

    // Walk up to the nearest parent widget constructor.
    final parent = _findParentWidgetCreation(node);
    if (parent == null) return;

    final parentType = parent.staticType;
    if (parentType == null) return;

    // Parent must be a Flex-family widget.
    if (!FlutterTypes.flexFamily.isAssignableFromType(parentType)) {
      reporter.atNode(node.constructorName, code);
    }
  });
}