Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit e2919ae

Browse files
authored
refactor: make violations field of summary lint report record as integer (#544)
* refactor: make metrics code more flexible * refactor: make violations field of summary lint report record as integer * chore: update cSpell dictionary * fix: include_file_not_found in analysis_options.yaml
1 parent 436140a commit e2919ae

File tree

12 files changed

+25
-19
lines changed

12 files changed

+25
-19
lines changed

.vscode/settings.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22
"files.eol": "\n",
33
"files.insertFinalNewline": true,
44
"cSpell.words": [
5-
"Backport",
6-
"Gitlab",
7-
"Halstead",
8-
"McCabe's",
9-
"SLOC",
105
"ansicolor",
6+
"Backport",
117
"codeclimate",
128
"codecov",
139
"cyclomatic",
1410
"dartanalyzer",
1511
"dartdocs",
1612
"dependabot",
1713
"dkrutskikh",
14+
"Gitlab",
15+
"Halstead",
1816
"incendial",
1917
"lcov",
18+
"McCabe's",
2019
"mocktail",
2120
"nullsafety",
21+
"pubignore",
2222
"pubspec",
2323
"semver",
24-
"setstate"
24+
"setstate",
25+
"SLOC",
26+
"unawaited"
2527
]
2628
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* refactor: make violations field of summary lint report record as integer
6+
37
## 4.6.0
48

59
* feat: CLI now can be compiled to and used as compiled executable.

lib/src/analyzers/lint_analyzer/metrics/metrics_list/maintainability_index_metric.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MaintainabilityIndexMetric extends FunctionMetric<int> {
4545
Iterable<ScopedClassDeclaration> classDeclarations,
4646
Iterable<ScopedFunctionDeclaration> functionDeclarations,
4747
InternalResolvedUnitResult source,
48-
Iterable<MetricValue<num>> otherMetricsValues,
48+
Iterable<MetricValue> otherMetricsValues,
4949
) =>
5050
super.supports(
5151
node,

lib/src/analyzers/lint_analyzer/metrics/metrics_list/number_of_parameters_metric.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class NumberOfParametersMetric extends FunctionMetric<int> {
4040
Iterable<ScopedClassDeclaration> classDeclarations,
4141
Iterable<ScopedFunctionDeclaration> functionDeclarations,
4242
InternalResolvedUnitResult source,
43-
Iterable<MetricValue<num>> otherMetricsValues,
43+
Iterable<MetricValue> otherMetricsValues,
4444
) {
4545
if (node is FunctionDeclaration) {
4646
return true;

lib/src/analyzers/lint_analyzer/metrics/metrics_list/weight_of_class_metric.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class WeightOfClassMetric extends ClassMetric<double> {
4444
Iterable<ScopedClassDeclaration> classDeclarations,
4545
Iterable<ScopedFunctionDeclaration> functionDeclarations,
4646
InternalResolvedUnitResult source,
47-
Iterable<MetricValue<num>> otherMetricsValues,
47+
Iterable<MetricValue> otherMetricsValues,
4848
) =>
4949
super.supports(
5050
node,

lib/src/analyzers/lint_analyzer/metrics/models/metric.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class Metric<T extends num> {
3939
Iterable<ScopedClassDeclaration> classDeclarations,
4040
Iterable<ScopedFunctionDeclaration> functionDeclarations,
4141
InternalResolvedUnitResult source,
42-
Iterable<MetricValue<num>> otherMetricsValues,
42+
Iterable<MetricValue> otherMetricsValues,
4343
) =>
4444
true;
4545

lib/src/analyzers/lint_analyzer/models/summary_lint_report_record.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class SummaryLintReportRecord<T> {
1010
final String title;
1111

1212
final T value;
13-
final T? violations;
13+
final int violations;
1414

1515
const SummaryLintReportRecord({
1616
this.status = SummaryLintReportRecordStatus.none,
1717
required this.title,
1818
required this.value,
19-
this.violations,
19+
this.violations = 0,
2020
});
2121
}

lib/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ class LintJsonReporter
5757
SummaryLintReportRecord<Object> record,
5858
) {
5959
final recordValue = record.value;
60-
final recordViolations = record.violations;
6160

6261
return {
6362
'status': record.status.toString(),
6463
'title': record.title,
6564
'value': recordValue is Iterable ? recordValue.toList() : recordValue,
66-
if (recordViolations != null)
67-
'violations': recordViolations is Iterable
68-
? recordViolations.toList()
69-
: recordViolations,
65+
'violations': record.violations,
7066
};
7167
}
7268

test/src/analyzers/lint_analyzer/reporters/reporters_list/lint_json_reporter_test.dart renamed to test/src/analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:dart_code_metrics/src/analyzers/lint_analyzer/reporters/reporter
66
import 'package:mocktail/mocktail.dart';
77
import 'package:test/test.dart';
88

9-
import 'report_example.dart';
9+
import '../report_example.dart';
1010

1111
class IOSinkMock extends Mock implements IOSink {}
1212

@@ -89,6 +89,7 @@ void main() {
8989
'status': 'none',
9090
'title': 'Scanned package folders',
9191
'value': ['bin', 'example', 'lib', 'test'],
92+
'violations': 0,
9293
}),
9394
);
9495

tools/analyzer_plugin/analysis_options.yaml

Whitespace-only changes.

tools/analyzer_plugin/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ environment:
77

88
dependencies:
99
dart_code_metrics: ^4.6.0
10+
11+
dev_dependencies:
12+
lints: ^1.0.1

website/docs/cli/analyze.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ The reporter prints a single JSON object containing meta information and the vio
142142
- `status` - a status of information in this record
143143
- `title` - a message with information about the record
144144
- `value` - an actual value of this record (can be an array or a single value)
145-
- `violations` - a value of a violations of a metric associated with this record (can be an array or a single value) _(optional)_
145+
- `violations` - a value of a violations count of a metric associated with this record
146146

147147
```JSON
148148
{

0 commit comments

Comments
 (0)