Skip to content
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

fix(typescript-estree): use simpler absolutify behavior for project service client file paths #8520

17 changes: 10 additions & 7 deletions packages/typescript-estree/src/useProgramFromProjectService.ts
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
@@ -1,23 +1,20 @@
import { minimatch } from 'minimatch';
import path from 'path';

import { createProjectProgram } from './create-program/createProjectProgram';
import type { ProjectServiceSettings } from './create-program/createProjectService';
import {
type ASTAndDefiniteProgram,
ensureAbsolutePath,
getCanonicalFileName,
} from './create-program/shared';
import { type ASTAndDefiniteProgram } from './create-program/shared';
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
import type { MutableParseSettings } from './parseSettings';

export function useProgramFromProjectService(
{ allowDefaultProjectForFiles, service }: ProjectServiceSettings,
parseSettings: Readonly<MutableParseSettings>,
hasFullTypeInformation: boolean,
): ASTAndDefiniteProgram | undefined {
const filePath = getCanonicalFileName(parseSettings.filePath);
const filePath = absolutify(parseSettings.filePath);

Check warning on line 14 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L14

Added line #L14 was not covered by tests

const opened = service.openClientFile(
ensureAbsolutePath(filePath, service.host.getCurrentDirectory()),
filePath,
parseSettings.codeFullText,
/* scriptKind */ undefined,
parseSettings.tsconfigRootDir,
Expand Down Expand Up @@ -48,6 +45,12 @@
}

return createProjectProgram(parseSettings, [program]);

function absolutify(filePath: string): string {
return path.isAbsolute(filePath)
? filePath
: path.join(service.host.getCurrentDirectory(), filePath);
}
}

function filePathMatchedBy(
Expand Down