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

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

Issue 1810103003: Analyzer directory recursing (tk 2) (#25129). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: re-apply tk 1 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
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 0154d739978d78ad0672cfdbb29af0c6c81b6ca8..d6bec887fceac077fc55337eb2072dae4290c0d7 100644
--- a/pkg/analyzer_cli/lib/src/error_formatter.dart
+++ b/pkg/analyzer_cli/lib/src/error_formatter.dart
@@ -13,19 +13,98 @@ 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.processSeverity = _identity]);
+ ErrorFormatter(this.out, this.options, this.stats,
+ [this.processSeverity = _identity]);
/// Compute the severity for this [error] or `null` if this error should be
/// filtered.
@@ -112,84 +191,26 @@ 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) {
- errorCount++;
+ stats.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) {
- errorCount++;
+ stats.errorCount++;
} else {
- warnCount++;
+ stats.warnCount++;
}
} else if (error.errorCode.type == ErrorType.HINT) {
- hintCount++;
+ stats.hintCount++;
} else if (error.errorCode.type == ErrorType.LINT) {
- lintCount++;
+ stats.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) {
@@ -202,17 +223,9 @@ 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 overriden by a processor.
+/// A severity with awareness of whether it was overridden by a processor.
class ProcessedSeverity {
ErrorSeverity severity;
bool overridden;

Powered by Google App Engine
This is Rietveld 408576698