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

🐛 useExhaustiveDependencies: false positive for out of scope dependency #651

Closed
1 task done
emab opened this issue Nov 2, 2023 · 4 comments · Fixed by #1069
Closed
1 task done

🐛 useExhaustiveDependencies: false positive for out of scope dependency #651

emab opened this issue Nov 2, 2023 · 4 comments · Fixed by #1069
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@emab
Copy link
Contributor

emab commented Nov 2, 2023

Environment information

CLI:
  Version:                      1.3.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "cygwin"
  JS_RUNTIME_VERSION:           "v18.12.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       unset

Workspace:
  Open Documents:               0

What happened?

When using a variable declared outside of the component scope, you should not add it to a React useEffect dependency array. A valid example of this in the React docs:

ESLint is aware of this, and gives a warning if it is added:

ESLint: React Hook useEffect has an unnecessary dependency: 'hasRequested'. Either exclude it or remove the dependency array. Outer scope values like 'hasRequested' aren't valid dependencies because mutating them doesn't re-render the component.(react-hooks/exhaustive-deps)

However Biome falsely tells you to add it as a dependency:

https://biomejs.dev/playground/?lintRules=all&code=aQBtAHAAbwByAHQAIAB7AHUAcwBlAEUAZgBmAGUAYwB0AH0AIABmAHIAbwBtACAAJwByAGUAYQBjAHQAJwA7AAoACgBsAGUAdAAgAGQAaQBkAEkAbgBpAHQAIAA9ACAAZgBhAGwAcwBlADsACgAKAGYAdQBuAGMAdABpAG8AbgAgAEEAcABwACgAKQAgAHsACgAgACAAdQBzAGUARQBmAGYAZQBjAHQAKAAoACkAIAA9AD4AIAB7AAoAIAAgACAAIABpAGYAIAAoACEAZABpAGQASQBuAGkAdAApACAAewAKACAAIAAgACAAIAAgAGQAaQBkAEkAbgBpAHQAIAA9ACAAdAByAHUAZQA7AAoAIAAgACAAIAAgACAALwAvACAABScgAE8AbgBsAHkAIAByAHUAbgBzACAAbwBuAGMAZQAgAHAAZQByACAAYQBwAHAAIABsAG8AYQBkAAoAIAAgACAAIAB9AAoAIAAgAH0ALAAgAFsAXQApADsACgAgACAALwAvACAALgAuAC4ACgB9AA%3D%3D

Expected result

You should not be prompted to add an out-of-scope variable to the dependency array.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

Duplicate of #608

@ematipico ematipico marked this as a duplicate of #608 Nov 2, 2023
@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2023
@emab
Copy link
Contributor Author

emab commented Nov 2, 2023

Duplicate of #608

I don't think this is a duplicate of that issue?

@ematipico
Copy link
Member

Apologies!

@ematipico ematipico reopened this Nov 2, 2023
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Nov 21, 2023
@kalleep
Copy link
Contributor

kalleep commented Dec 5, 2023

I can pick this one up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
4 participants