-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Fix: Add Storybook ESLint plugin to defineConfig from eslint/config #32878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
- Modified configureFlatConfig to handle CallExpression wrappers like defineConfig([...]) - Added test case for Next.js-style ESLint configuration - All existing tests continue to pass Co-authored-by: yannbf <1671563+yannbf@users.noreply.github.com>
- Added proper type checks before accessing array arguments - Verify argument is Expression or TS type before unwrapping - Addresses code review feedback about unsafe type casting Co-authored-by: yannbf <1671563+yannbf@users.noreply.github.com>
- Removed redundant TS type checks from type guard - t.isExpression is sufficient since unwrapTSExpression handles TS types - All tests continue to pass Co-authored-by: yannbf <1671563+yannbf@users.noreply.github.com>
- Prevent potential runtime error when unwrapTSExpression returns null/undefined - Makes code more defensive and robust - All tests continue to pass Co-authored-by: yannbf <1671563+yannbf@users.noreply.github.com>
code/core/src/cli/eslintPlugin.ts
Outdated
|
|
||
| if (t.isArrayExpression(init)) { | ||
| init.elements.push(t.spreadElement(storybookConfig)); | ||
| } else if (t.isCallExpression(init) && init.arguments.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot only if it's defineConfig from import { defineConfig } from "eslint/config"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 72ec435. Now specifically checks that defineConfig is imported from "eslint/config" before modifying the array. Added test to verify we don't modify defineConfig from other sources.
- Track eslintDefineConfigLocalName from "eslint/config" imports - Check callee matches defineConfig before modifying array - Add test for defineConfig from non-eslint/config source - Ensures we don't modify arbitrary function calls Co-authored-by: yannbf <1671563+yannbf@users.noreply.github.com>
Storybook init adds the
eslint-plugin-storybookimport but fails to register it in Next.js projects usingdefineConfig([...])fromeslint/config.Changes
code/core/src/cli/eslintPlugin.tsconfigureFlatConfigCase 3 to handle CallExpressions wrapping array argumentsdefineConfigimports specifically from"eslint/config"defineConfigidentifier before modifyingt.isExpression) and null checks before unwrapping and modifying arrayscode/core/src/cli/eslintPlugin.test.tsdefineConfigpattern from"eslint/config"defineConfigfrom other packages is not modifiedBehavior
Before:
After:
All existing ESLint config formats (direct arrays,
tseslint.config(), legacy.eslintrc) remain unaffected.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.