8000 fix(typescript-estree): only create project service from env setting … · StyleShit/typescript-eslint@5a33c2b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a33c2b

Browse files
fix(typescript-estree): only create project service from env setting if project is enabled (typescript-eslint#8136)
* fix(typescript-estree): only create project serve from env setting if project is enabled * fix lint
1 parent 4fdce89 commit 5a33c2b

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

packages/typescript-estree/src/parseSettings/createParseSettings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export function createParseSettings(
8080
errorOnTypeScriptSyntacticAndSemanticIssues: false,
8181
errorOnUnknownASTType: options.errorOnUnknownASTType === true,
8282
EXPERIMENTAL_projectService:
83-
(options.EXPERIMENTAL_useProjectService &&
84-
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER !== 'false') ||
85-
(process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER === 'true' &&
86-
options.EXPERIMENTAL_useProjectService !== false)
83+
options.EXPERIMENTAL_useProjectService ||
84+
(options.project &&
85+
options.EXPERIMENTAL_useProjectService !== false &&
86+
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER === 'true')
8787
? (TSSERVER_PROJECT_SERVICE ??= createProjectService(
8888
options.EXPERIMENTAL_useProjectService,
8989
jsDocParsingMode,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
import { createParseSettings } from '../../src/parseSettings/createParseSettings';
22

3+
const projectService = { service: true };
4+
5+
jest.mock('../../src/create-program/createProjectService', () => ({
6+
createProjectService: (): typeof projectService => projectService,
7+
}));
8+
39
describe('createParseSettings', () => {
10+
describe('EXPERIMENTAL_projectService', () => {
11+
it('is created when options.EXPERIMENTAL_useProjectService is enabled', () => {
12+
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'false';
13+
14+
const parseSettings = createParseSettings('', {
15+
EXPERIMENTAL_useProjectService: true,
16+
});
17+
18+
expect(parseSettings.EXPERIMENTAL_projectService).toBe(projectService);
19+
});
20+
21+
it('is created when options.EXPERIMENTAL_useProjectService is undefined, options.project is true, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
22+
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';
23+
24+
const parseSettings = createParseSettings('', {
25+
EXPERIMENTAL_useProjectService: undefined,
26+
project: true,
27+
});
28+
29+
expect(parseSettings.EXPERIMENTAL_projectService).toBe(projectService);
30+
});
31+
32+
it('is not created when options.EXPERIMENTAL_useProjectService is undefined, options.project is falsy, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
33+
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';
34+
35+
const parseSettings = createParseSettings('', {
36+
EXPERIMENTAL_useProjectService: undefined,
37+
});
38+
39+
expect(parseSettings.EXPERIMENTAL_projectService).toBeUndefined();
40+
});
41+
42+
it('is not created when options.EXPERIMENTAL_useProjectService is false, options.project is true, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
43+
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';
44+
45+
const parseSettings = createParseSettings('', {
46+
EXPERIMENTAL_useProjectService: false,
47+
project: true,
48+
});
49+
50+
expect(parseSettings.EXPERIMENTAL_projectService).toBeUndefined();
51+
});
52+
});
53+
454
describe('tsconfigMatchCache', () => {
555
it('reuses the TSConfig match cache when called a subsequent time', () => {
656
const parseSettings1 = createParseSettings('input.ts');

0 commit comments

Comments
 (0)
0