From c54bb48bfec4100067f56e2f713b34c9dfa5a7bb Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Tue, 15 Oct 2024 22:17:59 +0200 Subject: [PATCH 1/2] Add `lib/fix_data.yaml` for automatic migration with `dart fix`. These fixes will also show up as "quick fixes" in IDEs. Users do not need to run `dart fix --apply` manually. **Example:** ```dart import 'package:json_schema/json_schema.dart'; void main() { final schema = JsonSchema.empty(); schema.validateWithResults(null); final validator = Validator(schema); validator.validateWithResults(null); } ``` Will be updated by `dart fix --apply` to: ```dart import 'package:json_schema/json_schema.dart'; void main() { final schema = JsonSchema.empty(); schema.validate(null); final validator = Validator(schema); validator.validate(null); } ``` --- lib/fix_data.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/fix_data.yaml diff --git a/lib/fix_data.yaml b/lib/fix_data.yaml new file mode 100644 index 00000000..b36a9410 --- /dev/null +++ b/lib/fix_data.yaml @@ -0,0 +1,22 @@ +version: 1 +transforms: +- title: Rename to validate + date: 2024-10-15 + element: + uris: + - json_schema.dart + method: validateWithResults + inClass: Validator + changes: + - kind: rename + newName: validate +- title: Rename to validate + date: 2024-10-15 + element: + uris: + - json_schema.dart + method: validateWithResults + inClass: JsonSchema + changes: + - kind: rename + newName: validate From 1c7f66389747e02c09e425f93ad64c07fae42b74 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Mon, 21 Oct 2024 13:37:21 +0200 Subject: [PATCH 2/2] Add tests for lib/fix_data.yaml --- .github/workflows/dart_ci.yaml | 5 ++++- test_fixes/rename_to_validate.dart | 8 ++++++++ test_fixes/rename_to_validate.dart.expect | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test_fixes/rename_to_validate.dart create mode 100644 test_fixes/rename_to_validate.dart.expect diff --git a/.github/workflows/dart_ci.yaml b/.github/workflows/dart_ci.yaml index 9e6630fc..e655f7ad 100644 --- a/.github/workflows/dart_ci.yaml +++ b/.github/workflows/dart_ci.yaml @@ -38,4 +38,7 @@ jobs: - name: Publish - dry run if: ${{ matrix.sdk == 'stable' }} run: dart pub publish --dry-run --skip-validation - + - name: Test 'dart fix' + # if one of these tests stops working in a future Dart SDK, it may be + # fine to keep entries in lib/fix_data.yaml and just remove the tests. + run: dart fix --compare-to-golden test_fixes/ diff --git a/test_fixes/rename_to_validate.dart b/test_fixes/rename_to_validate.dart new file mode 100644 index 00000000..52aab678 --- /dev/null +++ b/test_fixes/rename_to_validate.dart @@ -0,0 +1,8 @@ +import 'package:json_schema/json_schema.dart'; + +void main() { + final schema = JsonSchema.empty(); + schema.validateWithResults(null); + final validator = Validator(schema); + validator.validateWithResults(null); +} diff --git a/test_fixes/rename_to_validate.dart.expect b/test_fixes/rename_to_validate.dart.expect new file mode 100644 index 00000000..c6255eaa --- /dev/null +++ b/test_fixes/rename_to_validate.dart.expect @@ -0,0 +1,8 @@ +import 'package:json_schema/json_schema.dart'; + +void main() { + final schema = JsonSchema.empty(); + schema.validate(null); + final validator = Validator(schema); + validator.validate(null); +}