Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[tool] Replace flutter format #6946

Merged
merged 1 commit into from
Jan 11, 2023
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
5 changes: 5 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 2 additions & 4 deletions script/tool/lib/src/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ class FormatCommand extends PackageCommand {
_getPathsWithExtensions(files, <String>{'.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, <String>['format'],
files: dartFiles);
final int exitCode =
await _runBatched('dart', <String>['format'], files: dartFiles);
if (exitCode != 0) {
printError('Failed to format Dart files: exit code $exitCode.');
throw ToolExit(_exitFlutterFormatFailed);
Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 9 additions & 8 deletions script/tool/test/format_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void main() {
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
'dart',
<String>['format', ...getPackagesDirRelativePaths(plugin, files)],
packagesDir.path),
]));
Expand Down Expand Up @@ -132,7 +132,7 @@ void main() {
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
'dart',
<String>[
'format',
...getPackagesDirRelativePaths(plugin, formattedFiles)
Expand All @@ -141,16 +141,17 @@ void main() {
]));
});

test('fails if flutter format fails', () async {
test('fails if dart format fails', () async {
const List<String> files = <String>[
'lib/a.dart',
'lib/src/b.dart',
'lib/src/c.dart',
];
createFakePlugin('a_plugin', packagesDir, extraFiles: files);

processRunner.mockProcessesForExecutable[getFlutterCommand(mockPlatform)] =
<io.Process>[MockProcess(exitCode: 1)];
processRunner.mockProcessesForExecutable['dart'] = <io.Process>[
MockProcess(exitCode: 1)
];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['format'], errorHandler: (Error e) {
Expand Down Expand Up @@ -465,7 +466,7 @@ void main() {
],
packagesDir.path),
ProcessCall(
getFlutterCommand(mockPlatform),
'dart',
<String>[
'format',
...getPackagesDirRelativePaths(plugin, dartFiles)
Expand Down Expand Up @@ -594,7 +595,7 @@ void main() {
processRunner.recordedCalls,
contains(
ProcessCall(
getFlutterCommand(mockPlatform),
'dart',
<String>[
'format',
'$pluginName\\$extraFile',
Expand Down Expand Up @@ -651,7 +652,7 @@ void main() {
processRunner.recordedCalls,
contains(
ProcessCall(
getFlutterCommand(mockPlatform),
'dart',
<String>[
'format',
'$pluginName/$extraFile',
Expand Down