run method

Runs the scan and returns all diagnostics found.

Returns null if no configuration was found and no tier was set (caller should tell the user to run init first), or if tier was set to an unknown value.

Implementation

List<ScanDiagnostic>? run() {
  final ruleNames = _resolveRuleNames();
  if (ruleNames == null) return null;

  if (ruleNames.isEmpty) {
    _out('All rules are disabled in the configuration.');
    return const [];
  }

  SaropaLintRule.enabledRules = ruleNames;
  SaropaLintRule.disabledRules = null;
  final rules = getRulesFromRegistry(ruleNames);
  if (tier != null) {
    _out('Loaded ${rules.length} rules for tier: $tier');
  } else {
    _out('Loaded ${rules.length} rules from analysis_options.yaml');
  }

  final filesToScan = _resolveDartFiles();
  if (filesToScan.isEmpty) {
    _out('No .dart files found in: $targetPath');
    return const [];
  }
  _out('Scanning ${filesToScan.length} files...\n');

  final registrations = _registerRules(rules);
  return _scanFiles(filesToScan, registrations);
}