Skip to content

Commit

Permalink
feat: maintain latest ecma version in ESLint (#17958)
Browse files Browse the repository at this point in the history
Fixes #15366
  • Loading branch information
mdjermanovic committed Jan 9, 2024
1 parent 701f1af commit a630edd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
16 changes: 16 additions & 0 deletions 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
};
3 changes: 2 additions & 1 deletion lib/linter/linter.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/linter/linter.js
Expand Up @@ -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
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -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" } };

Expand All @@ -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", () => {
Expand Down Expand Up @@ -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);
}
})
}
Expand Down Expand Up @@ -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);
}
})
}
Expand Down Expand Up @@ -8359,7 +8361,7 @@ describe("Linter with FlatConfigArray", () => {
}, "filename.js");

assert(spy.calledWithMatch(";", {
ecmaVersion: espree.latestEcmaVersion + 2009,
ecmaVersion: LATEST_ECMA_VERSION,
sourceType: "module"
}));
});
Expand Down

0 comments on commit a630edd

Please sign in to comment.