Skip to content

noExcessiveLinesPerFile

  • Rule available since: v2.3.12
  • Diagnostic Category: lint/style/noExcessiveLinesPerFile
  • This rule isn’t recommended, so you need to enable it.
  • This rule doesn’t have a fix.
  • The default severity of this rule is information.
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": {
"options": {
"maxLines": 2
}
}
}
}
}
}
.a { color: red; }
.b { color: blue; }
.c { color: green; }
code-block.css:1:1 lint/style/noExcessiveLinesPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

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

> 1 │ .a { color: red; }
^^^^^^^^^^^^^^^^^^
> 2 │ .b { color: blue; }
> 3 │ .c { color: green; }
^^^^^^^^^^^^^^^^^^^^
4 │

Consider splitting this file into smaller files.

.a { color: red; }
.b { color: blue; }

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": {
"options": {
"maxLines": 4
}
}
}
}
}
}
.a { color: red; }
.b { color: blue; }
.c { color: green; }
.d { color: yellow; }
.e { color: purple; }
code-block.css:1:1 lint/style/noExcessiveLinesPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

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

> 1 │ .a { color: red; }
^^^^^^^^^^^^^^^^^^
> 2 │ .b { color: blue; }
> 3 │ .c { color: green; }
> 4 │ .d { color: yellow; }
> 5 │ .e { color: purple; }
^^^^^^^^^^^^^^^^^^^^^
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": {
"options": {
"maxLines": 2,
"skipBlankLines": true
}
}
}
}
}
}
.a { color: red; }
.b { color: blue; }

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": {
"options": {
"maxLines": 2
}
}
}
}
}
}
/* biome-ignore-all lint/style/noExcessiveLinesPerFile: generated file */
.a { color: red; }
.b { color: blue; }
.c { color: green; }