Skip to content

Commit

Permalink
fix(typescript-estree): only create project service from env setting …
Browse files Browse the repository at this point in the history
…if project is enabled (#8136)

* fix(typescript-estree): only create project serve from env setting if project is enabled

* fix lint
  • Loading branch information
JoshuaKGoldberg committed Jan 7, 2024
1 parent 4fdce89 commit 5a33c2b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export function createParseSettings(
errorOnTypeScriptSyntacticAndSemanticIssues: false,
errorOnUnknownASTType: options.errorOnUnknownASTType === true,
EXPERIMENTAL_projectService:
(options.EXPERIMENTAL_useProjectService &&
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER !== 'false') ||
(process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER === 'true' &&
options.EXPERIMENTAL_useProjectService !== false)
options.EXPERIMENTAL_useProjectService ||
(options.project &&
options.EXPERIMENTAL_useProjectService !== false &&
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER === 'true')
? (TSSERVER_PROJECT_SERVICE ??= createProjectService(
options.EXPERIMENTAL_useProjectService,
jsDocParsingMode,
Expand Down
50 changes: 50 additions & 0 deletions packages/typescript-estree/tests/lib/createParseSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
import { createParseSettings } from '../../src/parseSettings/createParseSettings';

const projectService = { service: true };

jest.mock('../../src/create-program/createProjectService', () => ({
createProjectService: (): typeof projectService => projectService,
}));

describe('createParseSettings', () => {
describe('EXPERIMENTAL_projectService', () => {
it('is created when options.EXPERIMENTAL_useProjectService is enabled', () => {
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'false';

const parseSettings = createParseSettings('', {
EXPERIMENTAL_useProjectService: true,
});

expect(parseSettings.EXPERIMENTAL_projectService).toBe(projectService);
});

it('is created when options.EXPERIMENTAL_useProjectService is undefined, options.project is true, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';

const parseSettings = createParseSettings('', {
EXPERIMENTAL_useProjectService: undefined,
project: true,
});

expect(parseSettings.EXPERIMENTAL_projectService).toBe(projectService);
});

it('is not created when options.EXPERIMENTAL_useProjectService is undefined, options.project is falsy, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';

const parseSettings = createParseSettings('', {
EXPERIMENTAL_useProjectService: undefined,
});

expect(parseSettings.EXPERIMENTAL_projectService).toBeUndefined();
});

it('is not created when options.EXPERIMENTAL_useProjectService is false, options.project is true, and process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER is true', () => {
process.env.TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER = 'true';

const parseSettings = createParseSettings('', {
EXPERIMENTAL_useProjectService: false,
project: true,
});

expect(parseSettings.EXPERIMENTAL_projectService).toBeUndefined();
});
});

describe('tsconfigMatchCache', () => {
it('reuses the TSConfig match cache when called a subsequent time', () => {
const parseSettings1 = createParseSettings('input.ts');
Expand Down

0 comments on commit 5a33c2b

Please sign in to comment.