Skip to content

Commit 102d4e0

Browse files
authored
feat: add recommended presets for each plugin (#940)
1 parent 74a6eac commit 102d4e0

File tree

27 files changed

+614
-280
lines changed

27 files changed

+614
-280
lines changed

.vscode/settings.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,7 @@
3333
"eslint.workingDirectories": [
3434
{
3535
"changeProcessCWD": true,
36-
"mode": "location"
37-
},
38-
{
39-
"changeProcessCWD": true,
40-
"mode": "auto",
41-
"pattern": "examples/*"
42-
},
43-
{
44-
"changeProcessCWD": true,
45-
"mode": "auto",
46-
"pattern": "apps/*"
36+
"mode": "auto"
4737
}
4838
],
4939
"files.exclude": {

examples/dual-react-dom-lib/eslint.config.mjs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import eslintJs from "@eslint/js";
2-
import eslintReact from "@eslint-react/eslint-plugin";
2+
import eslintPluginReactx from "eslint-plugin-react-x";
3+
import eslintPluginReactDom from "eslint-plugin-react-dom";
4+
import eslintPluginReactWebApi from "eslint-plugin-react-web-api";
35
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
6+
import eslintPluginReactHooksExtra from "eslint-plugin-react-hooks-extra";
7+
import eslintPluginReactNamingConvention from "eslint-plugin-react-naming-convention";
48
import tseslint from "typescript-eslint";
59

610
import TSCONFIG from "./tsconfig.json" with { type: "json" };
@@ -45,12 +49,23 @@ export default tseslint.config(
4549
"no-console": "off",
4650
},
4751
},
48-
// React configuration
52+
// react specific configurations
4953
{
5054
files: TSCONFIG.include,
51-
...eslintReact.configs["recommended-type-checked"],
55+
...eslintPluginReactx.configs["recommended-type-checked"],
56+
},
57+
{
58+
files: TSCONFIG.include,
59+
...eslintPluginReactDom.configs.recommended,
60+
},
61+
{
62+
files: TSCONFIG.include,
63+
...eslintPluginReactWebApi.configs.recommended,
64+
},
65+
{
66+
files: TSCONFIG.include,
67+
...eslintPluginReactHooksExtra.configs.recommended,
5268
},
53-
// React Hooks configuration
5469
{
5570
files: TSCONFIG.include,
5671
plugins: {

examples/dual-react-dom-lib/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
"prepare": "pnpm run build"
3232
},
3333
"devDependencies": {
34-
"@eslint-react/eslint-plugin": "workspace:*",
34+
"eslint-plugin-react-x": "workspace:*",
35+
"eslint-plugin-react-dom": "workspace:*",
36+
"eslint-plugin-react-web-api": "workspace:*",
37+
"eslint-plugin-react-hooks-extra": "workspace:*",
38+
"eslint-plugin-react-naming-convention": "workspace:*",
3539
"@eslint/js": "^9.20.0",
3640
"@tsconfig/node22": "^22.0.0",
3741
"@tsconfig/strictest": "^2.0.5",

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@
115115
},
116116
"pnpm": {
117117
"overrides": {
118-
"is-core-module": "npm:@socketregistry/is-core-module@^1.0.7",
119-
"safe-buffer": "npm:@socketregistry/safe-buffer@^1.0.6",
120-
"safer-buffer": "npm:@socketregistry/safer-buffer@^1.0.6",
121-
"typedarray": "npm:@socketregistry/typedarray@^1.0.5",
122118
"@types/react": "^19.0.10",
123119
"@types/react-dom": "^19.0.4",
124120
"cross-spawn": "^7.0.6",
125121
"esbuild": "^0.25.0",
122+
"is-core-module": "npm:@socketregistry/is-core-module@^1.0.7",
126123
"next": "^15.1.7",
127124
"react": "^19.0.0",
128125
"react-dom": "^19.0.0",
126+
"safe-buffer": "npm:@socketregistry/safe-buffer@^1.0.6",
127+
"safer-buffer": "npm:@socketregistry/safer-buffer@^1.0.6",
129128
"ts-api-utils": "^2.0.1",
129+
"typedarray": "npm:@socketregistry/typedarray@^1.0.5",
130130
"typescript": "^5.7.3"
131131
}
132132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { RulePreset } from "@eslint-react/shared";
2+
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
3+
4+
export const name = "react-debug/all";
5+
6+
export const rules = {
7+
"react-debug/class-component": "warn",
8+
"react-debug/function-component": "warn",
9+
"react-debug/hook": "warn",
10+
"react-debug/is-from-react": "off",
11+
} as const satisfies RulePreset;
12+
13+
export const settings = {
14+
"react-x": DEFAULT_ESLINT_REACT_SETTINGS,
15+
};
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
import { name, version } from "../package.json";
2-
import classComponent from "./rules/class-component";
3-
import functionComponent from "./rules/function-component";
4-
import hook from "./rules/hook";
5-
import isFromReact from "./rules/is-from-react";
1+
import type { RulePreset } from "@eslint-react/shared";
62

7-
export default {
8-
meta: {
9-
name,
10-
version,
11-
},
12-
rules: {
13-
"class-component": classComponent,
14-
"function-component": functionComponent,
15-
hook: hook,
16-
"is-from-react": isFromReact,
3+
import * as allConfig from "./configs/all";
4+
import { plugin } from "./plugin";
5+
6+
function makeConfig(config: { name: string; rules: RulePreset }) {
7+
return {
8+
...config,
9+
plugins: {
10+
"react-x": plugin,
11+
},
12+
};
13+
}
1714

18-
// Part: deprecated rules
19-
/** @deprecated Use `hook` instead */
20-
"react-hooks": hook,
15+
function makeLegacyConfig(config: { rules: RulePreset }) {
16+
return {
17+
plugins: ["react-x"],
18+
rules: config.rules,
19+
};
20+
}
21+
22+
export default {
23+
...plugin,
24+
configs: {
25+
["all"]: makeConfig(allConfig),
26+
["all-legacy"]: makeLegacyConfig(allConfig),
2127
},
22-
} as const;
28+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { name, version } from "../package.json";
2+
import classComponent from "./rules/class-component";
3+
import functionComponent from "./rules/function-component";
4+
import hook from "./rules/hook";
5+
import isFromReact from "./rules/is-from-react";
6+
7+
export const plugin = {
8+
meta: {
9+
name,
10+
version,
11+
},
12+
rules: {
13+
"class-component": classComponent,
14+
"function-component": functionComponent,
15+
hook: hook,
16+
"is-from-react": isFromReact,
17+
18+
// Part: deprecated rules
19+
/** @deprecated Use `hook` instead */
20+
"react-hooks": hook,
21+
},
22+
} as const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { RulePreset } from "@eslint-react/shared";
2+
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
3+
4+
export const name = "react-dom/recommended";
5+
6+
export const rules = {
7+
"react-dom/no-dangerously-set-innerhtml": "warn",
8+
"react-dom/no-dangerously-set-innerhtml-with-children": "error",
9+
"react-dom/no-find-dom-node": "error",
10+
"react-dom/no-missing-button-type": "warn",
11+
"react-dom/no-missing-iframe-sandbox": "warn",
12+
"react-dom/no-namespace": "error",
13+
"react-dom/no-render-return-value": "error",
14+
"react-dom/no-script-url": "warn",
15+
"react-dom/no-unknown-property": "warn",
16+
"react-dom/no-unsafe-iframe-sandbox": "warn",
17+
"react-dom/no-unsafe-target-blank": "warn",
18+
"react-dom/no-void-elements-with-children": "warn",
19+
} as const satisfies RulePreset;
20+
21+
export const settings = {
22+
"react-x": DEFAULT_ESLINT_REACT_SETTINGS,
23+
};
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
1-
import { name, version } from "../package.json";
2-
import noDangerouslySetInnerHTML from "./rules/no-dangerously-set-innerhtml";
3-
import noDangerouslySetInnerHTMLWithChildren from "./rules/no-dangerously-set-innerhtml-with-children";
4-
import noFindDomNode from "./rules/no-find-dom-node";
5-
import noMissingButtonType from "./rules/no-missing-button-type";
6-
import noMissingIframeSandbox from "./rules/no-missing-iframe-sandbox";
7-
import noNamespace from "./rules/no-namespace";
8-
import noRenderReturnValue from "./rules/no-render-return-value";
9-
import noScriptUrl from "./rules/no-script-url";
10-
import noUnknownProperty from "./rules/no-unknown-property";
11-
import noUnsafeIframeSandbox from "./rules/no-unsafe-iframe-sandbox";
12-
import noUnsafeTargetBlank from "./rules/no-unsafe-target-blank";
13-
import noVoidElementsWithChildren from "./rules/no-void-elements-with-children";
1+
import type { RulePreset } from "@eslint-react/shared";
142

15-
export default {
16-
meta: {
17-
name,
18-
version,
19-
},
20-
rules: {
21-
"no-dangerously-set-innerhtml": noDangerouslySetInnerHTML,
22-
"no-dangerously-set-innerhtml-with-children": noDangerouslySetInnerHTMLWithChildren,
23-
"no-find-dom-node": noFindDomNode,
24-
"no-missing-button-type": noMissingButtonType,
25-
"no-missing-iframe-sandbox": noMissingIframeSandbox,
26-
"no-namespace": noNamespace,
27-
"no-render-return-value": noRenderReturnValue,
28-
"no-script-url": noScriptUrl,
29-
"no-unknown-property": noUnknownProperty,
30-
"no-unsafe-iframe-sandbox": noUnsafeIframeSandbox,
31-
"no-unsafe-target-blank": noUnsafeTargetBlank,
32-
"no-void-elements-with-children": noVoidElementsWithChildren,
3+
import * as recommendedConfig from "./configs/recommended";
4+
import { plugin } from "./plugin";
5+
6+
function makeConfig(config: { name: string; rules: RulePreset }) {
7+
return {
8+
...config,
9+
plugins: {
10+
"react-x": plugin,
11+
},
12+
};
13+
}
3314

34-
// Part: deprecated rules
35-
/** @deprecated Use `no-void-elements-with-children` instead */
36-
"no-children-in-void-dom-elements": noVoidElementsWithChildren,
15+
function makeLegacyConfig(config: { rules: RulePreset }) {
16+
return {
17+
plugins: ["react-x"],
18+
rules: config.rules,
19+
};
20+
}
21+
22+
export default {
23+
...plugin,
24+
configs: {
25+
["recommended"]: makeConfig(recommendedConfig),
26+
["recommended-legacy"]: makeLegacyConfig(recommendedConfig),
3727
},
38-
} as const;
28+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { name, version } from "../package.json";
2+
import noDangerouslySetInnerHTML from "./rules/no-dangerously-set-innerhtml";
3+
import noDangerouslySetInnerHTMLWithChildren from "./rules/no-dangerously-set-innerhtml-with-children";
4+
import noFindDomNode from "./rules/no-find-dom-node";
5+
import noMissingButtonType from "./rules/no-missing-button-type";
6+
import noMissingIframeSandbox from "./rules/no-missing-iframe-sandbox";
7+
import noNamespace from "./rules/no-namespace";
8+
import noRenderReturnValue from "./rules/no-render-return-value";
9+
import noScriptUrl from "./rules/no-script-url";
10+
import noUnknownProperty from "./rules/no-unknown-property";
11+
import noUnsafeIframeSandbox from "./rules/no-unsafe-iframe-sandbox";
12+
import noUnsafeTargetBlank from "./rules/no-unsafe-target-blank";
13+
import noVoidElementsWithChildren from "./rules/no-void-elements-with-children";
14+
15+
export const plugin = {
16+
meta: {
17+
name,
18+
version,
19+
},
20+
rules: {
21+
"no-dangerously-set-innerhtml": noDangerouslySetInnerHTML,
22+
"no-dangerously-set-innerhtml-with-children": noDangerouslySetInnerHTMLWithChildren,
23+
"no-find-dom-node": noFindDomNode,
24+
"no-missing-button-type": noMissingButtonType,
25+
"no-missing-iframe-sandbox": noMissingIframeSandbox,
26+
"no-namespace": noNamespace,
27+
"no-render-return-value": noRenderReturnValue,
28+
"no-script-url": noScriptUrl,
29+
"no-unknown-property": noUnknownProperty,
30+
"no-unsafe-iframe-sandbox": noUnsafeIframeSandbox,
31+
"no-unsafe-target-blank": noUnsafeTargetBlank,
32+
"no-void-elements-with-children": noVoidElementsWithChildren,
33+
34+
// Part: deprecated rules
35+
/** @deprecated Use `no-void-elements-with-children` instead */
36+
"no-children-in-void-dom-elements": noVoidElementsWithChildren,
37+
},
38+
} as const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { RulePreset } from "@eslint-react/shared";
2+
3+
export const name = "react-hooks-extra/recommended";
4+
5+
export const rules = {
6+
"react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
7+
"react-hooks-extra/no-useless-custom-hooks": "warn",
8+
"react-hooks-extra/prefer-use-state-lazy-initialization": "warn",
9+
} as const satisfies RulePreset;
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
1-
import { name, version } from "../package.json";
2-
import noDirectSetStateInUseEffect from "./rules/no-direct-set-state-in-use-effect";
3-
import noDirectSetStateInUseLayoutEffect from "./rules/no-direct-set-state-in-use-layout-effect";
4-
import noUnnecessaryUseCallback from "./rules/no-unnecessary-use-callback";
5-
import noUnnecessaryUseMemo from "./rules/no-unnecessary-use-memo";
6-
import noUselessCustomHooks from "./rules/no-useless-custom-hooks";
7-
import preferUseStateLazyInitialization from "./rules/prefer-use-state-lazy-initialization";
1+
import type { RulePreset } from "@eslint-react/shared";
82

9-
export default {
10-
meta: {
11-
name,
12-
version,
13-
},
14-
rules: {
15-
"no-direct-set-state-in-use-effect": noDirectSetStateInUseEffect,
16-
"no-direct-set-state-in-use-layout-effect": noDirectSetStateInUseLayoutEffect,
17-
"no-unnecessary-use-callback": noUnnecessaryUseCallback,
18-
"no-unnecessary-use-memo": noUnnecessaryUseMemo,
19-
"no-useless-custom-hooks": noUselessCustomHooks,
20-
"prefer-use-state-lazy-initialization": preferUseStateLazyInitialization,
3+
import * as recommendedConfig from "./configs/recommended";
4+
import { plugin } from "./plugin";
5+
6+
function makeConfig(config: { name: string; rules: RulePreset }) {
7+
return {
8+
...config,
9+
plugins: {
10+
"react-x": plugin,
11+
},
12+
};
13+
}
2114

22-
// Part: deprecated rules
23-
/** @deprecated Use `no-useless-custom-hooks` instead */
24-
"ensure-custom-hooks-using-other-hooks": noUselessCustomHooks,
25-
/** @deprecated Use `no-unnecessary-use-callback` instead */
26-
"ensure-use-callback-has-non-empty-deps": noUnnecessaryUseCallback,
27-
/** @deprecated Use `no-unnecessary-use-memo` instead */
28-
"ensure-use-memo-has-non-empty-deps": noUnnecessaryUseMemo,
29-
/** @deprecated Use `no-useless-custom-hooks` instead */
30-
"no-redundant-custom-hook": noUselessCustomHooks,
15+
function makeLegacyConfig(config: { rules: RulePreset }) {
16+
return {
17+
plugins: ["react-x"],
18+
rules: config.rules,
19+
};
20+
}
21+
22+
export default {
23+
...plugin,
24+
configs: {
25+
["recommended"]: makeConfig(recommendedConfig),
26+
["recommended-legacy"]: makeLegacyConfig(recommendedConfig),
3127
},
32-
} as const;
28+
};

0 commit comments

Comments
 (0)