diff --git a/conf/ecma-version.js b/conf/ecma-version.js new file mode 100644 index 00000000000..48b1e2f7edc --- /dev/null +++ b/conf/ecma-version.js @@ -0,0 +1,16 @@ +/** + * @fileoverview Configuration related to ECMAScript versions + * @author Milos Djermanovic + */ + +"use strict"; + +/** + * The latest ECMAScript version supported by ESLint. + * @type {number} year-based ECMAScript version + */ +const LATEST_ECMA_VERSION = 2024; + +module.exports = { + LATEST_ECMA_VERSION +}; diff --git a/lib/linter/linter.js b/lib/linter/linter.js index ed2e41b83c8..2ece33c8284 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -52,6 +52,7 @@ const DEFAULT_ECMA_VERSION = 5; const commentParser = new ConfigCommentParser(); const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, column: 1 } }; const parserSymbol = Symbol.for("eslint.RuleTester.parser"); +const { LATEST_ECMA_VERSION } = require("../../conf/ecma-version"); //------------------------------------------------------------------------------ // Typedefs @@ -594,7 +595,7 @@ function normalizeEcmaVersionForLanguageOptions(ecmaVersion) { * that is used for a number of processes inside of ESLint. It's normally * safe to assume people want the latest unless otherwise specified. */ - return espree.latestEcmaVersion + 2009; + return LATEST_ECMA_VERSION; } const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)(?:\*\/|$)/gsu; diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index f3b2d05ca43..8cd20c1b6fb 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -18,6 +18,8 @@ const { assert } = require("chai"), const { Linter } = require("../../../lib/linter"); const { FlatConfigArray } = require("../../../lib/config/flat-config-array"); +const { LATEST_ECMA_VERSION } = require("../../../conf/ecma-version"); + //------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------ @@ -5470,7 +5472,7 @@ var a = "test2"; assert.strictEqual(ecmaVersion, espree.latestEcmaVersion + 2009, "ecmaVersion should be 2022"); }); - it("the 'next' is equal to espree.latestEcmaVersion on languageOptions with custom parser", () => { + it("the 'next' is equal to ESLint's latest ECMA version on languageOptions with custom parser", () => { let ecmaVersion = null; const config = { rules: { "ecma-version": 2 }, parser: "custom-parser", parserOptions: { ecmaVersion: "next" } }; @@ -5483,7 +5485,7 @@ var a = "test2"; }) }); linter.verify("", config); - assert.strictEqual(ecmaVersion, espree.latestEcmaVersion + 2009, "ecmaVersion should be 2022"); + assert.strictEqual(ecmaVersion, LATEST_ECMA_VERSION, `ecmaVersion should be ${LATEST_ECMA_VERSION}`); }); it("missing ecmaVersion is equal to 5 on languageOptions with custom parser", () => { @@ -7649,7 +7651,7 @@ describe("Linter with FlatConfigArray", () => { checker: { create: context => ({ Program() { - assert.strictEqual(context.languageOptions.ecmaVersion, espree.latestEcmaVersion + 2009); + assert.strictEqual(context.languageOptions.ecmaVersion, LATEST_ECMA_VERSION); } }) } @@ -7694,7 +7696,7 @@ describe("Linter with FlatConfigArray", () => { checker: { create: context => ({ Program() { - assert.strictEqual(context.languageOptions.ecmaVersion, espree.latestEcmaVersion + 2009); + assert.strictEqual(context.languageOptions.ecmaVersion, LATEST_ECMA_VERSION); } }) } @@ -8359,7 +8361,7 @@ describe("Linter with FlatConfigArray", () => { }, "filename.js"); assert(spy.calledWithMatch(";", { - ecmaVersion: espree.latestEcmaVersion + 2009, + ecmaVersion: LATEST_ECMA_VERSION, sourceType: "module" })); });