Skip to content

Commit 44a2d90

Browse files
fix: loading react plugin
1 parent e0fcb5c commit 44a2d90

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

configs/react.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1-
import reactPlugin from "eslint-plugin-react";
1+
/**
2+
* @returns {Promise<Record<string, string>>} config
3+
*/
4+
async function getReactRecommendedConfig() {
5+
let reactPlugin;
26

3-
const { recommended, "jsx-runtime": jsxRuntime } = reactPlugin.configs.flat;
7+
try {
8+
reactPlugin = (await import("eslint-plugin-react")).default;
9+
// eslint-disable-next-line unicorn/prefer-optional-catch-binding
10+
} catch (_err) {
11+
// Nothing
12+
}
413

5-
const recommendedReactConfig = {
6-
...reactPlugin.configs.flat.recommended,
7-
files: ["**/*.{jsx,tsx}"],
8-
settings: {
9-
react: {
10-
version: "detect",
11-
defaultVersion: "19",
14+
const { recommended, "jsx-runtime": jsxRuntime } = (reactPlugin &&
15+
reactPlugin.configs &&
16+
reactPlugin.configs.flat) || { recommended: {}, "jsx-runtime": {} };
17+
18+
return {
19+
...recommended,
20+
files: ["**/*.{jsx,tsx}"],
21+
settings: {
22+
react: {
23+
version: "detect",
24+
defaultVersion: "19",
25+
},
1226
},
13-
},
14-
languageOptions: {
15-
...recommended.languageOptions,
16-
...jsxRuntime.languageOptions,
17-
},
18-
rules: {
19-
...recommended.rules,
20-
...jsxRuntime.rules,
21-
},
22-
};
27+
languageOptions: {
28+
...recommended.languageOptions,
29+
...jsxRuntime.languageOptions,
30+
},
31+
rules: {
32+
...recommended.rules,
33+
...jsxRuntime.rules,
34+
},
35+
};
36+
}
37+
38+
const reactRecommendedConfig = await getReactRecommendedConfig();
2339

2440
export default {
25-
"react/recommended": recommendedReactConfig,
41+
"react/recommended": reactRecommendedConfig,
2642
};

0 commit comments

Comments
 (0)