From 777f19c4a26ebb018c4d869bfdaefb932452e6b0 Mon Sep 17 00:00:00 2001 From: weihongyu12 Date: Sat, 11 Oct 2025 23:06:44 +0800 Subject: [PATCH] [eslint config] [deps] [breaking] update eslint-plugin-react-hooks --- packages/eslint-config-airbnb/package.json | 4 +- .../eslint-config-airbnb/rules/react-hooks.js | 64 ++++++++++++++++++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb/package.json b/packages/eslint-config-airbnb/package.json index c36359ea7c..1c4f7e5a8f 100644 --- a/packages/eslint-config-airbnb/package.json +++ b/packages/eslint-config-airbnb/package.json @@ -78,7 +78,7 @@ "eslint-plugin-import": "^2.30.0", "eslint-plugin-jsx-a11y": "^6.10.0", "eslint-plugin-react": "^7.36.1", - "eslint-plugin-react-hooks": "^5.1.0", + "eslint-plugin-react-hooks": "^7.0.0", "in-publish": "^2.0.1", "react": ">= 0.13.0", "safe-publish-latest": "^2.0.0", @@ -89,7 +89,7 @@ "eslint-plugin-import": "^2.30.0", "eslint-plugin-jsx-a11y": "^6.10.0", "eslint-plugin-react": "^7.36.1", - "eslint-plugin-react-hooks": "^5.1.0" + "eslint-plugin-react-hooks": "^7.0.0" }, "engines": { "node": "^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0" diff --git a/packages/eslint-config-airbnb/rules/react-hooks.js b/packages/eslint-config-airbnb/rules/react-hooks.js index be17c9a571..2cf016df17 100644 --- a/packages/eslint-config-airbnb/rules/react-hooks.js +++ b/packages/eslint-config-airbnb/rules/react-hooks.js @@ -11,11 +11,71 @@ module.exports = { rules: { // Enforce Rules of Hooks - // https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js + // https://react.dev/reference/eslint-plugin-react-hooks/lints/rules-of-hooks 'react-hooks/rules-of-hooks': 'error', // Verify the list of the dependencies for Hooks like useEffect and similar - // https://github.com/facebook/react/blob/1204c789776cb01fbaf3e9f032e7e2ba85a44137/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js + // https://react.dev/reference/eslint-plugin-react-hooks/lints/exhaustive-deps 'react-hooks/exhaustive-deps': 'error', + + // Validates higher order functions defining nested components or hooks + // https://react.dev/reference/eslint-plugin-react-hooks/lints/component-hook-factories + 'react-hooks/component-hook-factories': 'error', + + // Validates the compiler configuration options + // https://react.dev/reference/eslint-plugin-react-hooks/lints/config + 'react-hooks/config': 'error', + + // Validates usage of Error Boundaries instead of try/catch for child errors + // https://react.dev/reference/eslint-plugin-react-hooks/lints/error-boundaries + 'react-hooks/error-boundaries': 'error', + + // Validates configuration of gating mode + // https://react.dev/reference/eslint-plugin-react-hooks/lints/gating + 'react-hooks/gating': 'error', + + // Validates against assignment/mutation of globals during render + // https://react.dev/reference/eslint-plugin-react-hooks/lints/globals + 'react-hooks/globals': 'error', + + // Validates against mutating props, state, and other immutable values + // https://react.dev/reference/eslint-plugin-react-hooks/lints/immutability + 'react-hooks/immutability': 'error', + + // Validates against usage of libraries which are incompatible with memoization + // https://react.dev/reference/eslint-plugin-react-hooks/lints/incompatible-library + 'react-hooks/incompatible-library': 'warn', + + // Validates that existing manual memoization is preserved by the compiler + // https://react.dev/reference/eslint-plugin-react-hooks/lints/preserve-manual-memoization + 'react-hooks/preserve-manual-memoization': 'error', + + // Validates that existing manual memoization is preserved by the compiler + // https://react.dev/reference/eslint-plugin-react-hooks/lints/purity + 'react-hooks/purity': 'error', + + // Validates correct usage of refs, not reading/writing during render + // https://react.dev/reference/eslint-plugin-react-hooks/lints/refs + 'react-hooks/refs': 'error', + + // Validates against calling setState synchronously in an effect + // https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-effect + 'react-hooks/set-state-in-effect': 'error', + + // Validates against setting state during render + // https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-render + 'react-hooks/set-state-in-render': 'error', + + // Validates that components are static, not recreated every render + // https://react.dev/reference/eslint-plugin-react-hooks/lints/static-components + 'react-hooks/static-components': 'error', + + // Validates against syntax that React Compiler does not support + // https://react.dev/reference/eslint-plugin-react-hooks/lints/unsupported-syntax + 'react-hooks/unsupported-syntax': 'warn', + + // Validates usage of the `useMemo` hook without a return value + // https://react.dev/reference/eslint-plugin-react-hooks/lints/use-memo + 'react-hooks/use-memo': 'error', }, };