Skip to content

Commit a124d4f

Browse files
author
Emanuel Hoogeveen
authored
fix(typescript-estree): don't add in-project files to defaultProjectMatchedFiles (typescript-eslint#9097)
* fix(typescript-estree): don't add in-project files to defaultProjectMatchedFiles Only add path to defaultProjectMatchedFiles if opened.configFileName is falsy. * test(typescript-estree): add additional unit test for project service Ensure it does not throw for in-project files
1 parent 77fc366 commit a124d4f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/typescript-estree/src/useProgramFromProjectService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export function useProgramFromProjectService(
8383
return undefined;
8484
}
8585

86-
defaultProjectMatchedFiles.add(filePathAbsolute);
86+
if (!opened.configFileName) {
87+
defaultProjectMatchedFiles.add(filePathAbsolute);
88+
}
8789
if (defaultProjectMatchedFiles.size > maximumDefaultProjectFileMatchCount) {
8890
throw new Error(
8991
`Too many files (>${maximumDefaultProjectFileMatchCount}) have matched the default project.${DEFAULT_PROJECT_FILES_ERROR_EXPLANATION}

packages/typescript-estree/tests/lib/useProgramFromProjectService.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,29 @@ If you absolutely need more files included, set parserOptions.EXPERIMENTAL_usePr
220220

221221
expect(actual).toBe(program);
222222
});
223+
224+
it('returns a created program when hasFullTypeInformation is disabled, the file is in the project service, the service has a matching program, and no out-of-project files are allowed', () => {
225+
const { service } = createMockProjectService();
226+
const program = { getSourceFile: jest.fn() };
227+
228+
mockGetProgram.mockReturnValueOnce(program);
229+
230+
service.openClientFile.mockReturnValueOnce({
231+
configFileName: 'tsconfig.json',
232+
});
233+
mockCreateProjectProgram.mockReturnValueOnce(program);
234+
235+
const actual = useProgramFromProjectService(
236+
createProjectServiceSettings({
237+
allowDefaultProjectForFiles: [],
238+
maximumDefaultProjectFileMatchCount: 0,
239+
service,
240+
}),
241+
mockParseSettings,
242+
false,
243+
new Set(),
244+
);
245+
246+
expect(actual).toBe(program);
247+
});
223248
});

0 commit comments

Comments
 (0)
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