Skip to content
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

Bug: ESLint react-hooks/exhaustive-deps rule false positive on constants made with constant expressions #21274

Open
ToadKing opened this issue Apr 14, 2021 · 1 comment
Labels
Component: ESLint Rules Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Enhancement

Comments

@ToadKing
Copy link

ToadKing commented Apr 14, 2021

React version: 16.14.0 & 17.0.2

Steps To Reproduce

  1. Create a constant variable with an expression made of only constants.
  2. Run ESLint

Code example:

const a = 1
const b = 2 / 3
const c = -1
const d = +1

useEffect(() => {
  void a
  void b
  void c
  void d
}, [])

CodeSandbox: https://codesandbox.io/s/funny-wilson-33zxb

The current behavior

I see the following ESlint warning:

React Hook useEffect has missing dependencies: 'b', 'c', and 'd'. Either include them or remove the dependency array. (react-hooks/exhaustive-deps)

The expected behavior

I see no warning.

In my example the a variable is skipped in the ESlint warning, but not the other three variables even those they are all constant expressions.

@ToadKing ToadKing added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 14, 2021
@eps1lon
Copy link
Collaborator

eps1lon commented Apr 15, 2021

Thanks for the feedback.

I guess this would make sense for literals.

But you might as well move them into the module scope achieving the same thing:

const a = 1
const b = 2 / 3
const c = -1
const d = +1

function TestComponent() {

  useEffect(() => {
    void a
    void b
    void c
    void d
  }, [])

  return <></>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: ESLint Rules Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants