-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add linting for React Hooks #186
Comments
Some more information about hook rules: https://reactjs.org/docs/hooks-rules.html |
I took a quick stab at it and while porting AST specific differences is pretty straightforward I hit a wall with codepath analysis. For now I'm using // .eslintrc.js
module.exports = {
parser: 'typescript-eslint-parser',
parserOptions: {
jsx: true,
},
plugins: ['react-hooks'],
rules: {
'react-hooks/rules-of-hooks': 'error',
},
}; I'm using this with |
Take a look at https://github.com/Gelio/tslint-react-hooks I implemented a TSLint rule for detecting invalid uses of React Hooks, based on eslint-plugin-react-hooks. It relies on detecting nesting the possible misuses of hooks, like calling hooks inside loops, if statements, class components and functions that themselves are not components or custom hooks. I would love to receive some feedback 😄 I created some tests for the rule (the |
@Gelio
It should be error at useEffect but my vscode does not warning anything. |
@rainstormza Please try installing Having installed |
@Gelio thanks :) |
@Gelio, have you considered opening a PR in this project? |
@thejohnfreeman Good idea 👍 I have just filed a PR: #204 |
@Gelio what you mean "try installing tslint alongside tslint-react-hooks"? Can you give me step by step instruction? |
@vzgo0022 Just run Then, take a look at the readme of https://github.com/Gelio/tslint-react-hooks for instructions on how to install and configure the |
open to PRs, but I'm also curious to hear about your experiences (if any) using eslint-plugin-react with typescript-eslint, see #210 (edit: while I work on a migration guide...) |
@Gelio seems that it doesn't work with .tsx files |
@enoh-barbu Please file an issue in https://github.com/Gelio/tslint-react-hooks with more information and reproductions steps. Let's not pollute this thread with bug-related comments regarding another project 🙂 |
Closing due to #210, future work should be focused on getting the ESLint plugin working with TypeScript |
For anyone still here, it's time to get off of tslint. I've migrated a couple projects, and eslint-plugin-react-hooks works well with typescript-eslint. |
Similar to: https://www.npmjs.com/package/eslint-plugin-react-hooks
The text was updated successfully, but these errors were encountered: