What the difference between env.es6=true and parserOptions.ecmaVersion=6 at .eslintrc.js?

Viewed 1397

I do not understand why do I need to specify the same information in two different parameters.

module.exports = {
  env: {
    commonjs: true,
    es6: true,
    node: true
  },
  extends: [
    'eslint:recommended'
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parserOptions: {
    ecmaVersion: 6
  },
  rules: {
    indent: ['error', 2],
    quotes: ['error', 'single'],
    semi: ['error', 'always']
  }
};
1 Answers

ecmaVersion option of parserOptions is for syntax. On the otherhand, env option is for global variables.

If you want to use a Promise for example, "ecmaVersion:2020" is not enough. You also have to specify which env to use.

Note that env option automatically enables new syntax. But personally I recommend to set both of them properly.

For more information, see here

For ES6 syntax, use { "parserOptions": { "ecmaVersion": 6 } }; for new ES6 global variables, use { "env": { "es6": true } }. { "env": { "es6": true } } enables ES6 syntax automatically, but { "parserOptions": { "ecmaVersion": 6 } } does not enable ES6 globals automatically

Related