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

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

Issue 2770493003: fixes #29095, machine mode escapes newline/returns (Closed)
Patch Set: Created 3 years, 9 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/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 } 102 }
103 } 103 }
104 104
105 /// Helper for formatting [AnalysisError]s. 105 /// Helper for formatting [AnalysisError]s.
106 /// The two format options are a user consumable format and a machine consumable 106 /// The two format options are a user consumable format and a machine consumable
107 /// format. 107 /// format.
108 class ErrorFormatter { 108 class ErrorFormatter {
109 static final int _pipeCodeUnit = '|'.codeUnitAt(0); 109 static final int _pipeCodeUnit = '|'.codeUnitAt(0);
110 static final int _slashCodeUnit = '\\'.codeUnitAt(0); 110 static final int _slashCodeUnit = '\\'.codeUnitAt(0);
111 static final int _newline = '\n'.codeUnitAt(0);
112 static final int _return = '\r'.codeUnitAt(0);
111 113
112 final StringSink out; 114 final StringSink out;
113 final CommandLineOptions options; 115 final CommandLineOptions options;
114 final AnalysisStats stats; 116 final AnalysisStats stats;
115 117
116 final _SeverityProcessor processSeverity; 118 final _SeverityProcessor processSeverity;
117 119
118 ErrorFormatter(this.out, this.options, this.stats, 120 ErrorFormatter(this.out, this.options, this.stats,
119 [this.processSeverity = _identity]); 121 [this.processSeverity = _identity]);
120 122
(...skipping 16 matching lines...) Expand all
137 if (severity == ErrorSeverity.WARNING && options.warningsAreFatal) { 139 if (severity == ErrorSeverity.WARNING && options.warningsAreFatal) {
138 severity = ErrorSeverity.ERROR; 140 severity = ErrorSeverity.ERROR;
139 } 141 }
140 } 142 }
141 out.write(severity); 143 out.write(severity);
142 out.write('|'); 144 out.write('|');
143 out.write(error.errorCode.type); 145 out.write(error.errorCode.type);
144 out.write('|'); 146 out.write('|');
145 out.write(error.errorCode.name); 147 out.write(error.errorCode.name);
146 out.write('|'); 148 out.write('|');
147 out.write(escapePipe(source.fullName)); 149 out.write(escapeForMachineMode(source.fullName));
148 out.write('|'); 150 out.write('|');
149 out.write(location.lineNumber); 151 out.write(location.lineNumber);
150 out.write('|'); 152 out.write('|');
151 out.write(location.columnNumber); 153 out.write(location.columnNumber);
152 out.write('|'); 154 out.write('|');
153 out.write(length); 155 out.write(length);
154 out.write('|'); 156 out.write('|');
155 out.write(escapePipe(error.message)); 157 out.write(escapeForMachineMode(error.message));
156 out.writeln(); 158 out.writeln();
157 } else { 159 } else {
158 // Get display name. 160 // Get display name.
159 String errorType = severity.displayName; 161 String errorType = severity.displayName;
160 162
161 // Translate INFOs into LINTS and HINTS. 163 // Translate INFOs into LINTS and HINTS.
162 if (severity == ErrorSeverity.INFO) { 164 if (severity == ErrorSeverity.INFO) {
163 if (error.errorCode.type == ErrorType.HINT || 165 if (error.errorCode.type == ErrorType.HINT ||
164 error.errorCode.type == ErrorType.LINT) { 166 error.errorCode.type == ErrorType.LINT) {
165 errorType = error.errorCode.type.displayName; 167 errorType = error.errorCode.type.displayName;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 247 }
246 } else if (error.errorCode.type == ErrorType.HINT) { 248 } else if (error.errorCode.type == ErrorType.HINT) {
247 stats.hintCount++; 249 stats.hintCount++;
248 } else if (error.errorCode.type == ErrorType.LINT) { 250 } else if (error.errorCode.type == ErrorType.LINT) {
249 stats.lintCount++; 251 stats.lintCount++;
250 } 252 }
251 formatError(errorToLine, error); 253 formatError(errorToLine, error);
252 } 254 }
253 } 255 }
254 256
255 static String escapePipe(String input) { 257 static String escapeForMachineMode(String input) {
256 StringBuffer result = new StringBuffer(); 258 StringBuffer result = new StringBuffer();
257 for (int c in input.codeUnits) { 259 for (int c in input.codeUnits) {
258 if (c == _slashCodeUnit || c == _pipeCodeUnit) { 260 if (c == _newline) {
259 result.write('\\'); 261 result.write(r'\n');
262 } else if (c == _return) {
263 result.write(r'\r');
264 } else {
265 if (c == _slashCodeUnit || c == _pipeCodeUnit) {
266 result.write('\\');
267 }
268 result.writeCharCode(c);
260 } 269 }
261 result.writeCharCode(c);
262 } 270 }
263 return result.toString(); 271 return result.toString();
264 } 272 }
265 } 273 }
266 274
267 /// A severity with awareness of whether it was overridden by a processor. 275 /// A severity with awareness of whether it was overridden by a processor.
268 class ProcessedSeverity { 276 class ProcessedSeverity {
269 ErrorSeverity severity; 277 ErrorSeverity severity;
270 bool overridden; 278 bool overridden;
271 ProcessedSeverity(this.severity, [this.overridden = false]); 279 ProcessedSeverity(this.severity, [this.overridden = false]);
272 } 280 }
273 281
274 /// Given an absolute path, return a relative path if the file is contained in 282 /// Given an absolute path, return a relative path if the file is contained in
275 /// the current directory; return the original path otherwise. 283 /// the current directory; return the original path otherwise.
276 String _relative(String file) { 284 String _relative(String file) {
277 return file.startsWith(path.current) ? path.relative(file) : file; 285 return file.startsWith(path.current) ? path.relative(file) : file;
278 } 286 }
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