Skip to content

test/build: add eslint-plugin-react-hooks exhaustive-deps rule - #91

Open
jamesa94 wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
jamesa94:fix/eslint-exhaustive-deps
Open

test/build: add eslint-plugin-react-hooks exhaustive-deps rule#91
jamesa94 wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
jamesa94:fix/eslint-exhaustive-deps

Conversation

@jamesa94

Copy link
Copy Markdown

Background

The ESLint configuration in frontend/.eslintrc.cjs includes plugin:react-hooks/recommended, which enables the react-hooks/exhaustive-deps and react-hooks/rules-of-hooks rules. However, these rules are set to warn by default in the recommended preset, meaning missing dependencies in useEffect (like the bug in PR-F03 where CodeDashboard has a stale closure) are only warnings, not build-blocking errors.

This allows subtle bugs to slip through CI and reach production.

Changes

Added explicit rule configuration to elevate both React Hooks rules from warn to error:

  • react-hooks/exhaustive-deps: error (catches missing dependencies in useEffect/useCallback/useMemo)
  • react-hooks/rules-of-hooks: error (catches hooks called conditionally or outside components)

Before

rules: {
  react-refresh/only-export-components: off,
  @typescript-eslint/no-unused-vars: [error, { argsIgnorePattern: ^_ }],
},

After

rules: {
  react-refresh/only-export-components: off,
  @typescript-eslint/no-unused-vars: [error, { argsIgnorePattern: ^_ }],
  react-hooks/exhaustive-deps: error,
  react-hooks/rules-of-hooks: error,
},

Notes

After enabling this rule, running npm run lint will likely surface existing violations (e.g., the CodeDashboard.tsx useEffect with a stale loadSessions closure). Those should be fixed in follow-up PRs using useCallback wrappers or proper dependency arrays. This PR is intentionally minimal: it only changes the ESLint config, not the code that violates it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant