File length
The length of a file is the number of its lines, the number an editor shows on the last line. A long file holds several things that happen to live together: finding one means scrolling or searching, and a change to one shows up in the history of all.
It is the one metric of a file that a rule limits. Every file also has its code lines, which no rule limits.
How it is counted
Section titled “How it is counted”Every line of the file, blank lines and comments included. The line break at the end of the last line starts no further line. A part file is measured alone.
The page of the limit rule has every case: How the length is counted.
Example
Section titled “Example”// Prices, in cents.
import 'dart:math';
/// The cheapest of [prices].int cheapest(List<int> prices) => prices.reduce(min);Its length is 6: every line counts, the comment, the two blank lines and the documentation comment among them, and the line break after the last line starts no seventh line. The same file has 2 code lines, the import and the function: function length and the code lines leave out blank lines and comments, and the file length does not.
The limit rule is max_file_length, advisory: a file whose value is over the limit max is a violation of it. A file exactly at max is not reported.
| Preset | Limit |
|---|---|
core |
none: the preset does not hold the rule |
recommended |
600 |
strict |
400 |
recommended and strict make the rule silent in the test directories, test/**, integration_test/** and test_driver/**. A file in those directories has no limit, and the report marks it no limit here.
To change the limit, set the rule’s max; the rule’s exclude stays as the preset set it (Configuring metrics):
assay: rules: max_file_length: max: 800In the report
Section titled “In the report”assay metrics gives the metric a row in the box Metrics and a box of its own, with the limit and the counts on the right of its top line and the highest values first. A row of that box has the file alone, since the file length is a metric of whole files. assay metrics shows the report.
- JSON:
fileLengthof each file, with itsvalue, itslimitand whether it is over it. - HTML: the column of the file length in the table of files.
- Trend: the series File length over limit (Points and series).