@@ -3,6 +3,7 @@ import 'dart:io';
33import 'package:xml/xml.dart' ;
44
55import '../../../../../reporters/models/checkstyle_reporter.dart' ;
6+ import '../../../metrics/models/metric_value_level.dart' ;
67import '../../../models/lint_file_report.dart' ;
78import '../../../models/severity.dart' ;
89import '../../../models/summary_lint_report_record.dart' ;
@@ -39,22 +40,8 @@ class LintCheckstyleReporter extends CheckstyleReporter<LintFileReport,
3940 'file' ,
4041 attributes: {'name' : record.relativePath},
4142 nest: () {
42- final issues = [...record.issues, ...record.antiPatternCases];
43-
44- for (final issue in issues) {
45- final locationStart = issue.location.start;
46- builder.element (
47- 'error' ,
48- attributes: {
49- 'line' : '${locationStart .line }' ,
50- if (locationStart.column > 0 )
51- 'column' : '${locationStart .column }' ,
52- 'severity' : _severityMapping[issue.severity] ?? 'ignore' ,
53- 'message' : issue.message,
54- 'source' : issue.ruleId,
55- },
56- );
57- }
43+ _reportIssues (builder, record);
44+ _reportMetrics (builder, record);
5845 },
5946 );
6047 }
@@ -63,14 +50,84 @@ class LintCheckstyleReporter extends CheckstyleReporter<LintFileReport,
6350 output.writeln (builder.buildDocument ().toXmlString (pretty: true ));
6451 }
6552
53+ void _reportIssues (XmlBuilder builder, LintFileReport report) {
54+ final issues = [...report.issues, ...report.antiPatternCases];
55+
56+ for (final issue in issues) {
57+ final locationStart = issue.location.start;
58+ builder.element (
59+ 'error' ,
60+ attributes: {
61+ 'line' : '${locationStart .line }' ,
62+ if (locationStart.column > 0 ) 'column' : '${locationStart .column }' ,
63+ 'severity' : _issueSeverityMapping[issue.severity] ?? 'ignore' ,
64+ 'message' : issue.message,
65+ 'source' : issue.ruleId,
66+ },
67+ );
68+ }
69+ }
70+
71+ void _reportMetrics (XmlBuilder builder, LintFileReport record) {
72+ for (final metric in record.file.metrics) {
73+ if (_isMetricNeedToReport (metric.level)) {
74+ builder.element (
75+ 'error' ,
76+ attributes: {
77+ 'line' : '0' ,
78+ 'severity' : _metricSeverityMapping[metric.level] ?? 'ignore' ,
79+ 'message' : metric.comment,
80+ 'source' : metric.metricsId,
81+ },
82+ );
83+ }
84+ }
85+
86+ final metricRecords =
87+ {...record.classes, ...record.functions}.entries.toList ();
88+ for (final record in metricRecords) {
89+ if (! _isMetricNeedToReport (record.value.metricsLevel)) {
90+ continue ;
91+ }
92+
93+ final location = record.value.location;
94+
95+ for (final metricValue in record.value.metrics) {
96+ builder.element (
97+ 'error' ,
98+ attributes: {
99+ 'line' : '${location .start .line }' ,
100+ if (record.value.location.start.column > 0 )
101+ 'column' : '${record .value .location .start .column }' ,
102+ 'severity' : _metricSeverityMapping[metricValue.level] ?? 'ignore' ,
103+ 'message' : metricValue.comment,
104+ 'source' : metricValue.metricsId,
105+ },
106+ );
107+ }
108+ }
109+ }
110+
66111 bool _needToReport (LintFileReport report) =>
67- report.issues.isNotEmpty || report.antiPatternCases.isNotEmpty;
112+ report.issues.isNotEmpty ||
113+ report.antiPatternCases.isNotEmpty ||
114+ _isMetricNeedToReport (report.file.metricsLevel);
115+
116+ bool _isMetricNeedToReport (MetricValueLevel level) =>
117+ level > MetricValueLevel .none;
68118}
69119
70- const _severityMapping = {
120+ const _issueSeverityMapping = {
71121 Severity .error: 'error' ,
72122 Severity .warning: 'warning' ,
73123 Severity .style: 'info' ,
74124 Severity .performance: 'warning' ,
75125 Severity .none: 'ignore' ,
76126};
127+
128+ const _metricSeverityMapping = {
129+ MetricValueLevel .alarm: 'error' ,
130+ MetricValueLevel .warning: 'warning' ,
131+ MetricValueLevel .noted: 'info' ,
132+ MetricValueLevel .none: 'ignore' ,
133+ };
0 commit comments