Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: lib/src/error_formatter.dart

Issue 1382023002: Support for --fatal-hints. (Closed) Base URL: https://github.com/dart-lang/analyzer_cli.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/analyzer_impl.dart ('k') | lib/src/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer_cli.src.error_formatter; 5 library analyzer_cli.src.error_formatter;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer_cli/src/analyzer_impl.dart'; 10 import 'package:analyzer_cli/src/analyzer_impl.dart';
(...skipping 13 matching lines...) Expand all
24 final _ErrorFilter errorFilter; 24 final _ErrorFilter errorFilter;
25 25
26 ErrorFormatter(this.out, this.options, [this.errorFilter = _anyError]); 26 ErrorFormatter(this.out, this.options, [this.errorFilter = _anyError]);
27 27
28 void formatError( 28 void formatError(
29 Map<AnalysisError, LineInfo> errorToLine, AnalysisError error) { 29 Map<AnalysisError, LineInfo> errorToLine, AnalysisError error) {
30 Source source = error.source; 30 Source source = error.source;
31 LineInfo_Location location = errorToLine[error].getLocation(error.offset); 31 LineInfo_Location location = errorToLine[error].getLocation(error.offset);
32 int length = error.length; 32 int length = error.length;
33 ErrorSeverity severity = 33 ErrorSeverity severity =
34 AnalyzerImpl.computeSeverity(error, options.enableTypeChecks); 34 AnalyzerImpl.computeSeverity(error, options);
35 if (options.machineFormat) { 35 if (options.machineFormat) {
36 if (severity == ErrorSeverity.WARNING && options.warningsAreFatal) { 36 if (severity == ErrorSeverity.WARNING && options.warningsAreFatal) {
37 severity = ErrorSeverity.ERROR; 37 severity = ErrorSeverity.ERROR;
38 } 38 }
39 out.write(severity); 39 out.write(severity);
40 out.write('|'); 40 out.write('|');
41 out.write(error.errorCode.type); 41 out.write(error.errorCode.type);
42 out.write('|'); 42 out.write('|');
43 out.write(error.errorCode.name); 43 out.write(error.errorCode.name);
44 out.write('|'); 44 out.write('|');
(...skipping 28 matching lines...) Expand all
73 if (errorFilter(error)) { 73 if (errorFilter(error)) {
74 errors.add(error); 74 errors.add(error);
75 errorToLine[error] = errorInfo.lineInfo; 75 errorToLine[error] = errorInfo.lineInfo;
76 } 76 }
77 } 77 }
78 } 78 }
79 // Sort errors. 79 // Sort errors.
80 errors.sort((AnalysisError error1, AnalysisError error2) { 80 errors.sort((AnalysisError error1, AnalysisError error2) {
81 // Severity. 81 // Severity.
82 ErrorSeverity severity1 = 82 ErrorSeverity severity1 =
83 AnalyzerImpl.computeSeverity(error1, options.enableTypeChecks); 83 AnalyzerImpl.computeSeverity(error1, options);
84 ErrorSeverity severity2 = 84 ErrorSeverity severity2 =
85 AnalyzerImpl.computeSeverity(error2, options.enableTypeChecks); 85 AnalyzerImpl.computeSeverity(error2, options);
86 int compare = severity2.compareTo(severity1); 86 int compare = severity2.compareTo(severity1);
87 if (compare != 0) { 87 if (compare != 0) {
88 return compare; 88 return compare;
89 } 89 }
90 // Path. 90 // Path.
91 compare = Comparable.compare(error1.source.fullName.toLowerCase(), 91 compare = Comparable.compare(error1.source.fullName.toLowerCase(),
92 error2.source.fullName.toLowerCase()); 92 error2.source.fullName.toLowerCase());
93 if (compare != 0) { 93 if (compare != 0) {
94 return compare; 94 return compare;
95 } 95 }
96 // Offset. 96 // Offset.
97 return error1.offset - error2.offset; 97 return error1.offset - error2.offset;
98 }); 98 });
99 // Format errors. 99 // Format errors.
100 int errorCount = 0; 100 int errorCount = 0;
101 int warnCount = 0; 101 int warnCount = 0;
102 int hintCount = 0; 102 int hintCount = 0;
103 int lintCount = 0; 103 int lintCount = 0;
104 for (AnalysisError error in errors) { 104 for (AnalysisError error in errors) {
105 ErrorSeverity severity = 105 ErrorSeverity severity =
106 AnalyzerImpl.computeSeverity(error, options.enableTypeChecks); 106 AnalyzerImpl.computeSeverity(error, options);
107 if (severity == ErrorSeverity.ERROR) { 107 if (severity == ErrorSeverity.ERROR) {
108 errorCount++; 108 errorCount++;
109 } else if (severity == ErrorSeverity.WARNING) { 109 } else if (severity == ErrorSeverity.WARNING) {
110 if (options.warningsAreFatal) { 110 if (options.warningsAreFatal) {
111 errorCount++; 111 errorCount++;
112 } else { 112 } else {
113 warnCount++; 113 warnCount++;
114 } 114 }
115 } else if (error.errorCode.type == ErrorType.HINT) { 115 } else if (error.errorCode.type == ErrorType.HINT) {
116 hintCount++; 116 hintCount++;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 static String pluralize(String word, int count) { 189 static String pluralize(String word, int count) {
190 if (count == 1) { 190 if (count == 1) {
191 return word; 191 return word;
192 } else { 192 } else {
193 return word + "s"; 193 return word + "s";
194 } 194 }
195 } 195 }
196 } 196 }
OLDNEW
« no previous file with comments | « lib/src/analyzer_impl.dart ('k') | lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698