eslint-plugin-react-hooks - autofix useCallback/useMemo behaviour
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 251k
- Forks
- 51.4k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 53
Description
Do you want to request a feature or report a bug?
Discussion for new feature
What is the current behavior?
useCallback/useMemo hook's do nothing when there is no second argument provided for deps. The eslint plugin reports this but does not autofix
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.8.4
PR to implement:
https://github.com/facebook/react/pull/15146
Currently, the eslint plugin does not autofix useCallback/useMemo to infer deps if there isn't a second argument provided to the hook. We can autofix it to infer deps if needed, or autofix to remove the hook altogether if there no deps needed (according to https://reactjs.org/docs/hooks-reference.html#usememo, if no second argument is provided it behaves as if the hook doesn't exist anyways).
What would be the best way to implement this autofix? In my opinion, linting shouldn't be breaking functionality on an autofix, so autofixing to remove the hook is the safest to implement. Autofixing to infer deps will change behavior in code so I was thinking of having a config option the dev needs to specify so that linting changes that is affecting behavior is explicit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing PR #15146 and the eslint-plugin-react-hooks implementation for useCallback and useMemo calls without dependency arrays. Decide whether the autofix should remove the hook or infer dependencies, then verify that the selected behavior matches the Hooks reference and does not silently change application behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript, react
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100