Skip to content

Commit

Permalink
Fix logic bug in eslint 7
Browse files Browse the repository at this point in the history
  • Loading branch information
D4N14L committed Sep 26, 2023
1 parent 995ab71 commit 9174b9e
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions eslint/eslint-patch/src/_patch-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,28 @@ let eslintFolder: string | undefined = undefined;

// Probe for the ESLint >=8.0.0 layout:
for (let currentModule = module; ; ) {
if (!eslintrcBundlePath && currentModule.filename.endsWith('eslintrc.cjs')) {
// For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
// .../@eslint/eslintrc/dist/eslintrc.cjs
try {
const eslintrcFolder = path.dirname(
require.resolve('@eslint/eslintrc/package.json', { paths: [currentModule.path] })
);
if (!eslintrcBundlePath) {
if (currentModule.filename.endsWith('eslintrc.cjs')) {
// For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
// .../@eslint/eslintrc/dist/eslintrc.cjs
try {
const eslintrcFolder = path.dirname(
require.resolve('@eslint/eslintrc/package.json', { paths: [currentModule.path] })
);

// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
const resolvedEslintrcBundlePath: string = path.join(eslintrcFolder, 'dist/eslintrc.cjs');
if (resolvedEslintrcBundlePath === currentModule.filename) {
eslintrcBundlePath = resolvedEslintrcBundlePath;
}
} catch (ex: unknown) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
const resolvedEslintrcBundlePath: string = path.join(eslintrcFolder, 'dist/eslintrc.cjs');
if (resolvedEslintrcBundlePath === currentModule.filename) {
eslintrcBundlePath = resolvedEslintrcBundlePath;
}
} catch (ex: unknown) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
} else {
Expand Down

0 comments on commit 9174b9e

Please sign in to comment.