Angular: Discussion: solution for analyzing generated source

Created on 19 Jul 2018  路  2Comments  路  Source: angulardart/angular

This is a meta-issue for reference and discussion about the challenges posed by code generation for using dartanalyzer in CI.

Angular generates source under the .dart_tool/ directory. While the analysis server understands this convention, the command-line dartanalyzer tool does not, and will produce errors for missing imports.

We workaround this issue by prefixing all of our generated imports (e.g. import 'foo.template.dart' as foo_template;) and ignoring the error for missing imports:

https://github.com/dart-lang/angular/blob/cca2e39dcd726c9590079b82666e6c2006383cb0/analysis_options.yaml#L8-L9

Unfortunately this workaround isn't suitable for generated part files, such as those produced by package:pageloader, as part directives can't be prefixed. This leaves a few options:

  1. Build before analysis This solves the issue for part files generated within the source directory, but still doesn't work for libraries under .dart_tool/.
  2. Skip analysis Tests that wouldn't have passed analysis likely won't run either, so specific tests that rely on generated part files can be safely skipped.
  3. Check in generated parts This is likely a fine solution for client apps that aren't published, but isn't suitable for Angular.
  4. Wait for support from tooling It's possible the analyzer or build packages could facilitate analysis of source with generated dependencies.
not planned discussion

Most helpful comment

I think we are going to be asking for tooling to support this properly going forward.

I will open a bug on the SDK repo (https://github.com/dart-lang/sdk/issues/34098).

All 2 comments

I think we are going to be asking for tooling to support this properly going forward.

I will open a bug on the SDK repo (https://github.com/dart-lang/sdk/issues/34098).

I just wanted to add, that uri_has_not_been_generated: ignore also only solves part of the problem.

If you have implicit-casts: false then it will continue to fail, since the analyzer doesn't know the types of the imported classes and assumes dynamic for everything.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matanlurey picture matanlurey  路  3Comments

Adamovskiy picture Adamovskiy  路  6Comments

double11one picture double11one  路  6Comments

ranquild picture ranquild  路  6Comments

filiph picture filiph  路  4Comments