Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Update dart_style to pass in a language version to DartFormatter. #466

Merged
merged 4 commits into from
Oct 23, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev and 2.12.0.
# against Dart dev and an earlier stable version.
analyze:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [3.1.0, dev]
sdk: [3.5.0, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 4.10.1-wip

* Require Dart `^3.1.0`
* Require Dart `^3.5.0`
* Upgrade to `dart_style` 2.3.7.

## 4.10.0

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ void main() {
..name = 'eat'
..body = const Code("print('Yum!');"))));
final emitter = DartEmitter();
print(DartFormatter().format('${animal.accept(emitter)}'));
print(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format('${animal.accept(emitter)}'),
);
}
```

Expand Down Expand Up @@ -57,7 +60,10 @@ void main() {
..returns = refer('Other', 'package:b/b.dart')),
]));
final emitter = DartEmitter.scoped();
print(DartFormatter().format('${library.accept(emitter)}'));
print(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format('${library.accept(emitter)}'),
);
}
```

Expand Down Expand Up @@ -103,7 +109,7 @@ run from the snapshot instead of from source to avoid problems with deleted
files. These steps must be run without deleting the source files.

```bash
./tool/regenerate.sh
./tool/regenerate.sh
```

[build_runner]: https://pub.dev/packages/build_runner
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ linter:
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
Expand Down
4 changes: 3 additions & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';

final _dartfmt = DartFormatter();
final _dartfmt = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
);

void main() {
print('animalClass():\n${'=' * 40}\n${animalClass()}');
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A fluent, builder-based library for generating valid Dart code.
repository: https://github.com/dart-lang/code_builder

environment:
sdk: ^3.1.0
sdk: ^3.5.0

dependencies:
built_collection: ^5.0.0
Expand All @@ -18,6 +18,6 @@ dev_dependencies:
build_runner: ^2.0.3
built_value_generator: ^8.0.0
dart_flutter_team_lints: ^3.0.0
dart_style: ^2.3.4
dart_style: ^2.3.7
source_gen: ^1.0.0
test: ^1.16.0
9 changes: 6 additions & 3 deletions test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';

final DartFormatter _dartfmt = DartFormatter();
String _format(String source) {
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
);

try {
return _dartfmt.format(source);
return formatter.format(source);
} on FormatterException catch (_) {
return _dartfmt.formatStatement(source);
return formatter.formatStatement(source);
}
}

Expand Down