-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Scripts: Ensure that typescript-eslint checks for unused vars #62925
Conversation
…hecker is executed. eslint/no-unused-vars got disabled when introducing support for TypeScript with WordPress#27143 (2-3 years ago) when Gutenberg was moving to Typescript. By disabling this feature, the Typescript type checker will not be executed. We actively enable "no-unused-vars" and "@typescript-eslint/no-unused-vars" and additionally setting "ignoreRestSiblings" to "true", which is actively used in Gutenberg. See more information in: WordPress#54305
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Chrico! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
@gziolo {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [ 'error', { ignoreRestSiblings: true } ]
} At least, this is the recommended way in the docs https://typescript-eslint.io/rules/no-unused-vars/#how-to-use ;-) |
…pt-eslint/no-unused-vars"
Should we ( I ?) also fix the problems which now occur or is this a "follow-up" Issue/PR? :-) Probably, depending on how we want to continue, some code might needs to be touched and/or we need to add some |
It needs to be evaluated before landing whether these issues are correctly highlighted and the should get fixed. Alternatively, maybe there are some config options that could relax these checks to pass the validation. |
Maybe you could commit to all the proposed changes to help decide. |
token-list // disable and enable eslint "no-unused-var" for supports()-method.
Seems like, every time something is fixed, something new appears. The |
So far so good. 12 errors fixed, 12 more to go. |
Here we go @gziolo :) ☕ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, good spot! I've left a few suggestions I'd like to see changed before this moves ahead.
Will you also add a Breaking Changes changelog entry to the eslint-plugin package?
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thoughtful discussion. I'm ready to approve and land this pending two changes:
- Revert and eslint-disable this valid case: Scripts: Ensure that typescript-eslint checks for unused vars #62925 (comment)
- Remove other tsconfig
noUnused*
: Scripts: Ensure that typescript-eslint checks for unused vars #62925 (comment)
Change was done here: 2b21b06
Updates were done here: 93da83f |
editor/dataviews // remove unused vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, nice work on this one @Chrico.
Thank you both for taking it to the finish line 🥇 |
…#62925) Enable @typescript-eslint/no-unused-vars eslint rule in default eslint TypeScript configuration. Disable redundant `noUnusedLocals` and `noUnusedParameters` from TypeScript configuration. The TypeScript eslint configuration disabled no-unused-vars rules, resulting in many cases of unused vars appearing in code. The expectation was that TypeScript handle the linting via configuration such as `noUnusedLocals` and `noUnusedParameters`. This was unreliable because TypeScript may not run on entire projects, for example if `checkJs` is disabled. --- Co-authored-by: Chrico <chrico@git.wordpress.org> Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
What?
'no-unused-vars': 'off'
in eslint-plugin/configs/recommanded.js will also disable the Typescript eslint when runningwp-scripts lint-js
.Why?
eslint/no-unused-vars got disabled when introducing support for TypeScript with #27143 (2-3 years ago) when Gutenberg was moving to Typescript. By disabling this feature, the Typescript eslint will not be executed. We actively enable "no-unused-vars" and "@typescript-eslint/no-unused-vars" and additionally setting "ignoreRestSiblings" to "true", which is actively used in Gutenberg.
See more information in: #54305
Testing Instructions
Create a new file:
index.ts
with package.json:
and execute on cli:
$ wp-scripts lint-js *.{ts,tsx}
before this fix the Typescript eslint did not catch any type errors:
Done in 1.83s.
after this fix the Typescript eslint will match errors: