File tree Expand file tree Collapse file tree 1 file changed +36
-20
lines changed Expand file tree Collapse file tree 1 file changed +36
-20
lines changed Original file line number Diff line number Diff line change 1
- import reactPlugin from "eslint-plugin-react" ;
1
+ /**
2
+ * @returns {Promise<Record<string, string>> } config
3
+ */
4
+ async function getReactRecommendedConfig ( ) {
5
+ let reactPlugin ;
2
6
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
+ }
4
13
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
+ } ,
12
26
} ,
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 ( ) ;
23
39
24
40
export default {
25
- "react/recommended" : recommendedReactConfig ,
41
+ "react/recommended" : reactRecommendedConfig ,
26
42
} ;
You can’t perform that action at this time.
0 commit comments