[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] add deprecation message for "flutter format" #116145

Merged
merged 2 commits into from
Nov 30, 2022
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
11 changes: 11 additions & 0 deletions packages/flutter_tools/lib/src/commands/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class FormatCommand extends FlutterCommand {
@override
String get invocation => '${runner?.executableName} $name <one or more paths>';

@override
final bool deprecated = true;

@override
String get deprecationWarning {
return '${globals.logger.terminal.warningMark} The "format" command is '
'deprecated and will be removed in a future version of Flutter. '
'Please use the "dart format" sub-command instead, which takes all '
'of the same command-line arguments as "flutter format".\n';
}

@override
Future<FlutterCommandResult> runCommand() async {
final String dartBinary = globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;
Expand Down
15 changes: 9 additions & 6 deletions packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1269,14 +1269,17 @@ abstract class FlutterCommand extends Command<void> {
);
}

@visibleForOverriding
String get deprecationWarning {
return '${globals.logger.terminal.warningMark} The "$name" command is '
'deprecated and will be removed in a future version of Flutter. '
'See https://flutter.dev/docs/development/tools/sdk/releases '
'for previous releases of Flutter.\n';
}

void _printDeprecationWarning() {
if (deprecated) {
globals.printWarning(
'${globals.logger.terminal.warningMark} The "$name" command is deprecated and '
'will be removed in a future version of Flutter. '
'See https://flutter.dev/docs/development/tools/sdk/releases '
'for previous releases of Flutter.\n',
);
globals.printWarning(deprecationWarning);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,48 @@

import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/format.dart';
import 'package:flutter_tools/src/globals.dart' as globals;

import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';

void main() {
group('format', () {
late Directory tempDir;
late FakeStdio mockStdio;
late BufferLogger logger;

setUp(() {
Cache.disableLocking();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_format_test.');
mockStdio = FakeStdio();
logger = BufferLogger.test();
});

tearDown(() {
tryToDelete(tempDir);
});

testUsingContext('shows deprecation warning', () async {
final String projectPath = await createProject(tempDir);

final File srcFile = globals.fs.file(globals.fs.path.join(projectPath, 'lib', 'main.dart'));
final String original = srcFile.readAsStringSync();
srcFile.writeAsStringSync(original);

final FormatCommand command = FormatCommand(verboseHelp: false);
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['format', srcFile.path]);
expect(
logger.warningText,
contains('The "format" command is deprecated and will be removed in a future version of Flutter'),
);
}, overrides: <Type, Generator>{
Logger: () => logger,
});

testUsingContext('a file', () async {
final String projectPath = await createProject(tempDir);

Expand All @@ -43,7 +60,7 @@ void main() {
final String formatted = srcFile.readAsStringSync();
expect(formatted, original);
}, overrides: <Type, Generator>{
Stdio: () => mockStdio,
Logger: () => logger,
});

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

final String shouldNotFormatted = srcFile.readAsStringSync();
expect(shouldNotFormatted, nonFormatted);
}, overrides: <Type, Generator>{
Logger: () => logger,
});

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