From 0dd1669599fe6da319ae4aafc8376a798480adf8 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 11 Jan 2023 14:11:35 -0800 Subject: [PATCH] [tool] Replace `flutter format` (#6946) `flutter format` is deprecated on `master`, and prints a warning saying to switch to `dart format` instead. This updates `format` to make that switch. --- script/tool/CHANGELOG.md | 5 +++++ script/tool/lib/src/format_command.dart | 6 ++---- script/tool/pubspec.yaml | 2 +- script/tool/test/format_command_test.dart | 17 +++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 072d661f8d99..ffb56bd7a7a4 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.13.2+1 + +* Replaces deprecated `flutter format` with `dart format` in `format` + implementation. + ## 0.13.2 * Falls back to other executables in PATH when `clang-format` does not run. diff --git a/script/tool/lib/src/format_command.dart b/script/tool/lib/src/format_command.dart index 43c450cbcf7c..e4236878658c 100644 --- a/script/tool/lib/src/format_command.dart +++ b/script/tool/lib/src/format_command.dart @@ -191,10 +191,8 @@ class FormatCommand extends PackageCommand { _getPathsWithExtensions(files, {'.dart'}); if (dartFiles.isNotEmpty) { print('Formatting .dart files...'); - // `flutter format` doesn't require the project to actually be a Flutter - // project. - final int exitCode = await _runBatched(flutterCommand, ['format'], - files: dartFiles); + final int exitCode = + await _runBatched('dart', ['format'], files: dartFiles); if (exitCode != 0) { printError('Failed to format Dart files: exit code $exitCode.'); throw ToolExit(_exitFlutterFormatFailed); diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index ea20364d51d5..5438726d5bca 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_plugin_tools description: Productivity utils for flutter/plugins and flutter/packages repository: https://github.com/flutter/plugins/tree/main/script/tool -version: 0.13.2 +version: 0.13.2+1 dependencies: args: ^2.1.0 diff --git a/script/tool/test/format_command_test.dart b/script/tool/test/format_command_test.dart index 1aadafbd3d82..634a996bccc6 100644 --- a/script/tool/test/format_command_test.dart +++ b/script/tool/test/format_command_test.dart @@ -98,7 +98,7 @@ void main() { processRunner.recordedCalls, orderedEquals([ ProcessCall( - getFlutterCommand(mockPlatform), + 'dart', ['format', ...getPackagesDirRelativePaths(plugin, files)], packagesDir.path), ])); @@ -132,7 +132,7 @@ void main() { processRunner.recordedCalls, orderedEquals([ ProcessCall( - getFlutterCommand(mockPlatform), + 'dart', [ 'format', ...getPackagesDirRelativePaths(plugin, formattedFiles) @@ -141,7 +141,7 @@ void main() { ])); }); - test('fails if flutter format fails', () async { + test('fails if dart format fails', () async { const List files = [ 'lib/a.dart', 'lib/src/b.dart', @@ -149,8 +149,9 @@ void main() { ]; createFakePlugin('a_plugin', packagesDir, extraFiles: files); - processRunner.mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = - [MockProcess(exitCode: 1)]; + processRunner.mockProcessesForExecutable['dart'] = [ + MockProcess(exitCode: 1) + ]; Error? commandError; final List output = await runCapturingPrint( runner, ['format'], errorHandler: (Error e) { @@ -465,7 +466,7 @@ void main() { ], packagesDir.path), ProcessCall( - getFlutterCommand(mockPlatform), + 'dart', [ 'format', ...getPackagesDirRelativePaths(plugin, dartFiles) @@ -594,7 +595,7 @@ void main() { processRunner.recordedCalls, contains( ProcessCall( - getFlutterCommand(mockPlatform), + 'dart', [ 'format', '$pluginName\\$extraFile', @@ -651,7 +652,7 @@ void main() { processRunner.recordedCalls, contains( ProcessCall( - getFlutterCommand(mockPlatform), + 'dart', [ 'format', '$pluginName/$extraFile',