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

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

Issue 2109783003: Fix pipe escaping. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | no next file » | 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/options.dart'; 10 import 'package:analyzer_cli/src/options.dart';
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } else { 98 } else {
99 out.writeln("No issues found"); 99 out.writeln("No issues found");
100 } 100 }
101 } 101 }
102 } 102 }
103 103
104 /// Helper for formatting [AnalysisError]s. 104 /// Helper for formatting [AnalysisError]s.
105 /// The two format options are a user consumable format and a machine consumable 105 /// The two format options are a user consumable format and a machine consumable
106 /// format. 106 /// format.
107 class ErrorFormatter { 107 class ErrorFormatter {
108 static final int _pipeCodeUnit = '|'.codeUnitAt(0);
109 static final int _slashCodeUnit = '\\'.codeUnitAt(0);
110
108 final StringSink out; 111 final StringSink out;
109 final CommandLineOptions options; 112 final CommandLineOptions options;
110 final AnalysisStats stats; 113 final AnalysisStats stats;
114
111 final _SeverityProcessor processSeverity; 115 final _SeverityProcessor processSeverity;
112 116
113 ErrorFormatter(this.out, this.options, this.stats, 117 ErrorFormatter(this.out, this.options, this.stats,
114 [this.processSeverity = _identity]); 118 [this.processSeverity = _identity]);
115 119
116 /// Compute the severity for this [error] or `null` if this error should be 120 /// Compute the severity for this [error] or `null` if this error should be
117 /// filtered. 121 /// filtered.
118 ErrorSeverity computeSeverity(AnalysisError error) => 122 ErrorSeverity computeSeverity(AnalysisError error) =>
119 processSeverity(error)?.severity; 123 processSeverity(error)?.severity;
120 124
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 164 }
161 } 165 }
162 166
163 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) 167 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2)
164 out.write('[$errorType] ${error.message} '); 168 out.write('[$errorType] ${error.message} ');
165 out.write('(${source.fullName}'); 169 out.write('(${source.fullName}');
166 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); 170 out.write(', line ${location.lineNumber}, col ${location.columnNumber})');
167 } 171 }
168 out.writeln(); 172 out.writeln();
169 } 173 }
170
171 void formatErrors(List<AnalysisErrorInfo> errorInfos) { 174 void formatErrors(List<AnalysisErrorInfo> errorInfos) {
172 stats.unfilteredCount += errorInfos.length; 175 stats.unfilteredCount += errorInfos.length;
173 176
174 var errors = new List<AnalysisError>(); 177 var errors = new List<AnalysisError>();
175 var errorToLine = new Map<AnalysisError, LineInfo>(); 178 var errorToLine = new Map<AnalysisError, LineInfo>();
176 for (AnalysisErrorInfo errorInfo in errorInfos) { 179 for (AnalysisErrorInfo errorInfo in errorInfos) {
177 for (AnalysisError error in errorInfo.errors) { 180 for (AnalysisError error in errorInfo.errors) {
178 if (computeSeverity(error) != null) { 181 if (computeSeverity(error) != null) {
179 errors.add(error); 182 errors.add(error);
180 errorToLine[error] = errorInfo.lineInfo; 183 errorToLine[error] = errorInfo.lineInfo;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } else if (error.errorCode.type == ErrorType.HINT) { 219 } else if (error.errorCode.type == ErrorType.HINT) {
217 stats.hintCount++; 220 stats.hintCount++;
218 } else if (error.errorCode.type == ErrorType.LINT) { 221 } else if (error.errorCode.type == ErrorType.LINT) {
219 stats.lintCount++; 222 stats.lintCount++;
220 } 223 }
221 formatError(errorToLine, error); 224 formatError(errorToLine, error);
222 } 225 }
223 } 226 }
224 227
225 static String escapePipe(String input) { 228 static String escapePipe(String input) {
226 var result = new StringBuffer(); 229 StringBuffer result = new StringBuffer();
227 for (var c in input.codeUnits) { 230 for (int c in input.codeUnits) {
228 if (c == '\\' || c == '|') { 231 if (c == _slashCodeUnit || c == _pipeCodeUnit) {
229 result.write('\\'); 232 result.write('\\');
230 } 233 }
231 result.writeCharCode(c); 234 result.writeCharCode(c);
232 } 235 }
233 return result.toString(); 236 return result.toString();
234 } 237 }
235 } 238 }
236 239
237 /// A severity with awareness of whether it was overridden by a processor. 240 /// A severity with awareness of whether it was overridden by a processor.
238 class ProcessedSeverity { 241 class ProcessedSeverity {
239 ErrorSeverity severity; 242 ErrorSeverity severity;
240 bool overridden; 243 bool overridden;
241 ProcessedSeverity(this.severity, [this.overridden = false]); 244 ProcessedSeverity(this.severity, [this.overridden = false]);
242 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698