Skip to content

fix(typescript-eslint): address trailing path sep bug in tsconfigRootDir inference #11406

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand All @@ -51,4 +51,35 @@ describe(getTSConfigRootDirFromStack, () => {
expect(actual).toBe(expected);
},
);

it("doesn't get tricked by a 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\\dir' : '/path/to/dir';

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);
},
);
});
Loading
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