From 7ae5a3c613f4924a7f5091dc331e44880f037c56 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Tue, 22 Oct 2024 16:16:27 -0700 Subject: [PATCH 1/4] Update dart_style to pass in a language version to DartFormatter. We're in [the process of](https://github.com/dart-lang/dart_style/issues/1403) moving dart_style to [a new formatting style](https://github.com/dart-lang/dart_style/issues/1253). That involves making the formatter [aware of the language version of what it's formatting](https://github.com/dart-lang/dart_style/issues/1402). That in turn means that the library API now lets you pass in a language version. In dart_style 2.3.7 [you can pass in a language version but the parameter is optional](https://pub.dev/documentation/dart_style/latest/dart_style/DartFormatter/DartFormatter.html). In the forthcoming 3.0.0 release, that parameter will become mandatory. This updates every call to `DartFormatter()` to pass in the latest language version. If there's a more specific version that should be used, let me know and I'll update the PR. Thanks! --- README.md | 12 +++++++++--- example/example.dart | 4 +++- pubspec.yaml | 2 +- test/common.dart | 9 ++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f149c4ff..22d06f80 100644 --- a/README.md +++ b/README.md @@ -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)}'), + ); } ``` @@ -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)}'), + ); } ``` @@ -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 diff --git a/example/example.dart b/example/example.dart index 6d8584fa..6f73598e 100644 --- a/example/example.dart +++ b/example/example.dart @@ -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()}'); diff --git a/pubspec.yaml b/pubspec.yaml index 23a7b9ac..9093e854 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/common.dart b/test/common.dart index 9bfed545..b1db8d02 100644 --- a/test/common.dart +++ b/test/common.dart @@ -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); } } From 13bb107e2d5921210f727281252c0f50e92e6a4e Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Wed, 23 Oct 2024 12:04:59 -0700 Subject: [PATCH 2/4] Update CHANGELOG and analysis_options.yaml. --- CHANGELOG.md | 1 + analysis_options.yaml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fedf73b..e2bed5d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.10.1-wip * Require Dart `^3.1.0` +* Upgrade to dart_style `2.3.7`. ## 4.10.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index 589c326a..d052c68a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 From 93078d56794dfd0781ca93a2b8026f5d2327b700 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Wed, 23 Oct 2024 12:09:51 -0700 Subject: [PATCH 3/4] Stop testing on 3.1.0 and move to 3.3.0 instead. --- .github/workflows/test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 0578b2ba..e22563b4 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -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: @@ -43,7 +43,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [3.1.0, dev] + sdk: [3.3.0, dev] steps: - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 From 2ea346f0acb31bef891e66370f52c77f25b05e02 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Wed, 23 Oct 2024 12:19:22 -0700 Subject: [PATCH 4/4] Bump to 3.5.0. May this please the CI gods. --- .github/workflows/test-package.yml | 2 +- CHANGELOG.md | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index e22563b4..7016c4a6 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -43,7 +43,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [3.3.0, dev] + sdk: [3.5.0, dev] steps: - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 diff --git a/CHANGELOG.md b/CHANGELOG.md index e2bed5d0..00525f36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 4.10.1-wip -* Require Dart `^3.1.0` -* Upgrade to dart_style `2.3.7`. +* Require Dart `^3.5.0` +* Upgrade to `dart_style` 2.3.7. ## 4.10.0 diff --git a/pubspec.yaml b/pubspec.yaml index 9093e854..80b72284 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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