| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 error_formatter; | 5 library error_formatter; |
| 6 | 6 |
| 7 import 'package:analyzer/src/analyzer_impl.dart'; | 7 import 'package:analyzer/src/analyzer_impl.dart'; |
| 8 | 8 |
| 9 import '../options.dart'; | 9 import '../options.dart'; |
| 10 import 'generated/engine.dart'; | 10 import 'generated/engine.dart'; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if (compare != 0) { | 96 if (compare != 0) { |
| 97 return compare; | 97 return compare; |
| 98 } | 98 } |
| 99 // offset | 99 // offset |
| 100 return error1.offset - error2.offset; | 100 return error1.offset - error2.offset; |
| 101 }); | 101 }); |
| 102 // format errors | 102 // format errors |
| 103 int errorCount = 0; | 103 int errorCount = 0; |
| 104 int warnCount = 0; | 104 int warnCount = 0; |
| 105 int hintCount = 0; | 105 int hintCount = 0; |
| 106 int lintCount = 0; |
| 106 for (AnalysisError error in errors) { | 107 for (AnalysisError error in errors) { |
| 107 ErrorSeverity severity = | 108 ErrorSeverity severity = |
| 108 AnalyzerImpl.computeSeverity(error, options.enableTypeChecks); | 109 AnalyzerImpl.computeSeverity(error, options.enableTypeChecks); |
| 109 if (severity == ErrorSeverity.ERROR) { | 110 if (severity == ErrorSeverity.ERROR) { |
| 110 errorCount++; | 111 errorCount++; |
| 111 } else if (severity == ErrorSeverity.WARNING) { | 112 } else if (severity == ErrorSeverity.WARNING) { |
| 112 if (options.warningsAreFatal) { | 113 if (options.warningsAreFatal) { |
| 113 errorCount++; | 114 errorCount++; |
| 114 } else { | 115 } else { |
| 115 if (error.errorCode.type == ErrorType.HINT) { | 116 if (error.errorCode.type == ErrorType.HINT) { |
| 116 hintCount++; | 117 hintCount++; |
| 117 } else { | 118 } else { |
| 118 warnCount++; | 119 warnCount++; |
| 119 } | 120 } |
| 120 } | 121 } |
| 122 } else if (error.errorCode.type == ErrorType.LINT) { |
| 123 lintCount++; |
| 121 } | 124 } |
| 122 formatError(errorToLine, error); | 125 formatError(errorToLine, error); |
| 123 } | 126 } |
| 124 // print statistics | 127 // print statistics |
| 125 if (!options.machineFormat) { | 128 if (!options.machineFormat) { |
| 126 var hasErrors = errorCount != 0; | 129 var hasErrors = errorCount != 0; |
| 127 var hasWarns = warnCount != 0; | 130 var hasWarns = warnCount != 0; |
| 128 var hasHints = hintCount != 0; | 131 var hasHints = hintCount != 0; |
| 132 var hasLints = lintCount != 0; |
| 129 bool hasContent = false; | 133 bool hasContent = false; |
| 130 if (hasErrors) { | 134 if (hasErrors) { |
| 131 out.write(errorCount); | 135 out.write(errorCount); |
| 132 out.write(' '); | 136 out.write(' '); |
| 133 out.write(pluralize("error", errorCount)); | 137 out.write(pluralize("error", errorCount)); |
| 134 hasContent = true; | 138 hasContent = true; |
| 135 } | 139 } |
| 136 if (hasWarns) { | 140 if (hasWarns) { |
| 137 if (hasContent) { | 141 if (hasContent) { |
| 138 if (!hasHints) { | 142 if (!hasHints && !hasLints) { |
| 139 out.write(' and '); | 143 out.write(' and '); |
| 140 } else { | 144 } else { |
| 141 out.write(", "); | 145 out.write(", "); |
| 142 } | 146 } |
| 143 } | 147 } |
| 144 out.write(warnCount); | 148 out.write(warnCount); |
| 145 out.write(' '); | 149 out.write(' '); |
| 146 out.write(pluralize("warning", warnCount)); | 150 out.write(pluralize("warning", warnCount)); |
| 147 hasContent = true; | 151 hasContent = true; |
| 148 } | 152 } |
| 149 if (hasHints) { | 153 if (hasHints) { |
| 150 if (hasContent) { | 154 if (hasContent) { |
| 151 out.write(" and "); | 155 if (!hasLints) { |
| 156 out.write(' and '); |
| 157 } else { |
| 158 out.write(", "); |
| 159 } |
| 152 } | 160 } |
| 153 out.write(hintCount); | 161 out.write(hintCount); |
| 154 out.write(' '); | 162 out.write(' '); |
| 155 out.write(pluralize("hint", hintCount)); | 163 out.write(pluralize("hint", hintCount)); |
| 156 hasContent = true; | 164 hasContent = true; |
| 157 } | 165 } |
| 166 if (hasLints) { |
| 167 if (hasContent) { |
| 168 out.write(" and "); |
| 169 } |
| 170 out.write(lintCount); |
| 171 out.write(' '); |
| 172 out.write(pluralize("lint", lintCount)); |
| 173 hasContent = true; |
| 174 } |
| 158 if (hasContent) { | 175 if (hasContent) { |
| 159 out.writeln(" found."); | 176 out.writeln(" found."); |
| 160 } else { | 177 } else { |
| 161 out.writeln("No issues found"); | 178 out.writeln("No issues found"); |
| 162 } | 179 } |
| 163 } | 180 } |
| 164 } | 181 } |
| 165 | 182 |
| 166 static String escapePipe(String input) { | 183 static String escapePipe(String input) { |
| 167 var result = new StringBuffer(); | 184 var result = new StringBuffer(); |
| 168 for (var c in input.codeUnits) { | 185 for (var c in input.codeUnits) { |
| 169 if (c == '\\' || c == '|') { | 186 if (c == '\\' || c == '|') { |
| 170 result.write('\\'); | 187 result.write('\\'); |
| 171 } | 188 } |
| 172 result.writeCharCode(c); | 189 result.writeCharCode(c); |
| 173 } | 190 } |
| 174 return result.toString(); | 191 return result.toString(); |
| 175 } | 192 } |
| 176 | 193 |
| 177 static String pluralize(String word, int count) { | 194 static String pluralize(String word, int count) { |
| 178 if (count == 1) { | 195 if (count == 1) { |
| 179 return word; | 196 return word; |
| 180 } else { | 197 } else { |
| 181 return word + "s"; | 198 return word + "s"; |
| 182 } | 199 } |
| 183 } | 200 } |
| 184 } | 201 } |
| OLD | NEW |