Skip to content

Commit 0dd1669

Browse files
[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.
1 parent 44098fe commit 0dd1669

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

script/tool/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.13.2+1
2+
3+
* Replaces deprecated `flutter format` with `dart format` in `format`
4+
implementation.
5+
16
## 0.13.2
27

38
* Falls back to other executables in PATH when `clang-format` does not run.

script/tool/lib/src/format_command.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,8 @@ class FormatCommand extends PackageCommand {
191191
_getPathsWithExtensions(files, <String>{'.dart'});
192192
if (dartFiles.isNotEmpty) {
193193
print('Formatting .dart files...');
194-
// `flutter format` doesn't require the project to actually be a Flutter
195-
// project.
196-
final int exitCode = await _runBatched(flutterCommand, <String>['format'],
197-
files: dartFiles);
194+
final int exitCode =
195+
await _runBatched('dart', <String>['format'], files: dartFiles);
198196
if (exitCode != 0) {
199197
printError('Failed to format Dart files: exit code $exitCode.');
200198
throw ToolExit(_exitFlutterFormatFailed);

script/tool/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/main/script/tool
4-
version: 0.13.2
4+
version: 0.13.2+1
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/format_command_test.dart

+9-8
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void main() {
9898
processRunner.recordedCalls,
9999
orderedEquals(<ProcessCall>[
100100
ProcessCall(
101-
getFlutterCommand(mockPlatform),
101+
'dart',
102102
<String>['format', ...getPackagesDirRelativePaths(plugin, files)],
103103
packagesDir.path),
104104
]));
@@ -132,7 +132,7 @@ void main() {
132132
processRunner.recordedCalls,
133133
orderedEquals(<ProcessCall>[
134134
ProcessCall(
135-
getFlutterCommand(mockPlatform),
135+
'dart',
136136
<String>[
137137
'format',
138138
...getPackagesDirRelativePaths(plugin, formattedFiles)
@@ -141,16 +141,17 @@ void main() {
141141
]));
142142
});
143143

144-
test('fails if flutter format fails', () async {
144+
test('fails if dart format fails', () async {
145145
const List<String> files = <String>[
146146
'lib/a.dart',
147147
'lib/src/b.dart',
148148
'lib/src/c.dart',
149149
];
150150
createFakePlugin('a_plugin', packagesDir, extraFiles: files);
151151

152-
processRunner.mockProcessesForExecutable[getFlutterCommand(mockPlatform)] =
153-
<io.Process>[MockProcess(exitCode: 1)];
152+
processRunner.mockProcessesForExecutable['dart'] = <io.Process>[
153+
MockProcess(exitCode: 1)
154+
];
154155
Error? commandError;
155156
final List<String> output = await runCapturingPrint(
156157
runner, <String>['format'], errorHandler: (Error e) {
@@ -465,7 +466,7 @@ void main() {
465466
],
466467
packagesDir.path),
467468
ProcessCall(
468-
getFlutterCommand(mockPlatform),
469+
'dart',
469470
<String>[
470471
'format',
471472
...getPackagesDirRelativePaths(plugin, dartFiles)
@@ -594,7 +595,7 @@ void main() {
594595
processRunner.recordedCalls,
595596
contains(
596597
ProcessCall(
597-
getFlutterCommand(mockPlatform),
598+
'dart',
598599
<String>[
599600
'format',
600601
'$pluginName\\$extraFile',
@@ -651,7 +652,7 @@ void main() {
651652
processRunner.recordedCalls,
652653
contains(
653654
ProcessCall(
654-
getFlutterCommand(mockPlatform),
655+
'dart',
655656
<String>[
656657
'format',
657658
'$pluginName/$extraFile',

0 commit comments

Comments
 (0)