Skip to content

Enhancement: Allow parserOptions.project to be (true | string)[]? #7384

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

Closed
4 tasks done
JoshuaKGoldberg opened this issue Jul 30, 2023 · 4 comments
Closed
4 tasks done
Labels
enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. wontfix This will not be worked on

Comments

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jul 30, 2023

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

parser

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

In #6084 we added the ability to specify parserOptions.project: true. Doing so indicates each file should be linted with the closest tsconfig.json to that file.

But, what if a repo wants a different TSConfig for files that it matches, and true for all other files? For example, maybe it'd want:

  • tsconfig.eslint.json to apply for *.(c)js files
  • tsconfig.json for all other files

What if we allow specifiers like project: ['tsconfig.eslint.json', true]? In essence, this would be allowing configs to include true inside the already-present string[] option that says to find the first matching TSConfig.

Example repro case here: https://github.com/JoshuaKGoldberg/repros/tree/typescript-eslint-parserOptions-project-string-true

Additional Info

Somewhat of a sibling issue to #7383. If we end up allowing an object with a type name then this issue would be to change project to (boolean | string | ThatNewProjectSpecifierType)[].

@JoshuaKGoldberg JoshuaKGoldberg added enhancement New feature or request triage Waiting for team members to take a look labels Jul 30, 2023
@bradzacher
Copy link
Member

This is kind-of doable right now with eslint overrides config, eg:

module.exports = {
  parserOptions: { project: true },
  rules: { ... },
  overrides: [
    {
      // idk if this would 100% work but as an example...
      files: require('./tsconfig.eslint.json').includes,
      parserOptions: {
        project: ['./tsconfig.eslint.json'],
        tsconfigRootDir: __dirname,
      },
    },
  ],
}

This would cause ESLint to pass project: ['./tsconfig.eslint.json'] instead of project: true just for the files in question.

@bradzacher
Copy link
Member

The complicated thing about allowing [true, "path"] we've got is that order-of-operations is... unclear.

The big wins from relative mode are:
a) config simplicity - no need to manually specify globs or whatever - it "just works"
b) performance - we will only load the tsconfigs required for the lint run - nothing more, nothing less.

(b) is big because it means when you do yarn eslint ./some/file.ts:

  • on string[] config we'll load EVERY SINGLE PROJECT in order until we find the matching project
  • on true config we'll just load the nearest tsconfig - simples.

But as soon as you introduce BOTH - we now have this confusing approach in the form of "when should we load what config?"
Do we respect the order of definition - eg [true. "path"] means we try relative first, then try "path"? Or do we hard-code an ordering?
This could impact (b) above because if you do ["path", true] then we'll always load and chec "path" before trying relative resolution - so bad perf!

Also with ["path", true] you might have weirdness in the form of "some files in this folder are checked relative, but other files are checked via "path"" - which makes things more complex to reason about.

I'm of two minds about this... I don't really love the idea. I think I'd need to see a solid usecase to be convinced it's a good idea to implement it.

@JoshuaKGoldberg JoshuaKGoldberg added evaluating community engagement we're looking for community engagement on this issue to show that this problem is widely important and removed triage Waiting for team members to take a look labels Feb 4, 2024
@JoshuaKGoldberg
Copy link
Member Author

Marking as evaluating community engagement. If anybody listening to this issue has a solid use case, please do post it!

I personally am much less excited about it now that EXPERIMENTAL_useProjectService is looking more and more like our long-term recommendation (#7350).

@bradzacher
Copy link
Member

With our release of project services and the release of flat configs - I don't see much value in this.
We were already on the fence with this and it hasn't received too much community interaction in 1 year.
As such we are rejecting this proposal.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2024
@bradzacher bradzacher added wontfix This will not be worked on and removed evaluating community engagement we're looking for community engagement on this issue to show that this problem is widely important labels Aug 25, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Sep 2, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants