max-classes-per-file
Enforce a maximum number of classes per file
When a file holds several classes, its name can only describe one of them, and the others are hard to find.
Class declarations and class expressions both count. The default maximum is 1.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"max-classes-per-file" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"max-classes-per-file" = ["error", {
max = 1,
ignoreExpressions = false,
}]Examples#
example.js1 problem
class User {}File has too many classes (2). Maximum allowed is 1.
class Session {}example.jsNo problems
class User {}Options#
bunfig.toml
[lint.rules]
max-classes-per-file = ["error", { max = 2, ignoreExpressions = true }]The option is either a number (the maximum) or an object:
| Option | Default | What it does |
|---|---|---|
max | 1 | The number of classes a file can have. |
ignoreExpressions | false | Don't count class expressions. |
example.jswith
2No problemsclass User {}
class Session {}example.jswith
{ "max": 2 }1 problemclass User {}File has too many classes (3). Maximum allowed is 2.
class Session {}
class Token {}ignoreExpressions#
example.js1 problem
class User {}File has too many classes (2). Maximum allowed is 1.
const Guest = class extends User {};example.jswith
{ "ignoreExpressions": true }No problemsclass User {}
const Guest = class extends User {};