Skip to content
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: 5 additions & 1 deletion script/tool/lib/src/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const int _exitGitFailed = 6;
const int _exitDependencyMissing = 7;
const int _exitSwiftFormatFailed = 8;
const int _exitKotlinFormatFailed = 9;
const int _exitSwiftLintFoundIssues = 10;

final Uri _javaFormatterUrl = Uri.https('github.com',
'/google/google-java-format/releases/download/google-java-format-1.3/google-java-format-1.3-all-deps.jar');
Expand Down Expand Up @@ -239,7 +240,10 @@ class FormatCommand extends PackageLoopingCommand {
'--strict',
],
files: swiftFiles);
if (lintExitCode != 0) {
if (lintExitCode == 1) {
printError('Swift linter found issues. See above for linter output.');
throw ToolExit(_exitSwiftLintFoundIssues);
} else if (lintExitCode != 0) {
printError('Failed to lint Swift files: exit code $lintExitCode.');
throw ToolExit(_exitSwiftFormatFailed);
}
Expand Down
40 changes: 38 additions & 2 deletions script/tool/test/format_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void main() {
]));
});

test('fails if swift-format lint fails', () async {
test('fails if swift-format lint finds issues', () async {
const List<String> files = <String>[
'macos/foo.swift',
];
Expand Down Expand Up @@ -675,7 +675,43 @@ void main() {
expect(
output,
containsAllInOrder(<Matcher>[
contains('Failed to lint Swift files: exit code 1.'),
contains('Swift linter found issues. See above for linter output.'),
]));
});

test('fails if swift-format lint fails', () async {
const List<String> files = <String>[
'macos/foo.swift',
];
final RepositoryPackage plugin =
createFakePlugin('a_plugin', packagesDir, extraFiles: files);
fakePubGet(plugin);

processRunner.mockProcessesForExecutable['swift-format'] =
<FakeProcessInfo>[
FakeProcessInfo(MockProcess(),
<String>['--version']), // check for working swift-format
FakeProcessInfo(MockProcess(), <String>['-i']),
FakeProcessInfo(MockProcess(exitCode: 99), <String>[
'lint',
'--parallel',
'--strict',
]),
];
Error? commandError;
final List<String> output = await runCapturingPrint(runner, <String>[
'format',
'--swift',
'--swift-format-path=swift-format'
], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('Failed to lint Swift files: exit code 99.'),
]));
});

Expand Down