Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions code/lib/eslint-plugin/docs/rules/await-interactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

## Rule Details

Storybook provides an instrumented version of testing library in the [@storybook/test](https://github.com/storybookjs/storybook/tree/next/code/core/src/test) library (formerly available in [@storybook/testing-library](https://github.com/storybookjs/testing-library/) library). When [writing interactions](https://storybook.js.org/docs/essentials/interactions), make sure to **await** them, so that addon-interactions can intercept these helper functions and allow you to step through them when debugging.
Storybook provides an instrumented version of the testing library in the [storybook/test](https://github.com/storybookjs/storybook/tree/next/code/core/src/test) core package (formerly available in [@storybook/testing-library](https://github.com/storybookjs/testing-library/)). When [writing interactions](https://storybook.js.org/docs/writing-tests/interaction-testing#writing-interaction-tests), make sure to **await** them, so that addon-interactions can intercept these helper functions and allow you to step through them when debugging.

Examples of **incorrect** code for this rule:

```js
import { userEvent, within } from '@storybook/test';
import { userEvent, within } from 'storybook/test';

// or from the legacy package "@storybook/testing-library";

Expand All @@ -27,7 +27,7 @@ MyStory.play = (context) => {
Examples of **correct** code for this rule:

```js
import { userEvent, within } from '@storybook/test';
import { userEvent, within } from 'storybook/test';

// or from the legacy package "@storybook/testing-library";

Expand All @@ -40,4 +40,4 @@ MyStory.play = async (context) => {

## When Not To Use It

This rule should not be applied in test files. Please ensure you are defining the storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).
This rule should not be applied in test files. Please ensure you are defining the Storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ MyStory.play = ({ context, canvasElement }) => {

## When Not To Use It

This rule should not be applied in test files. Please ensure you are defining the storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).
This rule should not be applied in test files. Please ensure you are defining the Storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).
6 changes: 3 additions & 3 deletions code/lib/eslint-plugin/docs/rules/csf-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Rule Details

This rule encourages you to set the `component` property of your CSF default export. The `component` property is optional, but configuring unlocks a variety of features in Storybook, including automatic prop table documentation in most frameworks, auto-generated controls for dynamically editing your stories, and in CSF3, a resonable default for rendering your component without having to define a render function.
This rule encourages you to set the `component` property of your CSF default export. The `component` property is optional, but configuring it unlocks a variety of features in Storybook, including automatic prop table documentation in most frameworks, auto-generated controls for dynamically editing your stories, and, in CSF3, a reasonable default for rendering your component without having to define a render function.

Examples of **incorrect** code for this rule:

Expand All @@ -29,8 +29,8 @@ export default {

## When Not To Use It

While we encourage each CSF file to clearly correspond to a single component, it's possible to organize a Storybook in any way you choose. If you have some other organization scheme, this rule might not apply to you.
While we encourage each CSF file to clearly correspond to a single component, it's possible to organize a Storybook in any way you choose. If you have a different organizational scheme, this rule may not apply to you.

## Further Reading

- [Automatic argType inference](https://storybook.js.org/docs/api/argtypes#automatic-argtype-inference)
- [Automatic argType inference](https://storybook.js.org/docs/api/arg-types#automatic-argtype-inference)
2 changes: 1 addition & 1 deletion code/lib/eslint-plugin/docs/rules/default-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Primary = {};

## When Not To Use It

This rule should only be applied in your `.stories.*` files. Please ensure you are defining the storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).
This rule should only be applied in your `.stories.*` files. Please ensure that you define the Storybook rules only for story files. You can see more details [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).

If you're using Storybook 6.5 and [CSF in MDX](https://github.com/storybookjs/storybook/blob/v6.5.0/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs), you should disable this rule for the stories that use CSF in MDX. You can see how to override the rule [here](https://github.com/storybookjs/storybook/blob/next/code/lib/eslint-plugin#overridingdisabling-rules).

Expand Down
2 changes: 1 addition & 1 deletion code/lib/eslint-plugin/docs/rules/hierarchy-separator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Rule Details

Since Storybook 6.0, the ability to specify the hierarchy separators (how you control the grouping of story kinds in the sidebar) was removed. There is now a single separator `/`, which cannot be configured. If you are using `|` or `.` as a separator, you should change all of them to `/`.
Since Storybook 6.0, the ability to specify the hierarchy separators (how you control the grouping of story kinds in the sidebar) has been removed. There is now a single separator `/`, which cannot be configured. If you are using `|` or `.` as a separator, you should change all of them to `/`.

Examples of **incorrect** code for this rule:

Expand Down
6 changes: 3 additions & 3 deletions code/lib/eslint-plugin/docs/rules/meta-satisfies-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

## Rule Details

This rule enforces writing `satisfies Meta` after the meta object definition. This is useful to ensure that stories use the correct properties in the metadata.
This rule enforces writing `satisfies Meta` after the definition of the meta object. This is useful to ensure that stories use the correct properties in the metadata.

Additionally, `satisfies` is preferred over type annotations (`const meta: Meta = {...}`) and type assertions (`const meta = {...} as Meta`). This is because other types like `StoryObj` will check to see which properties are defined in meta and use it for increased type safety. Using type annotations or assertions hides this information from the type-checker, so satisfies should be used instead.
Additionally, `satisfies` is preferred over type annotations (`const meta: Meta = {...}`) and type assertions (`const meta = {...} as Meta`). This is because other types like `StoryObj` will check to see which properties are defined in meta and use them for increased type safety. Using type annotations or assertions hides this information from the type-checker, so `satisfies` should be used instead.

Examples of **incorrect** code for this rule:

Expand Down Expand Up @@ -56,4 +56,4 @@ If you aren't using TypeScript or you're using a version older than TypeScript 4

## Further Reading

- [Improved type safety in Storybook 7](https://storybook.js.org/blog/improved-type-safety-in-storybook-7/?ref=storybookblog.ghost.io)
More information on writing stories with TypeScript: https://storybook.js.org/docs/writing-stories/typescript
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export const PrimaryButton = {

## When Not To Use It

When you set a custom name for a story, it will make sure that the resolved story name will always be that same name, regardless if you rename the export later on. If that is your reason to keep story names set even if they are redundant, you should turn this rule off.
When you set a custom name for a story, it will ensure that the resolved story name will always be that same name, regardless of whether you rename the export later on. If that is your reason for keeping story names set, even if they are redundant, you should turn this rule off.
30 changes: 15 additions & 15 deletions code/lib/eslint-plugin/docs/rules/no-renderer-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

## Rule Details

This rule prevents importing Storybook renderer packages directly in stories. Instead, you should use framework-specific packages that are designed for your build tool (e.g., Vite, webpack).
This rule prevents importing Storybook renderer packages directly into stories. Instead, use framework-specific packages designed for your build tool (e.g., Vite, Webpack).

The rule will suggest appropriate framework packages based on which renderer you're trying to use:

- For `@storybook/html`: Use `@storybook/html-vite` or `@storybook/html-webpack5`
- For `@storybook/preact`: Use `@storybook/preact-vite` or `@storybook/preact-webpack5`
- For `@storybook/react`: Use `@storybook/nextjs`, `@storybook/react-vite`, `@storybook/react-webpack5`, `@storybook/react-native-web-vite`, or `@storybook/experimental-nextjs-vite`
- For `@storybook/html`: Use `@storybook/html-vite`
- For `@storybook/preact`: Use `@storybook/preact-vite`
- For `@storybook/react`: Use `@storybook/nextjs`, `@storybook/nextjs-vite`, `@storybook/react-vite`, `@storybook/react-webpack5`, or `@storybook/react-native-web-vite`
- For `@storybook/server`: Use `@storybook/server-webpack5`
- For `@storybook/svelte`: Use `@storybook/svelte-vite`, `@storybook/svelte-webpack5`, or `@storybook/sveltekit`
- For `@storybook/vue3`: Use `@storybook/vue3-vite` or `@storybook/vue3-webpack5`
- For `@storybook/web-components`: Use `@storybook/web-components-vite` or `@storybook/web-components-webpack5`
- For `@storybook/svelte`: Use `@storybook/svelte-vite`, or `@storybook/sveltekit`
- For `@storybook/vue3`: Use `@storybook/vue3-vite`
- For `@storybook/web-components`: Use `@storybook/web-components-vite`

Examples of **incorrect** code for this rule:

Expand All @@ -34,22 +34,22 @@ Examples of **correct** code for this rule:
```js
// Do use the appropriate framework package for your build tool
import { something } from '@storybook/react-vite'; // For Vite
import { something } from '@storybook/vue3-webpack5'; // For Webpack 5
import { something } from '@storybook/vue3-vite'; // For Vite
import { something } from '@storybook/web-components-vite'; // For Vite
import { something } from '@storybook/nextjs'; // For Next.js
```

## When Not To Use It

If you have a specific need to use renderer packages directly in your stories, you can disable this rule. However, it's recommended to use the framework-specific packages as they are optimized for your build tool and provide better integration with your development environment.
If you have a specific need to use renderer packages directly in your stories, you can turn off this rule. However, it's recommended to use the framework-specific packages as they are optimized for your build tool and provide better integration with your development environment.

## Further Reading

For more information about Storybook's framework-specific packages and build tools, see:

- [Storybook for React](https://storybook.js.org/docs/react/get-started/install)
- [Storybook for Vue](https://storybook.js.org/docs/vue/get-started/install)
- [Storybook for Web Components](https://storybook.js.org/docs/web-components/get-started/install)
- [Storybook for Svelte](https://storybook.js.org/docs/svelte/get-started/install)
- [Storybook for HTML](https://storybook.js.org/docs/html/get-started/install)
- [Storybook for Preact](https://storybook.js.org/docs/preact/get-started/install)
- [Storybook for React](https://storybook.js.org/docs/get-started/frameworks/react-vite)
- [Storybook for Vue](https://storybook.js.org/docs/get-started/frameworks/vue3-vite)
- [Storybook for Web Components](https://storybook.js.org/docs/get-started/frameworks/web-components-vite)
- [Storybook for Svelte](https://storybook.js.org/docs/get-started/frameworks/svelte-vite)
- [Storybook for HTML](https://storybook.js.org/docs/get-started/install?renderer=html)
- [Storybook for Preact](https://storybook.js.org/docs/get-started/frameworks/preact-vite)
2 changes: 1 addition & 1 deletion code/lib/eslint-plugin/docs/rules/no-stories-of.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Rule Details

Since Storybook 5.2, the [CSF format](https://storybook.js.org/docs/api/csf) was introduced and the `storiesOf` API has been deprecated.
Starting with Storybook 5.2, the Component Story Format ([CSF](https://storybook.js.org/docs/api/csf)) was introduced as the preferred way to write stories. The `storiesOf` API is now removed and should be avoided in favor of CSF.

Examples of **incorrect** code for this rule:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Rule Details

Starting in [CSF 3.0](https://storybook.js.org/blog/component-story-format-3-0/), story titles can be generated automatically. You can still specify a title like in CSF 2.0, but if you don't specify one, it can be inferred from the story's path on disk.
Starting in [CSF 3.0](https://storybook.js.org/blog/storybook-csf3-is-here/), story titles can be generated automatically. You can still specify a title like in CSF 2.0, but if you don't define it, it can be inferred from the story's path on disk.
This rule aims to enforce not setting a title, making the codebase consistent.

Examples of **incorrect** code for this rule:
Expand All @@ -30,7 +30,7 @@ export default {

## When Not To Use It

If you're not strictly enforcing this rule in your codebase (thus allowing custom titles), you should turn this rule off.
If you're not strictly enforcing this rule in your codebase (thus allowing custom titles), you should turn off this rule.

## Further Reading

Expand Down
29 changes: 13 additions & 16 deletions code/lib/eslint-plugin/docs/rules/no-uninstalled-addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

## Rule Details

This rule checks if all addons registered in `.storybook/main.js` are properly listed in the root `package.json` of your project.
This rule checks if all addons registered in `.storybook/main.js|ts` are properly listed in the root `package.json` of your project.

For instance, if the `@storybook/addon-links` is in the `.storybook/main.js` but is not listed in the `package.json` of the project, this rule will notify the user to add the addon to the `package.json` and install it.
For instance, if the `@storybook/addon-links` is in the `.storybook/main.js|ts` file but is not listed in the project's `package.json`, this rule will notify the user to install it.

As an important side note, this rule will check for the `package.json` in the **root level** of your project. You can customize the location of the `package.json` by [setting the `packageJsonLocation` option](#configure).
As an important side note, this rule checks for the `package.json` file at the **root level** of your project. You can customize the location of the `package.json` by [setting the `packageJsonLocation` option](#configure).

Another very important side note: your ESLint config must allow the linting of the `.storybook` folder. By default, ESLint ignores all dot-files so this folder will be ignored. In order to allow this rule to lint the `.storybook/main.js` file, it's important to configure ESLint to lint this file. This can be achieved by writing something like:
Another very important side note: your ESLint config must allow linting the `.storybook` folder. By default, ESLint ignores all dot-files, so this folder will be ignored. To allow this rule to lint the `.storybook/main.js` file, it's essential to configure ESLint to lint this file. This can be achieved by writing something like:

```
// Inside your .eslintignore file
Expand All @@ -30,16 +30,15 @@ Examples of **incorrect** code for this rule:
module.exports = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions', // <-- this addon is not listed in the package.json
'@storybook/addon-a11y', // <-- this addon is not listed in the package.json
],
}

// package.json
{
"devDependencies": {
"@storybook/addon-links": "0.0.1",
"@storybook/addon-essentials": "0.0.1",
"@storybook/addon-a11y": "0.0.1",
}
}
```
Expand All @@ -51,17 +50,15 @@ Examples of **correct** code for this rule:
module.exports = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-a11y',
],
}

// package.json
{
"devDependencies": {
"@storybook/addon-links": "0.0.1",
"@storybook/addon-essentials": "0.0.1",
"@storybook/addon-interactions": "0.0.1"
"@storybook/addon-a11y": "0.0.1"
}
}
```
Expand All @@ -80,11 +77,11 @@ module.exports = {
};
```

Note that the path must be relative to where ESLint runs from, which is usually relative to the root of the project.
Note that the path must be relative to the location from which ESLint runs, which is typically the root of the project.

#### `ignore`

You can also ignore certain addons by providing an ignore array in the options:
You can also ignore specific addons by providing an ignore array in the options:

```js
module.exports = {
Expand All @@ -100,9 +97,9 @@ module.exports = {
};
```

### What if I use a different storybook config directory?
### What if I use a different Storybook config directory?

Some Storybook folders use a different name for their config directory other than `.storybook`. This rule will not be applied there by default. If you have a custom location for your storybook config directory, then you must add an override in your `.eslintrc.js` file, defining your config directory:
Some Storybook folders use a different name for their config directory other than `.storybook`. This rule will not be applied there by default. If you have a custom location for your Storybook config directory, then you must add an override in your `.eslintrc.js` file, defining your config directory:

```js
{
Expand All @@ -119,7 +116,7 @@ Some Storybook folders use a different name for their config directory other tha

## When Not To Use It

This rule is very handy to be used because if the user tries to start storybook but has forgotten to install the plugin, storybook will throw very weird errors that will give no clue to the user to what's going wrong. To prevent that, this rule should be always on.
This rule is convenient to use because if the user tries to start Storybook but has forgotten to install the plugin, Storybook will throw very unusual errors that provide no clue to the user about what's going wrong. To prevent that, this rule should always be on.

## Further Reading

Expand Down
2 changes: 1 addition & 1 deletion code/lib/eslint-plugin/docs/rules/prefer-pascal-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Rule Details

As a best practice, stories should be defined in [_PascalCase_](https://en.wiktionary.org/wiki/Pascal_case). This makes it simpler to visually differ stories to other code. Plus, it makes it simpler to define regexes for [non-story exports](https://storybook.js.org/docs/api/csf#non-story-exports).
As a best practice, stories should be defined in [_PascalCase_](https://en.wiktionary.org/wiki/Pascal_case). This makes it easier to differentiate stories from other code visually. Plus, it makes it simpler to define regexes for [non-story exports](https://storybook.js.org/docs/api/csf#non-story-exports).

Examples of **incorrect** code for this rule:

Expand Down
Loading