1 # enforce a maximum number of classes per file (max-classes-per-file)
3 Files containing multiple classes can often result in a less navigable
4 and poorly structured codebase. Best practice is to keep each file
5 limited to a single responsibility.
9 This rule enforces that each file may contain only a particular number
10 of classes and no more.
12 Examples of **incorrect** code for this rule:
15 /*eslint max-classes-per-file: "error"*/
21 Examples of **correct** code for this rule:
24 /*eslint max-classes-per-file: "error"*/
31 This rule may be configured with either an object or a number.
33 If the option is an object, it may contain one or both of:
35 - `ignoreExpressions`: a boolean option (defaulted to `false`) to ignore class expressions.
36 - `max`: a numeric option (defaulted to 1) to specify the maximum number of classes.
42 "max-classes-per-file": ["error", 1]
48 "max-classes-per-file": [
50 { "ignoreExpressions": true, "max": 2 }
55 Examples of **correct** code for this rule with the `max` option set to `2`:
58 /* eslint max-classes-per-file: ["error", 2] */
64 Examples of **correct** code for this rule with the `ignoreExpressions` option set to `true`:
67 /* eslint max-classes-per-file: ["error", { ignoreExpressions: true }] */
69 class VisitorFactory {
70 forDescriptor(descriptor) {
73 return `Visiting ${descriptor}.`;