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;

    if (!FlutterTypes.textFieldFamily.isAssignableFromType(type)) return;

    // Walk up — check if inside a Row without width constraint.
    var current = node.parent;
    while (current != null) {
      if (current is InstanceCreationExpression) {
        final parentType = current.staticType;
        if (parentType == null) break;

        // If wrapped in Expanded/Flexible/SizedBox, it's constrained.
        if (FlutterTypes.expanded.isExactlyType(parentType) ||
            FlutterTypes.flexible.isExactlyType(parentType) ||
            FlutterTypes.sizedBox.isExactlyType(parentType)) {
          return;
        }

        // If we hit a Row without constraint wrapper, flag it.
        if (FlutterTypes.row.isExactlyType(parentType)) {
          reporter.atNode(node.constructorName, code);
          return;
        }
      }
      current = current.parent;
    }
  });
}