run method

  1. @override
List<Issue> run(
  1. DialectProject project
)
override

Inspect project and return findings. May return an empty list. Should NOT throw — turn unexpected conditions into Issues so the report surfaces them rather than crashing.

Implementation

@override
List<Issue> run(DialectProject project) {
  if (project.config.platforms.isEmpty) return const [];

  final scan = OutputScan.run(project);
  if (scan.isEmpty) return const [];

  final keys = scan.keys.toList()..sort();
  final preview = keys.length > 5
      ? '${keys.take(5).join(", ")}, … (${keys.length - 5} more)'
      : keys.join(', ');

  // One issue for the project, not one per key: the condition is "these
  // outputs and this source disagree", and the remedy is a single command
  // regardless of how many keys are involved.
  final files = <String>{
    for (final k in keys) ...scan.filesFor(k),
  }.map((f) => p.relative(f, from: project.root)).toList()..sort();

  return [
    Issue(
      severity: defaultSeverity,
      ruleName: name,
      message:
          '${keys.length} key(s) exist in a generated output but not in the '
          'source, so `dialect sync` will refuse until this is resolved: '
          '$preview  (in ${files.join(', ')})',
      hint:
          'They were almost certainly added straight to a generated file. '
          'Run `dialect sync --adopt` to pull them back into '
          'dialect/source/${project.config.sourceLocale}.arb, or '
          '`dialect sync --prune` to confirm dropping them.',
    ),
  ];
}