ESLint: bail out config setup if eslint-plugin-storybook is already imported#34089
ESLint: bail out config setup if eslint-plugin-storybook is already imported#34089valentinpalkovic merged 3 commits intonextfrom
Conversation
…eady imported Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
|
|
View your CI Pipeline Execution ↗ for commit fc1e789
☁️ Nx Cloud last updated this comment at |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe changes add early-return guards to the ESLint configuration setup functions to skip modification when eslint-plugin-storybook is already imported. Corresponding test coverage is added to verify this behavior prevents unnecessary file writes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
✨ Finishing Touches
Comment |
code/core/src/cli/eslintPlugin.ts
Outdated
|
|
||
| // Bail out if eslint-plugin-storybook is already imported to avoid referencing | ||
| // an undefined variable or duplicating the config spread. | ||
| const alreadyHasStorybookImport = ast.program.body.some( |
There was a problem hiding this comment.
should we instead walk through the AST and look for ImportDeclaration?
Sometimes we can have import expressions.
Quite a lot of projects uses https://github.com/antfu/eslint-flat-config-utils that accepts import(...)
There was a problem hiding this comment.
Good catch! Updated in fc1e789 to use traverse and walk the full AST. The check now covers both static ImportDeclaration nodes and dynamic import() expressions (represented in Babel's AST as a CallExpression with an Import callee). Added a test case for the dynamic import scenario using the eslint-flat-config-utils pattern.
…nd dynamic) Co-authored-by: valentinpalkovic <5889929+valentinpalkovic@users.noreply.github.com>
When
configureFlatConfigran against a config that already importedeslint-plugin-storybookunder a custom alias, it skipped adding a duplicate import but still appended...storybook.configs["flat/recommended"]— referencing an undefinedstorybookvariable.Example of broken output:
Changes
configureFlatConfig: Bails out immediately (returns code unchanged) by walking the full AST viatraverseto detect ifeslint-plugin-storybookis already referenced — covering both staticimportdeclarations and dynamicimport()expressions (used by tools likeeslint-flat-config-utils).configureEslintPlugin: Skips writing the flat config file whenconfigureFlatConfigreturns unchanged code — consistent with the existing early-return behavior in the.eslintrc.jsonand.eslintrc.jspaths.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.
Summary by CodeRabbit
Bug Fixes
Tests