Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: add es2021 environment (refs #13602) (#13603)
* Update: add es2021 environment (refs #13602)

* Add no-undef test
  • Loading branch information
mdjermanovic committed Aug 29, 2020
1 parent 0003dc0 commit 88a9ade
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/user-guide/configuring.md
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/init/config-initializer.js
Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/eslint.js
Expand Up @@ -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));
});

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/cli-engine/cli-engine.js
Expand Up @@ -821,7 +821,7 @@ describe("CLIEngine", () => {
engine = new CLIEngine({
parser: "espree",
parserOptions: {
ecmaVersion: 2020
ecmaVersion: 2021
},
useEslintrc: false
});
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/eslint/eslint.js
Expand Up @@ -899,7 +899,7 @@ describe("ESLint", () => {
overrideConfig: {
parser: "espree",
parserOptions: {
ecmaVersion: 2020
ecmaVersion: 2021
}
},
useEslintrc: false
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/init/config-initializer.js
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-extend-native.js
Expand Up @@ -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: [{
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-undef.js
Expand Up @@ -59,6 +59,7 @@ ruleTester.run("no-undef", rule, {
{ code: "requestIdleCallback;", env: { browser: true } },
{ code: "customElements;", env: { browser: true } },
{ code: "PromiseRejectionEvent;", env: { browser: true } },
{ code: "(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }", env: { es2021: true } },

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

0 comments on commit 88a9ade

Please sign in to comment.