From 1c590c100cb064aa0269d859e0a876408fe62131 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 26 Feb 2024 13:05:23 -0500 Subject: [PATCH] [tool] Ignore GeneratedPluginRegistrant.swift for `format` (#6195) This file fails `swift-format lint`, so including it in `format` causes lots of warnings when run locally. --- script/tool/lib/src/format_command.dart | 2 + script/tool/test/format_command_test.dart | 46 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/script/tool/lib/src/format_command.dart b/script/tool/lib/src/format_command.dart index f2713666435b..3091cf2e11f3 100644 --- a/script/tool/lib/src/format_command.dart +++ b/script/tool/lib/src/format_command.dart @@ -346,6 +346,8 @@ class FormatCommand extends PackageCommand { pathFragmentForDirectories(['example', 'build'])) && // Ignore files in Pods, which are not part of the repository. !path.contains(pathFragmentForDirectories(['Pods'])) && + // See https://github.com/flutter/flutter/issues/144039 + !path.endsWith('GeneratedPluginRegistrant.swift') && // Ignore .dart_tool/, which can have various intermediate files. !path.contains(pathFragmentForDirectories(['.dart_tool']))) .toList(); diff --git a/script/tool/test/format_command_test.dart b/script/tool/test/format_command_test.dart index cc6019862bae..d05aa14c2de8 100644 --- a/script/tool/test/format_command_test.dart +++ b/script/tool/test/format_command_test.dart @@ -737,6 +737,52 @@ void main() { ])); }); + test('skips GeneratedPluginRegistrant.swift', () async { + const String sourceFile = 'macos/Classes/Foo.swift'; + final RepositoryPackage plugin = createFakePlugin( + 'a_plugin', + packagesDir, + extraFiles: [ + sourceFile, + 'example/macos/Flutter/GeneratedPluginRegistrant.swift', + ], + ); + + await runCapturingPrint(runner, [ + 'format', + '--swift', + '--swift-format-path=/path/to/swift-format' + ]); + + expect( + processRunner.recordedCalls, + orderedEquals([ + const ProcessCall( + '/path/to/swift-format', + ['--version'], + null, + ), + ProcessCall( + '/path/to/swift-format', + [ + '-i', + ...getPackagesDirRelativePaths(plugin, [sourceFile]) + ], + packagesDir.path, + ), + ProcessCall( + '/path/to/swift-format', + [ + 'lint', + '--parallel', + '--strict', + ...getPackagesDirRelativePaths(plugin, [sourceFile]), + ], + packagesDir.path, + ), + ])); + }); + test('fails if files are changed with --fail-on-change', () async { const List files = [ 'linux/foo_plugin.cc',