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

Add a --quiet option. #55

Merged
merged 1 commit into from
Mar 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'dart:io';

import 'package:analyzer/src/generated/engine.dart';
import 'package:args/args.dart';
import 'package:linter/src/config.dart';
import 'package:linter/src/formatter.dart';
import 'package:linter/src/io.dart';
import 'package:linter/src/linter.dart';
import 'package:linter/src/config.dart';

void main(List<String> args) {
var parser = new ArgParser(allowTrailingOptions: true);
Expand All @@ -21,6 +21,7 @@ void main(List<String> args) {
abbr: "s", negatable: false, help: "Show lint statistics.")
..addFlag('visit-transitive-closure',
help: 'Visit the transitive closure of imported/exported libraries.')
..addFlag('quiet', abbr: 'q', help: "Don't show individual lint errors.")
..addOption('config', abbr: 'c', help: 'Use configuration from this file.')
..addOption('dart-sdk', help: 'Custom path to a Dart SDK.')
..addOption('package-root',
Expand Down Expand Up @@ -84,7 +85,8 @@ void main(List<String> args) {
errors, lintOptions.filter, outSink,
fileCount: filesToLint.length,
fileRoot: commonRoot,
showStatistics: stats);
showStatistics: stats,
quiet: options['quiet']);
reporter.write();
} catch (err, stack) {
errorSink.writeln('''An error occurred while linting
Expand Down
34 changes: 21 additions & 13 deletions lib/src/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ String shorten(String fileRoot, String fullName) {
class DetailedReporter extends SimpleFormatter {
DetailedReporter(
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
{int fileCount, String fileRoot, bool showStatistics: false})
{int fileCount, String fileRoot, bool showStatistics: false,
quiet: false})
: super(errors, filter, out,
fileCount: fileCount,
fileRoot: fileRoot,
showStatistics: showStatistics);
showStatistics: showStatistics,
quiet: quiet);

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

abstract class ReportFormatter {
factory ReportFormatter(
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
{int fileCount, String fileRoot, bool showStatistics: false}) =>
new DetailedReporter(errors, filter, out,
fileCount: fileCount,
fileRoot: fileRoot,
showStatistics: showStatistics);
Iterable<AnalysisErrorInfo> errors, LintFilter filter, IOSink out,
{int fileCount, String fileRoot, bool showStatistics: false,
bool quiet: false}) => new DetailedReporter(errors, filter, out,
fileCount: fileCount,
fileRoot: fileRoot,
showStatistics: showStatistics,
quiet: quiet);

write();
}
Expand All @@ -98,14 +101,15 @@ class SimpleFormatter implements ReportFormatter {
final int fileCount;
final String fileRoot;
final bool showStatistics;
final bool quiet;

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

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

SimpleFormatter(this.errors, this.filter, this.out,
{this.fileCount, this.fileRoot, this.showStatistics: false});
SimpleFormatter(this.errors, this.filter, this.out, {this.fileCount,
this.fileRoot, this.showStatistics: false, this.quiet: false});

/// Override to influence error sorting
int compare(AnalysisError error1, AnalysisError error2) {
Expand Down Expand Up @@ -148,10 +152,15 @@ class SimpleFormatter implements ReportFormatter {
filteredLintCount++;
} else {
++errorCount;
_writeLint(e, info.lineInfo);
if (!quiet) {
_writeLint(e, info.lineInfo);
}
_recordStats(e);
}
}));
out.writeln();
if (!quiet) {
out.writeln();
}
}

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

writeLint(error, offset: offset, column: column, line: line);
_recordStats(error);
}
}