-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Not sure if this should be an ESLint rule or a Preflight check (opened upleveled/preflight#193 for the Preflight check), but detecting infinite loops in student code would be really nice, especially when students get into using useEffect
in React.
#35 will help with warning about using useEffect
without a dependency array, but there are other forms of infinite loops.
One potential candidate for detecting infinite loops would be to detect if the student has an (unconditional) call to setX
in a useEffect
which also specifies the dependency x
. If the student has the setX
inside a condition, this would not trigger.
Some other, more general ideas for infinite loop detection:
- https://twitter.com/dan_abramov/status/938854883154939904 (leading to Add a test-only transform to catch infinite loops facebook/react#11790)
- https://blog.replit.com/infinite-loops
Potentially helpful for getting a reference to useEffect
(maybe already implemented in #35):
- How to get a reference to
useState
- can use this as a basis for this and also #35 - fromeslint-plugin-react
: https://github.com/yannickcr/eslint-plugin-react/blob/5f49f51dd237dd4c6758bc0c3e5b300a28770966/lib/rules/hook-use-state.js