[英]How can I turn off ESLint's no-restricted-syntax rule just for ForOfStatement?
I am using ESLint for my ES6 program, with the AirBNB rule-set.我将 ESLint 用于我的 ES6 程序,并带有 AirBNB 规则集。 For good and adequate reasons, I am using the
for...of
construction in my code, but ESLint objects to it, issuing a no-restricted-syntax
error.出于充分和充分的原因,我在我的代码中使用了
for...of
构造,但 ESLint 反对它,发出no-restricted-syntax
错误。
The documentation at http://eslint.org/docs/rules/no-restricted-syntax explains how I can specify in my .eslint
file the set of syntax-tree nodes that it objects to: for example, if all I dislike is the with
statement, I can use: http://eslint.org/docs/rules/no-restricted-syntax 上的文档解释了我如何在我的
.eslint
文件中指定它反对的语法树节点集:例如,如果我不喜欢的是with
语句,我可以使用:
"no-restricted-syntax": ["warn", "WithStatement"]
“无限制语法”:[“警告”,“WithStatement”]
But I don't want to specify a whole set of unapproved constructions, I just want to say that I consider one such construction OK.但我不想指定一整套未经批准的结构,我只想说我认为这样的结构可以。 Something conceptually similar to
概念上类似于
ESlint.rules['no-restricted-syntax'].removeEntry('ForOfStatement');
ESlint.rules['no-restricted-syntax'].removeEntry('ForOfStatement');
Is there a way to do this in the ESLint file?有没有办法在 ESLint 文件中做到这一点? Or, failing that, is there at least a way to get it to tell me what its current
no-restricted-syntax
configuration is, so I can manually remove ForOfStatement from it?或者,如果失败了,是否至少有一种方法可以让它告诉我它当前
no-restricted-syntax
配置是什么,以便我可以从中手动删除 ForOfStatement ?
Based on the current master branch, eslint-config-airbnb
currently disables four syntax forms : 基于当前的主分支,
eslint-config-airbnb
目前禁用四种语法形式 :
ForInStatement
ForOfStatement
LabeledStatement
WithStatement
You can verify this or see if there are any differences by using ESLint's --print-config
CLI flag : 您可以使用ESLint的
--print-config
CLI标志验证这一点或查看是否存在任何差异:
$ eslint --print-config file.js
ESLint will print out the config it would use to lint file.js
, and you can find the config for the no-restricted-syntax
rule there. ESLint将打印出它将使用皮棉的配置
file.js
,你可以找到的的配置no-restricted-syntax
规则存在。
no-restricted-syntax
no-restricted-syntax
If you want to override Airbnb's preset, you can do so in the rules
section of your .eslintrc.json
file: 如果要覆盖Airbnb的预设,可以在
.eslintrc.json
文件的rules
部分中.eslintrc.json
操作:
{
"rules": {
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"]
}
}
There's no way to configure the rule to use the no-restricted-syntax
config inherited from Airbnb's preset excepting only a single syntax form. 除了单一语法形式之外,
no-restricted-syntax
将规则配置为使用从Airbnb预设继承no-restricted-syntax
配置。
Add the below lines of code to restrict this error in your application in .eslintrc.js file在 .eslintrc.js 文件中添加以下代码行以限制应用程序中的此错误
module.exports = {
extends: ['airbnb-base', 'plugin:prettier/recommended'],
plugins: ['no-only-tests'],
rules: {
'no-only-tests/no-only-tests': 2,
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"]
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.