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

Configs: add a config that turns off all type-aware linting #6215

Closed
2 tasks done
bradzacher opened this issue Dec 14, 2022 · 3 comments
Closed
2 tasks done

Configs: add a config that turns off all type-aware linting #6215

bradzacher opened this issue Dec 14, 2022 · 3 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config

Comments

@bradzacher
Copy link
Member

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

Description

Our current guidance on how to setup an ESLint config is to turn everything on in the root of the config and be done with it. This advice includes turning on type-aware linting on all files.

However for a lot of codebases this can create a crappy experience because there are a lot of files NOT included in a tsconfig that ESLint will run over. This in turn causes the dreaded "The file must be included in at least one of the projects provided" error.

There's not really a good way around this right now, sadly. Our advice is pretty long winded and not the easiest thing to put into practice, especially if you don't actually want to lint the file with type-info. Possible workarounds include:

  1. .eslintignore the files.
  2. create a tsconfig.eslint.json that includes the files.
  3. manually turn off type-aware rules AND parserOptions.project on the files.
  4. rework your config so that you only enable type-aware linting on specific files using overrides config.

All of those options suck for a user because:

  1. these files are often files that you want to do at least basic lint checks on
  2. these files are often .js files with poor-to-no types or are config files where most type-aware rules aren't going to catch anything useful (if anything at all)
  3. it's difficult to know exactly what type-aware rules you have turned on due to config composition
  4. it's hard to rework your entire config without accidentally missing files that should be type-aware linted.

I realised that we're in a good position to help people automate this. We know what rules need type-info - so why not generate a config for it? That way the solution to the problem can simply be "use overrides to disable type-aware linting by extending this config", i.e.

module.exports = {
  // ...
  overrides: [
    // disable type-aware linting for some files
    {
      files: ['.eslintrc.js'/*, ... */],
      extends: ['plugin:@typescript-eslint/disable-type-aware-linting'],
    },
  ],
}

This would be a substantially better UX and is a pretty clean solution!

Impacted Configurations

No response

Additional Info

No response

@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look preset config change Proposal for an addition, removal, or general change to a preset config labels Dec 14, 2022
@Josh-Cena
Copy link
Member

Yesss...! This would make https://twitter.com/SidaChen63/status/1581749782980153344 so much easier

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Dec 15, 2022
@Josh-Cena
Copy link
Member

Closed by #6470; idk why the keyword isn't working.

@bradzacher
Copy link
Member Author

the keyword only works if you merge into the default branch sadly

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin preset config change Proposal for an addition, removal, or general change to a preset config
Projects
None yet
Development

No branches or pull requests

2 participants