Skip to content

Commit

Permalink
Update: add es2021 environment (refs #13602)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Aug 21, 2020
1 parent 2bee6d2 commit 12239fb
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 9 deletions.
10 changes: 10 additions & 0 deletions conf/environments.js
Expand Up @@ -55,6 +55,10 @@ const newGlobals2020 = {
BigUint64Array: false,
globalThis: false
};
const newGlobals2021 = {
FinalizationRegistry: false,
WeakRef: false
};

//------------------------------------------------------------------------------
// Public Interface
Expand Down Expand Up @@ -91,6 +95,12 @@ module.exports = new Map(Object.entries({
ecmaVersion: 11
}
},
es2021: {
globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
parserOptions: {
ecmaVersion: 12
}
},

// Platforms
browser: {
Expand Down
3 changes: 2 additions & 1 deletion docs/user-guide/configuring.md
Expand Up @@ -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
Expand Down 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
2 changes: 1 addition & 1 deletion lib/shared/types.js
Expand Up @@ -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.
*/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
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

0 comments on commit 12239fb

Please sign in to comment.