-
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
@wordpress/scripts: Improve TypeScript support in lint-js
#54305
Comments
Just wanted to add some "findings". It seems like the
See here: gutenberg/packages/eslint-plugin#usage It looks like there is already some support for Typescript according due: gutenberg/packages/eslint-plugin/configs/recommended.js#L31-L60 Edit: It looks like this line here: gutenberg/packages/eslint-plugin/configs/recommended.js Lines 52 to 53 in 65bf4f7
|
|
Thanks for your reply 👍🏻 Typescript is installed and actually the
So by turning this off...no Typescript type checks are done. As it is: $ wp-scripts lint-js resources/ts/**/*.{ts,tsx}
yarn run v1.22.19
Done in 1.83s. With L53 commented out: $ wp-scripts lint-js resources/ts/**/*.{ts,tsx}
yarn run v1.22.19
/{snip}/tsc-eslint\resources\ts\index.ts
5:32 error 'value' is defined but never used no-unused-vars
✖ 1 problem (1 error, 0 warnings)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. package.json {
"name": "tsc-eslint",
"version": "1.0.0",
"license": "GPL-2.0-or-later",
"devDependencies": {
"@wordpress/scripts": "^25.0.0",
"typescript": "^4.9.4"
}
} |
eslint/no-unused-vars got disabled when introducing support for TypeScript with #27143 (2-3 years ago). It's very likely that the way it's handled has changed, and we should have the rule enabled again, as there isn't a rule coming from |
Yeah, already thought about such a thing like "Gutenberg was not fully using Typescript and disabled it". Thanks for confirmation. Since you're also using |
Gutenberg uses In fact, it also extends It'd probably be best to switch to the |
I tried the following: diff --git a/packages/eslint-plugin/configs/recommended.js b/packages/eslint-plugin/configs/recommended.js
index 8f0399e8e1..7ef78a2b6a 100644
--- a/packages/eslint-plugin/configs/recommended.js
+++ b/packages/eslint-plugin/configs/recommended.js
@@ -49,11 +49,11 @@ if ( isPackageInstalled( 'typescript' ) ) {
// Don't require redundant JSDoc types in TypeScript files.
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
- // Handled by TS itself.
- 'no-unused-vars': 'off',
- // no-shadow doesn't work correctly in TS, so let's use a TS-dedicated version instead.
+ // Following rules don't work correctly in TS, so let's use a TS-dedicated version instead.
'no-shadow': 'off',
+ 'no-unused-vars': 'off',
'@typescript-eslint/no-shadow': 'error',
+ '@typescript-eslint/no-unused-vars': 'error',
},
},
]; It reports 42 errors, but they seem to be legit. |
I guess this is a blocker to "activate" it straight away, because it would break every current PR to run successful?! 😅 Can you quickly post the errors here so that everyone can see if those are "easy to fix" or maybe need some more time invested? |
I don't think it's a blocker. We can always signal a breaking change for const { ignoredVar, ...restArgs } = args;
doSomething( restArgs ); @tyxla, do you know if there is a better way to signal to ESLint that I also saw some reports in TS definitions when using generics which I'm not sure if should be reported. |
AFAIK
Let me know if that works for you. |
My understanding is that the direction here is clear and this just needs a developer to pick it up and open a PR, but I might be missing something, so I'll defer to @gziolo. |
Yes, this issue is waiting for any developer to enable the rule as outlined by @tyxla in #54305 (comment) in '@typescript-eslint/no-unused-vars': [ 'error', { ignoreRestSiblings: true } ], |
lint-js
…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
What problem does this address?
Right now the
@wordpress/scripts
package provideslint-js
(eslint),lint-style
(stylelint),lint-md-docs
(markdownlint) andlint-pkg-json
(npmPkgJsonLint).While tools like
lint-style
viastylelint
are able to find syntax errors - as an example:index.scss
the
lint-js
does not actually check typescript code to detect type errors. As an example:index.ts
$ yarn wp-scripts lint-js yarn run v1.22.19 Done in 2.10s.
Running
tsc
with--noEmit
will detect an error:What is your proposed solution?
Introduce a new
lint-ts
script in@wordpress/scripts
which does lint Typescript code. To do that we can make use of thetsc
with--noEmit
to do only the type checking part and not the compilation.See also: https://www.typescriptlang.org/tsconfig#noEmit
The text was updated successfully, but these errors were encountered: