Skip to content

Commit 7e151b4

Browse files
[flutter_tools] throw tool exit on invocation of flutter format (#121646)
[flutter_tools] throw tool exit on invocation of flutter format
1 parent 7003bfa commit 7e151b4

File tree

4 files changed

+9
-193
lines changed

4 files changed

+9
-193
lines changed

packages/flutter_tools/lib/executable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ List<FlutterCommand> generateCommands({
199199
signals: globals.signals,
200200
),
201201
EmulatorsCommand(),
202-
FormatCommand(verboseHelp: verboseHelp),
202+
FormatCommand(),
203203
GenerateCommand(),
204204
GenerateLocalizationsCommand(
205205
fileSystem: globals.fs,

packages/flutter_tools/lib/src/commands/format.dart

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,36 @@
44

55
import 'package:args/args.dart';
66

7-
import '../artifacts.dart';
87
import '../base/common.dart';
9-
import '../globals.dart' as globals;
108
import '../runner/flutter_command.dart';
119

1210
class FormatCommand extends FlutterCommand {
13-
FormatCommand({required this.verboseHelp});
11+
FormatCommand();
1412

1513
@override
1614
ArgParser argParser = ArgParser.allowAnything();
1715

18-
final bool verboseHelp;
19-
2016
@override
2117
final String name = 'format';
2218

2319
@override
2420
List<String> get aliases => const <String>['dartfmt'];
2521

2622
@override
27-
final String description = 'Format one or more Dart files.';
28-
29-
@override
30-
String get category => FlutterCommandCategory.project;
23+
String get description => deprecationWarning;
3124

3225
@override
33-
String get invocation => '${runner?.executableName} $name <one or more paths>';
34-
35-
@override
36-
final bool deprecated = true;
26+
final bool hidden = true;
3727

3828
@override
3929
String get deprecationWarning {
40-
return '${globals.logger.terminal.warningMark} The "format" command is '
41-
'deprecated and will be removed in a future version of Flutter. '
42-
'Please use the "dart format" sub-command instead, which takes all '
43-
'of the same command-line arguments as "flutter format".\n';
30+
return 'The "format" command is deprecated. Please use the "dart format" '
31+
'sub-command instead, which has the same command-line usage as '
32+
'"flutter format".\n';
4433
}
4534

4635
@override
4736
Future<FlutterCommandResult> runCommand() async {
48-
final String dartBinary = globals.artifacts!.getArtifactPath(Artifact.engineDartBinary);
49-
final List<String> command = <String>[
50-
dartBinary,
51-
'format',
52-
];
53-
final List<String> rest = argResults?.rest ?? <String>[];
54-
if (rest.isEmpty) {
55-
globals.printError(
56-
'No files specified to be formatted.'
57-
);
58-
command.add('-h');
59-
} else {
60-
command.addAll(<String>[
61-
for (String arg in rest)
62-
if (arg == '--dry-run' || arg == '-n')
63-
'--output=none'
64-
else
65-
arg,
66-
]);
67-
}
68-
69-
final int result = await globals.processUtils.stream(command);
70-
if (result != 0) {
71-
throwToolExit('Formatting failed: $result', exitCode: result);
72-
}
73-
74-
return FlutterCommandResult.success();
37+
throwToolExit(deprecationWarning);
7538
}
7639
}

packages/flutter_tools/test/commands.shard/permeable/format_test.dart

Lines changed: 0 additions & 147 deletions
This file was deleted.

packages/flutter_tools/test/general.shard/args_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323
).forEach(runner.addCommand);
2424
verifyCommandRunner(runner);
2525
for (final Command<void> command in runner.commands.values) {
26-
if(command.name == 'analyze') {
26+
if (command.name == 'analyze') {
2727
final AnalyzeCommand analyze = command as AnalyzeCommand;
2828
expect(analyze.allProjectValidators().length, 2);
2929
}

0 commit comments

Comments
 (0)