Skip to content

Commit

Permalink
Merge pull request #4719 from nzakas/main
Browse files Browse the repository at this point in the history
[eslint-patch] Update for v9
  • Loading branch information
D4N14L committed May 16, 2024
2 parents 73e4e90 + 1dc0e7d commit f82793b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
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

0 comments on commit f82793b

Please sign in to comment.