Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 869d168

Browse files
committed
Merge pull request #55 from stereotype441/add-quiet-option
Add a --quiet option.
2 parents 38ef91a + c6d72a4 commit 869d168

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

bin/linter.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import 'dart:io';
66

77
import 'package:analyzer/src/generated/engine.dart';
88
import 'package:args/args.dart';
9+
import 'package:linter/src/config.dart';
910
import 'package:linter/src/formatter.dart';
1011
import 'package:linter/src/io.dart';
1112
import 'package:linter/src/linter.dart';
12-
import 'package:linter/src/config.dart';
1313

1414
void main(List<String> args) {
1515
var parser = new ArgParser(allowTrailingOptions: true);
@@ -21,6 +21,7 @@ void main(List<String> args) {
2121
abbr: "s", negatable: false, help: "Show lint statistics.")
2222
..addFlag('visit-transitive-closure',
2323
help: 'Visit the transitive closure of imported/exported libraries.')
24+
..addFlag('quiet', abbr: 'q', help: "Don't show individual lint errors.")
2425
..addOption('config', abbr: 'c', help: 'Use configuration from this file.')
2526
..addOption('dart-sdk', help: 'Custom path to a Dart SDK.')
2627
..addOption('package-root',
@@ -84,7 +85,8 @@ void main(List<String> args) {
8485
errors, lintOptions.filter, outSink,
8586
fileCount: filesToLint.length,
8687
fileRoot: commonRoot,
87-
showStatistics: stats);
88+
showStatistics: stats,
89+
quiet: options['quiet']);
8890
reporter.write();
8991
} catch (err, stack) {
9092
errorSink.writeln('''An error occurred while linting

lib/src/formatter.dart

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ String shorten(String fileRoot, String fullName) {
5454
class DetailedReporter extends SimpleFormatter {
5555
DetailedReporter(
5656
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
57-
{int fileCount, String fileRoot, bool showStatistics: false})
57+
{int fileCount, String fileRoot, bool showStatistics: false,
58+
quiet: false})
5859
: super(errors, filter, out,
5960
fileCount: fileCount,
6061
fileRoot: fileRoot,
61-
showStatistics: showStatistics);
62+
showStatistics: showStatistics,
63+
quiet: quiet);
6264

6365
@override
6466
writeLint(AnalysisError error, {int offset, int line, int column}) {
@@ -76,12 +78,13 @@ class DetailedReporter extends SimpleFormatter {
7678

7779
abstract class ReportFormatter {
7880
factory ReportFormatter(
79-
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
80-
{int fileCount, String fileRoot, bool showStatistics: false}) =>
81-
new DetailedReporter(errors, filter, out,
82-
fileCount: fileCount,
83-
fileRoot: fileRoot,
84-
showStatistics: showStatistics);
81+
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
82+
{int fileCount, String fileRoot, bool showStatistics: false,
83+
bool quiet: false}) => new DetailedReporter(errors, filter, out,
84+
fileCount: fileCount,
85+
fileRoot: fileRoot,
86+
showStatistics: showStatistics,
87+
quiet: quiet);
8588

8689
write();
8790
}
@@ -98,14 +101,15 @@ class SimpleFormatter implements ReportFormatter {
98101
final int fileCount;
99102
final String fileRoot;
100103
final bool showStatistics;
104+
final bool quiet;
101105

102106
/// Cached for the purposes of statistics report formatting.
103107
int _summaryLength = 0;
104108

105109
Map<String, int> stats = <String, int>{};
106110

107-
SimpleFormatter(this.errors, this.filter, this.out,
108-
{this.fileCount, this.fileRoot, this.showStatistics: false});
111+
SimpleFormatter(this.errors, this.filter, this.out, {this.fileCount,
112+
this.fileRoot, this.showStatistics: false, this.quiet: false});
109113

110114
/// Override to influence error sorting
111115
int compare(AnalysisError error1, AnalysisError error2) {
@@ -148,10 +152,15 @@ class SimpleFormatter implements ReportFormatter {
148152
filteredLintCount++;
149153
} else {
150154
++errorCount;
151-
_writeLint(e, info.lineInfo);
155+
if (!quiet) {
156+
_writeLint(e, info.lineInfo);
157+
}
158+
_recordStats(e);
152159
}
153160
}));
154-
out.writeln();
161+
if (!quiet) {
162+
out.writeln();
163+
}
155164
}
156165

157166
void writeStatistics() {
@@ -193,6 +202,5 @@ class SimpleFormatter implements ReportFormatter {
193202
var column = lineInfo.getLocation(offset).columnNumber;
194203

195204
writeLint(error, offset: offset, column: column, line: line);
196-
_recordStats(error);
197205
}
198206
}

0 commit comments

Comments
 (0)