diff --git a/lib/src/analyzer_plugin/analyzer_plugin.dart b/lib/src/analyzer_plugin/analyzer_plugin.dart index c3eb0dd162..b72595814b 100644 --- a/lib/src/analyzer_plugin/analyzer_plugin.dart +++ b/lib/src/analyzer_plugin/analyzer_plugin.dart @@ -11,7 +11,6 @@ import 'package:analyzer/src/context/context_root.dart'; // ignore: implementation_imports import 'package:analyzer/src/dart/analysis/driver.dart'; import 'package:analyzer_plugin/plugin/plugin.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; import 'package:source_span/source_span.dart'; @@ -373,7 +372,7 @@ class MetricsAnalyzerPlugin extends ServerPlugin { for (final file in filesToFullyResolve) { final contextRoot = contextRootContaining(file); if (contextRoot != null) { - // TODO(dmitrykrutskih): Which driver should we use if there is no context root? + // TODO(dkrutskikh): Which driver should we use if there is no context root? final driver = driverMap[contextRoot]; filesByDriver.putIfAbsent(driver, () => []).add(file); } diff --git a/lib/src/metrics_analyzer.dart b/lib/src/metrics_analyzer.dart index a4bcca3791..740bb90489 100644 --- a/lib/src/metrics_analyzer.dart +++ b/lib/src/metrics_analyzer.dart @@ -136,23 +136,23 @@ class MetricsAnalyzer { function.declaration.visitChildren(linesWithCodeAstVisitor); builder.recordFunction( - function, - FunctionRecord( - firstLine: lineInfo - .getLocation(function.declaration - .firstTokenAfterCommentAndMetadata.offset) - .lineNumber, - lastLine: lineInfo - .getLocation(function.declaration.endToken.end) - .lineNumber, - argumentsCount: getArgumentsCount(function), - cyclomaticComplexityLines: - Map.unmodifiable(controlFlowAstVisitor.complexityLines), - linesWithCode: linesWithCodeAstVisitor.linesWithCode, - operators: - Map.unmodifiable(halsteadVolumeAstVisitor.operators), - operands: - Map.unmodifiable(halsteadVolumeAstVisitor.operands))); + function, + FunctionRecord( + firstLine: lineInfo + .getLocation(function + .declaration.firstTokenAfterCommentAndMetadata.offset) + .lineNumber, + lastLine: lineInfo + .getLocation(function.declaration.endToken.end) + .lineNumber, + argumentsCount: getArgumentsCount(function), + cyclomaticComplexityLines: + Map.unmodifiable(controlFlowAstVisitor.complexityLines), + linesWithCode: linesWithCodeAstVisitor.linesWithCode, + operators: Map.unmodifiable(halsteadVolumeAstVisitor.operators), + operands: Map.unmodifiable(halsteadVolumeAstVisitor.operands), + ), + ); } } diff --git a/lib/src/models/file_report.dart b/lib/src/models/file_report.dart index f1a3ed9fcc..d862dacb73 100644 --- a/lib/src/models/file_report.dart +++ b/lib/src/models/file_report.dart @@ -3,30 +3,30 @@ import 'package:meta/meta.dart'; @immutable class FileReport { final int averageArgumentsCount; - final int totalArgumentsCountViolations; + final int argumentsCountViolations; final double averageMaintainabilityIndex; - final int totalMaintainabilityIndexViolations; + final int maintainabilityIndexViolations; final int averageMethodsCount; - final int totalMethodsCountViolations; + final int methodsCountViolations; final int totalCyclomaticComplexity; - final int totalCyclomaticComplexityViolations; + final int cyclomaticComplexityViolations; final int totalLinesOfExecutableCode; - final int totalLinesOfExecutableCodeViolations; + final int linesOfExecutableCodeViolations; const FileReport({ @required this.averageArgumentsCount, - @required this.totalArgumentsCountViolations, + @required this.argumentsCountViolations, @required this.averageMaintainabilityIndex, - @required this.totalMaintainabilityIndexViolations, + @required this.maintainabilityIndexViolations, @required this.averageMethodsCount, - @required this.totalMethodsCountViolations, + @required this.methodsCountViolations, @required this.totalCyclomaticComplexity, - @required this.totalCyclomaticComplexityViolations, + @required this.cyclomaticComplexityViolations, @required this.totalLinesOfExecutableCode, - @required this.totalLinesOfExecutableCodeViolations, + @required this.linesOfExecutableCodeViolations, }); } diff --git a/lib/src/reporters/code_climate/code_climate_reporter.dart b/lib/src/reporters/code_climate/code_climate_reporter.dart index 341aaf7f0b..6ff0256890 100644 --- a/lib/src/reporters/code_climate/code_climate_reporter.dart +++ b/lib/src/reporters/code_climate/code_climate_reporter.dart @@ -8,7 +8,7 @@ import '../reporter.dart'; import '../utility_selector.dart'; import 'code_climate_issue.dart'; -/// Creates reports in Codeclimate format widely understood by various CI and analysis tools +/// Creates reports in Code Climate format widely understood by various CI and analysis tools // Code Climate Engine Specification https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md class CodeClimateReporter implements Reporter { final Config reportConfig; @@ -40,13 +40,24 @@ class CodeClimateReporter implements Reporter { }), ]; + return result + ..addAll(_functionMetrics(record)) + ..addAll(record.issues.map((issue) => + CodeClimateIssue.fromCodeIssue(issue, record.relativePath))) + ..addAll(record.designIssues.map((issue) => + CodeClimateIssue.fromDesignIssue(issue, record.relativePath))); + } + + Iterable _functionMetrics(FileRecord record) { + final issues = []; + for (final key in record.functions.keys) { final func = record.functions[key]; final report = UtilitySelector.functionReport(func, reportConfig); if (UtilitySelector.isIssueLevel( report.cyclomaticComplexity.violationLevel)) { - result.add(CodeClimateIssue.cyclomaticComplexity( + issues.add(CodeClimateIssue.cyclomaticComplexity( func, report.cyclomaticComplexity.value, record.relativePath, @@ -57,7 +68,7 @@ class CodeClimateReporter implements Reporter { if (UtilitySelector.isIssueLevel( report.maintainabilityIndex.violationLevel)) { - result.add(CodeClimateIssue.maintainabilityIndex( + issues.add(CodeClimateIssue.maintainabilityIndex( func, report.maintainabilityIndex.value.toInt(), record.relativePath, @@ -66,12 +77,6 @@ class CodeClimateReporter implements Reporter { } } - result - ..addAll(record.issues.map((issue) => - CodeClimateIssue.fromCodeIssue(issue, record.relativePath))) - ..addAll(record.designIssues.map((issue) => - CodeClimateIssue.fromDesignIssue(issue, record.relativePath))); - - return result; + return issues; } } diff --git a/lib/src/reporters/html/html_reporter.dart b/lib/src/reporters/html/html_reporter.dart index 5a25ac6451..79e4b1c409 100644 --- a/lib/src/reporters/html/html_reporter.dart +++ b/lib/src/reporters/html/html_reporter.dart @@ -8,6 +8,7 @@ import 'package:path/path.dart' as p; import '../../config/config.dart'; import '../../models/file_record.dart'; +import '../../models/file_report.dart'; import '../../models/violation_level.dart'; import '../reporter.dart'; import '../utility_selector.dart'; @@ -29,15 +30,15 @@ const _violationLevelLineStyle = { const _cyclomaticComplexity = 'Cyclomatic complexity'; const _cyclomaticComplexityWithViolations = - 'Cyclomatic complexity / violations'; + '$_cyclomaticComplexity / violations'; const _linesOfExecutableCode = 'Lines of executable code'; const _linesOfExecutableCodeWithViolations = - 'Lines of executable code / violations'; + '$_linesOfExecutableCode / violations'; const _maintainabilityIndex = 'Maintainability index'; const _maintainabilityIndexWithViolations = - 'Maintainability index / violations'; + '$_maintainabilityIndex / violations'; const _nuberOfArguments = 'Number of Arguments'; -const _nuberOfArgumentsWithViolations = 'Number of Arguments / violations'; +const _nuberOfArgumentsWithViolations = '$_nuberOfArguments / violations'; const _codeIssues = 'Issues'; const _designIssues = 'Design issues'; @@ -47,29 +48,13 @@ class ReportTableRecord { final String title; final String link; - final int cyclomaticComplexity; - final int cyclomaticComplexityViolations; - - final int linesOfExecutableCode; - final int linesOfExecutableCodeViolations; - - final double maintainabilityIndex; - final int maintainabilityIndexViolations; - - final int averageArgumentsCount; - final int argumentsCountViolations; - - const ReportTableRecord( - {@required this.title, - @required this.link, - @required this.cyclomaticComplexity, - @required this.cyclomaticComplexityViolations, - @required this.linesOfExecutableCode, - @required this.linesOfExecutableCodeViolations, - @required this.maintainabilityIndex, - @required this.maintainabilityIndexViolations, - @required this.averageArgumentsCount, - @required this.argumentsCountViolations}); + final FileReport report; + + const ReportTableRecord({ + @required this.title, + @required this.link, + @required this.report, + }); } /// HTML-doc reporter @@ -125,51 +110,58 @@ class HtmlReporter implements Reporter { ..sort((a, b) => a.title.compareTo(b.title)); final totalComplexity = sortedRecords.fold( - 0, (prevValue, record) => prevValue + record.cyclomaticComplexity); - final totalComplexityViolations = sortedRecords.fold( 0, (prevValue, record) => - prevValue + record.cyclomaticComplexityViolations); + prevValue + record.report.totalCyclomaticComplexity); + final complexityViolations = sortedRecords.fold( + 0, + (prevValue, record) => + prevValue + record.report.cyclomaticComplexityViolations); final totalLinesOfExecutableCode = sortedRecords.fold( - 0, (prevValue, record) => prevValue + record.linesOfExecutableCode); - final totalLinesOfExecutableCodeViolations = sortedRecords.fold( 0, (prevValue, record) => - prevValue + record.linesOfExecutableCodeViolations); + prevValue + record.report.totalLinesOfExecutableCode); + final linesOfExecutableCodeViolations = sortedRecords.fold( + 0, + (prevValue, record) => + prevValue + record.report.linesOfExecutableCodeViolations); final averageMaintainabilityIndex = sortedRecords.fold( - 0, (prevValue, record) => prevValue + record.maintainabilityIndex) / + 0, + (prevValue, record) => + prevValue + record.report.averageMaintainabilityIndex) / sortedRecords.length; - final totalMaintainabilityIndexViolations = sortedRecords.fold( + final maintainabilityIndexViolations = sortedRecords.fold( 0, (prevValue, record) => - prevValue + record.maintainabilityIndexViolations); + prevValue + record.report.maintainabilityIndexViolations); final averageArgumentsCount = (sortedRecords.fold( - 0, - (prevValue, record) => - prevValue + record.averageArgumentsCount) / - sortedRecords.length + - 0.5) - .toInt(); - final totalArgumentsCountViolations = sortedRecords.fold( - 0, (prevValue, record) => prevValue + record.argumentsCountViolations); - - final withCyclomaticComplexityViolations = totalComplexityViolations > 0; + 0, + (prevValue, record) => + prevValue + record.report.averageArgumentsCount) / + sortedRecords.length) + .round(); + final argumentsCountViolations = sortedRecords.fold( + 0, + (prevValue, record) => + prevValue + record.report.argumentsCountViolations); + + final withCyclomaticComplexityViolations = complexityViolations > 0; final withLinesOfExecutableCodeViolations = - totalLinesOfExecutableCodeViolations > 0; + linesOfExecutableCodeViolations > 0; final withMaintainabilityIndexViolations = - totalMaintainabilityIndexViolations > 0; - final withArgumentsCountViolations = totalArgumentsCountViolations > 0; + maintainabilityIndexViolations > 0; + final withArgumentsCountViolations = argumentsCountViolations > 0; final tableContent = Element.tag('tbody'); for (final record in sortedRecords) { final recordHaveCyclomaticComplexityViolations = - record.cyclomaticComplexityViolations > 0; + record.report.cyclomaticComplexityViolations > 0; final recordHaveLinesOfExecutableCodeViolations = - record.linesOfExecutableCodeViolations > 0; + record.report.linesOfExecutableCodeViolations > 0; final recordHaveMaintainabilityIndexViolations = - record.maintainabilityIndexViolations > 0; - final recordArgumentsCountViolations = - record.argumentsCountViolations > 0; + record.report.maintainabilityIndexViolations > 0; + final recordHaveArgumentsCountViolations = + record.report.argumentsCountViolations > 0; tableContent.append(Element.tag('tr') ..append(Element.tag('td') @@ -178,32 +170,31 @@ class HtmlReporter implements Reporter { ..text = record.title)) ..append(Element.tag('td') ..text = recordHaveCyclomaticComplexityViolations - ? '${record.cyclomaticComplexity} / ${record.cyclomaticComplexityViolations}' - : '${record.cyclomaticComplexity}' + ? '${record.report.totalCyclomaticComplexity} / ${record.report.cyclomaticComplexityViolations}' + : '${record.report.totalCyclomaticComplexity}' ..classes.add(recordHaveCyclomaticComplexityViolations ? 'with-violations' : '')) ..append(Element.tag('td') ..text = recordHaveLinesOfExecutableCodeViolations - ? '${record.linesOfExecutableCode} / ${record.linesOfExecutableCodeViolations}' - : '${record.linesOfExecutableCode}' + ? '${record.report.totalLinesOfExecutableCode} / ${record.report.linesOfExecutableCodeViolations}' + : '${record.report.totalLinesOfExecutableCode}' ..classes.add(recordHaveLinesOfExecutableCodeViolations ? 'with-violations' : '')) ..append(Element.tag('td') ..text = recordHaveMaintainabilityIndexViolations - ? '${record.maintainabilityIndex.toInt()} / ${record.maintainabilityIndexViolations}' - : '${record.maintainabilityIndex.toInt()}' + ? '${record.report.averageMaintainabilityIndex.toInt()} / ${record.report.maintainabilityIndexViolations}' + : '${record.report.averageMaintainabilityIndex.toInt()}' ..classes.add(recordHaveMaintainabilityIndexViolations ? 'with-violations' : '')) ..append(Element.tag('td') - ..text = recordArgumentsCountViolations - ? '${record.averageArgumentsCount} / ${record.argumentsCountViolations}' - : '${record.averageArgumentsCount}' - ..classes.add(recordHaveMaintainabilityIndexViolations - ? 'with-violations' - : ''))); + ..text = recordHaveArgumentsCountViolations + ? '${record.report.averageArgumentsCount} / ${record.report.argumentsCountViolations}' + : '${record.report.averageArgumentsCount}' + ..classes.add( + recordHaveArgumentsCountViolations ? 'with-violations' : ''))); } final cyclomaticComplexityTitle = withCyclomaticComplexityViolations @@ -238,25 +229,25 @@ class HtmlReporter implements Reporter { ..append(renderSummaryMetric( cyclomaticComplexityTitle, withCyclomaticComplexityViolations - ? '$totalComplexity / $totalComplexityViolations' + ? '$totalComplexity / $complexityViolations' : '$totalComplexity', withViolation: withCyclomaticComplexityViolations)) ..append(renderSummaryMetric( linesOfExecutableCodeTitle, withLinesOfExecutableCodeViolations - ? '$totalLinesOfExecutableCode / $totalLinesOfExecutableCodeViolations' + ? '$totalLinesOfExecutableCode / $linesOfExecutableCodeViolations' : '$totalLinesOfExecutableCode', withViolation: withLinesOfExecutableCodeViolations)) ..append(renderSummaryMetric( maintainabilityIndexTitle, withMaintainabilityIndexViolations - ? '${averageMaintainabilityIndex.toInt()} / $totalMaintainabilityIndexViolations' + ? '${averageMaintainabilityIndex.toInt()} / $maintainabilityIndexViolations' : '${averageMaintainabilityIndex.toInt()}', withViolation: withMaintainabilityIndexViolations)) ..append(renderSummaryMetric( argumentsCountTitle, withArgumentsCountViolations - ? '$averageArgumentsCount / $totalArgumentsCountViolations' + ? '$averageArgumentsCount / $argumentsCountViolations' : '$averageArgumentsCount', withViolation: withMaintainabilityIndexViolations))); } @@ -277,19 +268,10 @@ class HtmlReporter implements Reporter { reportConfig); return ReportTableRecord( - title: folder, - link: p.join(folder, 'index.html'), - cyclomaticComplexity: report.totalCyclomaticComplexity, - cyclomaticComplexityViolations: - report.totalCyclomaticComplexityViolations, - linesOfExecutableCode: report.totalLinesOfExecutableCode, - linesOfExecutableCodeViolations: - report.totalLinesOfExecutableCodeViolations, - maintainabilityIndex: report.averageMaintainabilityIndex, - maintainabilityIndexViolations: - report.totalMaintainabilityIndexViolations, - averageArgumentsCount: report.averageArgumentsCount, - argumentsCountViolations: report.totalArgumentsCountViolations); + title: folder, + link: p.join(folder, 'index.html'), + report: report, + ); }); final html = Element.tag('html') @@ -330,19 +312,10 @@ class HtmlReporter implements Reporter { final fileName = p.basename(record.relativePath); return ReportTableRecord( - title: fileName, - link: p.setExtension(fileName, '.html'), - cyclomaticComplexity: report.totalCyclomaticComplexity, - cyclomaticComplexityViolations: - report.totalCyclomaticComplexityViolations, - linesOfExecutableCode: report.totalLinesOfExecutableCode, - linesOfExecutableCodeViolations: - report.totalLinesOfExecutableCodeViolations, - maintainabilityIndex: report.averageMaintainabilityIndex, - maintainabilityIndexViolations: - report.totalMaintainabilityIndexViolations, - averageArgumentsCount: report.averageArgumentsCount, - argumentsCountViolations: report.totalArgumentsCountViolations); + title: fileName, + link: p.setExtension(fileName, '.html'), + report: report, + ); }); final html = Element.tag('html') @@ -606,13 +579,12 @@ class HtmlReporter implements Reporter { final report = UtilitySelector.fileReport(record, reportConfig); final totalMaintainabilityIndexViolations = - report.totalMaintainabilityIndexViolations > 0; - final withArgumentsCountViolations = - report.totalArgumentsCountViolations > 0; + report.maintainabilityIndexViolations > 0; + final withArgumentsCountViolations = report.argumentsCountViolations > 0; final withCyclomaticComplexityViolations = - report.totalCyclomaticComplexityViolations > 0; + report.cyclomaticComplexityViolations > 0; final withLinesOfExecutableCodeViolations = - report.totalLinesOfExecutableCodeViolations > 0; + report.linesOfExecutableCodeViolations > 0; return Element.tag('div') ..classes.add('metric-subheader') @@ -622,7 +594,7 @@ class HtmlReporter implements Reporter { ? _cyclomaticComplexityWithViolations : _cyclomaticComplexity, withCyclomaticComplexityViolations - ? '${report.totalCyclomaticComplexity} / ${report.totalCyclomaticComplexityViolations}' + ? '${report.totalCyclomaticComplexity} / ${report.cyclomaticComplexityViolations}' : '${report.totalCyclomaticComplexity}', withViolation: withCyclomaticComplexityViolations), renderSummaryMetric( @@ -630,7 +602,7 @@ class HtmlReporter implements Reporter { ? _linesOfExecutableCodeWithViolations : _linesOfExecutableCode, withLinesOfExecutableCodeViolations - ? '${report.totalLinesOfExecutableCode} / ${report.totalLinesOfExecutableCodeViolations}' + ? '${report.totalLinesOfExecutableCode} / ${report.linesOfExecutableCodeViolations}' : '${report.totalLinesOfExecutableCode}', withViolation: withLinesOfExecutableCodeViolations), renderSummaryMetric( @@ -638,7 +610,7 @@ class HtmlReporter implements Reporter { ? _maintainabilityIndexWithViolations : _maintainabilityIndex, totalMaintainabilityIndexViolations - ? '${report.averageMaintainabilityIndex.toInt()} / ${report.totalMaintainabilityIndexViolations}' + ? '${report.averageMaintainabilityIndex.toInt()} / ${report.maintainabilityIndexViolations}' : '${report.averageMaintainabilityIndex.toInt()}', withViolation: totalMaintainabilityIndexViolations), renderSummaryMetric( @@ -646,7 +618,7 @@ class HtmlReporter implements Reporter { ? _nuberOfArgumentsWithViolations : _nuberOfArguments, withArgumentsCountViolations - ? '${report.averageArgumentsCount} / ${report.totalArgumentsCountViolations}' + ? '${report.averageArgumentsCount} / ${report.argumentsCountViolations}' : '${report.averageArgumentsCount}', withViolation: withArgumentsCountViolations), if (record.issues.isNotEmpty) diff --git a/lib/src/reporters/json_reporter.dart b/lib/src/reporters/json_reporter.dart index 8b8073741c..6be5293718 100644 --- a/lib/src/reporters/json_reporter.dart +++ b/lib/src/reporters/json_reporter.dart @@ -50,13 +50,12 @@ class JsonReporter implements Reporter { 'designIssues': _reportDesignIssues(record.designIssues), 'average-$numberOfArgumentsKey': fileReport.averageArgumentsCount, 'total-$numberOfArgumentsKey-violations': - fileReport.totalArgumentsCountViolations, + fileReport.argumentsCountViolations, 'average-$numberOfMethodsKey': fileReport.averageMethodsCount, - 'total-$numberOfMethodsKey-violations': - fileReport.totalMethodsCountViolations, + 'total-$numberOfMethodsKey-violations': fileReport.methodsCountViolations, 'total-$linesOfExecutableCodeKey': fileReport.totalLinesOfExecutableCode, 'total-$linesOfExecutableCodeKey-violations': - fileReport.totalLinesOfExecutableCodeViolations, + fileReport.linesOfExecutableCodeViolations, }; } diff --git a/lib/src/reporters/utility_selector.dart b/lib/src/reporters/utility_selector.dart index 33b80ae476..b060a75ba9 100644 --- a/lib/src/reporters/utility_selector.dart +++ b/lib/src/reporters/utility_selector.dart @@ -60,19 +60,17 @@ class UtilitySelector { .length; return FileReport( - averageArgumentsCount: averageArgumentCount.round(), - totalArgumentsCountViolations: totalArgumentsCountViolations, - averageMaintainabilityIndex: averageMaintainabilityIndex, - totalMaintainabilityIndexViolations: - totalMaintainabilityIndexViolations, - averageMethodsCount: averageMethodsCount.round(), - totalMethodsCountViolations: totalMethodsCountViolations, - totalCyclomaticComplexity: totalCyclomaticComplexity.round(), - totalCyclomaticComplexityViolations: - totalCyclomaticComplexityViolations, - totalLinesOfExecutableCode: totalLinesOfExecutableCode.round(), - totalLinesOfExecutableCodeViolations: - totalLinesOfExecutableCodeViolations); + averageArgumentsCount: averageArgumentCount.round(), + argumentsCountViolations: totalArgumentsCountViolations, + averageMaintainabilityIndex: averageMaintainabilityIndex, + maintainabilityIndexViolations: totalMaintainabilityIndexViolations, + averageMethodsCount: averageMethodsCount.round(), + methodsCountViolations: totalMethodsCountViolations, + totalCyclomaticComplexity: totalCyclomaticComplexity.round(), + cyclomaticComplexityViolations: totalCyclomaticComplexityViolations, + totalLinesOfExecutableCode: totalLinesOfExecutableCode.round(), + linesOfExecutableCodeViolations: totalLinesOfExecutableCodeViolations, + ); } static ComponentReport componentReport( @@ -164,31 +162,31 @@ class UtilitySelector { .map((functionRecord) => functionReport(functionRecord, config))) .map(functionViolationLevel)); - static FileReport mergeFileReports(FileReport lhs, FileReport rhs) => FileReport( - averageArgumentsCount: - ((lhs.averageArgumentsCount + rhs.averageArgumentsCount) / 2).round(), - totalArgumentsCountViolations: - lhs.totalArgumentsCountViolations + rhs.totalArgumentsCountViolations, - averageMaintainabilityIndex: - (lhs.averageMaintainabilityIndex + rhs.averageMaintainabilityIndex) / - 2, - totalMaintainabilityIndexViolations: - lhs.totalMaintainabilityIndexViolations + - rhs.totalMaintainabilityIndexViolations, - averageMethodsCount: - ((lhs.averageMethodsCount + rhs.averageMethodsCount) / 2).round(), - totalMethodsCountViolations: - lhs.totalMethodsCountViolations + rhs.totalMethodsCountViolations, - totalCyclomaticComplexity: - lhs.totalCyclomaticComplexity + rhs.totalCyclomaticComplexity, - totalCyclomaticComplexityViolations: - lhs.totalCyclomaticComplexityViolations + - rhs.totalCyclomaticComplexityViolations, - totalLinesOfExecutableCode: - lhs.totalLinesOfExecutableCode + rhs.totalLinesOfExecutableCode, - totalLinesOfExecutableCodeViolations: - lhs.totalLinesOfExecutableCodeViolations + - rhs.totalLinesOfExecutableCodeViolations); + static FileReport mergeFileReports(FileReport lhs, FileReport rhs) => + FileReport( + averageArgumentsCount: + ((lhs.averageArgumentsCount + rhs.averageArgumentsCount) / 2) + .round(), + argumentsCountViolations: + lhs.argumentsCountViolations + rhs.argumentsCountViolations, + averageMaintainabilityIndex: (lhs.averageMaintainabilityIndex + + rhs.averageMaintainabilityIndex) / + 2, + maintainabilityIndexViolations: lhs.maintainabilityIndexViolations + + rhs.maintainabilityIndexViolations, + averageMethodsCount: + ((lhs.averageMethodsCount + rhs.averageMethodsCount) / 2).round(), + methodsCountViolations: + lhs.methodsCountViolations + rhs.methodsCountViolations, + totalCyclomaticComplexity: + lhs.totalCyclomaticComplexity + rhs.totalCyclomaticComplexity, + cyclomaticComplexityViolations: lhs.cyclomaticComplexityViolations + + rhs.cyclomaticComplexityViolations, + totalLinesOfExecutableCode: + lhs.totalLinesOfExecutableCode + rhs.totalLinesOfExecutableCode, + linesOfExecutableCodeViolations: lhs.linesOfExecutableCodeViolations + + rhs.linesOfExecutableCodeViolations, + ); static ViolationLevel _violationLevel(int value, int warningLevel) { if (warningLevel == null) { diff --git a/test/reporters/utility_selector_test.dart b/test/reporters/utility_selector_test.dart index 1abf6f4ba7..c536cfb3dc 100644 --- a/test/reporters/utility_selector_test.dart +++ b/test/reporters/utility_selector_test.dart @@ -32,9 +32,9 @@ void main() { const Config(), ); expect(report.averageArgumentsCount, 5); - expect(report.totalArgumentsCountViolations, 2); + expect(report.argumentsCountViolations, 2); expect(report.averageMethodsCount, 13); - expect(report.totalMethodsCountViolations, 2); + expect(report.methodsCountViolations, 2); }); group('componentReport calculates report for function', () {