Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint-patch] Update for v9 #4719

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions common/changes/@rushstack/eslint-patch/main_2024-05-16-16-05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-patch",
"comment": "[eslint-patch] Allow use of ESLint v9",
"type": "patch"
}
],
"packageName": "@rushstack/eslint-patch"
}
24 changes: 12 additions & 12 deletions eslint/eslint-patch/src/_patch-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let namingPath: string | undefined = undefined;
let eslintFolder: string | undefined = undefined;

// Probe for the ESLint >=8.0.0 layout:
for (let currentModule: NodeModule = module; ; ) {
for (let currentModule: NodeModule = module; ;) {
if (!eslintrcBundlePath) {
if (currentModule.filename.endsWith('eslintrc.cjs')) {
// For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
Expand Down Expand Up @@ -93,7 +93,7 @@ for (let currentModule: NodeModule = module; ; ) {

if (!eslintFolder) {
// Probe for the ESLint >=7.12.0 layout:
for (let currentModule: NodeModule = module; ; ) {
for (let currentModule: NodeModule = module; ;) {
if (!configArrayFactoryPath) {
// For ESLint >=7.12.0, config-array-factory.js is at this path:
// .../@eslint/eslintrc/lib/config-array-factory.js
Expand Down Expand Up @@ -154,7 +154,7 @@ if (!eslintFolder) {

if (!eslintFolder) {
// Probe for the <7.12.0 layout:
for (let currentModule: NodeModule = module; ; ) {
for (let currentModule: NodeModule = module; ;) {
// For ESLint <7.12.0, config-array-factory.js was at this path:
// .../eslint/lib/cli-engine/config-array-factory.js
if (/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js$/i.test(currentModule.filename)) {
Expand Down Expand Up @@ -185,8 +185,8 @@ if (!eslintFolder) {
// This was tested with ESLint 6.1.0 .. 7.12.1.
throw new Error(
'Failed to patch ESLint because the calling module was not recognized.\n' +
'If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues'
'If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues'
);
}
currentModule = currentModule.parent;
Expand All @@ -204,18 +204,18 @@ if (isNaN(ESLINT_MAJOR_VERSION)) {
);
}

if (!(ESLINT_MAJOR_VERSION >= 6 && ESLINT_MAJOR_VERSION <= 8)) {
if (!(ESLINT_MAJOR_VERSION >= 6 && ESLINT_MAJOR_VERSION <= 9)) {
throw new Error(
'The ESLint patch script has only been tested with ESLint version 6.x, 7.x, and 8.x.' +
` (Your version: ${eslintPackageVersion})\n` +
'Consider reporting a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues'
'The ESLint patch script has only been tested with ESLint version 6.x, 7.x, 8.x, and 9.x.' +
` (Your version: ${eslintPackageVersion})\n` +
'Consider reporting a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues'
);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let configArrayFactory: any;
if (ESLINT_MAJOR_VERSION === 8) {
if (ESLINT_MAJOR_VERSION >= 8) {
configArrayFactory = require(eslintrcBundlePath!).Legacy.ConfigArrayFactory;
} else {
configArrayFactory = require(configArrayFactoryPath!).ConfigArrayFactory;
Expand All @@ -225,7 +225,7 @@ if (ESLINT_MAJOR_VERSION === 8) {
let ModuleResolver: { resolve: any };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let Naming: { normalizePackageName: any };
if (ESLINT_MAJOR_VERSION === 8) {
if (ESLINT_MAJOR_VERSION >= 8) {
ModuleResolver = require(eslintrcBundlePath!).Legacy.ModuleResolver;
Naming = require(eslintrcBundlePath!).Legacy.naming;
} else {
Expand Down
Loading