Coder Social home page Coder Social logo

Comments (4)

XiNiHa avatar XiNiHa commented on June 11, 2024 1

I'm not sure how many edge cases we should handle. Currently having these in mind:

  • TS as operator (useRef(foo) as MutableRefObject<Foo>) (eslint-plugin-react-hooks only handles this)
  • TS satisfies operator (useRef(foo) satisfies MutableRefObject<Foo>)
  • TS non-null assertion operator (useRef(foo)!)

There are many other kind of edge cases, like....

  • Array destructure (const [a, b] = [useRef('a'), useRef('b')])
  • Comma operator (const a = (console.log('a'), useRef('a')))
  • IIFE (const a = (() => useRef('a'))(), can be much more complex)
  • let reassignment (let a = useRef('a'); a = Math.random())
  • ...

It's somewhat obvious that it is unrealistic to handle all of those edge cases. Therefore I believe we should scope which edge cases to handle. Personally, I think all of TS operator cases and array destructure should be handled, while other cases are too specific/niche to work on.

from biome.

XiNiHa avatar XiNiHa commented on June 11, 2024

I guess it's an edge case that was not handled correctly from #996. I'll look into it after fixing #1637.

from biome.

ematipico avatar ematipico commented on June 11, 2024

I think so too. We should strive to cover the most used patterns and call it a day.

We should take this opportunity and update the documentation explaining the expectations of this rule

from biome.

Sec-ant avatar Sec-ant commented on June 11, 2024

Speaking of IIFE, there're also cases where one can use IIFE to return a function that can be used in useCallback or useEffect. This is a common functional pattern in JS to hoist and memoize static variables. The useExhaustiveDependencies rule doesn't catch it currently. It would be great to handle this kind of edge cases.

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB7ACAAdQBzAGUARQBmAGYAZQBjAHQALAAgAHUAcwBlAFMAdABhAHQAZQAgAH0AIABmAHIAbwBtACAAIgByAGUAYQBjAHQAIgA7AAoACgBlAHgAcABvAHIAdAAgAGYAdQBuAGMAdABpAG8AbgAgAEYAKAApACAAewAKAAoAIAAgAGMAbwBuAHMAdAAgAFsAYQAsACAAcwBlAHQAQQBdACAAPQAgAHUAcwBlAFMAdABhAHQAZQAoADEAKQA7AAoAIAAgAAoAIAAgAHUAcwBlAEUAZgBmAGUAYwB0ACgAKAApACAAPQA%2BACAAYwBvAG4AcwBvAGwAZQAuAGwAbwBnACgAYQApACwAIABbAF0AKQA7AAoACgAgACAAdQBzAGUARQBmAGYAZQBjAHQAKAAoACgAKQAgAD0APgAgACgAKQAgAD0APgAgAGMAbwBuAHMAbwBsAGUALgBsAG8AZwAoAGEAKQApACgAKQAsACAAWwBdACkAOwAKAH0A

from biome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.