File tree Expand file tree Collapse file tree 1 file changed +21
-9
lines changed
src/components/MDX/Sandpack Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -21,22 +21,34 @@ const getCodeMirrorPosition = (
2121
2222const linter = new Linter ( ) ;
2323
24- const reactRules = require ( 'eslint-plugin-react-hooks' ) . rules ;
25- linter . defineRules ( {
26- 'react-hooks/rules-of-hooks' : reactRules [ 'rules-of-hooks' ] ,
27- 'react-hooks/exhaustive-deps' : reactRules [ 'exhaustive-deps' ] ,
28- } ) ;
24+ let reactRules ;
25+ try {
26+ reactRules = require ( 'eslint-plugin-react-hooks' ) . rules ;
27+ if ( reactRules ) {
28+ linter . defineRules ( {
29+ 'react-hooks/rules-of-hooks' : reactRules [ 'rules-of-hooks' ] ,
30+ 'react-hooks/exhaustive-deps' : reactRules [ 'exhaustive-deps' ] ,
31+ } ) ;
32+ }
33+ } catch ( e ) {
34+ console . warn ( 'Could not load react-hooks rules:' , e ) ;
35+ // Define empty rules as fallback
36+ reactRules = { } ;
37+ }
2938
3039const options = {
3140 parserOptions : {
3241 ecmaVersion : 12 ,
3342 sourceType : 'module' ,
3443 ecmaFeatures : { jsx : true } ,
3544 } ,
36- rules : {
37- 'react-hooks/rules-of-hooks' : 'error' ,
38- 'react-hooks/exhaustive-deps' : 'error' ,
39- } ,
45+ rules :
46+ reactRules [ 'rules-of-hooks' ] && reactRules [ 'exhaustive-deps' ]
47+ ? {
48+ 'react-hooks/rules-of-hooks' : 'error' ,
49+ 'react-hooks/exhaustive-deps' : 'error' ,
50+ }
51+ : { } ,
4052} ;
4153
4254export const runESLint = (
You can’t perform that action at this time.
0 commit comments