react/packages/eslint-plugin-react-hooks/src/index.ts
lauren 7568e71854
[eprh] Prepare for 7.0.0 (#34757)
For 7.0.0:

Slim down presets to just 2 configurations:

- `recommended`: legacy and flat config with all recommended rules, and
- `recommended-latest`: legacy and flat config with all recommended
rules plus new bleeding edge experimental compiler rules

Removed:
- `recommended-latest-legacy`
- `flat/recommended`

Please see the README for new install instructions.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34757).
* #34783
* #34782
* __->__ #34757
2025-10-08 15:17:31 -04:00

84 lines
1.9 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';
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>;
const basicRuleConfigs = {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
} as const satisfies Linter.RulesRecord;
const compilerRuleConfigs = Object.fromEntries(
Object.entries(recommendedRules).map(([name, ruleConfig]) => {
return [
`react-hooks/${name}` as const,
mapErrorSeverityToESlint(ruleConfig.severity),
] as const;
}),
) as Record<`react-hooks/${string}`, Linter.RuleEntry>;
const allRuleConfigs: Linter.RulesRecord = {
...basicRuleConfigs,
...compilerRuleConfigs,
};
const plugins = ['react-hooks'];
type ReactHooksFlatConfig = {
plugins: {react: any};
rules: Linter.RulesRecord;
};
const configs = {
recommended: {
plugins,
rules: allRuleConfigs,
},
'recommended-latest': {
plugins,
rules: allRuleConfigs,
},
flat: {} as Record<string, ReactHooksFlatConfig>,
};
const plugin = {
meta: {
name: 'eslint-plugin-react-hooks',
version: '7.0.0',
},
rules,
configs,
};
Object.assign(configs.flat, {
'recommended-latest': {
plugins: {'react-hooks': plugin},
rules: configs['recommended-latest'].rules,
},
recommended: {
plugins: {'react-hooks': plugin},
rules: configs.recommended.rules,
},
});
export default plugin;