Skip to content

Commit 24e260d

Browse files
authored
Enable rules-of-hooks for DevTools (#34645)
1 parent 2bbb7be commit 24e260d

10 files changed

Lines changed: 22 additions & 0 deletions

File tree

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ module.exports = {
517517
__IS_INTERNAL_VERSION__: 'readonly',
518518
},
519519
},
520+
{
521+
files: ['packages/react-devtools-*/**/*.js'],
522+
excludedFiles: '**/__tests__/**/*.js',
523+
plugins: ['eslint-plugin-react-hooks-published'],
524+
rules: {
525+
'react-hooks-published/rules-of-hooks': ERROR,
526+
},
527+
},
520528
{
521529
files: ['packages/eslint-plugin-react-hooks/src/**/*'],
522530
extends: ['plugin:@typescript-eslint/recommended'],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"eslint-plugin-no-for-of-loops": "^1.0.0",
7272
"eslint-plugin-no-function-declare-after-return": "^1.0.0",
7373
"eslint-plugin-react": "^6.7.1",
74+
"eslint-plugin-react-hooks-published": "npm:eslint-plugin-react-hooks@^5.2.0",
7475
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
7576
"fbjs-scripts": "^3.0.1",
7677
"filesize": "^6.0.1",

packages/react-devtools-shared/src/devtools/cache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type Resource<Input, Key, Value> = {
4242
let readContext;
4343
if (typeof React.use === 'function') {
4444
readContext = function (Context: ReactContext<null>) {
45+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
4546
return React.use(Context);
4647
};
4748
} else if (
@@ -141,6 +142,7 @@ export function createResource<Input, Key, Value>(
141142
const key = hashInput(input);
142143
const result: Thenable<Value> = accessResult(resource, fetch, input, key);
143144
if (typeof React.use === 'function') {
145+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
144146
return React.use(result);
145147
}
146148

packages/react-devtools-shared/src/devtools/views/ErrorBoundary/cache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const API_TIMEOUT = 3000;
2323
function readRecord<T>(record: Thenable<T>): T | null {
2424
if (typeof React.use === 'function') {
2525
try {
26+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
2627
return React.use(record);
2728
} catch (x) {
2829
if (x === null) {

packages/react-devtools-shared/src/dynamicImportCache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const moduleLoaderFunctionToModuleMap: Map<ModuleLoaderFunction, Module> =
3030
function readRecord<T>(record: Thenable<T>): T | null {
3131
if (typeof React.use === 'function') {
3232
try {
33+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
3334
return React.use(record);
3435
} catch (x) {
3536
if (x === null) {

packages/react-devtools-shared/src/hookNamesCache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const TIMEOUT = 30000;
3030
function readRecord<T>(record: Thenable<T>): T | null {
3131
if (typeof React.use === 'function') {
3232
try {
33+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
3334
return React.use(record);
3435
} catch (x) {
3536
if (record.status === 'rejected') {

packages/react-devtools-shared/src/inspectedElementCache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type {
3232

3333
function readRecord<T>(record: Thenable<T>): T {
3434
if (typeof React.use === 'function') {
35+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
3536
return React.use(record);
3637
}
3738
if (record.status === 'fulfilled') {

packages/react-devtools-shell/src/app/SuspenseTree/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ function LoadLater() {
314314

315315
function readRecord(promise: any): any {
316316
if (typeof React.use === 'function') {
317+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
317318
return React.use(promise);
318319
}
319320
switch (promise.status) {

packages/react-devtools-timeline/src/timelineCache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const fileNameToProfilerDataMap: Map<
2929
function readRecord<T>(record: Thenable<T>): T | Error {
3030
if (typeof React.use === 'function') {
3131
try {
32+
// eslint-disable-next-line react-hooks-published/rules-of-hooks
3233
return React.use(record);
3334
} catch (x) {
3435
if (record.status === 'rejected') {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8207,6 +8207,11 @@ eslint-plugin-no-unsanitized@4.0.2:
82078207
resolved "https://registry.yarnpkg.com/eslint-plugin-no-unsanitized/-/eslint-plugin-no-unsanitized-4.0.2.tgz#e872b302cdfb5fe1262db989ba29cfcc334b499b"
82088208
integrity sha512-Pry0S9YmHoz8NCEMRQh7N0Yexh2MYCNPIlrV52hTmS7qXnTghWsjXouF08bgsrrZqaW9tt1ZiK3j5NEmPE+EjQ==
82098209

8210+
"eslint-plugin-react-hooks-published@npm:eslint-plugin-react-hooks@^5.2.0":
8211+
version "5.2.0"
8212+
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.2.0.tgz#1be0080901e6ac31ce7971beed3d3ec0a423d9e3"
8213+
integrity sha512-+f15FfK64YQwZdJNELETdn5ibXEUQmW1DZL6KXhNnc2heoy/sg9VJJeT7n8TlMWouzWqSWavFkIhHyIbIAEapg==
8214+
82108215
"eslint-plugin-react-internal@link:./scripts/eslint-rules":
82118216
version "0.0.0"
82128217
uid ""

0 commit comments

Comments
 (0)