eslint-import-resolver-typescript icon indicating copy to clipboard operation
eslint-import-resolver-typescript copied to clipboard

Support declaring internal module regex or respect import/internal-regex setting

Open harunurhan opened this issue 1 year ago • 6 comments

Resolver performs way too slow on a medium to large TS project where every local/internal import is absolute from the project root, since https://github.com/import-js/eslint-import-resolver-typescript/blob/71b23a206514842fef70a99220e5ffb1d6da2a0e/src/index.ts#L276 optimization branch is not used.

It would be useful to allow users to specify internalRegex similar to https://github.com/import-js/eslint-plugin-import/tree/a89eadf3247af844da6b0f9e7bca7690777bf665#importinternal-regex.

Worth mentioning that using above import/internal-regex did speed up the linting times, but unexpectedly I have seen more improvements when implemented a custom resolver like below using the same regexp, so perhaps there is a bug (or misunderstanding) there and no new option is needed, just addressing that one.

export function resolve(
    importPath: string,
    importerFileAbsolutePath: string,
    tsResolverOptions: TsResolverOptions
): ResolveResult {
    if (internalModuleRegexp.test(importPath)) {
        const absoluteImportPath = path.resolve(`./${importPath}`);
        return {
            found: true,
            path: absoluteImportPath,
        };
    }

    return eslintImportResolverTypescript.resolve(importPath, importerFileAbsolutePath, tsResolverOptions);
}

harunurhan avatar May 24 '23 12:05 harunurhan