Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: make rule fixable
  • Loading branch information
cylewaitforit committed May 31, 2025
commit bc91687fe44617a534d0e03bc8a34c8ce9634dd4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ This plugin does not support MDX files.
| [`storybook/no-stories-of`](./docs/rules/no-stories-of.md) | storiesOf is deprecated and should not be used | | <ul><li>csf-strict</li><li>flat/csf-strict</li></ul> |
| [`storybook/no-title-property-in-meta`](./docs/rules/no-title-property-in-meta.md) | Do not define a title in meta | 🔧 | <ul><li>csf-strict</li><li>flat/csf-strict</li></ul> |
| [`storybook/no-uninstalled-addons`](./docs/rules/no-uninstalled-addons.md) | This rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name. | | <ul><li>recommended</li><li>flat/recommended</li></ul> |
| [`storybook/only-csf3`](./docs/rules/only-csf3.md) | Enforce Component Story Format 3.0 (CSF3) for stories | | N/A |
| [`storybook/only-csf3`](./docs/rules/only-csf3.md) | Enforce Component Story Format 3.0 (CSF3) for stories | 🔧 | N/A |
| [`storybook/prefer-pascal-case`](./docs/rules/prefer-pascal-case.md) | Stories should use PascalCase | 🔧 | <ul><li>recommended</li><li>flat/recommended</li></ul> |
| [`storybook/story-exports`](./docs/rules/story-exports.md) | A story file must contain at least one story export | | <ul><li>recommended</li><li>flat/recommended</li><li>csf</li><li>flat/csf</li><li>csf-strict</li><li>flat/csf-strict</li></ul> |
| [`storybook/use-storybook-expect`](./docs/rules/use-storybook-expect.md) | Use expect from `@storybook/test`, `storybook/test` or `@storybook/jest` | 🔧 | <ul><li>addon-interactions</li><li>flat/addon-interactions</li><li>recommended</li><li>flat/recommended</li></ul> |
Expand Down
30 changes: 28 additions & 2 deletions docs/rules/only-csf3.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export const Tertiary = () => <Button>Click me</Button>
export const WithArgs = Template.bind({})
WithArgs.args = { label: 'With Args' }
WithArgs.parameters = { layout: 'centered' }

// ❌ CSF2: Template.bind({}) with multiple stories
const Template = (args) => <Button {...args} />

export const Primary = Template.bind({})
Primary.args = { label: 'Primary', variant: 'primary' }
Primary.parameters = { backgrounds: { default: 'light' } }

export const Secondary = Template.bind({})
Secondary.args = { label: 'Secondary', variant: 'secondary' }
Secondary.parameters = { backgrounds: { default: 'dark' } }
```

Examples of **correct** code:
Expand All @@ -48,6 +59,21 @@ export const Primary = {
export const Secondary = {
render: (args) => <Button {...args}>Secondary</Button>,
}

// ✅ CSF3: Multiple stories sharing render logic
const render = (args) => <Button {...args} />

export const Primary = {
render,
args: { label: 'Primary', variant: 'primary' },
parameters: { backgrounds: { default: 'light' } },
}

export const Secondary = {
render,
args: { label: 'Secondary', variant: 'secondary' },
parameters: { backgrounds: { default: 'dark' } },
}
```

## When Not To Use It
Expand All @@ -68,8 +94,8 @@ Primary.args = { label: 'Primary' }

// ✅ CSF3
export const Primary = {
args: { label: 'Primary' },
render: (args) => <Button {...args} />,
args: { label: 'Primary' },
}
```

Expand Down Expand Up @@ -104,6 +130,7 @@ Primary.decorators = [

// ✅ CSF3
export const Primary = {
render: (args) => <Button {...args} />,
args: { label: 'Primary' },
parameters: { layout: 'centered' },
decorators: [
Expand All @@ -113,7 +140,6 @@ export const Primary = {
</div>
),
],
render: (args) => <Button {...args} />,
}
```

Expand Down
Loading