Files containing multiple classes can often result in a less navigable and poorly structured codebase. Best practice is to keep each file limited to a single responsibility.
This rule enforces that each file may contain only a particular number of classes and no more.
Examples of incorrect code for this rule:
/*eslint max-classes-per-file: "error"*/
class Foo {}
class Bar {}
Examples of correct code for this rule:
/*eslint max-classes-per-file: "error"*/
class Foo {}
This rule has a numeric option (defaulted to 1) to specify the maximum number of classes.
For example:
{
"max-classes-per-file": ["error", 1]
}
Examples of correct code for this rule with the numeric option set to 2
:
/* eslint max-classes-per-file: ["error", 2] */
class Foo {}
class Bar {}
This rule was introduced in ESLint 5.0.0-alpha.3.
© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/max-classes-per-file