buildReport method

IdeAnalysisReport buildReport({
  1. required ArchitectureGraph graph,
  2. required List<ArchitectureSmell> smells,
  3. required List<GovernanceViolation> violations,
})

Builds an IdeAnalysisReport from the supplied graph, smells, and violations.

Implementation

IdeAnalysisReport buildReport({
  required ArchitectureGraph graph,
  required List<ArchitectureSmell> smells,
  required List<GovernanceViolation> violations,
}) {
  final diagnostics =
      <IdeDiagnostic>[
        ...smells
            .map((smell) => _fromSmell(graph, smell))
            .whereType<IdeDiagnostic>(),
        ...violations
            .map((violation) => _fromViolation(graph, violation))
            .whereType<IdeDiagnostic>(),
      ]..sort((a, b) {
        final fileCompare = a.filePath.compareTo(b.filePath);
        if (fileCompare != 0) return fileCompare;
        final lineCompare = a.startLine.compareTo(b.startLine);
        if (lineCompare != 0) return lineCompare;
        return a.startColumn.compareTo(b.startColumn);
      });

  return IdeAnalysisReport(
    targetPath: targetPath,
    totalDiagnostics: diagnostics.length,
    architectureDiagnosticCount: diagnostics
        .where((diagnostic) => diagnostic.category == 'architecture')
        .length,
    governanceDiagnosticCount: diagnostics
        .where((diagnostic) => diagnostic.category == 'governance')
        .length,
    diagnostics: diagnostics,
  );
}