assay metrics [paths…]
Prints the metric report of the project, or of the given paths: every metric value by file, class and function, with the limits in effect. It judges nothing. See Metrics for the seven metrics; the page of each says how it is counted.
assay metrics [paths…] [--reporter <name>[:<file>]]… [--coverage <lcov file>] [--snapshot <file or directory>] [--color auto|always|never]The report also gives each file its code lines and, where the check duplicated_code is on, the duplicated code of the files under lib/. A value over its limit is a violation of the matching limit rule, which check and gate report. metrics only marks it, and exits with 0 whenever it could run.
Options
Section titled “Options”| Option | Effect |
|---|---|
paths… |
Measure only the files at and below these paths. A path outside the project, or one that does not exist, is a usage error. |
--reporter <name>[:<file>] |
console (the default), json or html, to standard output or to a file. Repeatable. See Commands. |
--coverage <lcov file> |
Add the line coverage of the measured files under lib/, from an lcov report the project’s tests wrote, by a path absolute or relative to the project root. assay runs no test. See Line coverage. |
--snapshot <file or directory> |
Record the code lines and the aggregates of each metric of the whole project, with the line coverage and the duplicated code where the report holds them, as one line of JSON. A path that exists as a directory, or ends with /, gets a file of its own. With paths, a usage error. See Snapshots and trends. |
--color auto|always|never |
The form of the console output, as for every command. |
Examples
Section titled “Examples”assay metrics # the whole project, on the consoleassay metrics lib/src # the files at and below the given pathsassay metrics --reporter json # the result schema, with the metrics fieldassay metrics --reporter json:build/metrics.jsonassay metrics --reporter html:build/metrics.html # one page to open and pass onassay metrics --coverage coverage/lcov.info # with the line coverage of lib/assay metrics --coverage coverage/lcov.info --snapshot assay-snapshots/Output
Section titled “Output”Console
Section titled “Console”╭─ assay metrics ──────────────────────────────────────────────────────────────╮│ Preset strict ││ Files 3 │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Not measured ────────────────────────────────────────────────────── 1 file ─╮│ Line Code ││ ──────────────────────────── ││ lib/broken.dart not measured · 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'. │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Metrics ────────────────────────────────────────────────────────────────────╮│ Metric Limit Measured Highest Over limit ││ ─────────────────────────────────────────────────────────────────────────── ││ cyclomatic complexity 10 16 11 1 ││ cognitive complexity 15 16 16 1 ││ function length 40 16 46 1 ││ nesting depth 3 16 4 2 (1 taken over) ││ parameter count 4 16 5 2 (1 suppressed) ││ methods per class none 2 2 - ││ file length 30 3 113 2 (1 suppressed) │╰──────────────────────────────────────────────────────────────────────────────╯
…
╭─ Function length ───────────────────────── limit 40 · 1 over · 16 functions ─╮│ No limit in test/**, integration_test/**, test_driver/** ││ ││ Value File Line Name ││ ─────────────────────────────────────────────────────────────── ││ 46 test/long_test.dart 1:6 main no limit here ││ ! 45 lib/over_limits.dart 53:14 longList ││ 25 lib/over_limits.dart 27:8 nameOf ││ 15 lib/over_limits.dart 99:5 nestedCount ││ 13 lib/over_limits.dart 13:5 deeplyNested ││ 9 lib/measured.dart 11:7 Cart.total ││ 4 lib/measured.dart 32:5 largest ││ 3 lib/measured.dart 3:3 Cart ││ 1 lib/measured.dart 9:11 Cart.count ││ 1 lib/measured.dart 21:15 Cart.empty ││ 6 more values, listed by `assay metrics --reporter json` │╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Nesting depth ──────────────────────────── limit 3 · 2 over · 16 functions ─╮│ Value File Line Name ││ ───────────────────────────────────────────────────────────── ││ ! 4 lib/over_limits.dart 13:5 deeplyNested ││ ! 4 lib/over_limits.dart 99:5 nestedCount taken over ││ 2 lib/measured.dart 11:7 Cart.total ││ 1 lib/over_limits.dart 27:8 nameOf ││ 0 lib/measured.dart 3:3 Cart ││ 0 lib/measured.dart 9:11 Cart.count ││ 0 lib/measured.dart 21:15 Cart.empty ││ 0 lib/measured.dart 26:11 Priced.price ││ 0 lib/measured.dart 28:8 Priced.isFree ││ 0 lib/measured.dart 32:5 largest ││ 6 more values, listed by `assay metrics --reporter json` │╰──────────────────────────────────────────────────────────────────────────────╯
…
3 files measured · 1 not measured · 9 values over their limitFrom the top:
- The head box: the preset and the number of files measured.
- The box
Not measured: the files not measured, with their compile errors. - The box
Metrics: one row per metric. The last column counts the values over their limit, with the suppressed and taken-over ones apart:2 (1 suppressed),2 (1 taken over). - One box per metric, with its limit and its counts on the right of its top line, highest value first: every value over its limit, then more up to ten. The last row of a box counts the values left out, which the JSON form lists.
- The line coverage and duplicated code boxes, where there are any, and below the last box the totals.
Each row of a metric’s box holds:
!for a value over its limit;- the value;
- the file, and the place
line:columnwherecheckwould report the violation; a metric of whole files, the file length, has the file alone; - the name: a member by its class (
Cart.total), a constructor by its class and its own name (Cart,Cart.empty), a local function by the function it is in (pick in largest), a closure by that function (closure in Engine.judge), an unnamed extension by the type it extends (extension on String). A name or a path too long for its column breaks inside it; suppressedortaken overwhere the value is one (see Over the limit, suppressed, taken over), andno limit herefor a value in a file the limit rule’sexcludecovers; the box’sNo limit in …row names those paths.
--reporter json writes the result schema assay.result/3 with command: metrics and a metrics field, which no other command writes. The result holds no violation and no suppression. Its verdict is pass unless the configuration is in error. A file not measured is in files as not_judged, with its compile errors in compileErrors.
"metrics": { "limits": [{"metric": "functionLength", "unit": "function", "rule": "max_function_length", "max": 40, "exclude": ["test/**", "integration_test/**", "test_driver/**"]}, …], "summaries": [{"metric": "parameterCount", "measured": 16, "highest": {"file": "lib/over_limits.dart", "name": "manyParameters", "line": 7, "column": 5, "value": 5}, "overLimit": 2, "suppressed": 1, "takenOver": 0}, …], "files": [{ "path": "lib/measured.dart", "limitsExcluded": [], "fileLength": {"value": 35, "limit": 30, "overLimit": true, "suppressed": false}, "codeLines": 25, "classes": [{"name": "Cart", "kind": "class", "line": 2, "column": 7, "methodsPerClass": {"value": 2, "limit": null, "overLimit": false, "suppressed": false}}], "functions": [{"name": "Cart.total", "line": 11, "column": 7, "cyclomaticComplexity": {"value": 3, "limit": 10, "overLimit": false, "suppressed": false}, "cognitiveComplexity": {"value": 3, "limit": 15, "overLimit": false, "suppressed": false}, "functionLength": {…}, "nestingDepth": {…}, "parameterCount": {…}}, …] }, …]}A value taken over names the rule that takes it over in takenOverBy; other values leave the field out:
{"name": "nestedCount", "line": 99, "column": 5, "cognitiveComplexity": {"value": 16, "limit": 15, "overLimit": true, "suppressed": false}, "nestingDepth": {"value": 4, "limit": 3, "overLimit": true, "suppressed": false, "takenOverBy": "max_cognitive_complexity"}, …}- A metric is named by its key, the field that holds its value:
cyclomaticComplexity,cognitiveComplexity,functionLength,nestingDepth,parameterCount,methodsPerClass,fileLength. limitsandsummarieshave one entry per metric, in the order of the summary table.filesare in the order of their paths; classes and functions in source order.- A value with no limit there has
limit: null, and its metric is named in the file’slimitsExcluded. - Every field is described in
packages/assay_cli/lib/schema/assay_result_3.schema.json, which ships withassay_cli.
--reporter html:<file> writes the report as one page, to open from the file system and pass on without a server. Only metrics writes HTML; check and gate refuse --reporter html as a usage error. Without a file the page goes to standard output, and then no JSON report can go there beside it.
The page shows, from the top:
- The head: assay metric report, the package (the
namein the root pubspec), assay’s version, when the report was written (local time with its offset from UTC), the preset, and how many files were measured and not measured. - The summary: one block per metric with its limit (or no limit), the highest value with its place, how many were measured, how many are over the limit (
▲ 2 (△ 1 suppressed),▲ 2 (△ 1 taken over)), and the paths where the limit rule’sexcludelifts the limit. - Links to the tables, and a legend of the marks.
- Three tables, each worst first:
- Functions: the function, the five values (Cyclomatic, Cognitive, Length, Nesting, Parameters, each with its limit in the heading), file and line;
- Classes: the class, its kind, methods per class, file and line;
- Files: the path, file length, code lines, number of functions, and the values over a limit in the file, with the suppressed and taken-over ones apart.
- The files not measured, with their compile errors.
- The foot: how each metric is counted, the name of its limit rule, and that a value over its limit is a violation
checkandgatereport, unless it is suppressed or taken over.
Marks. They do not rest on colour:
| Mark | Means |
|---|---|
▲ 72 / 60 |
Over its limit: the value and its limit, on a tinted cell. |
△ 72 / 60 suppressed |
Over its limit and suppressed, on a grey cell. |
△ 72 / 60 taken over |
Over its limit and taken over; its title names the rule that takes it over. |
no limit here |
In a file the limit rule excludes. |
Sorting and filtering. Click a column heading to sort by it, highest (or A to Z) first; click again to reverse. A field filters the rows by path or name as the page shows them: characters a terminal acts on are written out (\n, ), so typing new\nline finds the file shown as lib/new\nline.dart. The script reads its values from a data block in the page, <script type="application/json" id="assay-data">: for each table its columns, and one row per function, class or file in report order. A change of the page’s look leaves the data block as it is. Without scripts every table, value and mark is still there, worst first; only sorting and filtering are lost, and the filter field stays hidden.
Self-contained and safe. The style sheet and the script are in the page, the fonts are the system’s, and nothing refers to an outside address. A Content-Security-Policy lets nothing load and applies only the page’s own style sheet and script, each named by its SHA-256 hash. Every name and path from the project is escaped for where it stands, so markup in a name cannot run.
Screens. The page follows the system’s light or dark setting. On a phone-width window the summary blocks stack, names in a table break at their dots, and each table scrolls sideways inside its box; the page itself never does.
Size. The page holds every value twice, as markup and as data.
Line coverage
Section titled “Line coverage”With --coverage, a box after the metric boxes. What is counted is in Coverage.
-
Console:
- the share (
no coverable linewhere there is none) and the number of files measured; - the lines that ran and the report;
- only where there is something to say: what the figure leaves aside (files not in the report, stale files, ignored lines), and the files the report lists that are not measured (tests,
bin/, excluded files, files outside the project, files no longer there); - the ten files with the lowest share, by their counts (of two equal shares the one with more lines not run first, then by path), each with its share,
covered/coverable, its path and the marksnot in the reportandstale, then a count of the others. A file with no coverable line has no share and is not listed. Where no file underlib/was measured, the box says so.
- the share (
-
JSON:
metrics.coverage, only with--coverage($defs/coveragein the schema file):Field What it is reportThe report, by the path it was given. filesEvery measured file under lib/, in path order, a file that does not compile among them (it has coverage, but no metrics):path,coverableLines,coveredLines,ignoredLines,inReport,stale.totalcoverableLines,coveredLinesandpercent: the share rounded down to one decimal,nullwhere no line is coverable. It is for showing; a decision compares the counts.notInReportThe measured files with a coverable line that the report does not list; they count as not run. leftOutThe files of the project the report lists that are not measured, counted over the whole project. outsideProjectThe files the report lists outside the project. goneThe files of the project the report lists that are no longer there. -
HTML: a Line coverage card ends the summary: the share, its lines, the report, the files measured, those not in the report, the stale ones and the ignored lines. The Files table gets a last column Coverage (
lines run): a file’s share with the tagsnot in the reportandstale, a dash for a file with no coverable line, empty for a file outsidelib/. It sorts like the other columns, the files without a share last in either order; the data block’sfilesgains the columncoverage(the share, ornull).
Duplicated code
Section titled “Duplicated code”Where duplicated_code is on, a box after the line coverage. What is counted is in Code lines and duplicated code and Duplicated code. Where the check is switched off there is no box, no metrics.duplication, and no card or column of it.
╭─ Duplication ────────────────────────────────────────────── 80.6% · 4 files ─╮│ 58 of 72 code lines are duplicated, in 2 regions ││ 1 block of at least 100 tokens and 10 lines, sought across lib/ ││ ││ Duplicated Lines File ││ ────────────────────────────────────────── ││ 96.7% 29/30 lib/feature/detail.dart ││ 96.7% 29/30 lib/screens/home.dart │╰──────────────────────────────────────────────────────────────────────────────╯-
Console: the share (
no code linewhere there is none) and the number of files; the duplicated and code lines and the regions; the blocks and the thresholds (min_tokens,min_lines) they were found by; the ten files with the most duplicated lines (ties in path order), each with its share,duplicated/codeand its path, then a count of the others. A file with no duplicated line is not listed. Where no file underlib/was measured, the box says so. -
JSON:
metrics.duplication, where the check is on ($defs/duplicationin the schema file):"duplication": {"minTokens": 100,"minLines": 10,"files": [{"path": "lib/feature/detail.dart", "codeLines": 30, "duplicatedLines": 29, "regions": 1}, …],"total": {"codeLines": 72, "duplicatedLines": 58, "percent": 80.6},"blocks": 1}filesare in path order: every measured file the check reads, one with no duplicated line among them.regionsis the number of the file’s duplicated regions, which are the results ofassay cross-file.blocksis the number of duplicated blocks with a copy in a listed file.percentis the share rounded up to one decimal,nullwhere there is no code line; a decision compares the counts. -
HTML: a Duplication card ends the summary: the share, its lines, the files, the regions, the blocks and the smallest block. The Files table gets a last column Duplicated (
lines): the file’s duplicated lines, with its share in the title, empty for a file the check does not read, such as a test, which sorts last in either order; the data block’sfilesgains the columnduplication(the number, ornull).
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
| 0 | It could run, whatever the values, the coverage and the duplicated code. |
| 2 | A configuration error: nothing is measured, the report says so, and the coverage report is not read. Or a usage error, which writes no result: a reporter other than console, json and html; a path outside the project or one that does not exist; --snapshot with paths; a --coverage file that does not exist or cannot be read, is not lcov (the message names its first line that is not), holds no record, or names no file of the project (a report written on another machine; the message names its first record). See Reports that are refused. |
| 3 | It could not run, or could not write a report file or the snapshot. |