Skip to content

Conversation

cylewaitforit
Copy link

@cylewaitforit cylewaitforit commented Jul 6, 2025

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:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make 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/core team 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.

  • Modified code/lib/eslint-plugin/src/configs/csf-strict.ts to target only *.stories.* and *.story.* files using overrides
  • Fixed unintended disabling of react-hooks/rules-of-hooks and import/no-anonymous-default-export rules across entire projects
  • Updated both traditional and flat config generation scripts to respect story file patterns
  • Scoped rules to supported file extensions (ts, tsx, js, jsx, mjs, cjs) for better specificity

@cylewaitforit cylewaitforit changed the title fix(csf-strict): apply csf-strict rules on stories files fix(eslint-plugin): apply csf-strict rules on stories files Jul 6, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

@cylewaitforit cylewaitforit mentioned this pull request Jul 7, 2025
8 tasks
@cylewaitforit cylewaitforit changed the title fix(eslint-plugin): apply csf-strict rules on stories files ESLint: fix to only apply csf-strict rules on stories files Jul 7, 2025
@github-actions github-actions bot added the Stale label Jul 24, 2025
@cylewaitforit
Copy link
Author

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?

@valentinpalkovic
Copy link
Contributor

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)'],
Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

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.

Copy link
Author

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?

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.

csf-strict is applied on all files
4 participants