Eslint参考手册
规则 | Rules
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;
何时不使用它
如果您不关心文件中的行数,则可以关闭此规则。
进一步阅读
- Software Module size and file size
相关规则
- complexity
- max-depth
- max-nested-callbacks
- max-params
- max-statements
兼容性
- JSCS: maximumNumberOfLines
版本
该规则在ESLint 2.12.0中引入。
资源
- Rule source
- Documentation source
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |