Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dart-lang/dart_style
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.1
Choose a base ref
...
head repository: dart-lang/dart_style
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.0.2
Choose a head ref

Commits on Apr 13, 2021

  1. Copy the full SHA
    ade7f4e View commit details

Commits on May 13, 2021

  1. Merge branch 'remove-inlining-cascased-with-the-same-mathod-name' of h…

    …ttps://github.com/ManoyloK/dart_style into ManoyloK-remove-inlining-cascased-with-the-same-mathod-name
    munificent committed May 13, 2021
    Copy the full SHA
    f0fc7f7 View commit details

Commits on Jun 9, 2021

  1. Don't unnecessarily split argument lists with block comments.

    A very subtle bug in the comment handling would cause a /* */ inline
    comment to force the surrounding code to full split when not needed in
    some cases.
    
    This fixes that issue. It also slightly tweaks the formatting of code
    containing inline block comments in some rare cases. In practice, the
    only code I see affected by that is formatter tests. In the real world,
    all affected code is related to the bug itself and is fixed by this
    change.
    
    Fix #837.
    munificent committed Jun 9, 2021
    Copy the full SHA
    f093a89 View commit details
  2. Format.

    munificent committed Jun 9, 2021
    Copy the full SHA
    f9a4f47 View commit details
  3. Remove the special reverse indentation for cascade targets.

    This rule was always of dubious value and looking at how it affects a
    large corpus (now that we have one), I think it's pretty clear that the
    natural indentation is easier to read.
    munificent committed Jun 9, 2021
    Copy the full SHA
    d0a102b View commit details

Commits on Jun 11, 2021

  1. Optimize formatting large cascades.

    Fix #811.
    munificent committed Jun 11, 2021
    Copy the full SHA
    47248ba View commit details
  2. Merge pull request #1031 from dart-lang/837-block-comment-splits

    Don't unnecessarily split argument lists with block comments.
    munificent authored Jun 11, 2021
    Copy the full SHA
    5f93e07 View commit details

Commits on Jun 14, 2021

  1. Copy the full SHA
    6c36863 View commit details

Commits on Jun 15, 2021

  1. Apply review changes.

    munificent committed Jun 15, 2021
    Copy the full SHA
    ebc37b8 View commit details

Commits on Jun 18, 2021

  1. Return correct exit code from FormatCommand when formatting stdin.

    It reads from stdin asynchronously. Before this fix, the FormatCommand
    did not wait for that to complete before returning the exit code, so it
    would return before stdin had been formatted and any parse error
    detected.
    
    Fix #1035.
    munificent committed Jun 18, 2021
    Copy the full SHA
    a552e77 View commit details

Commits on Jun 21, 2021

  1. Update README.md

    mit-mit authored Jun 21, 2021
    Copy the full SHA
    a32cad0 View commit details
  2. Format.

    munificent committed Jun 21, 2021
    Copy the full SHA
    d173368 View commit details
  3. Merge pull request #1036 from dart-lang/stdin-exit-code

    Return correct exit code from FormatCommand when formatting stdin.
    munificent authored Jun 21, 2021
    Copy the full SHA
    41b5c49 View commit details
  4. Merge pull request #1033 from dart-lang/simpler-cascades

    Simpler cascades
    munificent authored Jun 21, 2021
    Copy the full SHA
    317b446 View commit details
  5. Copy the full SHA
    efad0c4 View commit details
  6. Merge pull request #1039 from dart-lang/changelog

    Update CHANGELOG with cascade changes.
    munificent authored Jun 21, 2021
    Copy the full SHA
    3b5a9cf View commit details
  7. Merge pull request #1037 from dart-lang/mit-mit-patch-1

    Update README.md
    munificent authored Jun 21, 2021
    Copy the full SHA
    942a52c View commit details

Commits on Jul 1, 2021

  1. Copy the full SHA
    d3bda9f View commit details
  2. Copy the full SHA
    172374b View commit details

Commits on Jul 2, 2021

  1. Merge pull request #1041 from dart-lang/1029-empty-catch

    Split empty catch blocks with finally clauses.
    munificent authored Jul 2, 2021
    Copy the full SHA
    427b502 View commit details
  2. Copy the full SHA
    8f561fb View commit details
  3. Simplify.

    munificent committed Jul 2, 2021
    Copy the full SHA
    a22345d View commit details
  4. Merge pull request #1042 from dart-lang/split-empty-catch

    Split empty catch
    munificent authored Jul 2, 2021
    Copy the full SHA
    e1c30d6 View commit details

Commits on Jul 12, 2021

  1. Bump version to publish 2.0.2. (#1043)

    * Bump version to publish 2.0.2.
    
    * Support the latest version of pkg:analyzer
    
    * revert me
    
    * format
    
    * Remove temporary CI testing code.
    
    * Regenerate lockfile.
    
    Co-authored-by: Kevin Moore <kevmoo@google.com>
    munificent and kevmoo authored Jul 12, 2021
    Copy the full SHA
    9d9dff9 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, bump-2.0.2 ]
schedule:
- cron: "0 0 * * 0"

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 2.0.2

* Don't unnecessarily split argument lists with `/* */` comments (#837).
* Return correct exit code from `FormatCommand` when formatting stdin (#1035).
* Always split cascades with multiple sections (#1006).
* Don't indent cascades farther than their receiver method chains.
* Optimize line splitting cascades (#811).
* Split empty catch blocks with finally clauses (#1029).
* Split empty catch blocks with catches after them.
* Allow the latest version of `package:analyzer`.

# 2.0.1

* Support triple-shift `>>>` and `>>>=` operators (#992).
74 changes: 36 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -55,49 +55,31 @@ greet(String name, {String title = "Captain"}) {
}
```

## Getting dartfmt
## Using the formatter

Dartfmt is included in the Dart SDK, so most users get it directly from there.
That has the latest version of dartfmt that was available when the SDK was
released.
The formatter is part of the unified [`dart`][] developer tool included in the
Dart SDK, so most users get it directly from there. That has the latest version
of the formatter that was available when the SDK was released.

If you want to make sure you are running the latest version of dartfmt, you can
[globally activate][] the package from the dart_style package on
pub.dev:

$ pub global activate dart_style
$ dartfmt ...

For this to work, you need to put pub's bin directory on your PATH before the
Dart SDK directory. Otherwise, the SDK's dartfmt will shadow this one.

[globally activate]: https://dart.dev/tools/pub/cmd/pub-global

If you don't want pub to put `dartfmt` on your PATH, you can run it explicitly:

$ pub global activate dart_style --no-executables
$ pub global run dart_style:format ...

## Using dartfmt
[`dart`]: https://dart.dev/tools/dart-tool

IDEs and editors that support Dart usually provide easy ways to run the
formatter. For example, in WebStorm you can right-click a .dart file and then
choose **Reformat with Dart Style**.

Here's a simple example of using dartfmt on the command line:
Here's a simple example of using the formatter on the command line:

$ dartfmt test.dart
$ dart format test.dart

This command formats the `test.dart` file and writes the result to standard
output.
This command formats the `test.dart` file and writes the result to the
file.

Dartfmt takes a list of paths, which can point to directories or files. If the
path is a directory, it processes every `.dart` file in that directory or any of
its subdirectories. If no file or directory is specified, dartfmt reads from
standard input.
`dart format` takes a list of paths, which can point to directories or files. If
the path is a directory, it processes every `.dart` file in that directory or
any of its subdirectories.

By default, it formats each file and just prints the resulting code to stdout.
If you pass `-w`, it overwrites your existing files with the formatted results.
By default, it formats each file and write the formatting changes to the files.
If you pass `--output show`, it prints the formatted code to stdout.

You may pass a `-l` option to control the width of the page that it wraps lines
to fit within, but you're strongly encouraged to keep the default line length of
@@ -106,13 +88,29 @@ to fit within, but you're strongly encouraged to keep the default line length of
### Validating files

If you want to use the formatter in something like a [presubmit script][] or
[commit hook][], you can use the `-n` dry run option. If you specify `-n`, the
formatter prints the paths of the files whose contents would change if the
formatter were run normally. If it prints no output, then everything is already
correctly formatted.
[commit hook][], you can pass flags to omit writing formatting changes to disk
and to update the exit code to indicate success/failure:

$ dart format --output=none --set-exit-if-changed .

[presubmit script]: https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
[commit hook]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
## Running other versions of the formatter CLI command

If you need to run a different version of the formatter, you can
[globally activate][] the package from the dart_style package on
pub.dev:

$ pub global activate dart_style
$ dartfmt ...

For this to work, you need to put pub's bin directory on your PATH before the
Dart SDK directory. Otherwise, the SDK's dartfmt will shadow this one.

[globally activate]: https://dart.dev/tools/pub/cmd/pub-global

If you don't want pub to put `dartfmt` on your PATH, you can run it explicitly:

$ pub global activate dart_style --no-executables
$ pub global run dart_style:format ...

## Using the dart_style API

90 changes: 90 additions & 0 deletions benchmark/after.dart.txt
Original file line number Diff line number Diff line change
@@ -22,6 +22,96 @@ import 'dependency_queue.dart';
import 'version_queue.dart';
import 'version_solver.dart';

class HttpRequest extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names')
? ''
: 'HttpRequest',
package: const $pb.PackageName(
const $core.bool.fromEnvironment('protobuf.omit_message_names')
? ''
: 'google.logging.type'),
createEmptyInstance: create)
..aOS(
1,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestMethod')
..aOS(
2,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestUrl')
..aInt64(
3,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestSize')
..a<$core.int>(
4,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'status',
$pb.PbFieldType.O3)
..aInt64(
5,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'responseSize')
..aOS(
6,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'userAgent')
..aOS(
7,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'remoteIp')
..aOS(
8,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'referer')
..aOB(
9,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheHit')
..aOB(
10,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheValidatedWithOriginServer')
..aOB(
11,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheLookup')
..aInt64(
12,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheFillBytes')
..aOS(
13,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'serverIp')
..aOM<$0.Duration>(
14,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'latency',
subBuilder: $0.Duration.create)
..aOS(
15,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'protocol')
..hasRequiredFields = false;
}

/// The top-level solver.
///
/// Keeps track of the current potential solution, and the other possible
90 changes: 90 additions & 0 deletions benchmark/before.dart.txt
Original file line number Diff line number Diff line change
@@ -22,6 +22,96 @@ import 'dependency_queue.dart';
import 'version_queue.dart';
import 'version_solver.dart';

class HttpRequest extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
const $core.bool.fromEnvironment('protobuf.omit_message_names')
? ''
: 'HttpRequest',
package: const $pb.PackageName(
const $core.bool.fromEnvironment('protobuf.omit_message_names')
? ''
: 'google.logging.type'),
createEmptyInstance: create)
..aOS(
1,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestMethod')
..aOS(
2,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestUrl')
..aInt64(
3,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'requestSize')
..a<$core.int>(
4,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'status',
$pb.PbFieldType.O3)
..aInt64(
5,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'responseSize')
..aOS(
6,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'userAgent')
..aOS(
7,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'remoteIp')
..aOS(
8,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'referer')
..aOB(
9,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheHit')
..aOB(
10,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheValidatedWithOriginServer')
..aOB(
11,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheLookup')
..aInt64(
12,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'cacheFillBytes')
..aOS(
13,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'serverIp')
..aOM<$0.Duration>(
14,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'latency',
subBuilder: $0.Duration.create)
..aOS(
15,
const $core.bool.fromEnvironment('protobuf.omit_field_names')
? ''
: 'protocol')
..hasRequiredFields = false;
}

/// The top-level solver.
///
/// Keeps track of the current potential solution, and the other possible
4 changes: 2 additions & 2 deletions bin/format.dart
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import 'package:dart_style/src/cli/summary.dart';
import 'package:dart_style/src/io.dart';
import 'package:dart_style/src/style_fix.dart';

void main(List<String> args) {
void main(List<String> args) async {
var parser = ArgParser(allowTrailingOptions: true);

defineOptions(parser,
@@ -135,7 +135,7 @@ void main(List<String> args) {
setExitIfChanged: setExitIfChanged);

if (argResults.rest.isEmpty) {
formatStdin(options, selection, argResults['stdin-name'] as String);
await formatStdin(options, selection, argResults['stdin-name'] as String);
} else {
formatPaths(options, argResults.rest);
}
4 changes: 2 additions & 2 deletions lib/src/argument_list_visitor.dart
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ class ArgumentSublist {
final int _trailingBlocks;

/// The rule used to split the bodies of all block arguments.
Rule? get blockRule => _blockRule;
Rule get blockRule => _blockRule!;
Rule? _blockRule;

/// The most recent chunk that split before an argument.
@@ -446,7 +446,7 @@ class ArgumentSublist {
rule.disableSplitOnInnerRules();

// Tell it to use the rule we've already created.
visitor.beforeBlock(argumentBlock, blockRule!, previousSplit);
visitor.beforeBlock(argumentBlock, blockRule, previousSplit);
} else if (_allArguments.length > 1) {
// Edge case: Only bump the nesting if there are multiple arguments. This
// lets us avoid spurious indentation in cases like:
12 changes: 2 additions & 10 deletions lib/src/call_chain_visitor.dart
Original file line number Diff line number Diff line change
@@ -173,14 +173,7 @@ class CallChainVisitor {
this._blockCalls, this._hangingCall);

/// Builds chunks for the call chain.
///
/// If [unnest] is `false` than this will not close the expression nesting
/// created for the call chain and the caller must end it. Used by cascades
/// to force a cascade after a method chain to be more deeply nested than
/// the methods.
void visit({bool? unnest}) {
unnest ??= true;

void visit() {
_visitor.builder.nestExpression();

// Try to keep the entire method invocation one line.
@@ -259,8 +252,7 @@ class CallChainVisitor {

_disableRule();
_endSpan();

if (unnest) _visitor.builder.unnest();
_visitor.builder.unnest();
}

/// Returns `true` if the method chain should split if a split occurs inside
Loading