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

Question: Why extending @typescript-eslint/recommended automatically adds tsx and ts extensions? #3824

Closed
fregante opened this issue Aug 30, 2021 · 2 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)

Comments

@fregante
Copy link
Contributor

Sorry, this is just a question. As far as I know eslint only runs on JS files and I have to use eslint --ext ts,tsx to run it on TypeScript files. There's no way around it… as far as I know. This is what your own docs say.

But actually I run eslint with just @typescript-eslint/recommended and eslint automatically picks up ts and tsx files. Why and most importantly how?!

Repro:

  npm init -y
  npm install eslint  @typescript-eslint/parser @typescript-eslint/eslint-plugin
  echo '// @ts-ignore' > index.ts
  echo '{}' > tsconfig.json
  echo '{"extends":["plugin:@typescript-eslint/recommended"]}' > .eslintrc
  npx eslint .
./index.ts
  1:1  error  Do not use "@ts-ignore" because it alters compilation errors  @typescript-eslint/ban-ts-comment

✖ 1 problem (1 error, 0 warnings)

🤔

We were wondering in xojs/eslint-config-xo-typescript#39

@fregante fregante added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 30, 2021
@bradzacher
Copy link
Member

It's likely because of our eslint-recommended config which explicitly disables/enables some rules on .ts/.tsx files:

This causes ESLint to recognise we want to lint .ts/.tsx files, and thus it automatically includes them when looking for files.
Then because the recommended config contains no restrictions - it just (correctly) applies the rules to the files.

@bradzacher bradzacher added question Questions! (i.e. not a bug / enhancment / documentation) and removed triage Waiting for maintainers to take a look labels Aug 30, 2021
@fregante
Copy link
Contributor Author

I have no idea how I missed that. I was just looking at this file https://github.com/typescript-eslint/typescript-eslint/blob/26de6459a38389fff86351c1aa0881b11dc2a76a/packages/eslint-plugin/src/configs/recommended.ts

Thank you for the quick answer!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)
Projects
None yet
Development

No branches or pull requests

2 participants