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

Commit 2ef2cc8

Browse files
[flutter_tools] add deprecation message for "flutter format" (#116145)
1 parent a29796e commit 2ef2cc8

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ class FormatCommand extends FlutterCommand {
3232
@override
3333
String get invocation => '${runner?.executableName} $name <one or more paths>';
3434

35+
@override
36+
final bool deprecated = true;
37+
38+
@override
39+
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';
44+
}
45+
3546
@override
3647
Future<FlutterCommandResult> runCommand() async {
3748
final String dartBinary = globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;

packages/flutter_tools/lib/src/runner/flutter_command.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -1269,14 +1269,17 @@ abstract class FlutterCommand extends Command<void> {
12691269
);
12701270
}
12711271

1272+
@visibleForOverriding
1273+
String get deprecationWarning {
1274+
return '${globals.logger.terminal.warningMark} The "$name" command is '
1275+
'deprecated and will be removed in a future version of Flutter. '
1276+
'See https://flutter.dev/docs/development/tools/sdk/releases '
1277+
'for previous releases of Flutter.\n';
1278+
}
1279+
12721280
void _printDeprecationWarning() {
12731281
if (deprecated) {
1274-
globals.printWarning(
1275-
'${globals.logger.terminal.warningMark} The "$name" command is deprecated and '
1276-
'will be removed in a future version of Flutter. '
1277-
'See https://flutter.dev/docs/development/tools/sdk/releases '
1278-
'for previous releases of Flutter.\n',
1279-
);
1282+
globals.printWarning(deprecationWarning);
12801283
}
12811284
}
12821285

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

+24-5
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,48 @@
44

55
import 'package:args/command_runner.dart';
66
import 'package:flutter_tools/src/base/file_system.dart';
7-
import 'package:flutter_tools/src/base/io.dart';
7+
import 'package:flutter_tools/src/base/logger.dart';
88
import 'package:flutter_tools/src/cache.dart';
99
import 'package:flutter_tools/src/commands/format.dart';
1010
import 'package:flutter_tools/src/globals.dart' as globals;
1111

1212
import '../../src/common.dart';
1313
import '../../src/context.dart';
14-
import '../../src/fakes.dart';
1514
import '../../src/test_flutter_command_runner.dart';
1615

1716
void main() {
1817
group('format', () {
1918
late Directory tempDir;
20-
late FakeStdio mockStdio;
19+
late BufferLogger logger;
2120

2221
setUp(() {
2322
Cache.disableLocking();
2423
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_format_test.');
25-
mockStdio = FakeStdio();
24+
logger = BufferLogger.test();
2625
});
2726

2827
tearDown(() {
2928
tryToDelete(tempDir);
3029
});
3130

31+
testUsingContext('shows deprecation warning', () async {
32+
final String projectPath = await createProject(tempDir);
33+
34+
final File srcFile = globals.fs.file(globals.fs.path.join(projectPath, 'lib', 'main.dart'));
35+
final String original = srcFile.readAsStringSync();
36+
srcFile.writeAsStringSync(original);
37+
38+
final FormatCommand command = FormatCommand(verboseHelp: false);
39+
final CommandRunner<void> runner = createTestCommandRunner(command);
40+
await runner.run(<String>['format', srcFile.path]);
41+
expect(
42+
logger.warningText,
43+
contains('The "format" command is deprecated and will be removed in a future version of Flutter'),
44+
);
45+
}, overrides: <Type, Generator>{
46+
Logger: () => logger,
47+
});
48+
3249
testUsingContext('a file', () async {
3350
final String projectPath = await createProject(tempDir);
3451

@@ -43,7 +60,7 @@ void main() {
4360
final String formatted = srcFile.readAsStringSync();
4461
expect(formatted, original);
4562
}, overrides: <Type, Generator>{
46-
Stdio: () => mockStdio,
63+
Logger: () => logger,
4764
});
4865

4966
testUsingContext('dry-run', () async {
@@ -61,6 +78,8 @@ void main() {
6178

6279
final String shouldNotFormatted = srcFile.readAsStringSync();
6380
expect(shouldNotFormatted, nonFormatted);
81+
}, overrides: <Type, Generator>{
82+
Logger: () => logger,
6483
});
6584

6685
testUsingContext('dry-run with -n', () async {

0 commit comments

Comments
 (0)