Skip to content

[code-simplifier] Simplify configureFlatConfig: remove redundant alreadyImported check#34102

Open
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/eslint-plugin-cleanup-2026-03-11-5a0a18e95cb9aab8
Open

[code-simplifier] Simplify configureFlatConfig: remove redundant alreadyImported check#34102
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/eslint-plugin-cleanup-2026-03-11-5a0a18e95cb9aab8

Conversation

@github-actions
Copy link
Contributor

Overview

PR #34089 added an early-return guard at the top of configureFlatConfig that exits immediately if eslint-plugin-storybook is already imported (statically or dynamically). This makes the alreadyImported check inside the Program visitor of the second traverse call 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 redundant alreadyImported variable and its if (!alreadyImported) guard from the Program visitor

What Changed

Before (in the Program visitor):

Program(path) {
  const alreadyImported = path.node.body.some(
    (node) => t.isImportDeclaration(node) && node.source.value === 'eslint-plugin-storybook'
  );
  if (!alreadyImported) {
    // add import…
    path.node.body.unshift(importDecl);
  }
},

After:

Program(path) {
  // We already bailed out at the top if the import exists, so insert unconditionally.
  const importDecl = ;
  path.node.body.unshift(importDecl);
},

The early-return at line 83–85 already covers:

  • Static import … from 'eslint-plugin-storybook' (via ImportDeclaration visitor)
  • Dynamic import('eslint-plugin-storybook') (via CallExpression visitor)

So when the Program handler executes, alreadyImported was always false — the condition never suppressed the unshift.

Based On

Testing

  • ✅ Brace balance verified (90 open = 90 close)
  • ✅ Existing tests (lines 587–635 in eslintPlugin.test.ts) continue to exercise both the early-bail-out path and the import-insertion path — behavior is identical
  • ✅ No functional changes — the Program handler now always inserts the import, which was the only reachable outcome before

Review Focus

Please verify the reasoning: if alreadyHasStorybookImport is false after the first traverse, then path.node.body.some(...) checking for the same ImportDeclaration will also always be false, making the guard unnecessary.


Automated by Code Simplifier Agent — analyzing code from the last 24 hours

Generated by Code Simplifier ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/code-simplifier.md@852cb06ad52958b402ed982b69957ffc57ca0619
  • expires on Mar 12, 2026, 12:32 PM UTC

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants