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

Unified Diff: pkg/analyzer_cli/lib/src/error_formatter.dart

Issue 1811753002: Revert "Directory support for the analyzer CLI (#25129)." [TBR] (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer_cli/lib/src/driver.dart ('k') | pkg/analyzer_cli/lib/src/package_analyzer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/lib/src/error_formatter.dart
diff --git a/pkg/analyzer_cli/lib/src/error_formatter.dart b/pkg/analyzer_cli/lib/src/error_formatter.dart
index d6bec887fceac077fc55337eb2072dae4290c0d7..0154d739978d78ad0672cfdbb29af0c6c81b6ca8 100644
--- a/pkg/analyzer_cli/lib/src/error_formatter.dart
+++ b/pkg/analyzer_cli/lib/src/error_formatter.dart
@@ -13,98 +13,19 @@ import 'package:analyzer_cli/src/options.dart';
ProcessedSeverity _identity(AnalysisError error) =>
new ProcessedSeverity(error.errorCode.errorSeverity);
-String _pluralize(String word, int count) => count == 1 ? word : word + "s";
-
/// Returns desired severity for the given [error] (or `null` if it's to be
/// suppressed).
typedef ProcessedSeverity _SeverityProcessor(AnalysisError error);
-/// Analysis statistics counter.
-class AnalysisStats {
- int errorCount;
- int hintCount;
- int lintCount;
- int warnCount;
-
- AnalysisStats() {
- init();
- }
-
- /// (Re)set initial values.
- void init() {
- errorCount = 0;
- hintCount = 0;
- lintCount = 0;
- warnCount = 0;
- }
-
- /// Print statistics to [out].
- void print(StringSink out) {
- var hasErrors = errorCount != 0;
- var hasWarns = warnCount != 0;
- var hasHints = hintCount != 0;
- var hasLints = lintCount != 0;
- bool hasContent = false;
- if (hasErrors) {
- out.write(errorCount);
- out.write(' ');
- out.write(_pluralize("error", errorCount));
- hasContent = true;
- }
- if (hasWarns) {
- if (hasContent) {
- if (!hasHints && !hasLints) {
- out.write(' and ');
- } else {
- out.write(", ");
- }
- }
- out.write(warnCount);
- out.write(' ');
- out.write(_pluralize("warning", warnCount));
- hasContent = true;
- }
- if (hasHints) {
- if (hasContent) {
- if (!hasLints) {
- out.write(' and ');
- } else {
- out.write(", ");
- }
- }
- out.write(hintCount);
- out.write(' ');
- out.write(_pluralize("hint", hintCount));
- hasContent = true;
- }
- if (hasLints) {
- if (hasContent) {
- out.write(" and ");
- }
- out.write(lintCount);
- out.write(' ');
- out.write(_pluralize("lint", lintCount));
- hasContent = true;
- }
- if (hasContent) {
- out.writeln(" found.");
- } else {
- out.writeln("No issues found");
- }
- }
-}
-
/// Helper for formatting [AnalysisError]s.
/// The two format options are a user consumable format and a machine consumable
/// format.
class ErrorFormatter {
final StringSink out;
final CommandLineOptions options;
- final AnalysisStats stats;
final _SeverityProcessor processSeverity;
- ErrorFormatter(this.out, this.options, this.stats,
- [this.processSeverity = _identity]);
+ ErrorFormatter(this.out, this.options, [this.processSeverity = _identity]);
/// Compute the severity for this [error] or `null` if this error should be
/// filtered.
@@ -191,26 +112,84 @@ class ErrorFormatter {
return error1.offset - error2.offset;
});
// Format errors.
+ int errorCount = 0;
+ int warnCount = 0;
+ int hintCount = 0;
+ int lintCount = 0;
for (AnalysisError error in errors) {
ProcessedSeverity processedSeverity = processSeverity(error);
ErrorSeverity severity = processedSeverity.severity;
if (severity == ErrorSeverity.ERROR) {
- stats.errorCount++;
+ errorCount++;
} else if (severity == ErrorSeverity.WARNING) {
/// Only treat a warning as an error if it's not been set by a
/// proccesser.
if (!processedSeverity.overridden && options.warningsAreFatal) {
- stats.errorCount++;
+ errorCount++;
} else {
- stats.warnCount++;
+ warnCount++;
}
} else if (error.errorCode.type == ErrorType.HINT) {
- stats.hintCount++;
+ hintCount++;
} else if (error.errorCode.type == ErrorType.LINT) {
- stats.lintCount++;
+ lintCount++;
}
formatError(errorToLine, error);
}
+ // Print statistics.
+ if (!options.machineFormat) {
+ var hasErrors = errorCount != 0;
+ var hasWarns = warnCount != 0;
+ var hasHints = hintCount != 0;
+ var hasLints = lintCount != 0;
+ bool hasContent = false;
+ if (hasErrors) {
+ out.write(errorCount);
+ out.write(' ');
+ out.write(pluralize("error", errorCount));
+ hasContent = true;
+ }
+ if (hasWarns) {
+ if (hasContent) {
+ if (!hasHints && !hasLints) {
+ out.write(' and ');
+ } else {
+ out.write(", ");
+ }
+ }
+ out.write(warnCount);
+ out.write(' ');
+ out.write(pluralize("warning", warnCount));
+ hasContent = true;
+ }
+ if (hasHints) {
+ if (hasContent) {
+ if (!hasLints) {
+ out.write(' and ');
+ } else {
+ out.write(", ");
+ }
+ }
+ out.write(hintCount);
+ out.write(' ');
+ out.write(pluralize("hint", hintCount));
+ hasContent = true;
+ }
+ if (hasLints) {
+ if (hasContent) {
+ out.write(" and ");
+ }
+ out.write(lintCount);
+ out.write(' ');
+ out.write(pluralize("lint", lintCount));
+ hasContent = true;
+ }
+ if (hasContent) {
+ out.writeln(" found.");
+ } else {
+ out.writeln("No issues found");
+ }
+ }
}
static String escapePipe(String input) {
@@ -223,9 +202,17 @@ class ErrorFormatter {
}
return result.toString();
}
+
+ static String pluralize(String word, int count) {
+ if (count == 1) {
+ return word;
+ } else {
+ return word + "s";
+ }
+ }
}
-/// A severity with awareness of whether it was overridden by a processor.
+/// A severity with awareness of whether it was overriden by a processor.
class ProcessedSeverity {
ErrorSeverity severity;
bool overridden;
« no previous file with comments | « pkg/analyzer_cli/lib/src/driver.dart ('k') | pkg/analyzer_cli/lib/src/package_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698