src/content/docs/linter/rules/no-excessive-lines-per-file.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="CSS" icon="seti:css"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.12` - Diagnostic Category: [`lint/nursery/noExcessiveLinesPerFile`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). ## How to configure ```json title="biome.json" { "linter": { "rules": { "nursery": { "noExcessiveLinesPerFile": "error" } } } }## Description
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.
## Examples
### Invalid
The following example will show a diagnostic when `maxLines` is set to 2:
```json title='biome.json'
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
.a { color: red; }
.b { color: blue; }
.c { color: green; }
.a { color: red; }
.b { color: blue; }
maxLinesThis option sets the maximum number of lines allowed in a file. If the file exceeds this limit, a diagnostic will be reported.
Default: 300
skipBlankLinesWhen this option is set to true, blank lines are not counted towards the maximum line limit.
Default: false
## Description
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.
## Examples
### Invalid
The following example will show a diagnostic when `maxLines` is set to 2:
```json title='biome.json'
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
query Foo { id }
query Bar { id }
query Baz { id }
query Foo { id }
query Bar { id }
maxLinesThis option sets the maximum number of lines allowed in a file. If the file exceeds this limit, a diagnostic will be reported.
Default: 300
skipBlankLinesWhen this option is set to true, blank lines are not counted towards the maximum line limit.
Default: false
{
"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:
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
const a = 1;
const b = 2;
The following options are available:
maxLinesThis 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:
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
const a = 1;
const b = 2;
const c = 3;
skipBlankLinesWhen 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:
{
"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:
{
"linter": {
"rules": {
"nursery": {
"noExcessiveLinesPerFile": {
"options": {
"maxLines": 2
}
}
}
}
}
}
// biome-ignore lint/nursery/noExcessiveLinesPerFile: generated file
const a = 1;
const b = 2;
const c = 3;