Skip to content

ecraig12345/repro-react-hooks-eslint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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() }
}

Repro setup

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.

Repro steps

  1. yarn
  2. Run with @typescript-eslint/parser v5, observe only 4 errors: yarn lint
  3. Run with @typescript-eslint/parser v4, observe 10 errors as expected: yarn lint-v4

Root cause

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.

About

Repro of an issue with eslint-plugin-react-hooks

Resources

Stars

Watchers

Forks