admin管理员组文章数量:1332382
I do not understand why I need to specify the same information in two different parameters,
both env: { es6: true }
and parserOptions: { ecmaVersion: 6 }
.
module.exports = {
env: {
monjs: true,
es6: true,
node: true
},
extends: [
'eslint:remended'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 6
},
};
I do not understand why I need to specify the same information in two different parameters,
both env: { es6: true }
and parserOptions: { ecmaVersion: 6 }
.
module.exports = {
env: {
monjs: true,
es6: true,
node: true
},
extends: [
'eslint:remended'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 6
},
};
Share
edited Nov 1, 2023 at 10:32
Henke - Нава́льный П с м
5,7976 gold badges41 silver badges51 bronze badges
asked May 22, 2020 at 19:10
MauroMauro
1152 silver badges8 bronze badges
0
2 Answers
Reset to default 6The ecmaVersion
option of parserOptions
is for syntax.
The env
option is for global variables.
If you want to use a Promise for example, ecmaVersion:latest
is not enough.
You also have to specify which environment (env
) to use.
Note that the env
option automatically enables new syntax.
But personally, I remend setting both of them properly.
From Configure Language Options :
For ES6 syntax, use
{ "parserOptions": { "ecmaVersion": 6 } }
; for new ES6 global variables, use{ "env": { "es6": true } }
. Setting{ "env": { "es6": true } }
enables ES6 syntax automatically, but{ "parserOptions": { "ecmaVersion": 6 } }
does not enable ES6 globals automatically.
For more information, see here.
By this https://eslint/docs/latest/use/configure/language-options#specifying-environments it is enough to set just env which automatically set correct parserOptions.ecmaVersion
. So you should prefer this way to avoid mismatch configuration.
es6 - enable all ECMAScript 6 features except for modules (this automatically sets the ecmaVersion parser option to 6).
es2016 - adds all ECMAScript 2016 globals and automatically sets the ecmaVersion parser option to 7.
es2017 - adds all ECMAScript 2017 globals and automatically sets the ecmaVersion parser option to 8.
es2018 - adds all ECMAScript 2018 globals and automatically sets the ecmaVersion parser option to 9.
es2019 - adds all ECMAScript 2019 globals and automatically sets the ecmaVersion parser option to 10.
es2020 - adds all ECMAScript 2020 globals and automatically sets the ecmaVersion parser option to 11.
es2021 - adds all ECMAScript 2021 globals and automatically sets the ecmaVersion parser option to 12.
es2022 - adds all ECMAScript 2022 globals and automatically sets the ecmaVersion parser option to 13.
UPDATE: There must be an error in ESLint doc because I have tested to add env.es2016 : true
without parserOptions.ecmaVersion : 2016
and parser is incorrectly fine with async functions which were added later in es2017. So rather set both env and ecmaVersion.
本文标签: javascriptWhy set both enves6true and parserOptionsecmaVersion6 in eslintrcjsStack Overflow
版权声明:本文标题:javascript - Why set both env.es6=true and parserOptions.ecmaVersion=6 in .eslintrc.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742293919a2448340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论