-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
ESLint: Only apply csf-strict rules on stories files #31963
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
ESLint: Only apply csf-strict rules on stories files #31963
Conversation
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.
LGTM
4 files reviewed, no comments
Edit PR Review Bot Settings | Greptile
|
Hey @valentinpalkovic I saw you had assigned this out, but I see last week it has been marked stale. Is there anything you need from me to address this? |
|
No. I think we're good, but just busy with the 9.1 release. I am sure that after releasing 9.1, @yannbf will take a look! |
| } as const, | ||
| overrides: [ | ||
| { | ||
| files: ['**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '**/*.story.@(ts|tsx|js|jsx|mjs|cjs)'], |
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.
Hey there @cylewaitforit, thanks for your contribution!
Won't this block users from specifying their own files to apply these rules? As it now has hardcode file paths? Perhaps we can do differently and leave things as they were, and only move these general, conflicting rules to a new entry that's always added, and has the hardcoded paths:
'react-hooks/rules-of-hooks': 'off',
'import/no-anonymous-default-export': 'off',
What do you think?
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.
Hey @yannbf, thanks for reviewing. This updates csf-strict to follow the same pattern used by the other configs (see https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin/src/configs/recommended.ts and https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin/src/configs/csf.ts). Users should still have the ability to make any overrides in their own config after extending.
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.
@yannbf Another option, if you’re concerned about this legacy config, might be to only leave the fix for the Flat Config and instead mark the legacy config options as deprecated for removal in V10 of this storybook eslint plugin.
Overriding files types for a config on the user side is very straight forward in the flat config and can be easily verified with the eslint config inspector.
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.
@yannbf Are the legacy configs staying in eslint for Storybook 10 or will they be removed?
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.
Hey there, I'm so sorry this has become stale for so long.
We don't have plans to drop ESLint v8 support as there are still tons of users on that version.
Additionally, I spent some time today on this PR and made changes to address my concern, by separating the normal rules (without any overrides) to the extra overrides (which would use the overrides), so that users can define any file name for stories.. but to be honest, this plugin's purpose is to help users follow standards, and the story file name is a standard 😅 so I'll just go on and accept your PR as is! Thank you so much for your contribution 🙏
If users report this as a breaking change I'll revisit this.
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.
Thanks @yannbf! Appreciate the time and thoughtfulness you gave to the review.
WalkthroughThe PR scopes the csf-strict ESLint rules to Storybook story files only. In the classic config and its generator script, top-level rules are replaced with an overrides array targeting STORIES_GLOBS. In the flat config and its generator script, a files field with STORIES_GLOBS is added to the rules entry. These changes ensure the csf-strict rule set applies only to files matching .stories. and .story. patterns across ts/tsx/js/jsx/mjs/cjs. Export signatures update accordingly where the config shape changes from rules to overrides. Possibly related issues
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-09-17T08:11:04.287ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (4)
Comment |
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
|
View your CI Pipeline Execution ↗ for commit 47d8e38
☁️ Nx Cloud last updated this comment at |
ESLint: Only apply csf-strict rules on stories files (cherry picked from commit d1b4c2f)
Closes storybookjs/eslint-plugin-storybook#155
What I did
Updated csf-strict rules to apply on stories files. This is to fix csf-strict from disabling 'react-hooks/rules-of-hooks' and 'import/no-anonymous-default-export' for an entire project.
This updates and moves a PR the was previously opened in the eslint-plugin-storybook repo.
storybookjs/eslint-plugin-storybook#201
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
Updates the ESLint csf-strict configuration to properly scope rules to story files only, fixing incorrect project-wide rule application.
code/lib/eslint-plugin/src/configs/csf-strict.tsto target only*.stories.*and*.story.*files using overridesreact-hooks/rules-of-hooksandimport/no-anonymous-default-exportrules across entire projectsSummary by CodeRabbit