Skip to content

Commit

Permalink
auto-apply the dartfmt single cascade fix (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Mar 8, 2022
1 parent fa9c1a6 commit 763cba2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 1.2.2-dev

* Enable the fix for single cascade statements when formatting Dart code.
* Individual builders can opt out of this by providing a custom `formatOutput`
function to the `PartBuilder` or `LibraryBuilder` constructors.

## 1.2.1

- Allow reviving constants which are static fields defined on the class which
Expand Down
2 changes: 1 addition & 1 deletion source_gen/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Future<bool> _hasAnyTopLevelAnnotations(
return false;
}

final _formatter = DartFormatter();
final _formatter = DartFormatter(fixes: [StyleFix.singleCascadeStatements]);

const defaultFileHeader = '// GENERATED CODE - DO NOT MODIFY BY HAND';

Expand Down
8 changes: 8 additions & 0 deletions source_gen/test/src/unformatted_code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ class UnformattedCodeGenerator extends Generator {

static const formattedCode = '''
void hello() => print('hello');
void x() {
<String>[].add('y');
}
''';

static const unformattedCode = '''
void hello ()=> print('hello');
void x() {
<String>[]..add('y');
}
''';
}

0 comments on commit 763cba2

Please sign in to comment.