Skip to content

Commit 74d0c68

Browse files
authored
Merge pull request #91 from storybookjs/fix/story-exports-error-highlighting
fix(story-exports): stop highlighting the entire code on error
2 parents e9e7e69 + 59f61dd commit 74d0c68

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/rules/story-exports.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @author Yann Braga
44
*/
55

6+
import type { Program } from '@typescript-eslint/types/dist/ast-spec'
7+
68
import { createStorybookRule } from '../utils/create-storybook-rule'
79
import { CategoryId } from '../utils/constants'
810
import {
@@ -11,6 +13,7 @@ import {
1113
getMetaObjectExpression,
1214
isValidStoryExport,
1315
} from '../utils'
16+
import { isImportDeclaration } from '../utils/ast'
1417

1518
//------------------------------------------------------------------------------
1619
// Rule Definition
@@ -70,7 +73,7 @@ export = createStorybookRule({
7073
ExportNamedDeclaration: function (node) {
7174
namedExports.push(...getAllNamedExports(node))
7275
},
73-
'Program:exit': function (node) {
76+
'Program:exit': function (program: Program) {
7477
if (hasStoriesOfImport || !meta) {
7578
return
7679
}
@@ -83,14 +86,19 @@ export = createStorybookRule({
8386
return
8487
}
8588

89+
const firstNonImportStatement = program.body.find((n) => !isImportDeclaration(n))
90+
const node = firstNonImportStatement || program.body[0] || program
91+
8692
// @TODO: bring apply this autofix with CSF3 release
8793
// const fix = (fixer) => fixer.insertTextAfter(node, `\n\nexport const Default = {}`)
8894

89-
context.report({
95+
const report = {
9096
node,
9197
messageId: 'shouldHaveStoryExport',
9298
// fix,
93-
})
99+
} as const
100+
101+
context.report(report)
94102
},
95103
}
96104
},

0 commit comments

Comments
 (0)