@@ -7,8 +7,10 @@ import 'package:collection/collection.dart';
77import '../../analyzers/lint_analyzer/lint_analyzer.dart' ;
88import '../../analyzers/lint_analyzer/metrics/metrics_factory.dart' ;
99import '../../analyzers/lint_analyzer/metrics/models/metric_value_level.dart' ;
10+ import '../../analyzers/lint_analyzer/models/lint_file_report.dart' ;
1011import '../../analyzers/lint_analyzer/models/severity.dart' ;
1112import '../../analyzers/lint_analyzer/reporters/lint_report_params.dart' ;
13+ import '../../analyzers/lint_analyzer/reporters/reporters_list/json/lint_json_reporter.dart' ;
1214import '../../analyzers/lint_analyzer/utils/report_utils.dart' ;
1315import '../../config_builder/config_builder.dart' ;
1416import '../../config_builder/models/deprecated_option.dart' ;
@@ -44,26 +46,29 @@ class AnalyzeCommand extends BaseCommand {
4446 ..isVerbose = isVerbose
4547 ..progress.start ('Analyzing' );
4648
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);
5550
5651 final config = ConfigBuilder .getLintConfigFromArgs (parsedArgs);
5752
5853 final lintAnalyzerResult = await _analyzer.runCliAnalysis (
5954 argResults.rest,
60- argResults[ FlagNames .rootFolder] as String ,
55+ parsedArgs .rootFolder,
6156 config,
6257 sdkPath: findSdkPath (),
6358 );
6459
6560 _logger.progress.complete ('Analysis is completed. Preparing the results:' );
6661
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+
6772 await _analyzer
6873 .getReporter (
6974 name: argResults[FlagNames .reporter] as String ,
@@ -76,6 +81,10 @@ class AnalyzeCommand extends BaseCommand {
7681 additionalParams: LintReportParams (congratulate: ! isNoCongratulate),
7782 );
7883
84+ _checkSeverity (lintAnalyzerResult);
85+ }
86+
87+ void _checkSeverity (Iterable <LintFileReport > lintAnalyzerResult) {
7988 if (hasIssueWithSeverity (lintAnalyzerResult, Severity .error)) {
8089 exit (3 );
8190 } else if ((argResults[FlagNames .fatalWarnings] as bool ) &&
@@ -133,6 +142,12 @@ class AnalyzeCommand extends BaseCommand {
133142 help: 'Write HTML output to OUTPUT.' ,
134143 valueHelp: 'OUTPUT' ,
135144 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 ,
136151 );
137152 }
138153
0 commit comments