diff --git a/conf/environments.js b/conf/environments.js index 096c6003179..aad4d65e0ef 100644 --- a/conf/environments.js +++ b/conf/environments.js @@ -55,6 +55,10 @@ const newGlobals2020 = { BigUint64Array: false, globalThis: false }; +const newGlobals2021 = { + FinalizationRegistry: false, + WeakRef: false +}; //------------------------------------------------------------------------------ // Public Interface @@ -91,6 +95,12 @@ module.exports = new Map(Object.entries({ ecmaVersion: 11 } }, + es2021: { + globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 }, + parserOptions: { + ecmaVersion: 12 + } + }, // Platforms browser: { diff --git a/docs/user-guide/configuring.md b/docs/user-guide/configuring.md index 50a0341fd06..5f413b5c704 100644 --- a/docs/user-guide/configuring.md +++ b/docs/user-guide/configuring.md @@ -24,7 +24,7 @@ For ES6 syntax, use `{ "parserOptions": { "ecmaVersion": 6 } }`; for new ES6 glo { "es6": true } }`. `{ "env": { "es6": true } }` enables ES6 syntax automatically, but `{ "parserOptions": { "ecmaVersion": 6 } }` does not enable ES6 globals automatically. Parser options are set in your `.eslintrc.*` file by using the `parserOptions` property. The available options are: -* `ecmaVersion` - set to 3, 5 (default), 6, 7, 8, 9, 10 or 11 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10) or 2020 (same as 11) to use the year-based naming. +* `ecmaVersion` - set to 3, 5 (default), 6, 7, 8, 9, 10, 11 or 12 to specify the version of ECMAScript syntax you want to use. You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11) or 2021 (same as 12) to use the year-based naming. * `sourceType` - set to `"script"` (default) or `"module"` if your code is in ECMAScript modules. * `ecmaFeatures` - an object indicating which additional language features you'd like to use: * `globalReturn` - allow `return` statements in the global scope @@ -138,6 +138,7 @@ An environment defines global variables that are predefined. The available envir * `es6` - enable all ECMAScript 6 features except for modules (this automatically sets the `ecmaVersion` parser option to 6). * `es2017` - adds all ECMAScript 2017 globals and automatically sets the `ecmaVersion` parser option to 8. * `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. * `worker` - web workers global variables. * `amd` - defines `require()` and `define()` as global variables as per the [amd](https://github.com/amdjs/amdjs-api/wiki/AMD) spec. * `mocha` - adds all of the Mocha testing global variables. diff --git a/lib/init/config-initializer.js b/lib/init/config-initializer.js index e14f1cb0824..1fd785303fe 100644 --- a/lib/init/config-initializer.js +++ b/lib/init/config-initializer.js @@ -265,7 +265,7 @@ function processAnswers(answers) { }; config.parserOptions.ecmaVersion = espree.latestEcmaVersion; - config.env.es2020 = true; + config.env.es2021 = true; // set the module type if (answers.moduleType === "esm") { diff --git a/lib/shared/types.js b/lib/shared/types.js index bbd95d1b378..8ad3b1b64ce 100644 --- a/lib/shared/types.js +++ b/lib/shared/types.js @@ -21,7 +21,7 @@ module.exports = {}; /** * @typedef {Object} ParserOptions * @property {EcmaFeatures} [ecmaFeatures] The optional features. - * @property {3|5|6|7|8|9|10|11|2015|2016|2017|2018|2019|2020} [ecmaVersion] The ECMAScript version (or revision number). + * @property {3|5|6|7|8|9|10|11|12|2015|2016|2017|2018|2019|2020|2021} [ecmaVersion] The ECMAScript version (or revision number). * @property {"script"|"module"} [sourceType] The source code type. */ diff --git a/package.json b/package.json index 0b0126bf258..1b812dc6d57 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "eslint-scope": "^5.1.0", "eslint-utils": "^2.1.0", "eslint-visitor-keys": "^1.3.0", - "espree": "^7.2.0", + "espree": "github:eslint/espree", "esquery": "^1.2.0", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", diff --git a/tests/bin/eslint.js b/tests/bin/eslint.js index cfc5128dc57..7500d6611ce 100644 --- a/tests/bin/eslint.js +++ b/tests/bin/eslint.js @@ -179,8 +179,8 @@ describe("bin/eslint.js", () => { describe("running on files", () => { it("has exit code 0 if no linting errors occur", () => assertExitCode(runESLint(["bin/eslint.js"]), 0)); - it("has exit code 0 if a linting warning is reported", () => assertExitCode(runESLint(["bin/eslint.js", "--env", "es2020", "--no-eslintrc", "--rule", "semi: [1, never]"]), 0)); - it("has exit code 1 if a linting error is reported", () => assertExitCode(runESLint(["bin/eslint.js", "--env", "es2020", "--no-eslintrc", "--rule", "semi: [2, never]"]), 1)); + it("has exit code 0 if a linting warning is reported", () => assertExitCode(runESLint(["bin/eslint.js", "--env", "es2021", "--no-eslintrc", "--rule", "semi: [1, never]"]), 0)); + it("has exit code 1 if a linting error is reported", () => assertExitCode(runESLint(["bin/eslint.js", "--env", "es2021", "--no-eslintrc", "--rule", "semi: [2, never]"]), 1)); it("has exit code 1 if a syntax error is thrown", () => assertExitCode(runESLint(["README.md"]), 1)); }); diff --git a/tests/lib/cli-engine/cli-engine.js b/tests/lib/cli-engine/cli-engine.js index 0ba01d2a5df..7ff97d1814a 100644 --- a/tests/lib/cli-engine/cli-engine.js +++ b/tests/lib/cli-engine/cli-engine.js @@ -821,7 +821,7 @@ describe("CLIEngine", () => { engine = new CLIEngine({ parser: "espree", parserOptions: { - ecmaVersion: 2020 + ecmaVersion: 2021 }, useEslintrc: false }); diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index d29dbb01640..c558b6c2fea 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -899,7 +899,7 @@ describe("ESLint", () => { overrideConfig: { parser: "espree", parserOptions: { - ecmaVersion: 2020 + ecmaVersion: 2021 } }, useEslintrc: false diff --git a/tests/lib/init/config-initializer.js b/tests/lib/init/config-initializer.js index 12fe18aa2c3..d607ccff52f 100644 --- a/tests/lib/init/config-initializer.js +++ b/tests/lib/init/config-initializer.js @@ -136,7 +136,7 @@ describe("configInitializer", () => { assert.deepStrictEqual(config.rules.quotes, ["error", "single"]); assert.deepStrictEqual(config.rules["linebreak-style"], ["error", "unix"]); assert.deepStrictEqual(config.rules.semi, ["error", "always"]); - assert.strictEqual(config.env.es2020, true); + assert.strictEqual(config.env.es2021, true); assert.strictEqual(config.parserOptions.ecmaVersion, espree.latestEcmaVersion); assert.strictEqual(config.parserOptions.sourceType, "module"); assert.strictEqual(config.env.browser, true); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index db07c123314..de3b0cd3f42 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -48,6 +48,12 @@ ruleTester.run("no-extend-native", rule, { { code: "{ let Object = function() {}; Object.prototype.p = 0 }", parserOptions: { ecmaVersion: 6 } + }, + + // TODO(mdjermanovic): This test should become `invalid` in the next major version, when we upgrade the `globals` package. + { + code: "WeakRef.prototype.p = 0", + env: { es2021: true } } ], invalid: [{