From b0598f8c6784bc30cd81a66a7b71705a78b2e324 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Thu, 17 Jul 2025 12:07:05 -0600 Subject: [PATCH 1/3] improve regex for tsconfigRootDir inference --- .../src/getTSConfigRootDirFromStack.ts | 5 ++- .../tests/getTsconfigRootDirFromStack.test.ts | 35 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/typescript-eslint/src/getTSConfigRootDirFromStack.ts b/packages/typescript-eslint/src/getTSConfigRootDirFromStack.ts index 01378b1618f..fd8cca55eb1 100644 --- a/packages/typescript-eslint/src/getTSConfigRootDirFromStack.ts +++ b/packages/typescript-eslint/src/getTSConfigRootDirFromStack.ts @@ -2,7 +2,10 @@ import { fileURLToPath } from 'node:url'; export function getTSConfigRootDirFromStack(stack: string): string | undefined { for (const line of stack.split('\n').map(line => line.trim())) { - const candidate = /(\S+)eslint\.config\.(c|m)?(j|t)s/.exec(line)?.[1]; + const candidate = /(\S+?)[/\\]+eslint\.config\.(c|m)?(j|t)s/.exec( + line, + )?.[1]; + if (!candidate) { continue; } diff --git a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts index 57a3b0b5f2a..327c7cd9f90 100644 --- a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts +++ b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts @@ -30,14 +30,14 @@ describe(getTSConfigRootDirFromStack, () => { ].join('\n'), ); - expect(actual).toBe('/path/to/file/'); + expect(actual).toBe('/path/to/file'); }, ); it.each(['cjs', 'cts', 'js', 'mjs', 'mts', 'ts'])( 'returns the path to the config file when its extension is %s', extension => { - const expected = isWindows ? 'C:\\path\\to\\file\\' : '/path/to/file/'; + const expected = isWindows ? 'C:\\path\\to\\file' : '/path/to/file'; const actual = getTSConfigRootDirFromStack( [ @@ -51,4 +51,35 @@ describe(getTSConfigRootDirFromStack, () => { expect(actual).toBe(expected); }, ); + + it("doesn't get tricked by a messed up by not-an-eslint.config.js", () => { + const actual = getTSConfigRootDirFromStack( + [ + `Error`, + ' at file:///a/b/not-an-eslint.config.js', + ' at ModuleJob.run', + 'at async NodeHfs.walk(...)', + ].join('\n'), + ); + + expect(actual).toBeUndefined(); + }); + + it.each(['cjs', 'cts', 'js', 'mjs', 'mts', 'ts'])( + 'correctly resolves the config file even when multiple path seps are present %s', + extension => { + const expected = isWindows ? 'C:\\path\\to\\file' : '/path/to/file'; + + const actual = getTSConfigRootDirFromStack( + [ + `Error`, + ` at ${expected + path.sep + path.sep}eslint.config.${extension}}`, + ' at ModuleJob.run', + 'at async NodeHfs.walk(...)', + ].join('\n'), + ); + + expect(actual).toBe(expected); + }, + ); }); From 23b4027465d118ba312867b1f901d90142468962 Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Thu, 17 Jul 2025 12:12:00 -0600 Subject: [PATCH 2/3] rename file to dir --- .../tests/getTsconfigRootDirFromStack.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts index 327c7cd9f90..7f5fd37bf16 100644 --- a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts +++ b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts @@ -24,20 +24,20 @@ describe(getTSConfigRootDirFromStack, () => { const actual = getTSConfigRootDirFromStack( [ `Error`, - ' at file:///path/to/file/eslint.config.js', + ' at file:///path/to/dir/eslint.config.js', ' at ModuleJob.run', 'at async NodeHfs.walk(...)', ].join('\n'), ); - expect(actual).toBe('/path/to/file'); + expect(actual).toBe('/path/to/dir'); }, ); it.each(['cjs', 'cts', 'js', 'mjs', 'mts', 'ts'])( 'returns the path to the config file when its extension is %s', extension => { - const expected = isWindows ? 'C:\\path\\to\\file' : '/path/to/file'; + const expected = isWindows ? 'C:\\path\\to\\dir' : '/path/to/dir'; const actual = getTSConfigRootDirFromStack( [ @@ -68,7 +68,7 @@ describe(getTSConfigRootDirFromStack, () => { it.each(['cjs', 'cts', 'js', 'mjs', 'mts', 'ts'])( 'correctly resolves the config file even when multiple path seps are present %s', extension => { - const expected = isWindows ? 'C:\\path\\to\\file' : '/path/to/file'; + const expected = isWindows ? 'C:\\path\\to\\dir' : '/path/to/dir'; const actual = getTSConfigRootDirFromStack( [ From 9aa89c1198990bff8796f0654c1fa0f1347e151e Mon Sep 17 00:00:00 2001 From: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com> Date: Thu, 17 Jul 2025 12:41:30 -0600 Subject: [PATCH 3/3] Update packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- .../typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts index 7f5fd37bf16..60d3598d73e 100644 --- a/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts +++ b/packages/typescript-eslint/tests/getTsconfigRootDirFromStack.test.ts @@ -52,7 +52,7 @@ describe(getTSConfigRootDirFromStack, () => { }, ); - it("doesn't get tricked by a messed up by not-an-eslint.config.js", () => { + it("doesn't get tricked by a not-an-eslint.config.js", () => { const actual = getTSConfigRootDirFromStack( [ `Error`, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy