Skip to content

Commit ccba007

Browse files
committed
feat: make rule fixable
1 parent 5fa61ae commit ccba007

File tree

4 files changed

+337
-120
lines changed

4 files changed

+337
-120
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ This plugin does not support MDX files.
185185
| [`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> |
186186
| [`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> |
187187
| [`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> |
188-
| [`storybook/only-csf3`](./docs/rules/only-csf3.md) | Enforce Component Story Format 3.0 (CSF3) for stories | | N/A |
188+
| [`storybook/only-csf3`](./docs/rules/only-csf3.md) | Enforce Component Story Format 3.0 (CSF3) for stories | 🔧 | N/A |
189189
| [`storybook/prefer-pascal-case`](./docs/rules/prefer-pascal-case.md) | Stories should use PascalCase | 🔧 | <ul><li>recommended</li><li>flat/recommended</li></ul> |
190190
| [`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> |
191191
| [`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> |

docs/rules/only-csf3.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ export const Tertiary = () => <Button>Click me</Button>
3232
export const WithArgs = Template.bind({})
3333
WithArgs.args = { label: 'With Args' }
3434
WithArgs.parameters = { layout: 'centered' }
35+
36+
// ❌ CSF2: Template.bind({}) with multiple stories
37+
const Template = (args) => <Button {...args} />
38+
39+
export const Primary = Template.bind({})
40+
Primary.args = { label: 'Primary', variant: 'primary' }
41+
Primary.parameters = { backgrounds: { default: 'light' } }
42+
43+
export const Secondary = Template.bind({})
44+
Secondary.args = { label: 'Secondary', variant: 'secondary' }
45+
Secondary.parameters = { backgrounds: { default: 'dark' } }
3546
```
3647

3748
Examples of **correct** code:
@@ -48,6 +59,21 @@ export const Primary = {
4859
export const Secondary = {
4960
render: (args) => <Button {...args}>Secondary</Button>,
5061
}
62+
63+
// ✅ CSF3: Multiple stories sharing render logic
64+
const render = (args) => <Button {...args} />
65+
66+
export const Primary = {
67+
render,
68+
args: { label: 'Primary', variant: 'primary' },
69+
parameters: { backgrounds: { default: 'light' } },
70+
}
71+
72+
export const Secondary = {
73+
render,
74+
args: { label: 'Secondary', variant: 'secondary' },
75+
parameters: { backgrounds: { default: 'dark' } },
76+
}
5177
```
5278

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

6995
// ✅ CSF3
7096
export const Primary = {
71-
args: { label: 'Primary' },
7297
render: (args) => <Button {...args} />,
98+
args: { label: 'Primary' },
7399
}
74100
```
75101

@@ -104,6 +130,7 @@ Primary.decorators = [
104130

105131
// ✅ CSF3
106132
export const Primary = {
133+
render: (args) => <Button {...args} />,
107134
args: { label: 'Primary' },
108135
parameters: { layout: 'centered' },
109136
decorators: [
@@ -113,7 +140,6 @@ export const Primary = {
113140
</div>
114141
),
115142
],
116-
render: (args) => <Button {...args} />,
117143
}
118144
```
119145

0 commit comments

Comments
 (0)