-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Add TypeScript linting support #5641
Comments
+1 Really need support for tslint..... |
I think TSLint also has a few that can catch errors that cannot be supported by ESLint, such as no-floating-promises - wouldn't it be a good idea to catch as many potential errors as possible, even if they diverge from the ESLint configuration? |
TSLint React Hooks: palantir/tslint-react#186 |
@copiali for now, you can add linting manually:
and then |
There was a discussion around If we could get this in, with close to parity on the Can I help with this effort? |
@mrmckeb we're well under way adding support for this. It will be part of the 3.0 release. See https://github.com/ianschmitz/create-react-app/tree/tslint and give it a try! |
I'll take a look, thanks @ianschmitz. In the interim we'll use the WIP version. |
I just published a working solution. Please check out Rescripts (specifically the use-tslint-config rescript). And please let me know what you think of it, how it could be improved, feature requests, criticisms, etc... I'd really love to hear from y'all! :) hope this helps |
you can use craco to rewrite cra configuration so you can add tslint-loader to webpack and use
|
Check the update by @ianschmitz in the PR: #5697 (comment) I think it would be better to integrate https://github.com/typescript-eslint/typescript-eslint when it is released and documented. |
If anyone is looking for such a plugin, I have created a rule similar to eslint-plugin-react-hooks. Check it out: https://github.com/Gelio/tslint-react-hooks Feel free to post your feedback 📝 😄 |
@Gelio this looks fantastic. Good work! |
Hi all, it looks like Microsoft is pushing full-steam towards ESLint. This config is great, and I would recommend people to use it for the interim - but I wanted to offer warning that this may not get merged if we decide to go in that direction. Further reading: |
Just to illustrate the eslint approach as suggested up above, I was able to start a new {
test: /\.(ts|tsx)$/,
enforce: 'pre',
use: [
{
options: {
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
parser: require.resolve('@typescript-eslint/parser'),
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
} There is a warning about mismatched TypeScript versions so that's one thing to solve. |
@kumar303 is the best way to apply that change through Rescripts? I feel like linting config and rules really should be customisable. |
as @mrmckeb said. TSLint is going bye bye as the "standard" TypeScript linter. I've started to migrate all projects to eslint and it works very well. https://twitter.com/martin_hotell/status/1093174635015880705?s=20 What should be done is to incorporate |
@Ciaran0 👌 nit: Yup I'm using similar approach. Anyways IMHO having run linters as pre-hook within webpack is big mistake (especially if you use typescript as you code won't compile if it contains compilation === most of the runtime errors ) |
@Hotell I'll transition my existing TSLint PR to use ESLint. We just need to make sure it's ready for prime time before shipping it in CRA. |
To make sure what is ready for prime time? Eslint for TypeScript ? Everything works as expected, I would push it ASAP, because as for now, CRA TS users have no linting support at all, just useless recompile slowdown (eslint pre-hook in wp running eslint ) |
Yes, @Hotell :) We're just being cautious as the |
We've created #6513 to add support for linting via typescript-eslint. |
Using your command, I end up having troubles with some projects that don't have any JS files inside the src, with eslint reporting the following:
Looks like eslint will break if it doesn't find any file for each of the extensions in the glob. It was hard to debug, because the command ran fine in other projects :p The following command worked for me, ignoring missing patterns.
|
I have added tslint to my project as suggested by @copiali above. However it requires to run tslint manually. Is there any way to run the tslint on file save, preferably by react-scripts? I could add some kind of watcher that would run the linter in a separate shell, but that is very awkward. Is there some kind of a hook in react-scripts that would allow me to do this more elegantly? |
We should lint TypeScript files and try to approximate to match our ESLint configuration as close as possible.
TSLint rules we want:
no-namespace
: enforce usage of ES Modules / disallow deprecated behaviorno-duplicate-super
: prevent runtime errorno-duplicate-switch-case
no-duplicate-variable
: prevent redeclare ofvar
no-invalid-template-strings
no-invalid-this
triple-equals
use-isnan
maybe:
no-switch-case-fall-through
no-implicit-dependencies
The text was updated successfully, but these errors were encountered: