max-statements
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"max-statements": "error",
},
},
];Enforce a maximum number of statements allowed in function blocks
function foo() {
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;
const foo11 = 11; // Too many.
}
const bar = () => {
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;
const foo11 = 11; // Too many.
};function foo() {
let one;
let two = class {
static {
let three;
let four;
let five;
if (six) {
let seven;
let eight;
let nine;
}
}
};
}function foo() {
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;
const foo11 = 11;
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
max-statements
eslint
export default [
{
rules: {
"max-statements": "error",
},
},
];max-statements
eslint plugin · style
{
"rules": {
"max-statements": "error"
}
}nursery/noExcessiveStatementsPerFunction
nursery · since 2.6.0
{
"linter": {
"rules": {
"nursery": {
"noExcessiveStatementsPerFunction": "error"
}
}
}
}Enforce a maximum number of lines of code in a function
Require or disallow initialization in variable declarations
Disallow assignments that can lead to race conditions due to usage of await or yield
Enforce or disallow capitalization of the first letter of a comment