Skip to content

Commit a630edd

Browse files
authoredJan 9, 2024
feat: maintain latest ecma version in ESLint (#17958)
Fixes #15366
1 parent 701f1af commit a630edd

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
 

‎conf/ecma-version.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @fileoverview Configuration related to ECMAScript versions
3+
* @author Milos Djermanovic
4+
*/
5+
6+
"use strict";
7+
8+
/**
9+
* The latest ECMAScript version supported by ESLint.
10+
* @type {number} year-based ECMAScript version
11+
*/
12+
const LATEST_ECMA_VERSION = 2024;
13+
14+
module.exports = {
15+
LATEST_ECMA_VERSION
16+
};

‎lib/linter/linter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const DEFAULT_ECMA_VERSION = 5;
5252
const commentParser = new ConfigCommentParser();
5353
const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, column: 1 } };
5454
const parserSymbol = Symbol.for("eslint.RuleTester.parser");
55+
const { LATEST_ECMA_VERSION } = require("../../conf/ecma-version");
5556

5657
//------------------------------------------------------------------------------
5758
// Typedefs
@@ -594,7 +595,7 @@ function normalizeEcmaVersionForLanguageOptions(ecmaVersion) {
594595
* that is used for a number of processes inside of ESLint. It's normally
595596
* safe to assume people want the latest unless otherwise specified.
596597
*/
597-
return espree.latestEcmaVersion + 2009;
598+
return LATEST_ECMA_VERSION;
598599
}
599600

600601
const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)(?:\*\/|$)/gsu;

‎tests/lib/linter/linter.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const { assert } = require("chai"),
1818
const { Linter } = require("../../../lib/linter");
1919
const { FlatConfigArray } = require("../../../lib/config/flat-config-array");
2020

21+
const { LATEST_ECMA_VERSION } = require("../../../conf/ecma-version");
22+
2123
//------------------------------------------------------------------------------
2224
// Constants
2325
//------------------------------------------------------------------------------
@@ -5470,7 +5472,7 @@ var a = "test2";
54705472
assert.strictEqual(ecmaVersion, espree.latestEcmaVersion + 2009, "ecmaVersion should be 2022");
54715473
});
54725474

5473-
it("the 'next' is equal to espree.latestEcmaVersion on languageOptions with custom parser", () => {
5475+
it("the 'next' is equal to ESLint's latest ECMA version on languageOptions with custom parser", () => {
54745476
let ecmaVersion = null;
54755477
const config = { rules: { "ecma-version": 2 }, parser: "custom-parser", parserOptions: { ecmaVersion: "next" } };
54765478

@@ -5483,7 +5485,7 @@ var a = "test2";
54835485
})
54845486
});
54855487
linter.verify("", config);
5486-
assert.strictEqual(ecmaVersion, espree.latestEcmaVersion + 2009, "ecmaVersion should be 2022");
5488+
assert.strictEqual(ecmaVersion, LATEST_ECMA_VERSION, `ecmaVersion should be ${LATEST_ECMA_VERSION}`);
54875489
});
54885490

54895491
it("missing ecmaVersion is equal to 5 on languageOptions with custom parser", () => {
@@ -7649,7 +7651,7 @@ describe("Linter with FlatConfigArray", () => {
76497651
checker: {
76507652
create: context => ({
76517653
Program() {
7652-
assert.strictEqual(context.languageOptions.ecmaVersion, espree.latestEcmaVersion + 2009);
7654+
assert.strictEqual(context.languageOptions.ecmaVersion, LATEST_ECMA_VERSION);
76537655
}
76547656
})
76557657
}
@@ -7694,7 +7696,7 @@ describe("Linter with FlatConfigArray", () => {
76947696
checker: {
76957697
create: context => ({
76967698
Program() {
7697-
assert.strictEqual(context.languageOptions.ecmaVersion, espree.latestEcmaVersion + 2009);
7699+
assert.strictEqual(context.languageOptions.ecmaVersion, LATEST_ECMA_VERSION);
76987700
}
76997701
})
77007702
}
@@ -8359,7 +8361,7 @@ describe("Linter with FlatConfigArray", () => {
83598361
}, "filename.js");
83608362

83618363
assert(spy.calledWithMatch(";", {
8362-
ecmaVersion: espree.latestEcmaVersion + 2009,
8364+
ecmaVersion: LATEST_ECMA_VERSION,
83638365
sourceType: "module"
83648366
}));
83658367
});

0 commit comments

Comments
 (0)
Please sign in to comment.