我在用
"extends": "eslint:recommended",
Run Code Online (Sandbox Code Playgroud)
在我的.eslintrc档案中。默认情况下,这些规则会使皮棉失效。我有办法将所有这些都更改为警告,而不必分别指定每个警告吗?因此,是否有办法更改扩展规则集的规则级别?
例如,我很想能够做类似的事情:
"extends": [
["eslint:recommended", 1]
],
Run Code Online (Sandbox Code Playgroud)
正如@Gyandeep 所提到的,没有:http ://eslint.org/docs/user-guide/configuring.html#configuring-rules
我写了一个脚本来减轻你的痛苦:
#!/bin/sh
list=$(curl -silent http://eslint.org/docs/rules/ | grep '(recommended)' | sed -e 's,.*<a .*>\([^<]*\)</a>.*,\1,g' | grep -v 'configuration documentation')
for rule in ${list}; do
echo \"$rule\": 1,
done;
Run Code Online (Sandbox Code Playgroud)
这将导致:
"comma-dangle": 1,
"no-cond-assign": 1,
"no-console": 1,
"no-constant-condition": 1,
"no-control-regex": 1,
"no-debugger": 1,
"no-dupe-args": 1,
"no-dupe-keys": 1,
"no-duplicate-case": 1,
"no-empty-character-class": 1,
"no-empty": 1,
"no-ex-assign": 1,
"no-extra-boolean-cast": 1,
"no-extra-semi": 1,
"no-func-assign": 1,
"no-inner-declarations": 1,
"no-invalid-regexp": 1,
"no-irregular-whitespace": 1,
"no-negated-in-lhs": 1,
"no-obj-calls": 1,
"no-regex-spaces": 1,
"no-sparse-arrays": 1,
"no-unreachable": 1,
"use-isnan": 1,
"valid-typeof": 1,
"no-fallthrough": 1,
"no-octal": 1,
"no-redeclare": 1,
"no-delete-var": 1,
"no-undef": 1,
"no-unused-vars": 1,
"no-mixed-spaces-and-tabs": 1,
Run Code Online (Sandbox Code Playgroud)
如果您查看此处:http : //eslint.org/docs/rules/,您会注意到 包含的规则eslint:recommended后跟(recommended)。该脚本会拉出网站,使用 geps 行(recommended)然后用于sed执行一些从锚标记中提取规则的正则表达式魔术。
不要忘记取出最后一个,- 我必须留下一些事情让你做;) - 并将其插入到您的.eslintrc文件中:
"rules": {
...output of script goes here...
}
Run Code Online (Sandbox Code Playgroud)
如果您不熟悉 bash 脚本,请不要忘记使其可执行……甚至更简单,只需复制我上面粘贴的输出即可!:)
希望这可以帮助。
如果需要将所有 ESLint 错误更改为警告,可以使用 eslint 插件eslint-plugin-only-warn 。
如果您仍然需要一些规则来触发完整错误,您可以尝试这个仅警告的分支, eslint-plugin-switch-error-warn(免责声明 - 我是分支作者)。它将错误切换为警告,反之亦然,因此您可以将特定规则设置为“警告”,以使它们再次触发错误。这将为您提供指定异常的附加功能,尽管它可能会变得相当混乱!
您还需要将默认警告(例如“无控制台”)的所有规则明确设置为“错误”模式,以使它们仅使用切换器插件发出警告。
| 归档时间: |
|
| 查看次数: |
1762 次 |
| 最近记录: |