max-lines
有些人认为大文件代码味道。大文件往往会做很多事情,并且可能会让事情变得很难。虽然在文件中没有客观的最大数量的线被认为是可以接受的,但大多数人会认为它不应该是成千上万。建议通常范围从100到500行。
Rule Details
此规则为每个文件强制执行最多行数,以帮助维护和降低复杂性。
Options
此规则有一个数字或对象选项:
"max"
(默认300
)在文件中强制执行最大行数"skipBlankLines": true
忽略纯粹由空白组成的线条。"skipComments": true
忽略仅包含评论的行
code
此规则的错误代码示例,最大值为2
:
/*eslint max-lines: ["error", 2]*/
var a,
b,
c;
/*eslint max-lines: ["error", 2]*/
var a,
b,c;
/*eslint max-lines: ["error", 2]*/
// a comment
var a,
b,c;
此规则的正确代码示例,最大值为2
:
/*eslint max-lines: ["error", 2]*/
var a,
b, c;
/*eslint max-lines: ["error", 2]*/
var a, b, c;
/*eslint max-lines: ["error", 2]*/
// a comment
var a, b, c;
skipBlankLines
此规则的错误代码示例包含以下{ "skipBlankLines": true }
选项:
/*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/
var a,
b,
c;
此规则的正确代码示例包含以下{ "skipBlankLines": true }
选项:
/*eslint max-lines: ["error", {"max": 2, "skipBlankLines": true}]*/
var a,
b, c;
skipComments
此规则的错误代码示例包含以下{ "skipComments": true }
选项:
/*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/
// a comment
var a,
b,
c;
此规则的正确代码示例包含以下{ "skipComments": true }
选项:
/*eslint max-lines: ["error", {"max": 2, "skipComments": true}]*/
// a comment
var a,
b, c;
何时不使用它
如果您不关心文件中的行数,则可以关闭此规则。
进一步阅读
相关规则
- complexity
- max-depth
- max-nested-callbacks
- max-params
- max-statements
兼容性
- JSCS: maximumNumberOfLines
版本
该规则在ESLint 2.12.0中引入。
资源
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com