diff --git a/.eslintrc.js b/.eslintrc.js index 8b38b1890d32..439b434235fb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -314,15 +314,31 @@ module.exports = { 'test/jest/rendering.js', 'ui/**/*.js', ], - extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'], + extends: ['plugin:react/recommended'], parserOptions: { ecmaFeatures: { jsx: true, }, }, - plugins: ['react', 'react-compiler'], + plugins: ['react', 'react-hooks'], rules: { - 'react-compiler/react-compiler': 'error', + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + 'react-hooks/component-hook-factories': 'warn', // Validates higher order functions defining nested components or hooks + 'react-hooks/config': 'error', // Validates the compiler configuration options + 'react-hooks/error-boundaries': 'error', // Validates usage of Error Boundaries instead of try/catch for child errors + 'react-hooks/gating': 'error', // Validates configuration of gating mode + 'react-hooks/globals': 'warn', // Validates against assignment/mutation of globals during render + 'react-hooks/immutability': 'warn', // Validates against mutating props, state, and other immutable values + 'react-hooks/incompatible-library': 'warn', // Validates against usage of libraries which are incompatible with memoization + 'react-hooks/preserve-manual-memoization': 'warn', // Validates that existing manual memoization is preserved by the compiler + 'react-hooks/purity': 'warn', // Validates that components/hooks are pure by checking known-impure functions + 'react-hooks/refs': 'warn', // Validates correct usage of refs, not reading/writing during render + 'react-hooks/set-state-in-effect': 'warn', // Validates against calling setState synchronously in an effect + 'react-hooks/set-state-in-render': 'warn', // Validates against setting state during render + 'react-hooks/static-components': 'warn', // Validates that components are static, not recreated every render + 'react-hooks/unsupported-syntax': 'warn', // Validates against syntax that React Compiler does not support + 'react-hooks/use-memo': 'warn', // Validates usage of the useMemo hook without a return value 'react/no-unused-prop-types': 'error', 'react/no-unused-state': 'error', 'react/jsx-boolean-value': 'error', @@ -357,15 +373,31 @@ module.exports = { */ { files: ['ui/**/*.ts', 'ui/**/*.tsx'], - extends: ['plugin:react/recommended', 'plugin:react-hooks/recommended'], + extends: ['plugin:react/recommended'], parserOptions: { ecmaFeatures: { jsx: true, }, }, - plugins: ['react', 'react-compiler'], + plugins: ['react', 'react-hooks'], rules: { - 'react-compiler/react-compiler': 'error', + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + 'react-hooks/component-hook-factories': 'error', // Validates higher order functions defining nested components or hooks + 'react-hooks/config': 'error', // Validates the compiler configuration options + 'react-hooks/error-boundaries': 'error', // Validates usage of Error Boundaries instead of try/catch for child errors + 'react-hooks/gating': 'error', // Validates configuration of gating mode + 'react-hooks/globals': 'error', // Validates against assignment/mutation of globals during render + 'react-hooks/immutability': 'error', // Validates against mutating props, state, and other immutable values + 'react-hooks/incompatible-library': 'error', // Validates against usage of libraries which are incompatible with memoization + 'react-hooks/preserve-manual-memoization': 'error', // Validates that existing manual memoization is preserved by the compiler + 'react-hooks/purity': 'error', // Validates that components/hooks are pure by checking known-impure functions + 'react-hooks/refs': 'error', // Validates correct usage of refs, not reading/writing during render + 'react-hooks/set-state-in-effect': 'error', // Validates against calling setState synchronously in an effect + 'react-hooks/set-state-in-render': 'error', // Validates against setting state during render + 'react-hooks/static-components': 'error', // Validates that components are static, not recreated every render + 'react-hooks/unsupported-syntax': 'error', // Validates against syntax that React Compiler does not support + 'react-hooks/use-memo': 'error', // Validates usage of the useMemo hook without a return value 'react/no-unused-prop-types': 'warn', 'react/no-unused-state': 'warn', 'react/jsx-boolean-value': 'off', @@ -378,7 +410,6 @@ module.exports = { 'react/prop-types': 'off', 'react/no-children-prop': 'off', 'react/jsx-key': 'warn', // TODO - increase this into 'error' level - 'react-hooks/rules-of-hooks': 'error', }, settings: { react: { diff --git a/lavamoat/build-system/policy.json b/lavamoat/build-system/policy.json index 497155b5ec35..293185b40ec5 100644 --- a/lavamoat/build-system/policy.json +++ b/lavamoat/build-system/policy.json @@ -2956,8 +2956,22 @@ } }, "eslint-plugin-react-hooks": { + "builtin": { + "crypto.createHmac": true, + "util.isDeepStrictEqual": true + }, "globals": { - "process.env.NODE_ENV": true + "console": true, + "performance.mark": true, + "performance.measure": true, + "process": true + }, + "packages": { + "@babel/core": true, + "@babel/core>@babel/parser": true, + "eslint-plugin-react-hooks>hermes-parser": true, + "eslint-plugin-react-hooks>zod-validation-error": true, + "eslint-plugin-react-hooks>zod": true } }, "eslint>eslint-scope": { @@ -3974,6 +3988,32 @@ "browserify>has>function-bind": true } }, + "eslint-plugin-react-hooks>hermes-parser": { + "builtin": { + "fs.readFile": true, + "fs.readFileSync": true, + "path.dirname": true, + "path.normalize": true + }, + "globals": { + "Buffer.from": true, + "TextDecoder": true, + "URL": true, + "WebAssembly": true, + "__dirname": true, + "__filename": true, + "atob": true, + "clearInterval": true, + "clearTimeout": true, + "console": true, + "define": true, + "document": true, + "navigator": true, + "performance.now": true, + "process": true, + "setTimeout": true + } + }, "stylelint>postcss-html>htmlparser2": { "builtin": { "buffer.Buffer": true, @@ -8900,6 +8940,22 @@ "packages": { "gulp-zip>yazl>buffer-crc32": true } + }, + "eslint-plugin-react-hooks>zod-validation-error": { + "packages": { + "eslint-plugin-react-hooks>zod": true + } + }, + "eslint-plugin-react-hooks>zod": { + "globals": { + "File": true, + "URL": true, + "__zod_globalRegistry": true, + "atob": true, + "btoa": true, + "console.warn": true, + "navigator": true + } } } } \ No newline at end of file diff --git a/package.json b/package.json index 4547675a38cc..2173dd274ed6 100644 --- a/package.json +++ b/package.json @@ -616,8 +616,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^5.5.1", "eslint-plugin-react": "^7.37.5", - "eslint-plugin-react-compiler": "19.1.0-rc.2", - "eslint-plugin-react-hooks": "^5.2.0", + "eslint-plugin-react-hooks": "^7.0.1", "eslint-plugin-storybook": "^0.6.15", "eslint-plugin-tailwindcss": "^3.18.0", "eta": "^3.2.0", diff --git a/yarn.lock b/yarn.lock index 1c49185b79ee..5944d22ba9b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -306,7 +306,7 @@ __metadata: languageName: node linkType: hard -"@babel/helper-create-class-features-plugin@npm:^7.18.6, @babel/helper-create-class-features-plugin@npm:^7.25.9": +"@babel/helper-create-class-features-plugin@npm:^7.25.9": version: 7.28.3 resolution: "@babel/helper-create-class-features-plugin@npm:7.28.3" dependencies: @@ -666,18 +666,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-proposal-private-methods@npm:^7.18.6": - version: 7.18.6 - resolution: "@babel/plugin-proposal-private-methods@npm:7.18.6" - dependencies: - "@babel/helper-create-class-features-plugin": "npm:^7.18.6" - "@babel/helper-plugin-utils": "npm:^7.18.6" - peerDependencies: - "@babel/core": ^7.0.0-0 - checksum: 10/22d8502ee96bca99ad2c8393e8493e2b8d4507576dd054490fd8201a36824373440106f5b098b6d821b026c7e72b0424ff4aeca69ed5f42e48f029d3a156d5ad - languageName: node - linkType: hard - "@babel/plugin-proposal-private-property-in-object@npm:7.21.0-placeholder-for-preset-env.2": version: 7.21.0-placeholder-for-preset-env.2 resolution: "@babel/plugin-proposal-private-property-in-object@npm:7.21.0-placeholder-for-preset-env.2" @@ -24304,28 +24292,18 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-compiler@npm:19.1.0-rc.2": - version: 19.1.0-rc.2 - resolution: "eslint-plugin-react-compiler@npm:19.1.0-rc.2" +"eslint-plugin-react-hooks@npm:^7.0.1": + version: 7.0.1 + resolution: "eslint-plugin-react-hooks@npm:7.0.1" dependencies: "@babel/core": "npm:^7.24.4" "@babel/parser": "npm:^7.24.4" - "@babel/plugin-proposal-private-methods": "npm:^7.18.6" hermes-parser: "npm:^0.25.1" - zod: "npm:^3.22.4" - zod-validation-error: "npm:^3.0.3" - peerDependencies: - eslint: ">=7" - checksum: 10/cabdcbe884722049c11e84a13d1b2747c0612c61b23505fdf7b69dd9ee26e0f4bb86452486708fb359205ab5770b279d8dabac3a2d0c4409a176773eed7a4471 - languageName: node - linkType: hard - -"eslint-plugin-react-hooks@npm:^5.2.0": - version: 5.2.0 - resolution: "eslint-plugin-react-hooks@npm:5.2.0" + zod: "npm:^3.25.0 || ^4.0.0" + zod-validation-error: "npm:^3.5.0 || ^4.0.0" peerDependencies: eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 - checksum: 10/ebb79e9cf69ae06e3a7876536653c5e556b5fd8cd9dc49577f10a6e728360e7b6f5ce91f4339b33e93b26e3bb23805418f8b5e75db80baddd617b1dffe73bed1 + checksum: 10/12e96c68d58c6588305fd17d660524a1ef1e872650ec591d5b138f059431290831c373d4b1c9ae8991fb25f96c43935497d2149678c027e65d0417d3d99ecc85 languageName: node linkType: hard @@ -33049,8 +33027,7 @@ __metadata: eslint-plugin-node: "npm:^11.1.0" eslint-plugin-prettier: "npm:^5.5.1" eslint-plugin-react: "npm:^7.37.5" - eslint-plugin-react-compiler: "npm:19.1.0-rc.2" - eslint-plugin-react-hooks: "npm:^5.2.0" + eslint-plugin-react-hooks: "npm:^7.0.1" eslint-plugin-storybook: "npm:^0.6.15" eslint-plugin-tailwindcss: "npm:^3.18.0" eta: "npm:^3.2.0" @@ -45418,12 +45395,12 @@ __metadata: languageName: node linkType: hard -"zod-validation-error@npm:^3.0.3": - version: 3.5.3 - resolution: "zod-validation-error@npm:3.5.3" +"zod-validation-error@npm:^3.5.0 || ^4.0.0": + version: 4.0.2 + resolution: "zod-validation-error@npm:4.0.2" peerDependencies: zod: ^3.25.0 || ^4.0.0 - checksum: 10/f550565ffb2a0a1733616d856302184dbe2080ec649ff9361125467065c3dfa02aeb5bf399605cdb61fe640f79ff1fe8ad0805f6e0c8144fa34764cad58f4401 + checksum: 10/5e35ca8ebb4602dcb526e122d7e9fca695c4a479bd97535f3400a732d49160f24f7213a9ed64986fc9dc3a2e8a6c4e1241ec0c4d8a4e3e69ea91a0328ded2192 languageName: node linkType: hard @@ -45434,13 +45411,20 @@ __metadata: languageName: node linkType: hard -"zod@npm:3.25.76, zod@npm:^3.22.4": +"zod@npm:3.25.76": version: 3.25.76 resolution: "zod@npm:3.25.76" checksum: 10/f0c963ec40cd96858451d1690404d603d36507c1fc9682f2dae59ab38b578687d542708a7fdbf645f77926f78c9ed558f57c3d3aa226c285f798df0c4da16995 languageName: node linkType: hard +"zod@npm:^3.25.0 || ^4.0.0": + version: 4.1.13 + resolution: "zod@npm:4.1.13" + checksum: 10/0679190318928f69fcb07751063719de232c663b13955fcdb55db59839569d39f3f29b955cb0cba7af0b724233f88c06b3e84c550397ad4e68f8088fa6799d88 + languageName: node + linkType: hard + "zstd-codec@npm:^0.1.4": version: 0.1.4 resolution: "zstd-codec@npm:0.1.4"