Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dart fix doesn't work on pub dev package #52233

Closed
chunhtai opened this issue May 1, 2023 · 5 comments
Closed

dart fix doesn't work on pub dev package #52233

chunhtai opened this issue May 1, 2023 · 5 comments
Assignees
Labels
analyzer-data-driven-fixes analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@chunhtai
Copy link

chunhtai commented May 1, 2023

Step to reproduce:

  1. do a Flutter create
  2. in main.dart, use the following code
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(
    MaterialApp.router(
      routerConfig: GoRouter(
        routes: [GoRoute(
          name: 'home',
          path: '/',
          redirect: (context, state) {
            print('named lcation ${state.queryParams['abc']}');
            return null;
          },
          builder: (_, state) {
            return Text('${state.fullPath}');
          }
        )]
      ),
    ),
  );
}
  1. in pubspec.yaml, adds the following dependecies
go_router: ^7.0.0
  1. run dart fix --apply

expected result:

The state.queryParams['abc'] should be replaced with state.queryParameters['abc']

actual result:

nothing happens

The fix_data for this entry is in https://github.com/flutter/packages/blob/c3f4c46bbbf1d5d8ad980850aacc82955d187b64/packages/go_router/lib/fix_data.yaml#L109

Note: if in step 3 you replace go_router with path dependency and do a flutter pub get again, dart fix work as expected

 go_router:
   path: /Users/chtai/git/packages/packages/go_router/
@lrhn lrhn added area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-fix labels May 1, 2023
@ahmednfwela
Copy link

I think the feature isn't even supported for non-flutter packages yet
src: https://github.com/flutter/flutter/wiki/Data-driven-Fixes
image

@ahmednfwela
Copy link

ahmednfwela commented May 1, 2023

@chunhtai here is an easier workaround:
copy fix_data.yaml from here to the lib folder of the project

Update: doesn't work, I was fooled by vscode automatically suggesting typo changes
image

Update 2: You need 2 steps to fix this issue:

  1. copy this 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:
import 'package:go_router/go_router.dart';

@chunhtai
Copy link
Author

chunhtai commented May 1, 2023

@ahmednfwela thanks for looking into this.

I knew this is not officially supported, but I still decide to give a try so that go_router customers can still benefit from this.

Hi @lrhn , it would be good to know if dart plan to support this use case or not.

@ahmednfwela
Copy link

after some trial and error, I finally found a way to fix this in this PR flutter/packages#3877

@bwilkerson bwilkerson added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server analyzer-data-driven-fixes and removed area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-fix labels May 8, 2023
@bwilkerson
Copy link
Member

@keertip

@pq pq added the P2 A bug or feature request we're likely to work on label May 9, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this issue May 11, 2023
…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';
```
nploi pushed a commit to nploi/packages that referenced this issue Jul 16, 2023
…lutter#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';
```
copybara-service bot pushed a commit that referenced this issue Dec 18, 2023
Bug:
Change-Id: I1d98420ce20ec6d52baef5683ae1ab83b21066e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342103
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
@keertip keertip self-assigned this Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-data-driven-fixes analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

6 participants