Add presubmit test for trailing whitespace. (#19412)
Checks only changed source files (C++, Dart, Java, ObjC) for trailing whitespace.
This commit is contained in:
@@ -95,6 +95,41 @@ Future<Null> _verifyInternationalizations() async {
|
||||
print('Contents of $localizationsFile matches output of gen_localizations.dart script.');
|
||||
}
|
||||
|
||||
Future<Null> _checkForTrailingSpaces() async {
|
||||
if (!Platform.isWindows) {
|
||||
final String commitRange = Platform.environment.containsKey('TEST_COMMIT_RANGE')
|
||||
? Platform.environment['TEST_COMMIT_RANGE']
|
||||
: 'master..HEAD';
|
||||
print('Checking for trailing whitespace in source files.');
|
||||
final List<String> fileTypes = <String>[
|
||||
'*.dart', '*.cxx', '*.cpp', '*.cc', '*.c', '*.C', '*.h', '*.java', '*.mm', '*.m',
|
||||
];
|
||||
final EvalResult changedFilesResult = await _evalCommand(
|
||||
'git', <String>['diff', '-U0', '--no-color', '--name-only', commitRange, '--'] + fileTypes,
|
||||
workingDirectory: flutterRoot,
|
||||
);
|
||||
if (changedFilesResult.stdout == null) {
|
||||
print('No Results for whitespace check.');
|
||||
return;
|
||||
}
|
||||
final List<String> changedFiles = changedFilesResult.stdout.trim().split('\n')
|
||||
.where((String item) => item.trim().isNotEmpty).toList();
|
||||
if (changedFiles.isNotEmpty) {
|
||||
await _runCommand('grep',
|
||||
<String>[
|
||||
'--line-number',
|
||||
'--extended-regexp',
|
||||
r'[[:space:]]+$',
|
||||
] + changedFiles,
|
||||
workingDirectory: flutterRoot,
|
||||
printOutput: false,
|
||||
expectFailure: true, // Just means a non-zero exit code is expected.
|
||||
expectedExitCode: 1, // Indicates that zero lines were found.
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _analyzeRepo() async {
|
||||
await _verifyGeneratedPluginRegistrants(flutterRoot);
|
||||
await _verifyNoBadImportsInFlutter(flutterRoot);
|
||||
@@ -123,6 +158,8 @@ Future<Null> _analyzeRepo() async {
|
||||
options: <String>['--flutter-repo', '--watch', '--benchmark'],
|
||||
);
|
||||
|
||||
await _checkForTrailingSpaces();
|
||||
|
||||
// Try an analysis against a big version of the gallery.
|
||||
await _runCommand(dart,
|
||||
<String>['--preview-dart-2', path.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')],
|
||||
@@ -331,6 +368,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
|
||||
String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool expectFailure = false,
|
||||
int expectedExitCode,
|
||||
bool printOutput = true,
|
||||
bool skip = false,
|
||||
Duration timeout = _kLongTimeout,
|
||||
@@ -363,7 +401,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
|
||||
stderr.writeln('Process timed out after $timeout');
|
||||
return expectFailure ? 0 : 1;
|
||||
});
|
||||
if ((exitCode == 0) == expectFailure) {
|
||||
if ((exitCode == 0) == expectFailure || (expectedExitCode != null && exitCode != expectedExitCode)) {
|
||||
if (!printOutput) {
|
||||
stdout.writeln(utf8.decode((await savedStdout).expand((List<int> ints) => ints).toList()));
|
||||
stderr.writeln(utf8.decode((await savedStderr).expand((List<int> ints) => ints).toList()));
|
||||
|
||||
@@ -59,5 +59,5 @@ elif [ "$SHARD" = "docs" ]; then
|
||||
./dev/bots/docs.sh
|
||||
fi
|
||||
else
|
||||
dart ./dev/bots/test.dart
|
||||
TEST_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}" dart ./dev/bots/test.dart
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user