Skip to content

Commit f4b4192

Browse files
committed
fix: enable rules-of-hooks
1 parent bb1376e commit f4b4192

File tree

9 files changed

+26
-85
lines changed

9 files changed

+26
-85
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"ignorePatterns": ["examples/**"],
99
"parser": "@typescript-eslint/parser",
10-
"plugins": ["import", "unicorn", "eslint-plugin-react-compiler"],
10+
"plugins": ["import", "unicorn"],
1111
"parserOptions": {
1212
"project": "./tsconfig.json",
1313
"ecmaVersion": 2018, // Allows for the parsing of modern ECMAScript features
@@ -92,7 +92,6 @@
9292
"eqeqeq": "error", // Only type-safe equality operators
9393
"unicorn/expiring-todo-comments": ["error"],
9494
"no-console": "error",
95-
"react-compiler/react-compiler": 2,
9695
"no-useless-computed-key": "error",
9796

9897
"spaced-comment": ["error", "always", { "exceptions": ["#__PURE__"] }]

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"eslint-plugin-import": "^2.32.0",
5959
"eslint-plugin-jsdoc": "^61.5.0",
6060
"eslint-plugin-react": "^7.33.2",
61-
"eslint-plugin-react-compiler": "0.0.0-experimental-56229e1-20240813",
6261
"eslint-plugin-react-hooks": "^7.0.1",
6362
"eslint-plugin-react-server-components": "^1.2.0",
6463
"eslint-plugin-unicorn": "^55.0.0",

packages/vkui-docs-theme/src/components/Sidebar/Menu/Menu.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function Folder({ item }: FolderProps) {
3939
const handleClick = React.useCallback(() => {
4040
if (isLink) {
4141
if (active) {
42-
// eslint-disable-next-line react-compiler/react-compiler
4342
TreeState[item.route] = !open;
4443
} else {
4544
TreeState[item.route] = true;

packages/vkui/.eslintrc.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module.exports = {
3333
Element: true,
3434
},
3535
rules: {
36-
'react-hooks/immutability': 'warn', // TODO [#6919] поменять на 'error'
37-
'react-hooks/refs': 'warn', // TODO [#6919] поменять на 'error'
36+
'react-hooks/immutability': 'error',
37+
'react-hooks/refs': 'error',
3838
'no-restricted-imports': [
3939
'error',
4040
{
@@ -191,7 +191,7 @@ module.exports = {
191191
extends: ['plugin:@vitest/legacy-recommended'],
192192
plugins: ['@vitest'],
193193
rules: {
194-
'react-hooks/globals': 'warn', // TODO [#6919] поменять на 'error' (при необходимости, точечно отключить в тестах)
194+
'react-hooks/globals': 'error',
195195
'@vitest/valid-describe-callback': 'off',
196196
'@vitest/expect-expect': 'off',
197197
'@vitest/valid-title': 'off',

packages/vkui/src/hooks/useGlobalOnClickOutside.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const WrapperUseGlobalOnClickOutside = ({
1818
const target1Ref = React.createRef<HTMLDivElement>();
1919
const target2Ref = React.createRef<HTMLDivElement>();
2020

21-
// eslint-disable-next-line react-compiler/react-compiler
2221
useGlobalOnClickOutsideImpl(
2322
globalClickHandler,
2423
disableAllTarget || disableTarget === 'target-1' ? null : target1Ref,

packages/vkui/src/hooks/usePatchChildren.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ type ExpectedReactElement<T> = React.ReactElement<HasRootRef<T> & React.DOMAttri
2020

2121
type ChildrenElement<T> = ExpectedReactElement<T> | React.ReactNode;
2222

23+
function useWarn<ElementType extends HTMLElement = HTMLElement>(
24+
shouldUseRef: boolean,
25+
childRef: React.RefObject<ElementType | null>,
26+
) {
27+
React.useEffect(() => {
28+
if (process.env.NODE_ENV === 'development') {
29+
if (!childRef.current && !shouldUseRef) {
30+
warn(
31+
'Кажется, в children передан компонент, который не поддерживает свойство getRootRef. Мы не можем получить ссылку на корневой dom-элемент этого компонента',
32+
'error',
33+
);
34+
}
35+
}
36+
}, [shouldUseRef, childRef]);
37+
}
38+
2339
/**
2440
* Хук позволяет пропатчить переданный компонент так, чтобы можно было получить ссылку на его
2541
* DOM-элемент. Также есть возможность прокинуть дополнительные параметры.
@@ -76,16 +92,7 @@ export const usePatchChildren = <ElementType extends HTMLElement = HTMLElement>(
7692

7793
const patchedChildren = isValidElementResult ? React.cloneElement(children, props) : children;
7894

79-
React.useEffect(() => {
80-
if (process.env.NODE_ENV === 'development') {
81-
if (!childRef.current && !shouldUseRef) {
82-
warn(
83-
'Кажется, в children передан компонент, который не поддерживает свойство getRootRef. Мы не можем получить ссылку на корневой dom-элемент этого компонента',
84-
'error',
85-
);
86-
}
87-
}
88-
}, [shouldUseRef, childRef]);
95+
useWarn(shouldUseRef, childRef);
8996

9097
return [childRef, patchedChildren];
9198
};

packages/vkui/src/testing/useCustomArgs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useArgs } from 'storybook/preview-api';
44
// @ts-expect-error: TS2322 мокаем useArgs
55
export const useCustomArgs: typeof useArgs = () => {
66
try {
7-
// eslint-disable-next-line react-compiler/react-compiler
87
return useArgs();
98
} catch {
109
return [{}, noop, noop];

website/app/[[...mdxPath]]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Metadata } from 'next';
22
import { generateStaticParamsFor, importPage } from 'nextra/pages';
3-
import { useMDXComponents } from '../../mdx-components';
3+
import { useMDXComponents as mdxComponents } from '../../mdx-components';
44

55
export const generateStaticParams = generateStaticParamsFor('mdxPath');
66

@@ -9,8 +9,8 @@ type PageProps = Readonly<{
99
mdxPath: string[];
1010
}>;
1111
}>;
12-
// eslint-disable-next-line react-hooks/rules-of-hooks
13-
const Wrapper = useMDXComponents().wrapper!;
12+
13+
const Wrapper = mdxComponents().wrapper!;
1414

1515
export async function generateMetadata(props: PageProps): Promise<Metadata> {
1616
const params = await props.params;

yarn.lock

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ __metadata:
169169
languageName: node
170170
linkType: hard
171171

172-
"@babel/helper-create-class-features-plugin@npm:^7.18.6, @babel/helper-create-class-features-plugin@npm:^7.27.1":
172+
"@babel/helper-create-class-features-plugin@npm:^7.27.1":
173173
version: 7.27.1
174174
resolution: "@babel/helper-create-class-features-plugin@npm:7.27.1"
175175
dependencies:
@@ -235,7 +235,7 @@ __metadata:
235235
languageName: node
236236
linkType: hard
237237

238-
"@babel/helper-plugin-utils@npm:^7.18.6, @babel/helper-plugin-utils@npm:^7.27.1":
238+
"@babel/helper-plugin-utils@npm:^7.27.1":
239239
version: 7.27.1
240240
resolution: "@babel/helper-plugin-utils@npm:7.27.1"
241241
checksum: 10/96136c2428888e620e2ec493c25888f9ceb4a21099dcf3dd4508ea64b58cdedbd5a9fb6c7b352546de84d6c24edafe482318646932a22c449ebd16d16c22d864
@@ -307,18 +307,6 @@ __metadata:
307307
languageName: node
308308
linkType: hard
309309

310-
"@babel/plugin-proposal-private-methods@npm:^7.18.6":
311-
version: 7.18.6
312-
resolution: "@babel/plugin-proposal-private-methods@npm:7.18.6"
313-
dependencies:
314-
"@babel/helper-create-class-features-plugin": "npm:^7.18.6"
315-
"@babel/helper-plugin-utils": "npm:^7.18.6"
316-
peerDependencies:
317-
"@babel/core": ^7.0.0-0
318-
checksum: 10/22d8502ee96bca99ad2c8393e8493e2b8d4507576dd054490fd8201a36824373440106f5b098b6d821b026c7e72b0424ff4aeca69ed5f42e48f029d3a156d5ad
319-
languageName: node
320-
linkType: hard
321-
322310
"@babel/plugin-syntax-flow@npm:^7.27.1":
323311
version: 7.27.1
324312
resolution: "@babel/plugin-syntax-flow@npm:7.27.1"
@@ -5305,7 +5293,6 @@ __metadata:
53055293
eslint-plugin-import: "npm:^2.32.0"
53065294
eslint-plugin-jsdoc: "npm:^61.5.0"
53075295
eslint-plugin-react: "npm:^7.33.2"
5308-
eslint-plugin-react-compiler: "npm:0.0.0-experimental-56229e1-20240813"
53095296
eslint-plugin-react-hooks: "npm:^7.0.1"
53105297
eslint-plugin-react-server-components: "npm:^1.2.0"
53115298
eslint-plugin-unicorn: "npm:^55.0.0"
@@ -9066,22 +9053,6 @@ __metadata:
90669053
languageName: node
90679054
linkType: hard
90689055

9069-
"eslint-plugin-react-compiler@npm:0.0.0-experimental-56229e1-20240813":
9070-
version: 0.0.0-experimental-56229e1-20240813
9071-
resolution: "eslint-plugin-react-compiler@npm:0.0.0-experimental-56229e1-20240813"
9072-
dependencies:
9073-
"@babel/core": "npm:^7.24.4"
9074-
"@babel/parser": "npm:^7.24.4"
9075-
"@babel/plugin-proposal-private-methods": "npm:^7.18.6"
9076-
hermes-parser: "npm:^0.20.1"
9077-
zod: "npm:^3.22.4"
9078-
zod-validation-error: "npm:^3.0.3"
9079-
peerDependencies:
9080-
eslint: ">=7"
9081-
checksum: 10/cba57ca6515d2a6c55c7f131a3c13d7905c1e65b99efd2c6b81868f7e3229897c5d9b07930ffd263b8597e4e6d63581b1debba1c9dfeb7c48bf44603d7de0ed0
9082-
languageName: node
9083-
linkType: hard
9084-
90859056
"eslint-plugin-react-hooks@npm:^7.0.1":
90869057
version: 7.0.1
90879058
resolution: "eslint-plugin-react-hooks@npm:7.0.1"
@@ -10733,29 +10704,13 @@ __metadata:
1073310704
languageName: node
1073410705
linkType: hard
1073510706

10736-
"hermes-estree@npm:0.20.1":
10737-
version: 0.20.1
10738-
resolution: "hermes-estree@npm:0.20.1"
10739-
checksum: 10/b98fc2943bd9fdd904c094e995f79cb7d5958393e221006af81d88f3aed52ddbf15138a6606766d5e6be7ba166576be65f577d0c72ae5eb0f3f56d4720b32baa
10740-
languageName: node
10741-
linkType: hard
10742-
1074310707
"hermes-estree@npm:0.25.1":
1074410708
version: 0.25.1
1074510709
resolution: "hermes-estree@npm:0.25.1"
1074610710
checksum: 10/7b1eca98b264a25632064cffa5771360d30cf452e77db1e191f9913ee45cf78c292b2dbca707e92fb71b0870abb97e94b506a5ab80abd96ba237fee169b601fe
1074710711
languageName: node
1074810712
linkType: hard
1074910713

10750-
"hermes-parser@npm:^0.20.1":
10751-
version: 0.20.1
10752-
resolution: "hermes-parser@npm:0.20.1"
10753-
dependencies:
10754-
hermes-estree: "npm:0.20.1"
10755-
checksum: 10/b1ae9e9f6b49234fcf2bd45eafde140a3c727b8bcb845ab398016a538f040d326291d1f8b75fd91793b8817f2c600a890e251984d55bdedea74a5143d29f0c81
10756-
languageName: node
10757-
linkType: hard
10758-
1075910714
"hermes-parser@npm:^0.25.1":
1076010715
version: 0.25.1
1076110716
resolution: "hermes-parser@npm:0.25.1"
@@ -19937,15 +19892,6 @@ __metadata:
1993719892
languageName: node
1993819893
linkType: hard
1993919894

19940-
"zod-validation-error@npm:^3.0.3":
19941-
version: 3.5.3
19942-
resolution: "zod-validation-error@npm:3.5.3"
19943-
peerDependencies:
19944-
zod: ^3.25.0 || ^4.0.0
19945-
checksum: 10/f550565ffb2a0a1733616d856302184dbe2080ec649ff9361125467065c3dfa02aeb5bf399605cdb61fe640f79ff1fe8ad0805f6e0c8144fa34764cad58f4401
19946-
languageName: node
19947-
linkType: hard
19948-
1994919895
"zod-validation-error@npm:^3.5.0 || ^4.0.0":
1995019896
version: 4.0.2
1995119897
resolution: "zod-validation-error@npm:4.0.2"
@@ -19955,13 +19901,6 @@ __metadata:
1995519901
languageName: node
1995619902
linkType: hard
1995719903

19958-
"zod@npm:^3.22.4":
19959-
version: 3.25.76
19960-
resolution: "zod@npm:3.25.76"
19961-
checksum: 10/f0c963ec40cd96858451d1690404d603d36507c1fc9682f2dae59ab38b578687d542708a7fdbf645f77926f78c9ed558f57c3d3aa226c285f798df0c4da16995
19962-
languageName: node
19963-
linkType: hard
19964-
1996519904
"zod@npm:^3.25.0 || ^4.0.0":
1996619905
version: 4.1.12
1996719906
resolution: "zod@npm:4.1.12"

0 commit comments

Comments
 (0)