Skip to content

fix(parser): error when both projectService and project are set #11333

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Testing] Looks like our own test infrastructure is getting in the way. Both are set because that was easier to do in CI:

- name: Run unit tests for ${{ matrix.package }}
run: yarn nx test ${{ matrix.package }} --coverage=false
env:
CI: true
TYPESCRIPT_ESLINT_PROJECT_SERVICE: true

projectService:
tsestreeOptions.projectService ||
(tsestreeOptions.project &&
tsestreeOptions.projectService !== false &&
process.env.TYPESCRIPT_ESLINT_PROJECT_SERVICE === 'true')
? populateProjectService(tsestreeOptions.projectService, {
jsDocParsingMode,
tsconfigRootDir,
})
: undefined,

Maybe we should temporarily give users a way to disable the new error? TYPESCRIPT_ESLINT_IGNORE_PROJECT_AND_PROJECT_SERVICE_ERROR or some similarly unwieldy name? I'll post in #11319.

Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
tsconfigRootDir,
};

if (parseSettings.projectService && tsestreeOptions.project) {
throw new Error(

Check failure on line 149 in packages/typescript-estree/src/parseSettings/createParseSettings.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests with Project Service (typescript-estree)

tests/lib/parse.test.ts > parseAndGenerateServices > preserveNodeMaps > should not preserve node maps for parseAndGenerateServices() when option is `false`, regardless of `project` config > with project

Error: Cannot use both projectService and project parser options. ❯ createParseSettings src/parseSettings/createParseSettings.ts:149:11 ❯ Module.parseAndGenerateServices src/parser.ts:172:25 ❯ tests/lib/parse.test.ts:152:36

Check failure on line 149 in packages/typescript-estree/src/parseSettings/createParseSettings.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests with Project Service (typescript-estree)

tests/lib/parse.test.ts > parseAndGenerateServices > preserveNodeMaps > should preserve node maps for parseAndGenerateServices() when option is `true`, regardless of `project` config > with project

Error: Cannot use both projectService and project parser options. ❯ createParseSettings src/parseSettings/createParseSettings.ts:149:11 ❯ Module.parseAndGenerateServices src/parser.ts:172:25 ❯ tests/lib/parse.test.ts:152:36

Check failure on line 149 in packages/typescript-estree/src/parseSettings/createParseSettings.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests with Project Service (typescript-estree)

tests/lib/parse.test.ts > parseAndGenerateServices > preserveNodeMaps > should preserve node maps by default for parseAndGenerateServices()

Error: Cannot use both projectService and project parser options. ❯ createParseSettings src/parseSettings/createParseSettings.ts:149:11 ❯ Module.parseAndGenerateServices src/parser.ts:172:25 ❯ tests/lib/parse.test.ts:124:45

Check failure on line 149 in packages/typescript-estree/src/parseSettings/createParseSettings.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests with Project Service (typescript-estree)

tests/lib/createParseSettings.test.ts > createParseSettings > projectService > is created when options.projectService is undefined, options.project is true, and process.env.TYPESCRIPT_ESLINT_PROJECT_SERVICE is true

Error: Cannot use both projectService and project parser options. ❯ Module.createParseSettings src/parseSettings/createParseSettings.ts:149:11 ❯ tests/lib/createParseSettings.test.ts:24:29

Check failure on line 149 in packages/typescript-estree/src/parseSettings/createParseSettings.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests (ubuntu-latest, 18, typescript-estree)

tests/lib/createParseSettings.test.ts > createParseSettings > projectService > is created when options.projectService is undefined, options.project is true, and process.env.TYPESCRIPT_ESLINT_PROJECT_SERVICE is true

Error: Cannot use both projectService and project parser options. ❯ Module.createParseSettings src/parseSettings/createParseSettings.ts:149:11 ❯ tests/lib/createParseSettings.test.ts:24:29
'Cannot use both projectService and project parser options.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Docs] I think users who are enabling both are probably not super familiar with them. We'll need to guide them a bit more. Maybe something like...

Suggested change
'Cannot use both projectService and project parser options.',
'Enabling 'project' does nothing when 'projectService' is already enabled. You can remove 'project'.',

Note that we can't assume project: true rather than string / string[]. Example from the wild, https://sourcegraph.com/github.com/software-mansion/smelter/-/blob/ts/eslint.config.js?L28-35

);
}

// debug doesn't support multiple `enable` calls, so have to do it all at once
if (parseSettings.debugLevel.size > 0) {
const namespaces = [];
Expand Down
Loading