Skip to content

assay cross-file [checks…]

Runs the cross-file checks on the whole project: the checks whose results cannot be decided from one file alone. They are advisory, so the command exits with 0 whatever they find.

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

With no name it runs every cross-file check; with names, only those:

Check Reports
unused_code A declaration nothing in the project refers to.
unused_files A Dart file no entry point reaches through imports, exports or parts.
unused_l10n A localization entry nothing in the project uses: a member of a class of Flutter’s localization generator, or a key of the translation files of easy_localization.
unnecessary_nullable A parameter declared nullable to which every call in the project passes a value that cannot be null.
duplicated_code A region of the shipped code (the Dart files under lib/ of each package) that copies of a block of code found elsewhere in it cover; its message and its related places name the other copies.

A name that is not one of the five is a usage error. The command takes no paths: it always reads the whole project. See Cross-file checks for what each check sees.

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 cross-file # every check, on the console
assay cross-file unused_files # one check
assay cross-file --reporter json # the result schema, with the crossFileChecks field
assay cross-file --reporter sarif:build/cross-file.sarif
╭─ assay cross-file ───────────────────────────────────────────────────────────╮
│ Preset strict │
│ Checks unused_files │
│ Files 2 │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Not judged ──────────────────────────────────────────────────────── 1 file ─╮
│ Line Code │
│ ──────────────────────────── │
│ lib/broken.dart not judged · 1 compile error │
│ ✗ 1:17 return_of_invalid_type │
│ A value of type 'String' can't be returned from the function │
│ 'broken' because it has a return type of 'int'. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Violations ─────────────────────────────────────────────────── 1 in 1 file ─╮
│ Line Rule Tier │
│ ──────────────────────────── │
│ lib/unused.dart 1 violation │
│ ! 1:1 unused_files advisory │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Checks ─────────────────────────────────────────────────────────────────────╮
│ Check Tier Count │
│ ───────────────────────────── │
│ unused_files advisory 1 │
│ No entry point reaches this file through imports, exports or parts. │
│ → Delete the file if nothing needs it, or import it where it is used. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ ✓ PASS ─────────────────────────────────────────────────────────────────────╮
│ 0 blocking · 1 advisory · 1 of 2 files · 1 not judged │
╰──────────────────────────────────────────────────────────────────────────────╯
The cross-file pass read 4 Dart files and took 0.9 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 judged. A row Switched off names the checks the configuration switches off.
  2. The box Not judged: the files that are not judged, each with its reasons and its compile errors.
  3. The box Violations: the results, each file a sub-heading over its rows. The results of duplicated_code stand in a box of their own instead, each group of copies with every place it is at (see Duplicated code).
  4. The box Checks: the checks that found something, each once with its tier, its count, its message and how to fix it. A box Checks that failed names a check that threw, with what it threw.
  5. The verdict box, which counts the results. Below it, a line says how many Dart files the pass read, those in excluded paths among them, and how long the pass and the checks took.

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

  • violations: one per result, with source: cross_file, the check’s name as rule, tier: advisory and a fingerprint. summary.crossFile counts them.
  • files: the files check would judge, each judged or not_judged, with the compile errors in compileErrors.
  • The verdict is pass unless the configuration is in error.
  • crossFileChecks, which only this command writes:
"crossFileChecks": {
"checks": [
{"name": "unused_files", "status": "ran"},
{"name": "unused_code", "status": "failed",
"failure": "The check failed with `Bad state: …`. That is a defect of the check, not of the project."}
],
"filesRead": 416,
"milliseconds": 12200
}
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).
filesRead The Dart files the pass read. Only Dart files count, though unused_l10n also reads l10n.yaml and JSON translation files.
milliseconds How long the pass and the checks took, the fingerprints of the results included.

A result is advisory like any other: level note, severity minor, a notice annotation.

Code When
0 The checks ran, whatever they found, also with files that do not compile and 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.

The checks share one pass of assay’s own engine, in the command-line program only.

  • Every Dart file of the project, generated files and files in assay.exclude and analyzer.exclude among them, so that a use from generated code counts. Left out, as check leaves them out: .dart_tool and the other tool directories, and every directory directly under the project root whose name starts with a dot.
  • Each file resolved as check resolves it. A file that does not compile, or cannot be read, is listed as not judged. The pass still uses what the analyzer could read of it, so that nothing is reported in another file because of it.
  • Tokens for duplicated_code only where it runs. With it switched off, or with other checks named, the pass reads none.

No result is placed in a file that assay.exclude, analyzer.exclude or the check’s own exclude covers. The one exception is unused_l10n: it reports in the generated localization class although the default assay.exclude covers it, and only its own exclude silences it there. Its results for easy_localization are placed at the line and column of the key in the JSON translation file.

The pass resolves every file of the project once, as check does.

The gate, assay baseline update and assay baseline status run the same checks; check does not. Their results pass through the baseline and never fail anything: see In the gate.

Each check has enabled and exclude under assay.cross_file:

assay:
cross_file:
unused_files:
enabled: false # or the short form `unused_files: false`
# unused_files:
# exclude: ["tool/templates/**"]
  • 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 name under assay.cross_file that is not one of the five is a configuration error. Its message names the closest check where the name looks misspelt (unused_filez → “Did you mean unused_files?”), and else the five names.