我在我的.eslintrc
文件中使用更改 「eslint:建議」,以警告
"extends": "eslint:recommended",
。這些規則默認會使lint無法使用。有沒有辦法讓我將它們全部更改爲警告,而無需單獨指定每個警告?那麼,是否有辦法改變擴展規則集的規則級別?
比如,我很想能夠做到像:
"extends": [
["eslint:recommended", 1]
],
我在我的.eslintrc
文件中使用更改 「eslint:建議」,以警告
"extends": "eslint:recommended",
。這些規則默認會使lint無法使用。有沒有辦法讓我將它們全部更改爲警告,而無需單獨指定每個警告?那麼,是否有辦法改變擴展規則集的規則級別?
比如,我很想能夠做到像:
"extends": [
["eslint:recommended", 1]
],
正如@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;
這會導致:
"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,
如果你看這裏:http://eslint.org/docs/rules/你會注意到規則包括eslint:recommended
後面是(recommended)
。該腳本拉動網站,將行與(recommended)
對齊,然後使用sed
做一些正則表達式魔法,從錨標記中提取規則。
不要忘記取出最後,
- 我要留下點什麼給你做;) - 和你之間的文件.eslintrc
插入這樣的:如果你不熟悉
"rules": {
...output of script goes here...
}
bash腳本,不要忘記讓它可執行......更簡單,只需複製粘貼在上面的輸出! :)
希望這會有所幫助。
感謝您的想法和腳本! –
很高興能幫助@MatthewHerbst--你會介意將此標記爲公認的答案嗎?謝謝! – jpoveda
不,那是不可能的。唯一的辦法是提及每個規則並將其設置爲警告。 – Gyandeep