@@ -13,7 +13,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
13
13
| "namedExport"
14
14
| "anonymousExport"
15
15
| "noExport"
16
- | "localComponents" ,
16
+ | "localComponents"
17
+ | "reactContext" ,
17
18
| [ ]
18
19
| [
19
20
{
@@ -35,6 +36,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
35
36
"Fast refresh only works when a file only exports components. Move your component(s) to a separate file." ,
36
37
noExport :
37
38
"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." ,
38
41
} ,
39
42
type : "problem" ,
40
43
schema : [
@@ -56,7 +59,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
56
59
checkJS = false ,
57
60
allowExportNames,
58
61
} = context . options [ 0 ] ?? { } ;
59
- const filename = context . getFilename ( ) ;
62
+ const filename = context . filename ;
60
63
// Skip tests & stories files
61
64
if (
62
65
filename . includes ( ".test." ) ||
@@ -86,6 +89,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
86
89
| TSESTree . BindingName
87
90
| TSESTree . StringLiteral
88
91
) [ ] = [ ] ;
92
+ const reactContextExports : TSESTree . Identifier [ ] = [ ] ;
89
93
90
94
const handleLocalIdentifier = (
91
95
identifierNode : TSESTree . BindingName ,
@@ -124,6 +128,15 @@ export const onlyExportComponents: TSESLint.RuleModule<
124
128
nonComponentExports . push ( identifierNode ) ;
125
129
}
126
130
} 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
+ }
127
140
if (
128
141
init &&
129
142
// Switch to allowList?
@@ -263,6 +276,9 @@ export const onlyExportComponents: TSESLint.RuleModule<
263
276
for ( const node of nonComponentExports ) {
264
277
context . report ( { messageId : "namedExport" , node } ) ;
265
278
}
279
+ for ( const node of reactContextExports ) {
280
+ context . report ( { messageId : "reactContext" , node } ) ;
281
+ }
266
282
} else if ( localComponents . length ) {
267
283
for ( const node of localComponents ) {
268
284
context . report ( { messageId : "localComponents" , node } ) ;
0 commit comments