Skip to content

assay assets [checks…]

Runs the asset checks on the assets that the package at the project root declares under flutter: assets:. The checks report and never judge: the command exits with 0 whatever they find, and their results enter neither the gate nor the baseline.

assay assets [checks…] [--reporter <name>[:<file>]]… [--color auto|always|never]

With no name it runs every asset check; with names, only those:

Check Reports
unused_assets A declared asset that no Dart source of the project names.
oversized_assets A declared image file larger than the size limit for its resolution.
missing_asset_variants A declared image, in a directory that uses resolution variants, that lacks a variant it is asked for (2.0x and 3.0x by default), or variants without their base file. Silent in a project that uses no resolution variant.

A name that is not one of the three is a usage error. The asset checks are a kind of their own: assay cross-file does not run them, and this command runs no cross-file check. See Asset checks.

The command takes no paths: it always reads the whole package.

  • The asset inventory is read once and shared by every check: the files the root pubspec declares, each base file with its resolution variants and the size of each file, read the way Flutter’s tool reads the list (see Which files count as declared assets). No image is decoded.
  • The Dart files are read only when a check needs them: unused_assets does, except in a publishable package. All of them are read, tests, excluded and generated files among them, each resolved as check resolves it. A file that does not compile is read as far as the analyzer can, and does not fail the command.
Option Effect
checks… Run only these checks.
--reporter <name>[:<file>] console (the default), json, sarif, gitlab, github or markdown, to standard output or to a file. Repeatable. See Commands.
--color auto|always|never The form of the console output, as for every command.
assay assets # every check, on the console
assay assets unused_assets # one check
assay assets --reporter json # the result schema, with the assetChecks field
assay assets --reporter sarif:build/assets.sarif

assay assets unused_assets oversized_assets on a small project:

╭─ assay assets ───────────────────────────────────────────────────────────────╮
│ Preset strict │
│ Checks unused_assets, oversized_assets │
│ Files 4 │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Violations ────────────────────────────────────────────────── 2 in 2 files ─╮
│ Line Rule Tier │
│ ──────────────────────────────── │
│ assets/2.0x/logo.png 1 violation │
│ ! — oversized_assets advisory │
│ │
│ assets/old.png 1 violation │
│ ! — unused_assets advisory │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Checks ─────────────────────────────────────────────────────────────────────╮
│ Check Tier Count │
│ ───────────────────────────────── │
│ oversized_assets advisory 1 │
│ The 2.0x image is 1000.001 kB, over its limit of 1000 kB. │
│ → Compress the image or store it in a smaller format; if it must stay this │
│ large, raise max_kb for its resolution or add its path to the check's │
│ exclude. │
│ │
│ unused_assets advisory 1 │
│ No Dart source of the project names the asset `assets/old.png`, nor its │
│ variant. │
│ → Delete the file and its variants if nothing needs them, or add the path │
│ to the check's exclude when it is used in a way the check cannot see. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ ✓ PASS ─────────────────────────────────────────────────────────────────────╮
│ 0 blocking · 2 advisory · 2 of 4 files │
╰──────────────────────────────────────────────────────────────────────────────╯
The asset inventory holds 3 assets, and the run took 0.8 s.
Reading 2 Dart files for what they name took 0.8 s.

From the top (the boxes are those of every result report, see The console report):

  1. The head box: the preset, the checks that ran, and the number of files: each declared asset once, plus each other file of an asset that has a result, such as a variant that is too large. A row Switched off names the checks the configuration switches off.
  2. The box Violations: each file a sub-heading over its results. An asset is a file as a whole, so a row has — where a line and a column would be.
  3. The box Checks: each check that found something once, with its tier and count, its message and how to fix it. Where a message is specific to one result, it is written below that result instead, and the how-to-fix line stays under the check (as for missing_asset_variants, whose messages name each image’s own variants). A box Checks that failed names a check that threw.
  4. The verdict box: always PASS, unless the configuration is in error.
  5. Below it, how many assets the inventory holds and how long the run took; how many Dart files were read and how long that took (No Dart file was read when no check needed them).

--reporter json writes the result schema assay.result/3 with command: assets and scope: project.

  • violations: one per result, with source: assets, the check’s name as rule, tier: advisory, the asset’s path as file, the range 1:1–1:1 and a fingerprint of the check’s name, the path and the empty text.
  • files: the declared assets, each judged, by the file a result on the whole asset is placed at (the base file, or the lowest variant where there is none), each followed by every other file of it that has a result (a variant that oversized_assets reports).
  • The verdict is pass unless the configuration is in error.
  • assetChecks, which only this command writes:
"assetChecks": {
"checks": [
{"name": "unused_assets", "status": "ran"},
{"name": "oversized_assets", "status": "ran"},
{"name": "missing_asset_variants", "status": "ran"}
],
"assetsDeclared": 11,
"filesRead": 5,
"readingMilliseconds": 5650,
"milliseconds": 5700
}
Field What it is
checks The checks the run was asked for, in the order of the checks. status is ran, off (switched off by the configuration) or failed (it threw and has no result; failure says what it threw).
assetsDeclared The assets of the inventory.
filesRead The Dart files read for what they name; 0 when no check needed them.
readingMilliseconds How long reading the Dart files took.
milliseconds How long the inventory, the reading and the checks took together.

An asset result is advisory like any other: SARIF level note, GitLab severity minor, a GitHub notice annotation. In SARIF it carries the property source: assets. An asset has no line, so each format places it in its own way:

Reporter An asset result
console A row under the file with the mark, — in the column of line:column, the check and the tier: ! — unused_assets advisory.
json file is the asset’s path and range is the empty range 1:1–1:1, which stands for the file as a whole.
sarif A physicalLocation with the path under %SRCROOT% and a region of startLine: 1 alone, because GitHub code scanning requires a start line. This is valid SARIF 2.1.0.
github ::notice file=<path>,title=<check>::<text>, with no line and no col. GitHub shows it on the file in the annotation list and the summary, not on a line of the diff. A tab in the path is written as it is, since the format has no escape for it.
gitlab location.path is the asset’s path and location.lines.begin is 1, since the format asks every entry for a line.

assets does not write html: that is the metric report.

Code When
0 The checks ran, whatever they found, also with a check that failed.
2 A configuration error (no check runs then), or a usage error: a name that is not one of the checks, a reporter the command does not take.
3 assay could not run, or could not write a report file it was asked for.

A check that throws is reported as failed, with what it threw, and the other checks still run. That is a defect of assay.

Each check has enabled and exclude under assay.assets, then its own keys: oversized_assets has max_kb and image_extensions, missing_asset_variants has variants and image_extensions (see their pages).

assay:
assets:
unused_assets:
exclude: ["assets/native/**"]
oversized_assets:
max_kb: {3.0x: 2000} # laid over the default: only 3.0x changes
missing_asset_variants:
variants: [2x]
# unused_assets: false # the short form of enabled: false
  • Every check is on under every preset.
  • A check switched off does not run, even when you name it; the result says it is off. A run in which no check needs the Dart files reads none.
  • No result is placed at a file that assay.exclude, analyzer.exclude or the check’s own exclude covers.
  • An unknown name under assay.assets is a configuration error. Its message names the closest check where the name looks misspelt, and else the three names. A key a check does not have is an error that names the keys it has, and so is a value a key does not take.
  • The gate lists a change of any key under assay.assets among the configuration changes, like every other key.
  • assay config prints the asset checks between the rules and the excluded paths where the project changed one of them; assay config --verbose always does, with every key and the file its value came from.