biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
14.19k stars 439 forks source link

πŸ’… `useExhaustiveDependencies` incorrectly requires `React.useRef()` values to be specified #1411

Closed atomiks closed 8 months ago

atomiks commented 8 months ago

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.19.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/10.2.3"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    true
  VCS disabled:                 false

Workspace:
  Open Documents:               0

Rule name

useExhaustiveDependencies

Playground link

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAAqACAAYQBzACAAUgBlAGEAYwB0ACAAZgByAG8AbQAgACcAcgBlAGEAYwB0ACcAOwAKAAoAZgB1AG4AYwB0AGkAbwBuACAAdQBzAGUAQQBwAHAAKAApACAAewAKACAAIABjAG8AbgBzAHQAIAByAGUAZgAgAD0AIABSAGUAYQBjAHQALgB1AHMAZQBSAGUAZgAoAG4AdQBsAGwAKQA7AAoAIAAgAFIAZQBhAGMAdAAuAHUAcwBlAEUAZgBmAGUAYwB0ACgAKAApACAAPQA%2BACAAewAKACAAIAAgACAAcgBlAGYALgBjAHUAcgByAGUAbgB0ADsACgAgACAAfQAsACAAWwBdACkAOwAKAH0ACgA%3D

Expected result

It errors when you use React.useRef():

import * as React from 'react';

function useApp() {
  const ref = React.useRef(null);
  React.useEffect(() => {
    ref.current;
  }, []);
}

But doesn't error when importing separately:

import {useRef, useEffect} from 'react';

function useApp() {
  const ref = useRef(null);
  useEffect(() => {
    ref.current;
  }, []);
}

The error:

  β„Ή This dependency is not specified in the hook dependency list.

    4 β”‚   const ref = React.useRef(null);
    5 β”‚   React.useEffect(() => {
  > 6 β”‚     ref.current;
      β”‚     ^^^^^^^^^^^
    7 β”‚   }, []);
    8 β”‚ }

FWIW, the playground doesn't seem to error for some reason, but a fresh install of 1.4.1 does. Might be missing something basic?

{
  "$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
  "linter": {
    "rules": {
      "complexity": {
        "noUselessConstructor": "off"
      }
    }
  }
}

Code of Conduct

ematipico commented 8 months ago

FWIW, the playground doesn't seem to error for some reason, but a fresh install of 1.4.1 does. Might be missing something basic?

That's because the playground uses the latest code we have on main. This means that the issue is fixed and it will be available in the next release.

atomiks commented 8 months ago

Gotcha, thanks