Skip to content

Commit

Permalink
[go_router] change fix_data.yaml uris to be absolute to fix lints (#…
Browse files Browse the repository at this point in the history
…3877)

a workaround for dart-lang/sdk#52233

for consumers to use this fix while it's being reviewed/published:
1. copy this [fix_data.yaml](https://github.com/Bdaya-Dev/packages/blob/280bb99050a7a8083d3e73cf5a63e66d18ab64f8/packages/go_router/lib/fix_data.yaml) file with the correct uris from this PR to your project's `lib` folder
2. ensure each file that needs to be fixed using `dart fix` imports the `go_router` package directly, and not proxied via some other `exports`:
```dart
import 'package:go_router/go_router.dart';
```
  • Loading branch information
ahmednfwela authored May 11, 2023
1 parent 5b7d732 commit 07055aa
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 19 deletions.
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.0.1

- Adds a workaround for the `dart fix --apply` issue, https://github.com/dart-lang/sdk/issues/52233.

## 7.0.0

- **BREAKING CHANGE**:
Expand Down
30 changes: 20 additions & 10 deletions packages/go_router/lib/fix_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'replaceNamed'
inClass: 'GoRouter'
changes:
Expand All @@ -35,7 +36,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'pushReplacementNamed'
inClass: 'GoRouter'
changes:
Expand All @@ -50,7 +52,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'pushNamed'
inClass: 'GoRouter'
changes:
Expand All @@ -65,7 +68,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'goNamed'
inClass: 'GoRouter'
changes:
Expand All @@ -80,7 +84,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'namedLocation'
inClass: 'GoRouter'
changes:
Expand All @@ -95,7 +100,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
method: 'namedLocation'
inClass: 'GoRouterState'
changes:
Expand All @@ -110,7 +116,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'queryParams'
inClass: 'GoRouterState'
changes:
Expand All @@ -121,7 +128,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'fullpath'
inClass: 'GoRouterState'
changes:
Expand All @@ -132,7 +140,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'params'
inClass: 'GoRouterState'
changes:
Expand All @@ -143,7 +152,8 @@ transforms:
date: 2023-04-24
bulkApply: true
element:
uris: [ 'go_router.dart' ]
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'subloc'
inClass: 'GoRouterState'
changes:
Expand Down
3 changes: 2 additions & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 7.0.0
version: 7.0.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand All @@ -21,4 +21,5 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
io: ^1.0.4
path: ^1.8.2
83 changes: 75 additions & 8 deletions packages/go_router/tool/run_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,92 @@
// ignore_for_file: avoid_print

import 'dart:io';
import 'package:io/io.dart' as io;
import 'package:path/path.dart' as p;

// This test runner simulates a consumption of go_router that checks if
// the dart fixes are applied correctly.
// This is done by copying the `test_fixes/` directory to a temp directory
// that references `go_router`, and running `dart fix --compare-to-golden`
// on the temp directory.
Future<void> main(List<String> args) async {
if (!Platform.isMacOS) {
print('This test can only be run on macOS.');
exit(0);
final Directory goRouterPackageRoot =
File.fromUri(Platform.script).parent.parent;

final Directory testTempDir = await Directory.systemTemp.createTemp();

// Cleans up the temp directory and exits with a given statusCode.
Future<Never> cleanUpAndExit(int statusCode) async {
await testTempDir.delete(recursive: true);
exit(statusCode);
}
final Directory packageRoot =
Directory(p.dirname(Platform.script.path)).parent;
final int status = await _runProcess(

// Copy the test_fixes folder to the temporary testFixesTargetDir.
//
// This also creates the proper pubspec.yaml in the temp directory.
await _prepareTemplate(
packageRoot: goRouterPackageRoot,
testTempDir: testTempDir,
);

// Run dart pub get in the temp directory to set it up.
final int pubGetStatusCode = await _runProcess(
'dart',
<String>[
'pub',
'get',
],
workingDirectory: testTempDir.path,
);

if (pubGetStatusCode != 0) {
await cleanUpAndExit(pubGetStatusCode);
}

// Run dart fix --compare-to-golden in the temp directory.
final int dartFixStatusCode = await _runProcess(
'dart',
<String>[
'fix',
'--compare-to-golden',
],
workingDirectory: p.join(packageRoot.path, 'test_fixes'),
workingDirectory: testTempDir.path,
);

exit(status);
await cleanUpAndExit(dartFixStatusCode);
}

Future<void> _prepareTemplate({
required Directory packageRoot,
required Directory testTempDir,
}) async {
// The src test_fixes directory.
final Directory testFixesSrcDir =
Directory(p.join(packageRoot.path, 'test_fixes'));

// Copy from src `test_fixes/` to the temp directory.
await io.copyPath(testFixesSrcDir.path, testTempDir.path);

// The pubspec.yaml file to create.
final File targetPubspecFile = File(p.join(testTempDir.path, 'pubspec.yaml'));

final String targetYaml = '''
name: test_fixes
publish_to: "none"
version: 1.0.0
environment:
sdk: ">=2.18.0 <4.0.0"
flutter: ">=3.3.0"
dependencies:
flutter:
sdk: flutter
go_router:
path: ${packageRoot.path}
''';

await targetPubspecFile.writeAsString(targetYaml);
}

Future<Process> _streamOutput(Future<Process> processFuture) async {
Expand Down
1 change: 1 addition & 0 deletions script/configs/allowed_unpinned_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- html
- http
- intl
- io
- js
- json_serializable
- lints
Expand Down

0 comments on commit 07055aa

Please sign in to comment.