Skip to content

noExcessiveLinesPerFile

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": "error"
}
}
}
}

Restrict the number of lines in a file.

This rule checks the number of lines in a file and reports a diagnostic if it exceeds a specified limit. Some people consider large files a code smell. Large files tend to do many things and can make it hard to follow what’s going on. Many coding style guides dictate a limit of the number of lines that a file can comprise of. This rule can help enforce that style.

The following example will show a diagnostic when maxLines is set to 2:

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
code-block.js:1:1 lint/nursery/noExcessiveLinesPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This file has too many lines (3). Maximum allowed is 2.

> 1 │ const a = 1;
^^^^^^^^^^^^
> 2 │ const b = 2;
> 3 │ const c = 3;
^^^^^^^^^^^^
4 │

Consider splitting this file into smaller files.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const a = 1;
const b = 2;

The following options are available:

This option sets the maximum number of lines allowed in a file. If the file exceeds this limit, a diagnostic will be reported.

Default: 300

When maxLines: 2, the following file will be considered invalid:

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
code-block.js:1:1 lint/nursery/noExcessiveLinesPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This file has too many lines (3). Maximum allowed is 2.

> 1 │ const a = 1;
^^^^^^^^^^^^
> 2 │ const b = 2;
> 3 │ const c = 3;
^^^^^^^^^^^^
4 │

Consider splitting this file into smaller files.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

When this option is set to true, blank lines are not counted towards the maximum line limit. This means that only lines with actual code or comments will be counted.

Default: false

When maxLines: 3 and skipBlankLines: true, the following file will be considered valid even though it has 5 total lines, because only 3 lines contain code:

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 3,
"skipBlankLines": true
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;

If you need to exceed the line limit in a specific file, you can suppress this rule at the top of the file:

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
// biome-ignore lint/nursery/noExcessiveLinesPerFile: generated file
const a = 1;
const b = 2;
const c = 3;