wigy
wigy

Reputation: 2222

Exclude all generated code from dartanalyzer

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.

Upvotes: 19

Views: 5590

Answers (2)

tmaihoff
tmaihoff

Reputation: 3550

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

Upvotes: 32

Related Questions