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

Unnecessary use of string interpolation while the argument is used as the whole path. #500

Closed
ghost opened this issue Sep 4, 2023 · 4 comments · Fixed by #501
Closed
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Sep 4, 2023

Steps to Reproduce

  1. Create any code like this:
  @Get(path: '{url}')
  Future<Response<List<Status>>> statusesByUrl(@Path() String url);
  1. Run build_runner and open its result

Expected results:

  @override
  Future<Response<List<Status>>> statusesByUrl(String url) {
    final Uri $url = Uri.parse(url); // or any other way to avoid the warning
    final Request $request = Request(
      'GET',
      $url,
      client.baseUrl,
    );
    return client.send<List<Status>, Status>($request);
  }

Actual results:

  @override
  Future<Response<List<Status>>> statusesByUrl(String url) {
    final Uri $url = Uri.parse('${url}'); // WARNING: Unnecessary use of string interpolation.
    final Request $request = Request(
      'GET',
      $url,
      client.baseUrl,
    );
    return client.send<List<Status>, Status>($request);
  }
@ghost ghost added the bug Something isn't working label Sep 4, 2023
@ghost
Copy link
Author

ghost commented Sep 4, 2023

@Get(path: '{url}#') fixes the warning but it's a dirty hack

@techouse techouse self-assigned this Sep 5, 2023
@techouse
Copy link
Collaborator

techouse commented Sep 5, 2023

@Get(path: '{url}#') fixes the warning but it's a dirty hack

In general, analysis tools should ignore generated files. You can achieve that by adding them to the exclude list in your analysis_options.yaml, i.e.

include: package:lints/recommended.yaml

analyzer:
  exclude:
    - "**.g.dart"
    - "**.chopper.dart"

Otherwise, we could add something like

// ignore_for_file: unnecessary_string_interpolations

@techouse
Copy link
Collaborator

techouse commented Sep 5, 2023

@gualse I have fixed this in #501, however, it will take some time to release this. If you need to use it ASAP you can either modify your analysis_options.yaml as explained in the comment above, or add this to your pubspec.yaml

dependency_overrides:
  chopper_generator:
    git:
      url: https://github.com/techouse/chopper.git
      ref: fix/chopper_generator/ignore_unnecessary_string_interpolations
      path: chopper_generator

@techouse techouse closed this as completed Sep 5, 2023
@techouse
Copy link
Collaborator

techouse commented Sep 5, 2023

@gualse I have deleted the PR branch as it's due to be released in chopper_generaror v7.0.4 in #502. Meanwhile, you can simply use the development branch of this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant