max-statements

强制执行功能块中允许的最大语句数

max-statements 规则允许您指定函数中允许的最大语句数。

function foo() {
  var bar = 1; // one statement
  var baz = 2; // two statements
  var qux = 3; // three statements
}

规则详情

此规则强制执行功能块中允许的最大语句数。

选项

此规则有一个数字或对象选项:

  • "max"(默认 10)强制执行功能块中允许的最大语句数

n1eL+0rNztiY1sKneJqy/xV4xbQkUUIbptdfSJpsdehOl7DBNwC4zOjfXPwUyGTAr1if021TqUQLY/oh4lwes89C8LNNH2S2Cu1JWkC/mTpHWcQOrZAfarO/puHmrUfbyqrWkzZSntz5WvN6BmZfRyGLwU/6m2MrsOWlGlKGut4=

WhtdTe+SyJ0WUNUgKbqftH14r+kYEYAMLB+y3h0fvE5TyeVcrDm7eioz/kqA+xeS

    dyZvgXoGbMj0tyIhlnPOZMKeRTejxijJ4pIj9SZcfJR55Tp8noUyw0DhmCaJUAZUIpyAA2J9G4vU57RKlPKFG7AK9XdWGhEsXMcVujJTxas=

max

IkNtK1AnBCO6NSjlzxSStbQSG2j5zpy3wTSTNPG9LcMRvVm0e9DBPuNdlR14hOQQmALHkjtyiVLofAUrySkNG75qHsMwmRQBS7xpqfQXfxA=

/*eslint max-statements: ["error", 10]*/
/*eslint-env es6*/

function foo() {
  var foo1 = 1;
  var foo2 = 2;
  var foo3 = 3;
  var foo4 = 4;
  var foo5 = 5;
  var foo6 = 6;
  var foo7 = 7;
  var foo8 = 8;
  var foo9 = 9;
  var foo10 = 10;

  var foo11 = 11; // Too many.
}

let foo = () => {
  var foo1 = 1;
  var foo2 = 2;
  var foo3 = 3;
  var foo4 = 4;
  var foo5 = 5;
  var foo6 = 6;
  var foo7 = 7;
  var foo8 = 8;
  var foo9 = 9;
  var foo10 = 10;

  var foo11 = 11; // Too many.
};

IkNtK1AnBCO6NSjlzxSStbQSG2j5zpy3wTSTNPG9LcMRvVm0e9DBPuNdlR14hOQQahCmSJN08PoyFk5ez1S65YPzSYFhetXWB9ADwEKK4RI=

/*eslint max-statements: ["error", 10]*/
/*eslint-env es6*/

function foo() {
  var foo1 = 1;
  var foo2 = 2;
  var foo3 = 3;
  var foo4 = 4;
  var foo5 = 5;
  var foo6 = 6;
  var foo7 = 7;
  var foo8 = 8;
  var foo9 = 9;
  var foo10 = 10;
  return function () {

    // The number of statements in the inner function does not count toward the
    // statement maximum.

    return 42;
  };
}

let foo = () => {
  var foo1 = 1;
  var foo2 = 2;
  var foo3 = 3;
  var foo4 = 4;
  var foo5 = 5;
  var foo6 = 6;
  var foo7 = 7;
  var foo8 = 8;
  var foo9 = 9;
  var foo10 = 10;
  return function () {

    // The number of statements in the inner function does not count toward the
    // statement maximum.

    return 42;
  };
}

3Pjnj37R6ALOeem0iPhdQQ5mC7uzDQwY6wrENXgMhKYIvmrH1HmPNMOlXcg366LC2PvnbRtMGLXkp3weTYLqwpxBJ9lOvf/khZSYlK9HvyT22BdTgFUt/jBlnZ7ahaShDDmM5RP9wujjux/JfAjmj79MITIROzV/LGRzxNgfQEY=

dg8a89Fcmdiuqkj/gGSI6iw4/NevaIi9IfFxSFKTuxNCrAGUD8YCM+2iIFRWyufS2YDJLSoSWsQ5XpEVoIqdsAlPWlDCehLDkFgdFVGZZTM=

/*eslint max-statements: ["error", 2]*/

function foo() {
    let one;
    let two = class {
        static {
            let three;
            let four;
            let five;
            if (six) {
                let seven;
                let eight;
                let nine;
            }
        }
    };
}

ignoreTopLevelFunctions

dg8a89Fcmdiuqkj/gGSI6swm8WWM5uh/Q4lkQpsDSG16Y1+N695D7lJM2EpKf6Ryy9CywcoDqv19q6IUu0UH8wvoETCuFzN09AvwMmTB4dXmX9WUNCxY5Yep1gQfZj8rcFJAoJI0XkaKUSFoMXFU/Io8KEIWYOmFyLs8zLRpz/s=

/*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/

function foo() {
  var foo1 = 1;
  var foo2 = 2;
  var foo3 = 3;
  var foo4 = 4;
  var foo5 = 5;
  var foo6 = 6;
  var foo7 = 7;
  var foo8 = 8;
  var foo9 = 9;
  var foo10 = 10;
  var foo11 = 11;
}