analyzeSource static method

Future<CoverageReport> analyzeSource(
  1. String source, {
  2. String? configPath,
})

Analyzes an inline Dart source snippet and returns a CoverageReport.

Does NOT touch the filesystem — the source is parsed in memory and run through every detector directly. Use this in detector unit tests:

final report = await EthosTestHelper.analyzeSource(
  "Icon(Icons.search, semanticLabel: 'Search')",
);
expect(report, passesRule('wcag_1_1_1_non_text_content'));

Implementation

static Future<CoverageReport> analyzeSource(
  String source, {
  String? configPath,
}) async {
  // Wrap in a minimal Flutter preamble so widget names are recognised.
  final wrapped = '''
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() {
$source;
}
''';

  final parsedFile = parseDartFile('inline_test.dart', wrapped);

  // Load the built-in spec (no project path needed — use '.' which always
  // exists, and skip configPath so we never hit CONFIG_NOT_FOUND).
  final spec = await SpecLoader.load(
    projectPath: '.',
    configPath: configPath,
  );
  final analyzer = CoverageAnalyzer(spec: spec, projectPath: '.');

  // Bypass the file-system scan and run directly on our in-memory file.
  return analyzer.analyzeFiles([parsedFile]);
}