Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions code/core/src/cli/eslintPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,20 @@ export const configureFlatConfig = async (code: string) => {
},

Program(path) {
const alreadyImported = path.node.body.some(
(node) => t.isImportDeclaration(node) && node.source.value === 'eslint-plugin-storybook'
// We already bailed out at the top of this function if an eslint-plugin-storybook import
// exists (static or dynamic), so we can unconditionally insert it here.
const importDecl = t.importDeclaration(
[t.importDefaultSpecifier(t.identifier('storybook'))],
t.stringLiteral('eslint-plugin-storybook')
);

if (!alreadyImported) {
// Add import: import storybook from 'eslint-plugin-storybook'
const importDecl = t.importDeclaration(
[t.importDefaultSpecifier(t.identifier('storybook'))],
t.stringLiteral('eslint-plugin-storybook')
);
(importDecl as any).comments = [
{
type: 'CommentLine',
value:
' For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format',
},
];
path.node.body.unshift(importDecl);
}
(importDecl as any).comments = [
{
type: 'CommentLine',
value:
' For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format',
},
];
path.node.body.unshift(importDecl);
},
});

Expand Down