You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[compiler] Script to produce markdown of lint rule docs (facebook#34260)
The docs site is in a separate repo, but this gives us a semi-automated
way to update the docs about our lint rules. The script generates
markdown files from the rule definitions which we can then manually
copy/paste into the docs site somewhere. In the future we can automate
this fully.
DiffTrain build for [425ba0a](facebook@425ba0a)
Copy file name to clipboardExpand all lines: compiled/eslint-plugin-react-hooks/index.js
+23-14Lines changed: 23 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -18001,14 +18001,20 @@ var ErrorCategory;
18001
18001
ErrorCategory["Fire"] = "Fire";
18002
18002
ErrorCategory["FBT"] = "FBT";
18003
18003
})(ErrorCategory || (ErrorCategory = {}));
18004
+
const RULE_NAME_PATTERN = /^[a-z]+(-[a-z]+)*$/;
18004
18005
function getRuleForCategory(category) {
18006
+
const rule = getRuleForCategoryImpl(category);
18007
+
invariant(RULE_NAME_PATTERN.test(rule.name), `Invalid rule name, got '${rule.name}' but rules must match ${RULE_NAME_PATTERN.toString()}`);
18008
+
return rule;
18009
+
}
18010
+
function getRuleForCategoryImpl(category) {
18005
18011
switch (category) {
18006
18012
case ErrorCategory.AutomaticEffectDependencies: {
18007
18013
return {
18008
18014
category,
18009
18015
name: 'automatic-effect-dependencies',
18010
18016
description: 'Verifies that automatic effect dependencies are compiled if opted-in',
18011
-
recommended: true,
18017
+
recommended: false,
18012
18018
};
18013
18019
}
18014
18020
case ErrorCategory.CapitalizedCalls: {
@@ -18023,7 +18029,7 @@ function getRuleForCategory(category) {
18023
18029
return {
18024
18030
category,
18025
18031
name: 'config',
18026
-
description: 'Validates the configuration',
18032
+
description: 'Validates the compiler configuration options',
18027
18033
recommended: true,
18028
18034
};
18029
18035
}
@@ -18047,15 +18053,15 @@ function getRuleForCategory(category) {
18047
18053
return {
18048
18054
category,
18049
18055
name: 'set-state-in-effect',
18050
-
description: 'Validates against calling setState synchronously in an effect',
18056
+
description: 'Validates against calling setState synchronously in an effect, which can lead to re-renders that degrade performance',
18051
18057
recommended: true,
18052
18058
};
18053
18059
}
18054
18060
case ErrorCategory.ErrorBoundaries: {
18055
18061
return {
18056
18062
category,
18057
18063
name: 'error-boundaries',
18058
-
description: 'Validates usage of error boundaries instead of try/catch for errors in JSX',
18064
+
description: 'Validates usage of error boundaries instead of try/catch for errors in child components',
18059
18065
recommended: true,
18060
18066
};
18061
18067
}
@@ -18079,15 +18085,16 @@ function getRuleForCategory(category) {
18079
18085
return {
18080
18086
category,
18081
18087
name: 'gating',
18082
-
description: 'Validates configuration of gating mode',
18088
+
description: 'Validates configuration of [gating mode](https://react.dev/reference/react-compiler/gating)',
18083
18089
recommended: true,
18084
18090
};
18085
18091
}
18086
18092
case ErrorCategory.Globals: {
18087
18093
return {
18088
18094
category,
18089
18095
name: 'globals',
18090
-
description: 'Validates against assignment/mutation of globals during render',
18096
+
description: 'Validates against assignment/mutation of globals during render, part of ensuring that ' +
18097
+
'[side effects must render outside of render](https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)',
18091
18098
recommended: true,
18092
18099
};
18093
18100
}
@@ -18103,7 +18110,7 @@ function getRuleForCategory(category) {
18103
18110
return {
18104
18111
category,
18105
18112
name: 'immutability',
18106
-
description: 'Validates that immutable values (props, state, etc) are not mutated',
18113
+
description: 'Validates against mutating props, state, and other values that [are immutable](https://react.dev/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable)',
18107
18114
recommended: true,
18108
18115
};
18109
18116
}
@@ -18119,39 +18126,41 @@ function getRuleForCategory(category) {
18119
18126
return {
18120
18127
category,
18121
18128
name: 'preserve-manual-memoization',
18122
-
description: 'Validates that existing manual memoized is preserved by the compiler',
18129
+
description: 'Validates that existing manual memoized is preserved by the compiler. ' +
18130
+
'React Compiler will only compile components and hooks if its inference ' +
18131
+
'[matches or exceeds the existing manual memoization](https://react.dev/learn/react-compiler/introduction#what-should-i-do-about-usememo-usecallback-and-reactmemo)',
18123
18132
recommended: true,
18124
18133
};
18125
18134
}
18126
18135
case ErrorCategory.Purity: {
18127
18136
return {
18128
18137
category,
18129
18138
name: 'purity',
18130
-
description: 'Validates that the component/hook is pure, and does not call known-impure functions',
18139
+
description: 'Validates that [components/hooks are pure](https://react.dev/reference/rules/components-and-hooks-must-be-pure) by checking that they do not call known-impure functions',
18131
18140
recommended: true,
18132
18141
};
18133
18142
}
18134
18143
case ErrorCategory.Refs: {
18135
18144
return {
18136
18145
category,
18137
18146
name: 'refs',
18138
-
description: 'Validates correct usage of refs, not reading/writing during render',
18147
+
description: 'Validates correct usage of refs, not reading/writing during render. See the "pitfalls" section in [`useRef()` usage](https://react.dev/reference/react/useRef#usage)',
18139
18148
recommended: true,
18140
18149
};
18141
18150
}
18142
18151
case ErrorCategory.RenderSetState: {
18143
18152
return {
18144
18153
category,
18145
18154
name: 'set-state-in-render',
18146
-
description: 'Validates against setting state during render',
18155
+
description: 'Validates against setting state during render, which can trigger additional renders and potential infinite render loops',
18147
18156
recommended: true,
18148
18157
};
18149
18158
}
18150
18159
case ErrorCategory.StaticComponents: {
18151
18160
return {
18152
18161
category,
18153
18162
name: 'static-components',
18154
-
description: 'Validates that components are static, not recreated every render',
18163
+
description: 'Validates that components are static, not recreated every render. Components that are recreated dynamically can reset state and trigger excessive re-rendering',
18155
18164
recommended: true,
18156
18165
};
18157
18166
}
@@ -18183,15 +18192,15 @@ function getRuleForCategory(category) {
18183
18192
return {
18184
18193
category,
18185
18194
name: 'unsupported-syntax',
18186
-
description: 'Validates against syntax that we do not plan to support',
18195
+
description: 'Validates against syntax that we do not plan to support in React Compiler',
18187
18196
recommended: true,
18188
18197
};
18189
18198
}
18190
18199
case ErrorCategory.UseMemo: {
18191
18200
return {
18192
18201
category,
18193
18202
name: 'use-memo',
18194
-
description: 'Validates usage of the useMemo() hook',
18203
+
description: 'Validates usage of the useMemo() hook against common mistakes. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.',
0 commit comments