Skip to content

Commit d1a06cf

Browse files
jwrencommit-bot@chromium.org
authored andcommitted
Update dartdev to use the format command object from dart_style.
I thought that this landed over a month ago. This needs to be rolled into the Dart SDK 2.9 New output from dart format --help: Idiomatically formats Dart source code. Usage: dart format [options...] <files or directories...> -h, --help Print this usage information. Common options: -o, --output Where formatted output should be written. [json] Print code and selection as JSON [none] Discard. [show] Print code to terminal. [write] (default) Overwrite formatted files on disc. --show Which filenames to print. [all] All visited files and directories. [changed] (default) Only the names of files whose formatting is changed. [none] No file names or directories. --summary Summary shown after formatting completes. [line] (default) Single line summary. [none] No summary. [profile] Tracks how long it took for format each file. Non-whitespace fixes (off by default): --fix Apply all style fixes. --fix-doc-comments Use triple slash for documentation comments. --fix-function-typedefs Use new syntax for function type typedefs. --fix-named-default-separator Use "=" as the separator before named parameter default values. --fix-optional-const Remove "const" keyword inside constant context. --fix-optional-new Remove "new" keyword. --fix-single-cascade-statements Remove unnecessary single cascades from expression statements. Other options: -l, --line-length Wrap lines longer than this. (defaults to "80") -i, --indent Spaces of leading indentation. (defaults to "0") --set-exit-if-changed Return exit code 1 if there are any formatting changes. --follow-links Follow links to files and directories. If unset, links will be ignored. --version Show version information. Options when formatting from stdin: --selection Selection to preserve formatted as "start:length". --stdin-name The path name to show when an error occurs. (defaults to "stdin") Run "dart help" to see global options. Change-Id: I18a49abd919672e988296f83c23636b14c29bdeb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153900 Reviewed-by: Bob Nystrom <[email protected]> Commit-Queue: Jaime Wren <[email protected]>
1 parent ad3202b commit d1a06cf

File tree

3 files changed

+10
-85
lines changed

3 files changed

+10
-85
lines changed

pkg/dartdev/lib/dartdev.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io' as io;
77
import 'package:analyzer/src/dart/analysis/experiments.dart';
88
import 'package:args/args.dart';
99
import 'package:args/command_runner.dart';
10+
import 'package:dart_style/src/cli/format_command.dart';
1011
import 'package:cli_util/cli_logging.dart';
1112
import 'package:nnbd_migration/migration_cli.dart';
1213
import 'package:usage/usage.dart';
@@ -15,7 +16,6 @@ import 'src/analytics.dart';
1516
import 'src/commands/analyze.dart';
1617
import 'src/commands/compile.dart';
1718
import 'src/commands/create.dart';
18-
import 'src/commands/format.dart';
1919
import 'src/commands/pub.dart';
2020
import 'src/commands/run.dart';
2121
import 'src/commands/test.dart';

pkg/dartdev/lib/src/commands/format.dart

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

pkg/dartdev/test/commands/format_test.dart

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,33 @@ void format() {
1717

1818
tearDown(() => p?.dispose());
1919

20-
test('implicit --help', () {
21-
p = project();
22-
var result = p.runSync('format', []);
23-
expect(result.exitCode, 0);
24-
expect(result.stderr, isEmpty);
25-
expect(result.stdout, contains('Format Dart source code.'));
26-
expect(result.stdout, contains('Usage: dart format [arguments]'));
27-
});
28-
2920
test('--help', () {
3021
p = project();
3122
var result = p.runSync('format', ['--help']);
3223
expect(result.exitCode, 0);
3324
expect(result.stderr, isEmpty);
34-
expect(result.stdout, contains('Format Dart source code.'));
35-
expect(result.stdout, contains('Usage: dart format [arguments]'));
25+
expect(result.stdout, contains('Idiomatically formats Dart source code.'));
26+
expect(result.stdout,
27+
contains('Usage: dart format [options...] <files or directories...>'));
3628
});
3729

3830
test('unchanged', () {
3931
p = project(mainSrc: 'int get foo => 1;\n');
4032
ProcessResult result = p.runSync('format', [p.relativeFilePath]);
4133
expect(result.exitCode, 0);
4234
expect(result.stderr, isEmpty);
43-
expect(result.stdout, startsWith('Unchanged ${p.relativeFilePath}'));
35+
expect(result.stdout, startsWith('Formatted 1 file (0 changed) in '));
4436
});
4537

4638
test('formatted', () {
4739
p = project(mainSrc: 'int get foo => 1;\n');
4840
ProcessResult result = p.runSync('format', [p.relativeFilePath]);
4941
expect(result.exitCode, 0);
5042
expect(result.stderr, isEmpty);
51-
expect(result.stdout, startsWith('Formatted ${p.relativeFilePath}'));
52-
});
53-
54-
test('dry-run changes', () {
55-
p = project(mainSrc: 'int get foo => 1;\n');
56-
ProcessResult result =
57-
p.runSync('format', ['--dry-run', p.relativeFilePath]);
58-
expect(result.exitCode, 0);
59-
expect(result.stderr, isEmpty);
60-
expect(result.stdout, startsWith(p.relativeFilePath));
61-
});
62-
63-
test('dry-run no changes', () {
64-
p = project(mainSrc: 'int get foo => 1;\n');
65-
ProcessResult result =
66-
p.runSync('format', ['--dry-run', p.relativeFilePath]);
67-
expect(result.exitCode, 0);
68-
expect(result.stderr, isEmpty);
69-
expect(result.stdout, isEmpty);
43+
expect(
44+
result.stdout,
45+
startsWith(
46+
'Formatted lib/main.dart\nFormatted 1 file (1 changed) in '));
7047
});
7148

7249
test('unknown file', () {
@@ -76,6 +53,6 @@ void format() {
7653
expect(result.exitCode, 0);
7754
expect(result.stderr,
7855
startsWith('No file or directory found at "$unknownFilePath".'));
79-
expect(result.stdout, isEmpty);
56+
expect(result.stdout, startsWith('Formatted no files in '));
8057
});
8158
}

0 commit comments

Comments
 (0)