File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 3
3
* @author Yann Braga
4
4
*/
5
5
6
+ import type { Program } from '@typescript-eslint/types/dist/ast-spec'
7
+
6
8
import { createStorybookRule } from '../utils/create-storybook-rule'
7
9
import { CategoryId } from '../utils/constants'
8
10
import {
@@ -11,6 +13,7 @@ import {
11
13
getMetaObjectExpression ,
12
14
isValidStoryExport ,
13
15
} from '../utils'
16
+ import { isImportDeclaration } from '../utils/ast'
14
17
15
18
//------------------------------------------------------------------------------
16
19
// Rule Definition
@@ -70,7 +73,7 @@ export = createStorybookRule({
70
73
ExportNamedDeclaration : function ( node ) {
71
74
namedExports . push ( ...getAllNamedExports ( node ) )
72
75
} ,
73
- 'Program:exit' : function ( node ) {
76
+ 'Program:exit' : function ( program : Program ) {
74
77
if ( hasStoriesOfImport || ! meta ) {
75
78
return
76
79
}
@@ -83,14 +86,19 @@ export = createStorybookRule({
83
86
return
84
87
}
85
88
89
+ const firstNonImportStatement = program . body . find ( ( n ) => ! isImportDeclaration ( n ) )
90
+ const node = firstNonImportStatement || program . body [ 0 ] || program
91
+
86
92
// @TODO : bring apply this autofix with CSF3 release
87
93
// const fix = (fixer) => fixer.insertTextAfter(node, `\n\nexport const Default = {}`)
88
94
89
- context . report ( {
95
+ const report = {
90
96
node,
91
97
messageId : 'shouldHaveStoryExport' ,
92
98
// fix,
93
- } )
99
+ } as const
100
+
101
+ context . report ( report )
94
102
} ,
95
103
}
96
104
} ,
You can’t perform that action at this time.
0 commit comments