mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
With #34176 we now have granular lint rules created for each compiler ErrorCategory. However, we had remnants of our old error severities still in use which makes reporting errors quite clunky. Previously you would need to specify both a category and severity which often ended up being the same. This PR moves severity definition into our rules which are generated from our categories. For now I decided to defer "upgrading" categories from a simple string to a sum type since we are only using severities to map errors to eslint severity. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34401). * #34409 * #34404 * #34403 * #34402 * __->__ #34401
35 lines
1001 B
JavaScript
35 lines
1001 B
JavaScript
const ReactCompiler = require('../packages/babel-plugin-react-compiler/dist');
|
|
|
|
const combinedRules = [
|
|
{
|
|
name: 'rules-of-hooks',
|
|
recommended: true,
|
|
description:
|
|
'Validates that components and hooks follow the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks)',
|
|
},
|
|
{
|
|
name: 'exhaustive-deps',
|
|
recommended: true,
|
|
description:
|
|
'Validates that hooks which accept dependency arrays (`useMemo()`, `useCallback()`, `useEffect()`, etc) ' +
|
|
'list all referenced variables in their dependency array. Referencing a value without including it in the ' +
|
|
'dependency array can lead to stale UI or callbacks.',
|
|
},
|
|
...ReactCompiler.LintRules,
|
|
];
|
|
|
|
const printed = combinedRules
|
|
.filter(
|
|
ruleConfig => ruleConfig.rule.recommended && ruleConfig.severity !== 'Off'
|
|
)
|
|
.map(ruleConfig => {
|
|
return `
|
|
## \`react-hooks/${ruleConfig.rule.name}\`
|
|
|
|
${ruleConfig.rule.description}
|
|
`.trim();
|
|
})
|
|
.join('\n\n');
|
|
|
|
console.log(printed);
|