Demonstrating an issue with eslint-plugin-react-hooks: with @typescript-eslint/parser >= 5, the rules-of-hooks rule misses hook usage in class properties.
class Test {
useHook = () => { useState() }
}package.json includes dependencies on both @typescript-eslint/parser v4 and v5, and both eslint-plugin-react-hooks latest and next.
.eslintrc.js sets the parser to @typescript-eslint/parser (v5) and enables both the latest and next versions of react-hooks/rules-of-hooks.
index.ts has several rule violations.
The script yarn lint repros the issue.
yarn lint-v4 changes the parser to @typescript-eslint/parser v4 to show that it previously worked.
yarn- Run with
@typescript-eslint/parserv5, observe only 4 errors:yarn lint - Run with
@typescript-eslint/parserv4, observe 10 errors as expected:yarn lint-v4
In @typescript-eslint/parser v5, ClassProperty was renamed to PropertyDefinition. The rules-of-hooks rule needs to be updated to check for this additional name.