Skip to content

noExcessiveLinesPerFile (JavaScript)

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

Restrict the number of lines in a file.

Large files tend to do many things and can make it hard to follow what’s going on. This rule can help enforce a limit on the number of lines in a file.

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

biome.json
{
"linter": {
"rules": {
"style": {
"noExcessiveLinesPerFile": {
"level": "on",
"options": {
"maxLines": 2
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
code-block.js:1:1 lint/style/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.

const a = 1;
const b = 2;

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

The default value for maxLines is 300. The following example shows how to set the maxLines option to a smaller value. It reports a diagnostic because the file has more than 4 lines:

biome.json
{
"linter": {
"rules": {
"style": {
"noExcessiveLinesPerFile": {
"level": "on",
"options": {
"maxLines": 4
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
const d = 4;
const e = 5;
code-block.js:1:1 lint/style/noExcessiveLinesPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This file has too many lines (5). Maximum allowed is 4.

> 1 │ const a = 1;
^^^^^^^^^^^^
> 2 │ const b = 2;
> 3 │ const c = 3;
> 4 │ const d = 4;
> 5 │ const e = 5;
^^^^^^^^^^^^
6 │

Consider splitting this file into smaller files.

When this option is set to true, blank lines are not counted towards the maximum line limit.

Default: false

The following example shows how skipBlankLines can prevent a diagnostic by excluding blank lines from the total count:

biome.json
{
"linter": {
"rules": {
"style": {
"noExcessiveLinesPerFile": {
"level": "on",
"options": {
"maxLines": 2,
"skipBlankLines": true
}
}
}
}
}
}
const a = 1;
const b = 2;

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": {
"style": {
"noExcessiveLinesPerFile": {
"level": "on",
"options": {
"maxLines": 2
}
}
}
}
}
}
// biome-ignore-all lint/style/noExcessiveLinesPerFile: generated file
const a = 1;
const b = 2;
const c = 3;