This repository was archived by the owner on Jul 16, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +31
-14
lines changed
lib/src/analyzers/lint_analyzer/utils
test/src/analyzers/lint_analyzer/utils Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -52,22 +52,27 @@ int totalClasses(Iterable<LintFileReport> records) => records.fold(
5252 (prevValue, fileReport) => prevValue + fileReport.classes.keys.length,
5353 );
5454
55- double averageCYCLO (Iterable <LintFileReport > records) =>
56- records.fold <num >(
57- 0 ,
58- (prevValue, fileReport) =>
59- prevValue +
60- fileReport.functions.values.fold (
55+ double averageCYCLO (Iterable <LintFileReport > records) {
56+ final totalSloc = totalSLOC (records);
57+
58+ return totalSloc > 0
59+ ? records.fold <num >(
6160 0 ,
62- (prevValue, functionReport ) =>
61+ (prevValue, fileReport ) =>
6362 prevValue +
64- (functionReport
65- .metric (CyclomaticComplexityMetric .metricId)
66- ? .value ??
67- 0 ),
68- ),
69- ) /
70- totalSLOC (records);
63+ fileReport.functions.values.fold (
64+ 0 ,
65+ (prevValue, functionReport) =>
66+ prevValue +
67+ (functionReport
68+ .metric (CyclomaticComplexityMetric .metricId)
69+ ? .value ??
70+ 0 ),
71+ ),
72+ ) /
73+ totalSloc
74+ : 0 ;
75+ }
7176
7277int averageSLOC (Iterable <LintFileReport > records) {
7378 final functionsCount = records.fold <int >(
Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ void main() {
2121 const fullPathStub3 = '~/lib/src/bar.dart' ;
2222 const relativePathStub3 = 'lib/src/bar.dart' ;
2323
24+ final emptyRecord = [
25+ LintFileReport (
26+ path: fullPathStub,
27+ relativePath: relativePathStub,
28+ classes: const {},
29+ functions: {'a' : buildFunctionRecordStub (metrics: [])},
30+ issues: const [],
31+ antiPatternCases: const [],
32+ ),
33+ ];
34+
2435 final fileRecords = [
2536 LintFileReport (
2637 path: fullPathStub,
@@ -146,6 +157,7 @@ void main() {
146157 test (
147158 'averageCYCLO returns average numbers of cyclomatic complexity per source lines of code' ,
148159 () {
160+ expect (averageCYCLO (emptyRecord), closeTo (0.0 , 0.01 ));
149161 expect (averageCYCLO (fileRecords), closeTo (1.08 , 0.01 ));
150162 },
151163 );
You can’t perform that action at this time.
0 commit comments