[code-simplifier] Simplify configureFlatConfig: remove redundant alreadyImported check#34102
Open
github-actions[bot] wants to merge 1 commit intomainfrom
Open
Conversation
The Program handler's alreadyImported check is now dead code since the early-return guard at the top of configureFlatConfig already handles both static and dynamic eslint-plugin-storybook imports. When the second traverse runs, it is guaranteed no storybook import exists, so the import can be inserted unconditionally. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
PR #34089 added an early-return guard at the top of
configureFlatConfigthat exits immediately ifeslint-plugin-storybookis already imported (statically or dynamically). This makes thealreadyImportedcheck inside theProgramvisitor of the secondtraversecall dead code — if we reach the second traversal at all, it's guaranteed no storybook import exists.Files Simplified
code/core/src/cli/eslintPlugin.ts— removed the redundantalreadyImportedvariable and itsif (!alreadyImported)guard from theProgramvisitorWhat Changed
Before (in the
Programvisitor):After:
The early-return at line 83–85 already covers:
import … from 'eslint-plugin-storybook'(viaImportDeclarationvisitor)import('eslint-plugin-storybook')(viaCallExpressionvisitor)So when the
Programhandler executes,alreadyImportedwas alwaysfalse— the condition never suppressed theunshift.Based On
Testing
eslintPlugin.test.ts) continue to exercise both the early-bail-out path and the import-insertion path — behavior is identicalProgramhandler now always inserts the import, which was the only reachable outcome beforeReview Focus
Please verify the reasoning: if
alreadyHasStorybookImportisfalseafter the first traverse, thenpath.node.body.some(...)checking for the sameImportDeclarationwill also always befalse, making the guard unnecessary.Automated by Code Simplifier Agent — analyzing code from the last 24 hours