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

Silencing analyzer warnings #625

Closed
edwardaux opened this issue Mar 29, 2020 · 5 comments
Closed

Silencing analyzer warnings #625

edwardaux opened this issue Mar 29, 2020 · 5 comments

Comments

@edwardaux
Copy link

edwardaux commented Mar 29, 2020

The generated code from 3.3.0 causes some output that violates a couple of the analyzer rules. Sadly, though, I don't seem to be able to ignore generated files in my flutter project due to dart-lang/sdk#25551

I've confirmed that if I manually add an ignore_for_file line in the generated file, the warnings go away.

Happy to create a PR if someone can give me a nudge in the right direction of which file is the likely best place. Thanks

// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter, non_constant_identifier_names

Flutter version

Flutter 1.12.13+hotfix.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 0b8abb4724 (7 weeks ago) • 2020-02-11 11:44:36 -0800
Engine • revision e1e6ced81d
Tools • Dart 2.7.0
@kevmoo
Copy link
Collaborator

kevmoo commented Mar 29, 2020

@kevmoo kevmoo closed this as completed Mar 29, 2020
@slightfoot
Copy link
Contributor

@kevmoo I just tried the build.yaml and I now see this.

> flutter pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 261ms

[WARNING] These options were ignored: `{ignore_for_file: [unnecessary_cast]}`.
[INFO] Initializing inputs
...

Is there a specific version of build_runner/source_gen this feature was added in?

@slightfoot
Copy link
Contributor

I found it.. source_gen: 0.9.5

@kevmoo
Copy link
Collaborator

kevmoo commented Mar 29, 2020 via email

@edwardaux
Copy link
Author

Thanks for the pointer @kevmoo and @slightfoot. I'm up and running now...

Even with the nudge in the right direction, I must admit I wasn't sure exactly what I needed to do... the way I read the source_gen doc, it looks like the ignore_for_file directive should be in json_serializable's build.yaml file, but after an hour or so of trial and error, it turns out it needs to be in /my/ project.

So, just in case anyone else has this problem, the fix I ended up doing was as follows:

  • Create a new file in the root directory of your project called build.yaml
  • Add the following content:
targets:
  $default:
    builders:
      source_gen|combining_builder:
        options:
          ignore_for_file:
            - implicit_dynamic_parameter
            - non_constant_identifier_names
  • Regenerate using the standard command: flutter pub run build_runner build --delete-conflicting-outputs

Note also: don't confuse build.yaml for pubspec.yaml - they're obviously different files with different purposes, but this was also a mistake I made 😊

chrisbobbe added a commit to chrisbobbe/zulip-flutter that referenced this issue Apr 21, 2023
chrisbobbe added a commit to chrisbobbe/zulip-flutter that referenced this issue May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants