14

I am trying to exclude all generated files from a package using the following analysis_options.yaml file.

include: package:pedantic/analysis_options.yaml
analyzer:
    strong-mode:
        implicit-casts: false
        implicit-dynamic: false
    exclude:
        - lib/**.g.dart

I still get errors for a file called lib/store/state/presentations_state.g.dart breaking the rule implicit_dynamic_parameter. If I exlcude **.g.dart without the lib/ prefix, dartanalyzer works properly, but the dart-code.dart-code VS Code plugin reports Undefined alias. dart(parse_error) somewhere in the first line of the YAML file, leaving the whole project marked as having an error.

I could reproduce this in both monorepos having multiple packages and single packages as well.

Gama11
  • 31,714
  • 9
  • 78
  • 100
wigy
  • 2,174
  • 19
  • 32
  • https://github.com/dart-lang/sdk/issues/25551 – jamesdlin Apr 15 '20 at 09:30
  • Wow, I got pretty angry reading that there are issues open for 4 years now with this. What is worse is that writing `- "**.g.dart"`, `- lib/**.g.dart` and `- **.g.dart` all end up with different errors and lints, so it seems to be dependent on the rule how they exclude files. – wigy Apr 15 '20 at 12:45

2 Answers2

23

I put the following to the analysis_options.yaml which worked for me:


analyzer:
  exclude:
    - '**.freezed.dart'
    - '**.g.dart'
    - '**.gr.dart'
    - '**/generated_plugin_registrant.dart'

All files matching the patterns are no longer analysed, independent of its location in the file path.

The quotation marks are necessary to prevent syntax errors in the yaml

Jakub S.
  • 5,580
  • 2
  • 42
  • 37
tmaihoff
  • 2,867
  • 1
  • 18
  • 40
1

See https://github.com/dart-lang/source_gen/tree/master/source_gen#configuring-combining_builder-ignore_for_file

Assuming the generator you use is based on package:source_gen you can use this trick to create the right ignores in the generated file!

https://github.com/kevmoo/peanut.dart/commit/9877105daecf59b8f5eb25431ac691a38a3e636c https://github.com/kevmoo/stats/commit/bb2fefaa22fc11c10acfe2f6418b3abba1e51909 https://github.com/kevmoo/build_cli/commit/619495c91caab873c2f48ac36a941c893d9b86b7

Kevin Moore
  • 5,921
  • 2
  • 29
  • 43
  • Thanks. I will check how to `ignore_for_file` the `implicit-dynamic: false` analysis option. – wigy Apr 16 '20 at 14:59
  • 1
    If you copy the warning in your IDE or run analyzer from the command line you will see the "code name" for the warning – that's what you ignore! – Kevin Moore Apr 16 '20 at 18:40
  • 1
    In this case, there are many: implicit_dynamic_parameter implicit_dynamic_variable implicit_dynamic_type implicit_dynamic_function and likely others... – Kevin Moore Apr 16 '20 at 18:42