Commit 4631717f authored by Devon Carew's avatar Devon Carew Committed by GitHub

De-duplicate the dartanalyzer command output (#9441)

parent 79afc775
......@@ -118,7 +118,7 @@ Future<Null> _pubRunTest(
String workingDirectory, {
String testPath,
}) {
final List<String> args = <String>['run', 'test'];
final List<String> args = <String>['run', 'test', '-rexpanded'];
if (testPath != null)
args.add(testPath);
return _runCommand(pub, args, workingDirectory: workingDirectory);
......
......@@ -11,6 +11,7 @@ import 'package:yaml/yaml.dart' as yaml;
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/process.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../dart/analysis.dart';
import '../globals.dart';
......@@ -83,19 +84,34 @@ class AnalyzeOnce extends AnalyzeBase {
final String dartanalyzer = fs.path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dartanalyzer');
arguments.insert(0, dartanalyzer);
bool noErrors = false;
final Set<String> issues = new Set<String>();
int exitCode = await runCommandAndStreamOutput(
arguments,
workingDirectory: workingDirectory?.path,
mapFunction: (String line) {
// De-duplicate the dartanalyzer command output (https://github.com/dart-lang/sdk/issues/25697).
if (line.startsWith(' ')) {
if (!issues.add(line.trim()))
return null;
}
// Workaround for the fact that dartanalyzer does not exit with a non-zero exit code
// when errors are found.
// TODO(danrubel): Fix dartanalyzer to return non-zero exit code
if (line == 'No issues found!')
noErrors = true;
// Remove text about the issue count ('2 hints found.'); with the duplicates
// above, the printed count would be incorrect.
if (line.endsWith(' found.'))
return null;
return line;
},
);
stopwatch.stop();
if (issues.isNotEmpty)
printStatus('${issues.length} ${pluralize('issue', issues.length)} found.');
final String elapsed = (stopwatch.elapsedMilliseconds / 1000.0).toStringAsFixed(1);
// Workaround for the fact that dartanalyzer does not exit with a non-zero exit code
// when errors are found.
......
......@@ -84,14 +84,14 @@ void main() {
);
await libMain.writeAsString(source);
/// Analyze in the current directory - no arguments
// Analyze in the current directory - no arguments
await runCommand(
command: new AnalyzeCommand(workingDirectory: tempDir),
arguments: <String>['analyze'],
statusTextContains: <String>[
'Analyzing',
'warning $analyzerSeparator The parameter \'child\' is required',
'1 warning found.',
'1 issue found.',
],
toolExit: true,
);
......@@ -105,7 +105,7 @@ void main() {
statusTextContains: <String>[
'Analyzing',
'warning $analyzerSeparator The parameter \'child\' is required',
'1 warning found.',
'1 issue found.',
],
toolExit: true,
);
......@@ -124,7 +124,7 @@ void main() {
- only_throw_errors
''');
/// Analyze in the current directory - no arguments
// Analyze in the current directory - no arguments
await runCommand(
command: new AnalyzeCommand(workingDirectory: tempDir),
arguments: <String>['analyze'],
......@@ -132,12 +132,46 @@ void main() {
'Analyzing',
'warning $analyzerSeparator The parameter \'child\' is required',
'lint $analyzerSeparator Only throw instances of classes extending either Exception or Error',
'1 warning and 1 lint found.',
'2 issues found.',
],
toolExit: true,
);
});
testUsingContext('flutter analyze no duplicate issues', () async {
final Directory tempDir = fs.systemTempDirectory.createTempSync('analyze_once_test_').absolute;
try {
final File foo = fs.file(fs.path.join(tempDir.path, 'foo.dart'));
foo.writeAsStringSync('''
import 'bar.dart';
foo() => bar();
''');
final File bar = fs.file(fs.path.join(tempDir.path, 'bar.dart'));
bar.writeAsStringSync('''
import 'dart:async'; // unused
void bar() {
}
''');
// Analyze in the current directory - no arguments
await runCommand(
command: new AnalyzeCommand(workingDirectory: tempDir),
arguments: <String>['analyze'],
statusTextContains: <String>[
'Analyzing',
'1 issue found.',
],
toolExit: true,
);
} finally {
tempDir.deleteSync(recursive: true);
}
});
// Analyze a specific file outside the current directory
testUsingContext('flutter analyze one file with local options', () async {
await runCommand(
......@@ -147,7 +181,7 @@ void main() {
'Analyzing',
'warning $analyzerSeparator The parameter \'child\' is required',
'lint $analyzerSeparator Only throw instances of classes extending either Exception or Error',
'1 warning and 1 lint found.',
'2 issues found.',
],
toolExit: true,
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment