Eslint 无法识别 Reflect
Eslint not recognizing Reflect
我在我的代码中使用 Reflect。问题是 Eslint 认为它是一个未声明的变量。我收到此错误:
eslint --config ./.eslintrc.json src
30:25 error 'Reflect' is not defined no-undef
32:9 error 'Reflect' is not defined no-undef
39:21 error 'Reflect' is not defined no-undef
40:5 error 'Reflect' is not defined no-undef
我的 .eslintrc
文件设置为 ECMAScript 2015:
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module",
"ecmaFeatures": {
"globalReturn": true
}
}
不确定为什么将 no-undef
规则应用于 Reflect。我所有的代码都是典型的 ECMAScript 2015,没有什么异常。
除了设置 ecmaVersion
之外,您还需要告诉它包含 "es6" 全局变量:
{
"env": {
"es6": true
}
}
(您可能还需要其他人,例如 browser
。)
文档 Specifying Environments 中有更多内容。
我在我的代码中使用 Reflect。问题是 Eslint 认为它是一个未声明的变量。我收到此错误:
eslint --config ./.eslintrc.json src
30:25 error 'Reflect' is not defined no-undef
32:9 error 'Reflect' is not defined no-undef
39:21 error 'Reflect' is not defined no-undef
40:5 error 'Reflect' is not defined no-undef
我的 .eslintrc
文件设置为 ECMAScript 2015:
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module",
"ecmaFeatures": {
"globalReturn": true
}
}
不确定为什么将 no-undef
规则应用于 Reflect。我所有的代码都是典型的 ECMAScript 2015,没有什么异常。
除了设置 ecmaVersion
之外,您还需要告诉它包含 "es6" 全局变量:
{
"env": {
"es6": true
}
}
(您可能还需要其他人,例如 browser
。)
文档 Specifying Environments 中有更多内容。