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.
Options
Section titled “Options”| 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. |
Examples
Section titled “Examples”assay cross-file # every check, on the consoleassay cross-file unused_files # one checkassay cross-file --reporter json # the result schema, with the crossFileChecks fieldassay cross-file --reporter sarif:build/cross-file.sarifOutput
Section titled “Output”Console
Section titled “Console”╭─ 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):
- The head box: the preset, the checks that ran and the number of files judged. A row
Switched offnames the checks the configuration switches off. - The box
Not judged: the files that are not judged, each with its reasons and its compile errors. - The box
Violations: the results, each file a sub-heading over its rows. The results ofduplicated_codestand in a box of their own instead, each group of copies with every place it is at (see Duplicated code). - The box
Checks: the checks that found something, each once with its tier, its count, its message and how to fix it. A boxChecks that failednames a check that threw, with what it threw. - 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, withsource: cross_file, the check’s name asrule,tier: advisoryand a fingerprint.summary.crossFilecounts them.files: the filescheckwould judge, eachjudgedornot_judged, with the compile errors incompileErrors.- The verdict is
passunless 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. |
Other formats
Section titled “Other formats”A result is advisory like any other: level note, severity minor, a notice annotation.
Exit codes
Section titled “Exit codes”| 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.
Which files are read
Section titled “Which files are read”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.excludeandanalyzer.excludeamong them, so that a use from generated code counts. Left out, ascheckleaves them out:.dart_tooland the other tool directories, and every directory directly under the project root whose name starts with a dot. - Each file resolved as
checkresolves 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_codeonly 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.
Configuration
Section titled “Configuration”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_filethat 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 meanunused_files?”), and else the five names.