analyzeMetrics static method

Future<AggregatedReport> analyzeMetrics(
  1. String path, {
  2. MetricsThresholds thresholds = const MetricsThresholds(),
})

Analyzes code metrics for a directory or file.

Automatically handles resource cleanup. Returns an AggregatedReport containing project-wide metrics, violations, and health score.

path is the directory or file to analyze. thresholds configures violation detection limits.

Example:

final report = await Anteater.analyzeMetrics('lib');
if (report.hasViolations) {
  for (final violation in report.violations) {
    print('${violation.functionName}: MI=${violation.result.maintainabilityIndex}');
  }
}

Implementation

static Future<AggregatedReport> analyzeMetrics(
  String path, {
  MetricsThresholds thresholds = const MetricsThresholds(),
}) async {
  final loader = SourceLoader(path);
  try {
    final aggregator = MetricsAggregator(thresholds: thresholds);

    for (final file in loader.discoverDartFiles()) {
      final result = await loader.resolveFile(file);
      if (result != null) {
        aggregator.addFile(file, result.unit);
      }
    }

    return aggregator.generateReport();
  } finally {
    await loader.dispose();
  }
}