main
js 34 lines 1001 Bytes
Raw
1 const ReactCompiler = require('../packages/babel-plugin-react-compiler/dist');
2
3 const combinedRules = [
4 {
5 name: 'rules-of-hooks',
6 recommended: true,
7 description:
8 'Validates that components and hooks follow the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks)',
9 },
10 {
11 name: 'exhaustive-deps',
12 recommended: true,
13 description:
14 'Validates that hooks which accept dependency arrays (`useMemo()`, `useCallback()`, `useEffect()`, etc) ' +
15 'list all referenced variables in their dependency array. Referencing a value without including it in the ' +
16 'dependency array can lead to stale UI or callbacks.',
17 },
18 ...ReactCompiler.LintRules,
19 ];
20
21 const printed = combinedRules
22 .filter(
23 ruleConfig => ruleConfig.rule.recommended && ruleConfig.severity !== 'Off'
24 )
25 .map(ruleConfig => {
26 return `
27 ## \`react-hooks/${ruleConfig.rule.name}\`
28
29 ${ruleConfig.rule.description}
30 `.trim();
31 })
32 .join('\n\n');
33
34 console.log(printed);