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

linter: react/exhaustive-deps false negative #9788

Open
vemoo opened this issue Mar 14, 2025 · 1 comment
Open

linter: react/exhaustive-deps false negative #9788

vemoo opened this issue Mar 14, 2025 · 1 comment
Assignees
Labels
A-linter Area - Linter

Comments

@vemoo
Copy link

vemoo commented Mar 14, 2025

What version of Oxlint are you using?

0.15.15

What command did you run?

oxlint ./src

What does your .oxlintrc.json config file look like?

{
    "$schema": "./node_modules/oxlint/configuration_schema.json",
    "rules": {
        "react/exhaustive-deps": "warn",
        "no-unused-vars": "off"
    },
    "env": {
        "builtin": true,
        "browser": true
    },
    "ignorePatterns": ["dist/**", "out/**", "node_modules/**"]
}

What happened?

For this code:

import { useCallback, useEffect } from "react";

function Component({ foo }) {
    const log = useCallback(() => {
        console.log(foo);
    }, [foo]);
    useEffect(() => {
        log();
    }, []);
}

no warning is emitted.

Both react-hooks/exhaustive-deps from eslint-plugin-react-hooks and lint/correctness/useExhaustiveDependencies from biome emit a warning:

react-hooks/exhaustive-deps:

/home/berni/Documents/src/test/linters/src/index.js
  9:8  warning  React Hook useEffect has a missing dependency: 'log'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

✖ 1 problem (0 errors, 1 warning)

lint/correctness/useExhaustiveDependencies:

./src/index.js:7:5 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ This hook does not specify all of its dependencies: log
  
    5 │         console.log(foo);
    6 │     }, [foo]);
  > 7 │     useEffect(() => {
      │     ^^^^^^^^^
    8 │         log();
    9 │     }, []);
  
  ℹ This dependency is not specified in the hook dependency list.
  
     6 │     }, [foo]);
     7 │     useEffect(() => {
   > 8 │         log();
       │         ^^^
     9 │     }, []);
    10 │ }
  
  ℹ Either include it or remove the dependency array
  

Checked 1 file in 1396µs. No fixes applied.
Found 1 error.
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Some errors were emitted while running checks.
@vemoo vemoo added the A-linter Area - Linter label Mar 14, 2025
@shulaoda
Copy link
Member

It seems that we currently do not support it:

// TODO: not supported yet
// r"function Example({ prop }) {
// const foo = useCallback(() => {
// prop.hello(foo);
// }, [foo]);
// const bar = useCallback(() => {
// foo();
// }, [foo]);
// }",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter
Projects
None yet
Development

No branches or pull requests

3 participants