Skip to content

Commit

Permalink
Update dartdev to use the format command object from dart_style.
Browse files Browse the repository at this point in the history
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 <rnystrom@google.com>
Commit-Queue: Jaime Wren <jwren@google.com>
  • Loading branch information
jwren authored and commit-bot@chromium.org committed Jul 10, 2020
1 parent ad3202b commit d1a06cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 85 deletions.
2 changes: 1 addition & 1 deletion pkg/dartdev/lib/dartdev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io' as io;
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:dart_style/src/cli/format_command.dart';
import 'package:cli_util/cli_logging.dart';
import 'package:nnbd_migration/migration_cli.dart';
import 'package:usage/usage.dart';
Expand All @@ -15,7 +16,6 @@ import 'src/analytics.dart';
import 'src/commands/analyze.dart';
import 'src/commands/compile.dart';
import 'src/commands/create.dart';
import 'src/commands/format.dart';
import 'src/commands/pub.dart';
import 'src/commands/run.dart';
import 'src/commands/test.dart';
Expand Down
52 changes: 0 additions & 52 deletions pkg/dartdev/lib/src/commands/format.dart

This file was deleted.

41 changes: 9 additions & 32 deletions pkg/dartdev/test/commands/format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,33 @@ void format() {

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

test('implicit --help', () {
p = project();
var result = p.runSync('format', []);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, contains('Format Dart source code.'));
expect(result.stdout, contains('Usage: dart format [arguments]'));
});

test('--help', () {
p = project();
var result = p.runSync('format', ['--help']);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, contains('Format Dart source code.'));
expect(result.stdout, contains('Usage: dart format [arguments]'));
expect(result.stdout, contains('Idiomatically formats Dart source code.'));
expect(result.stdout,
contains('Usage: dart format [options...] <files or directories...>'));
});

test('unchanged', () {
p = project(mainSrc: 'int get foo => 1;\n');
ProcessResult result = p.runSync('format', [p.relativeFilePath]);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, startsWith('Unchanged ${p.relativeFilePath}'));
expect(result.stdout, startsWith('Formatted 1 file (0 changed) in '));
});

test('formatted', () {
p = project(mainSrc: 'int get foo => 1;\n');
ProcessResult result = p.runSync('format', [p.relativeFilePath]);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, startsWith('Formatted ${p.relativeFilePath}'));
});

test('dry-run changes', () {
p = project(mainSrc: 'int get foo => 1;\n');
ProcessResult result =
p.runSync('format', ['--dry-run', p.relativeFilePath]);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, startsWith(p.relativeFilePath));
});

test('dry-run no changes', () {
p = project(mainSrc: 'int get foo => 1;\n');
ProcessResult result =
p.runSync('format', ['--dry-run', p.relativeFilePath]);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
expect(result.stdout, isEmpty);
expect(
result.stdout,
startsWith(
'Formatted lib/main.dart\nFormatted 1 file (1 changed) in '));
});

test('unknown file', () {
Expand All @@ -76,6 +53,6 @@ void format() {
expect(result.exitCode, 0);
expect(result.stderr,
startsWith('No file or directory found at "$unknownFilePath".'));
expect(result.stdout, isEmpty);
expect(result.stdout, startsWith('Formatted no files in '));
});
}

0 comments on commit d1a06cf

Please sign in to comment.