Excluding code
An exclude is a list of path globs that leaves files out. assay has three kinds, all under the assay: key of the project’s root analysis_options.yaml (Configuration):
| Key | Leaves the paths out of |
|---|---|
assay.exclude |
every rule and every metric, and the results of every check |
assay.rules.<rule>.exclude |
that rule alone |
assay.cross_file.<check>.exclude, assay.assets.<check>.exclude, assay.project_files.<check>.exclude |
that check alone |
To silence a rule at one place instead of in a path, write a suppression.
Excluding paths from everything
Section titled “Excluding paths from everything”assay.exclude lists path globs where no rule and no metric judges, and where no cross-file, asset or project-file result is placed.
assay: exclude: - "lib/legacy/**" # The default list, written again to keep it: - "**/*.g.dart" - "**/*.freezed.dart" - "**/*.gen.dart" - "**/*.mocks.dart" - "**/app_localizations.dart" - "**/app_localizations_*.dart"- Default: the common generated files,
**/*.g.dart,**/*.freezed.dart,**/*.gen.dart,**/*.mocks.dart,**/app_localizations.dartand**/app_localizations_*.dart. A list of your own replaces it, so write those again to keep them, as above. analyzer: exclude:is honoured as well: the paths under it are left out too.
Excluding paths from one rule
Section titled “Excluding paths from one rule”assay: rules: avoid_dynamic: exclude: ["lib/interop/**"]Excluding paths from one check
Section titled “Excluding paths from one check”assay: cross_file: unused_files: exclude: ["tool/templates/**"] assets: unused_assets: exclude: ["assets/native/**"] project_files: secret_in_shipped_file: exclude: ["assets/fixtures/**"]A check’s exclude places no result in the files it covers. It is how a result of a cross-file check, an asset check or a project-file check is silenced: a suppression comment does not reach them.
exclude works differently for duplicated_code:
duplicated_code: the excluded files leave the detection altogether. A copy in them is neither reported nor makes the code it copies reported.- The other four cross-file checks:
excludeonly places no result there.
assay.exclude and analyzer: exclude: keep the results of a check out of the files they cover as well, with one exception, unused_l10n: see Cross-file checks.
How a glob is read
Section titled “How a glob is read”A glob is read the same way in every exclude:
- from the project root, from the directory of the options file that sets it, and from the root of every package between either of them and the judged file;
- a glob that ends in a slash names a directory and everything below it.