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
Bug: EXPERIMENTAL_useProjectService does not respect extraFileExtensions #8899
Comments
I'm not very familiar with the codebase, so I can't really tell if it makes sense to do this at this specific place, but here's a suggested fix: // packages/typescript-estree/src/useProgramFromProjectService.ts
import { ScriptKind } from 'typescript';
export function useProgramFromProjectService(
{ allowDefaultProjectForFiles, service }: ProjectServiceSettings,
parseSettings: Readonly<MutableParseSettings>,
hasFullTypeInformation: boolean,
): ASTAndDefiniteProgram | undefined {
// We don't canonicalize the filename because it caused a performance regression.
// See https://github.com/typescript-eslint/typescript-eslint/issues/8519
const filePathAbsolute = absolutify(parseSettings.filePath);
log(
'Opening project service file for: %s at absolute path %s',
parseSettings.filePath,
filePathAbsolute,
);
if (parseSettings.extraFileExtensions.length) {
service.setHostConfiguration({
extraFileExtensions: parseSettings.extraFileExtensions.map(extension => ({
extension,
isMixedContent: false,
scriptKind: ScriptKind.Deferred
})),
});
}
const opened = service.openClientFile(
filePathAbsolute,
parseSettings.codeFullText,
/* scriptKind */ undefined,
parseSettings.tsconfigRootDir,
);
/* ... */
} I'm also not sure if setting |
That got a chuckle out of me 🙂. I'm in favor of this - would want a review from someone else in @typescript-eslint/triage-team too, but I think this makes a ton of sense. Thanks for trying out the project service & posting such an informative issue+repro! |
Before You File a Bug Report Please Confirm You Have Done The Following...
Issue Description
When linting a project containing e.g. svelte files, you need to provide
extraFileExtensions: ['.svelte']
to make the parser use the correct tsconfig for the specific file. This works well withproject: true
, since that path ends up increateWatchProgram
where we provide theextraFileExtensions
option to ts.However, if we switch
EXPERIMENTAL_useProjectService
on, we end up in a code path where the extraFileExtensions are not passed to ts. In my reproduction case this is surfaced by the fact that ts will then use the default compiler options, which transpiles the code back to ES5, instead of using the correct tsconfig.While this reproduction example is using Svelte, the same issue should apply to other cases where
extraFileExtensions
would be used (such as when using Vite).Reproduction Repository Link
https://github.com/alfredringstad/typescript-eslint-svelte-use-project-service-bug-reproduction
Repro Steps
npm i
npm run lint
Switch
EXPERIMENTAL_useProjectService
tofalse
ineslint.config.js
and runnpm run lint
to see how it works well without the project service.Versions
@typescript-eslint/parser
7.6.0
@typescript-eslint/typescript-estree
7.6.0
TypeScript
5.4.5
ESLint
8.57.0
The text was updated successfully, but these errors were encountered: