Skip to content
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

Allow setting tsconfig config directly in the parser #1613

Open
sindresorhus opened this issue Feb 18, 2020 · 6 comments
Open

Allow setting tsconfig config directly in the parser #1613

sindresorhus opened this issue Feb 18, 2020 · 6 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@sindresorhus
Copy link

Currently, we can specify parserOptions.project for a path to our tsconfig, but the parser handles the loading of tsconfig, so there's no way for us to provide a custom tsconfig (not on disk) directly to @typescript-eslint/parser.

My specific use-case is that we're adding built-in TypeScript support (xojs/xo#426) to XO. XO is a "zero-config" ESLint wrapper that ships with great defaults and lots of plugins. We want to add the ability to lint ambient d.ts files. However, JS packages with a d.ts file don't usually have a tsconfig file, and I feel that TypeScript is too loose by default, so I would like to provide some sensible tsconfig defaults for d.ts files in JS projects.

It would be great if there was a way to set a default tsconfig object that is used if there's no tsconfig file in the project.

@sindresorhus sindresorhus added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Feb 18, 2020
@bradzacher
Copy link
Member

I don't think that this is really possible without significant effort.

When we call into the TS API, we have to provide a compiler host, which for us gets created via
ts.createWatchCompilerHost.
This function accepts either a config file path on disk, or it accepts a config object, and an array of root filenames to seed the project from.

The significant effort would be us manually implementing a compiler host to work around this API limitation.
If this were added to TS itself, then sure we could add it in, but that then ties the feature (and thus your project) to a brand new version of TS.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Feb 18, 2020
@sindresorhus
Copy link
Author

or it accepts a config object, and an array of root filenames to seed the project from.

Wouldn't this solve the problem? Or am I misunderstanding something?

In XO, we have the config and TS file paths, just not the config file on disk.

@ark120202
Copy link

Do you have a raw json file content or parsed one (an instance of ts.CompilerOptions)? If it's the first, such object can be parsed with ts.parseJsonConfigFileContent to get ts.CompilerOptions and fileNames, which can be passed to a second overload of ts.createWatchCompilerHost

@sindresorhus
Copy link
Author

Raw

@bradzacher
Copy link
Member

XO makes its own calls into the ESLint api right?

If yes, then this might be a good use case for a more generic solution like in #1442

I'm hesitant to accept tsconfig via parserOptions, because it would be even more reliant upon the tsconfigRootDir option, which I know already causes problems for people.
I'm probably worrying about nothing though.

@sindresorhus
Copy link
Author

XO makes its own calls into the ESLint api right?

Yes, it uses ESLint's programmatic interface (CLIEngine).

@bradzacher bradzacher added enhancement New feature or request package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed awaiting response Issues waiting for a reply from the OP or another party package: parser Issues related to @typescript-eslint/parser labels Mar 26, 2020
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

No branches or pull requests

4 participants