@@ -7,8 +7,10 @@ import 'package:collection/collection.dart';
7
7
import '../../analyzers/lint_analyzer/lint_analyzer.dart' ;
8
8
import '../../analyzers/lint_analyzer/metrics/metrics_factory.dart' ;
9
9
import '../../analyzers/lint_analyzer/metrics/models/metric_value_level.dart' ;
10
+ import '../../analyzers/lint_analyzer/models/lint_file_report.dart' ;
10
11
import '../../analyzers/lint_analyzer/models/severity.dart' ;
11
12
import '../../analyzers/lint_analyzer/reporters/lint_report_params.dart' ;
13
+ import '../../analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart' ;
12
14
import '../../analyzers/lint_analyzer/utils/report_utils.dart' ;
13
15
import '../../config_builder/config_builder.dart' ;
14
16
import '../../config_builder/models/deprecated_option.dart' ;
@@ -44,26 +46,29 @@ class AnalyzeCommand extends BaseCommand {
44
46
..isVerbose = isVerbose
45
47
..progress.start ('Analyzing' );
46
48
47
- final parsedArgs = ParsedArguments (
48
- excludePath: argResults[FlagNames .exclude] as String ,
49
- metricsConfig: {
50
- for (final metric in getMetrics (config: {}))
51
- if (argResults.wasParsed (metric.id))
52
- metric.id: argResults[metric.id] as Object ,
53
- },
54
- );
49
+ final parsedArgs = ParsedArguments .fromArgs (argResults);
55
50
56
51
final config = ConfigBuilder .getLintConfigFromArgs (parsedArgs);
57
52
58
53
final lintAnalyzerResult = await _analyzer.runCliAnalysis (
59
54
argResults.rest,
60
- argResults[ FlagNames .rootFolder] as String ,
55
+ parsedArgs .rootFolder,
61
56
config,
62
57
sdkPath: findSdkPath (),
63
58
);
64
59
65
60
_logger.progress.complete ('Analysis is completed. Preparing the results:' );
66
61
62
+ final jsonReportPath = parsedArgs.jsonReportPath;
63
+ if (jsonReportPath != null ) {
64
+ final jsonReporter =
65
+ LintJsonReporter .toFile (jsonReportPath, parsedArgs.rootFolder);
66
+ await jsonReporter.report (
67
+ lintAnalyzerResult,
68
+ summary: _analyzer.getSummary (lintAnalyzerResult),
69
+ );
70
+ }
71
+
67
72
await _analyzer
68
73
.getReporter (
69
74
name: argResults[FlagNames .reporter] as String ,
@@ -76,6 +81,10 @@ class AnalyzeCommand extends BaseCommand {
76
81
additionalParams: LintReportParams (congratulate: ! isNoCongratulate),
77
82
);
78
83
84
+ _checkSeverity (lintAnalyzerResult);
85
+ }
86
+
87
+ void _checkSeverity (Iterable <LintFileReport > lintAnalyzerResult) {
79
88
if (hasIssueWithSeverity (lintAnalyzerResult, Severity .error)) {
80
89
exit (3 );
81
90
} else if ((argResults[FlagNames .fatalWarnings] as bool ) &&
@@ -133,6 +142,12 @@ class AnalyzeCommand extends BaseCommand {
133
142
help: 'Write HTML output to OUTPUT.' ,
134
143
valueHelp: 'OUTPUT' ,
135
144
defaultsTo: 'metrics' ,
145
+ )
146
+ ..addOption (
147
+ FlagNames .jsonReportPath,
148
+ help: 'Path to the JSON file with the output of the analysis.' ,
149
+ valueHelp: 'path/to/file.json' ,
150
+ defaultsTo: null ,
136
151
);
137
152
}
138
153
0 commit comments