Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/packages/eslint-plugin-react-compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import react from "eslint-plugin-react"

export default [
// Your existing config
{ ...pluginReact.configs.flat.recommended, settings: { react: { version: "detect" } } },
{ ...pluginReact.configs.recommended, settings: { react: { version: "detect" } } },
+ reactCompiler.configs.recommended
]
```
Expand Down
2 changes: 1 addition & 1 deletion fixtures/eslint-v6/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["plugin:react-hooks/recommended"],
"extends": ["plugin:react-hooks/recommended-legacy"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/eslint-v7/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["plugin:react-hooks/recommended"],
"extends": ["plugin:react-hooks/recommended-legacy"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/eslint-v8/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["plugin:react-hooks/recommended"],
"extends": ["plugin:react-hooks/recommended-legacy"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/eslint-v9/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {defineConfig} from 'eslint/config';
import reactHooks from 'eslint-plugin-react-hooks';

export default defineConfig([
reactHooks.configs.flat['recommended-latest'],
reactHooks.configs['recommended-latest'],
{
languageOptions: {
ecmaVersion: 'latest',
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin-react-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([
reactHooks.configs.flat.recommended,
reactHooks.configs.recommended,
]);
```

Expand All @@ -36,17 +36,17 @@ import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([
reactHooks.configs.flat['recommended-latest'],
reactHooks.configs['recommended-latest'],
]);
```

### Legacy Config (.eslintrc)

If you are still using ESLint below 9.0.0, the `recommended` preset can also be used to enable all recommended rules.
If you are still using ESLint below 9.0.0, the `recommended-legacy` preset can also be used to enable all recommended rules.

```js
{
"extends": ["plugin:react-hooks/recommended"],
"extends": ["plugin:react-hooks/recommended-legacy"],
// ...
}

Expand Down
57 changes: 22 additions & 35 deletions packages/eslint-plugin-react-hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 type {Linter, Rule, ESLint} from 'eslint';

import ExhaustiveDeps from './rules/ExhaustiveDeps';
import {
Expand Down Expand Up @@ -55,46 +55,33 @@ const recommendedLatestRuleConfigs: Linter.RulesRecord = {
...recommendedLatestCompilerRuleConfigs,
};

const plugins = ['react-hooks'];

type ReactHooksFlatConfig = {
plugins: {react: any};
rules: Linter.RulesRecord;
};

const configs = {
recommended: {
plugins,
rules: recommendedRuleConfigs,
},
'recommended-latest': {
plugins,
rules: recommendedLatestRuleConfigs,
},
flat: {} as {
recommended: ReactHooksFlatConfig;
'recommended-latest': 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,
configs: {
'recommended-legacy': {
plugins: ['react-hooks'],
rules: recommendedRuleConfigs,
},
'recommended-latest-legacy': {
plugins: ['react-hooks'],
rules: recommendedLatestRuleConfigs,
},
recommended: {
plugins: {'react-hooks': {}},
rules: recommendedRuleConfigs,
},
'recommended-latest': {
plugins: {'react-hooks': {}},
rules: recommendedLatestRuleConfigs,
},
},
});
} satisfies ESLint.Plugin;

plugin.configs.recommended.plugins['react-hooks'] = plugin;
plugin.configs['recommended-latest'].plugins['react-hooks'] = plugin;

export default plugin;
Loading