@@ -62,6 +62,7 @@ export = createStorybookRule({
62
62
//----------------------------------------------------------------------
63
63
64
64
let hasDefaultExport = false
65
+ let isCsf4Style = false
65
66
let hasStoriesOfImport = false
66
67
67
68
return {
@@ -70,14 +71,35 @@ export = createStorybookRule({
70
71
hasStoriesOfImport = true
71
72
}
72
73
} ,
74
+ VariableDeclaration ( node ) {
75
+ // we check for variables declared at the root in a CSF4 style
76
+ // e.g. const meta = config.meta({})
77
+ if ( node . parent . type === 'Program' ) {
78
+ node . declarations . forEach ( ( declaration ) => {
79
+ const init = declaration . init
80
+
81
+ if ( init && init . type === 'CallExpression' ) {
82
+ const callee = init . callee
83
+
84
+ if (
85
+ callee . type === 'MemberExpression' &&
86
+ callee . property . type === 'Identifier' &&
87
+ callee . property . name === 'meta'
88
+ ) {
89
+ isCsf4Style = true
90
+ }
91
+ }
92
+ } )
93
+ }
94
+ } ,
73
95
ExportDefaultSpecifier : function ( ) {
74
96
hasDefaultExport = true
75
97
} ,
76
98
ExportDefaultDeclaration : function ( ) {
77
99
hasDefaultExport = true
78
100
} ,
79
101
'Program:exit' : function ( program : TSESTree . Program ) {
80
- if ( ! hasDefaultExport && ! hasStoriesOfImport ) {
102
+ if ( ! isCsf4Style && ! hasDefaultExport && ! hasStoriesOfImport ) {
81
103
const componentName = getComponentName ( program , context . getFilename ( ) )
82
104
const firstNonImportStatement = program . body . find ( ( n ) => ! isImportDeclaration ( n ) )
83
105
const node = firstNonImportStatement || program . body [ 0 ] || program
0 commit comments