Skip to content

Commit 88a9ade

Browse files
authored
Update: add es2021 environment (refs eslint#13602) (eslint#13603)
* Update: add es2021 environment (refs eslint#13602) * Add no-undef test
1 parent 0003dc0 commit 88a9ade

File tree

8 files changed

+14
-6
lines changed

8 files changed

+14
-6
lines changed

docs/user-guide/configuring.md

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ An environment defines global variables that are predefined. The available envir
138138
* `es6` - enable all ECMAScript 6 features except for modules (this automatically sets the `ecmaVersion` parser option to 6).
139139
* `es2017` - adds all ECMAScript 2017 globals and automatically sets the `ecmaVersion` parser option to 8.
140140
* `es2020` - adds all ECMAScript 2020 globals and automatically sets the `ecmaVersion` parser option to 11.
141+
* `es2021` - adds all ECMAScript 2021 globals and automatically sets the `ecmaVersion` parser option to 12.
141142
* `worker` - web workers global variables.
142143
* `amd` - defines `require()` and `define()` as global variables as per the [amd](https://github.com/amdjs/amdjs-api/wiki/AMD) spec.
143144
* `mocha` - adds all of the Mocha testing global variables.

lib/init/config-initializer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function processAnswers(answers) {
265265
};
266266

267267
config.parserOptions.ecmaVersion = espree.latestEcmaVersion;
268-
config.env.es2020 = true;
268+
config.env.es2021 = true;
269269

270270
// set the module type
271271
if (answers.moduleType === "esm") {

tests/bin/eslint.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ describe("bin/eslint.js", () => {
179179

180180
describe("running on files", () => {
181181
it("has exit code 0 if no linting errors occur", () => assertExitCode(runESLint(["bin/eslint.js"]), 0));
182-
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));
183-
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));
182+
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));
183+
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));
184184
it("has exit code 1 if a syntax error is thrown", () => assertExitCode(runESLint(["README.md"]), 1));
185185
});
186186

tests/lib/cli-engine/cli-engine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ describe("CLIEngine", () => {
821821
engine = new CLIEngine({
822822
parser: "espree",
823823
parserOptions: {
824-
ecmaVersion: 2020
824+
ecmaVersion: 2021
825825
},
826826
useEslintrc: false
827827
});

tests/lib/eslint/eslint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ describe("ESLint", () => {
899899
overrideConfig: {
900900
parser: "espree",
901901
parserOptions: {
902-
ecmaVersion: 2020
902+
ecmaVersion: 2021
903903
}
904904
},
905905
useEslintrc: false

tests/lib/init/config-initializer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe("configInitializer", () => {
136136
assert.deepStrictEqual(config.rules.quotes, ["error", "single"]);
137137
assert.deepStrictEqual(config.rules["linebreak-style"], ["error", "unix"]);
138138
assert.deepStrictEqual(config.rules.semi, ["error", "always"]);
139-
assert.strictEqual(config.env.es2020, true);
139+
assert.strictEqual(config.env.es2021, true);
140140
assert.strictEqual(config.parserOptions.ecmaVersion, espree.latestEcmaVersion);
141141
assert.strictEqual(config.parserOptions.sourceType, "module");
142142
assert.strictEqual(config.env.browser, true);

tests/lib/rules/no-extend-native.js

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ ruleTester.run("no-extend-native", rule, {
4848
{
4949
code: "{ let Object = function() {}; Object.prototype.p = 0 }",
5050
parserOptions: { ecmaVersion: 6 }
51+
},
52+
53+
// TODO(mdjermanovic): This test should become `invalid` in the next major version, when we upgrade the `globals` package.
54+
{
55+
code: "WeakRef.prototype.p = 0",
56+
env: { es2021: true }
5157
}
5258
],
5359
invalid: [{

tests/lib/rules/no-undef.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ruleTester.run("no-undef", rule, {
5959
{ code: "requestIdleCallback;", env: { browser: true } },
6060
{ code: "customElements;", env: { browser: true } },
6161
{ code: "PromiseRejectionEvent;", env: { browser: true } },
62+
{ code: "(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }", env: { es2021: true } },
6263

6364
// Notifications of readonly are removed: https://github.com/eslint/eslint/issues/4504
6465
"/*global b:false*/ function f() { b = 1; }",

0 commit comments

Comments
 (0)