@@ -13,7 +13,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
1313  |  "namedExport" 
1414  |  "anonymousExport" 
1515  |  "noExport" 
16-   |  "localComponents" , 
16+   |  "localComponents" 
17+   |  "reactContext" , 
1718  |  [ ] 
1819  |  [ 
1920      { 
@@ -35,6 +36,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
3536        "Fast refresh only works when a file only exports components. Move your component(s) to a separate file." , 
3637      noExport :
3738        "Fast refresh only works when a file has exports. Move your component(s) to a separate file." , 
39+       reactContext :
40+         "Fast refresh only works when a file only exports components. Move your React context(s) to a separate file." , 
3841    } , 
3942    type : "problem" , 
4043    schema : [ 
@@ -56,7 +59,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
5659      checkJS =  false , 
5760      allowExportNames, 
5861    }  =  context . options [ 0 ]  ??  { } ; 
59-     const  filename  =  context . getFilename ( ) ; 
62+     const  filename  =  context . filename ; 
6063    // Skip tests & stories files 
6164    if  ( 
6265      filename . includes ( ".test." )  || 
@@ -86,6 +89,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
8689          |  TSESTree . BindingName 
8790          |  TSESTree . StringLiteral 
8891        ) [ ]  =  [ ] ; 
92+         const  reactContextExports : TSESTree . Identifier [ ]  =  [ ] ; 
8993
9094        const  handleLocalIdentifier  =  ( 
9195          identifierNode : TSESTree . BindingName , 
@@ -124,6 +128,15 @@ export const onlyExportComponents: TSESLint.RuleModule<
124128              nonComponentExports . push ( identifierNode ) ; 
125129            } 
126130          }  else  { 
131+             if  ( 
132+               init  && 
133+               init . type  ===  "CallExpression"  && 
134+               init . callee . type  ===  "Identifier"  && 
135+               init . callee . name  ===  "createContext" 
136+             )  { 
137+               reactContextExports . push ( identifierNode ) ; 
138+               return ; 
139+             } 
127140            if  ( 
128141              init  && 
129142              // Switch to allowList? 
@@ -263,6 +276,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
263276            for  ( const  node  of  nonComponentExports )  { 
264277              context . report ( {  messageId : "namedExport" ,  node } ) ; 
265278            } 
279+             for  ( const  node  of  reactContextExports )  { 
280+               context . report ( {  messageId : "reactContext" ,  node } ) ; 
281+             } 
266282          }  else  if  ( localComponents . length )  { 
267283            for  ( const  node  of  localComponents )  { 
268284              context . report ( {  messageId : "localComponents" ,  node } ) ; 
0 commit comments