mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00: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
80 lines
1.6 KiB
TypeScript
80 lines
1.6 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
import type {Linter, Rule} from 'eslint';
|
|
|
|
import ExhaustiveDeps from './rules/ExhaustiveDeps';
|
|
import {
|
|
allRules,
|
|
mapErrorSeverityToESlint,
|
|
recommendedRules,
|
|
} from './shared/ReactCompiler';
|
|
import RulesOfHooks from './rules/RulesOfHooks';
|
|
|
|
// All rules
|
|
const rules = {
|
|
'exhaustive-deps': ExhaustiveDeps,
|
|
'rules-of-hooks': RulesOfHooks,
|
|
...Object.fromEntries(
|
|
Object.entries(allRules).map(([name, config]) => [name, config.rule])
|
|
),
|
|
} satisfies Record<string, Rule.RuleModule>;
|
|
|
|
// Config rules
|
|
const ruleConfigs = {
|
|
'react-hooks/rules-of-hooks': 'error',
|
|
'react-hooks/exhaustive-deps': 'warn',
|
|
// Compiler rules
|
|
...Object.fromEntries(
|
|
Object.entries(recommendedRules).map(([name, ruleConfig]) => {
|
|
return [
|
|
'react-hooks/' + name,
|
|
mapErrorSeverityToESlint(ruleConfig.severity),
|
|
];
|
|
}),
|
|
),
|
|
} satisfies Linter.RulesRecord;
|
|
|
|
const plugin = {
|
|
meta: {
|
|
name: 'eslint-plugin-react-hooks',
|
|
},
|
|
configs: {},
|
|
rules,
|
|
};
|
|
|
|
Object.assign(plugin.configs, {
|
|
'recommended-legacy': {
|
|
plugins: ['react-hooks'],
|
|
rules: ruleConfigs,
|
|
},
|
|
|
|
'flat/recommended': [
|
|
{
|
|
plugins: {
|
|
'react-hooks': plugin,
|
|
},
|
|
rules: ruleConfigs,
|
|
},
|
|
],
|
|
|
|
'recommended-latest': [
|
|
{
|
|
plugins: {
|
|
'react-hooks': plugin,
|
|
},
|
|
rules: ruleConfigs,
|
|
},
|
|
],
|
|
|
|
recommended: {
|
|
plugins: ['react-hooks'],
|
|
rules: ruleConfigs,
|
|
},
|
|
});
|
|
|
|
export default plugin;
|