diff --git a/script/tool/lib/src/format_command.dart b/script/tool/lib/src/format_command.dart index a646cbfde5f..5fbcd93265b 100644 --- a/script/tool/lib/src/format_command.dart +++ b/script/tool/lib/src/format_command.dart @@ -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'); @@ -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); } diff --git a/script/tool/test/format_command_test.dart b/script/tool/test/format_command_test.dart index 670cc0c1586..eb4f3bb7bcd 100644 --- a/script/tool/test/format_command_test.dart +++ b/script/tool/test/format_command_test.dart @@ -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 files = [ 'macos/foo.swift', ]; @@ -675,7 +675,43 @@ void main() { expect( output, containsAllInOrder([ - 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 files = [ + 'macos/foo.swift', + ]; + final RepositoryPackage plugin = + createFakePlugin('a_plugin', packagesDir, extraFiles: files); + fakePubGet(plugin); + + processRunner.mockProcessesForExecutable['swift-format'] = + [ + FakeProcessInfo(MockProcess(), + ['--version']), // check for working swift-format + FakeProcessInfo(MockProcess(), ['-i']), + FakeProcessInfo(MockProcess(exitCode: 99), [ + 'lint', + '--parallel', + '--strict', + ]), + ]; + Error? commandError; + final List output = await runCapturingPrint(runner, [ + 'format', + '--swift', + '--swift-format-path=swift-format' + ], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('Failed to lint Swift files: exit code 99.'), ])); });