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 targetType = node.staticType;
    if (targetType == null ||
        !fileSystemEntityTypeChecker.isAssignableFromType(targetType)) {
      return;
    }

    final arguments = node.argumentList.arguments;
    if (arguments.isEmpty) return;

    final pathArgument = arguments.first;
    if (pathArgument is! StringLiteral) return;

    // Strip leading/trailing quotes
    final pathSource = pathArgument.toSource();
    final path = pathSource.substring(1, pathSource.length - 1);
    if (!_pathSeparatorRegex.hasMatch(path)) return;

    reporter.atNode(pathArgument, _code, data: path);
  });
}