Skip to content

Commit 64c1204

Browse files
fix: improve react support
1 parent 6750fc3 commit 64c1204

File tree

11 files changed

+424
-14
lines changed

11 files changed

+424
-14
lines changed

configs.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,6 @@ function getTypescriptJSdocConfig() {
216216
* @returns {Promise<Record<string, string>>} config
217217
*/
218218
function getTypescriptConfig() {
219-
if (packageJson === null) {
220-
return [];
221-
}
222-
223-
const dependencies = packageJson.dependencies || [];
224-
const devDependencies = packageJson.devDependencies || [];
225-
226-
if (
227-
typeof dependencies.typescript === "undefined" &&
228-
typeof devDependencies.typescript === "undefined"
229-
) {
230-
return [];
231-
}
232-
233219
const tsconfigJson = getJsonFile("tsconfig.json");
234220

235221
const isNoEmitEnabled =
@@ -262,6 +248,23 @@ function getTypescriptConfig() {
262248
];
263249
}
264250

251+
/**
252+
* @returns {Promise<Record<string, string>>} config
253+
*/
254+
function getReactConfig() {
255+
if (packageJson === null) {
256+
return [];
257+
}
258+
259+
const dependencies = packageJson.dependencies || [];
260+
const devDependencies = packageJson.devDependencies || [];
261+
262+
return typeof dependencies.react !== "undefined" ||
263+
typeof devDependencies.react !== "undefined"
264+
? configs["react/recommended"]
265+
: [];
266+
}
267+
265268
/**
266269
* @returns {Promise<Record<string, string>>} config
267270
*/
@@ -282,6 +285,7 @@ function getJestConfig() {
282285
const javascriptConfig = getJavascriptConfig();
283286
const typescriptJSDocConfig = getTypescriptJSdocConfig();
284287
const typescriptConfig = getTypescriptConfig();
288+
const reactConfig = getReactConfig();
285289
const jestConfig = getJestConfig();
286290

287291
configs.recommended = [
@@ -292,6 +296,7 @@ configs.recommended = [
292296
javascriptConfig,
293297
typescriptJSDocConfig,
294298
typescriptConfig,
299+
reactConfig,
295300
jestConfig,
296301
configs["markdown/recommended"],
297302
configs["stylistic/recommended"],
@@ -304,6 +309,7 @@ configs["recommended-module"] = [
304309
javascriptConfig,
305310
typescriptJSDocConfig,
306311
typescriptConfig,
312+
reactConfig,
307313
jestConfig,
308314
configs["markdown/recommended"],
309315
configs["stylistic/recommended"],
@@ -316,6 +322,7 @@ configs["recommended-commonjs"] = [
316322
javascriptConfig,
317323
typescriptJSDocConfig,
318324
typescriptConfig,
325+
reactConfig,
319326
jestConfig,
320327
configs["markdown/recommended"],
321328
configs["stylistic/recommended"],

configs/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jestConfig from "./jest.js";
44
import markdownConfig from "./markdown.js";
55
import nodeConfig from "./node.js";
66
import packageJSON from "./package-json.js";
7+
import reactConfig from "./react.js";
78
import stylisticConfig from "./stylistic.js";
89
import typescriptConfig from "./typescript.js";
910
import webpackSpecial from "./webpack-special.js";
@@ -16,6 +17,7 @@ const configs = {
1617
...nodeConfig,
1718
...stylisticConfig,
1819
...typescriptConfig,
20+
...reactConfig,
1921
...packageJSON,
2022
...webpackSpecial,
2123
};

configs/react.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import reactPlugin from "eslint-plugin-react";
2+
3+
const { recommended, "jsx-runtime": jsxRuntime } = reactPlugin.configs.flat;
4+
5+
const recommendedReactConfig = {
6+
...reactPlugin.configs.flat.recommended,
7+
files: ["**/*.{jsx,tsx}"],
8+
settings: {
9+
react: {
10+
version: "detect",
11+
defaultVersion: "19",
12+
},
13+
},
14+
languageOptions: {
15+
...recommended.languageOptions,
16+
...jsxRuntime.languageOptions,
17+
},
18+
rules: {
19+
...recommended.rules,
20+
...jsxRuntime.rules,
21+
},
22+
};
23+
24+
export default {
25+
"react/recommended": recommendedReactConfig,
26+
};

0 commit comments

Comments
 (0)