@ada-support/eslint-plugin-object-newline 中文文档教程
eslint-plugin-object-pattern-newline
ESLint 插件,用于在 ES6 对象模式中强制换行。
该插件中只有一个规则,默认情况下当一行中的值超过 4 个时会报告。
Installation
$ npm install eslint-plugin-object-pattern-newline --save-dev
或者
$ yarn add eslint-plugin-object-pattern-newline -D
Usage
将 object-newline
添加到 .eslintrc
配置文件的插件部分。
{
"plugins": [
"object-newline"
]
}
然后在规则部分添加规则。
{
"rules": {
"object-newline/enforce": "error"
}
}
Options
第一种也是最易读的方法是使用一个允许您指定任何可用选项的对象,将未指定的所有内容保留为默认值。
{
"rules": {
"max-len": ["error", 100],
"object-newline/enforce": [
"error",
{
"items": 2,
"max-len": 100
}
]
}
}
items
[number] (default: 4
)
指定在插件需要将项目分解为多行之前的最大项目数。
max-len
[number] (default: Infinity
)
指定项目中源代码行的最大长度。 这允许插件防止应用快速修复,这些修复会导致您的代码违反此限制。 如果超过限制,该规则还会自动为您拆分行。
Testing
可以通过 npm run test
运行测试,确保这些在每次更改后都通过。 请务必为新功能添加测试。
eslint-plugin-object-pattern-newline
ESLint plugin to enforce newlines in ES6 object pattern.
There is only one rule in this plugin which will report when there are more than 4 values in a line by default.
Installation
$ npm install eslint-plugin-object-pattern-newline --save-dev
Or
$ yarn add eslint-plugin-object-pattern-newline -D
Usage
Add object-newline
to the plugins section of your .eslintrc
configuration file.
{
"plugins": [
"object-newline"
]
}
Then add the rule in the rules section.
{
"rules": {
"object-newline/enforce": "error"
}
}
Options
The first and most readable way is to use an object which allows you to specify any of the available options, leaving everything that's not specified as the default.
{
"rules": {
"max-len": ["error", 100],
"object-newline/enforce": [
"error",
{
"items": 2,
"max-len": 100
}
]
}
}
items
[number] (default: 4
)
Specifies the maximum number of items before the plugin requires breaking items to multiple lines.
max-len
[number] (default: Infinity
)
Specifies the maximum length for source code lines in your project. This allows the plugin to prevent quick fixes that would cause your code to violate this limit from being applied. The rule will also automatically split lines for you should they exceed the limit.
Testing
Tests can be run via npm run test
, make sure these pass after every change. Be sure to add tests for new features.