
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
eslint-plugin-storybook
Advanced tools
Storybook ESLint Plugin: Best practice rules for writing stories
Build bulletproof UI components faster
Best practice rules for Storybook
You'll first need to install ESLint:
npm install eslint --save-dev
# or
yarn add eslint --dev
Next, install eslint-plugin-storybook:
npm install eslint-plugin-storybook --save-dev
# or
yarn add eslint-plugin-storybook --dev
And finally, add this to your .eslintignore file:
// Inside your .eslintignore file
!.storybook
This allows for this plugin to also lint your configuration files inside the .storybook folder, so that you always have a correct configuration and don't face any issues regarding mistyped addon names, for instance.
For more info on why this line is required in the .eslintignore file, check this ESLint documentation.
If you are using flat config style, add this to your configuration file:
export default [
// ...
{
// Inside your .eslintignore file
ignores: ['!.storybook'],
},
];
Use the following table to use the correct version of this package, based on the version of ESLint you're using:
| ESLint version | Storybook plugin version |
|---|---|
| ^9.0.0 | ^0.10.0 |
| ^8.57.0 | ^0.10.0 |
| ^7.0.0 | ~0.9.0 |
.eslintrc)Use .eslintrc.* file to configure rules in ESLint < v9. See also: https://eslint.org/docs/latest/use/configure/.
Add plugin:storybook/recommended to the extends section of your .eslintrc configuration file. Note that we can omit the eslint-plugin- prefix:
{
// extend plugin:storybook/<configuration>, such as:
"extends": ["plugin:storybook/recommended"]
}
This plugin will only be applied to files following the *.stories.* (we recommend this) or *.story.* pattern. This is an automatic configuration, so you don't have to do anything.
Optionally, you can override, add or disable rules settings. You likely don't want these settings to be applied in every file, so make sure that you add a overrides section in your .eslintrc.* file that applies the overrides only to your stories files.
{
"overrides": [
{
// or whatever matches stories specified in .storybook/main.js
"files": ['**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)'],
"rules": {
// example of overriding a rule
'storybook/hierarchy-separator': 'error',
// example of disabling a rule
'storybook/default-exports': 'off',
}
}
]
}
eslint.config.[c|m]?js)Use eslint.config.[c|m]?js file to configure rules using the flat config style. This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
import storybook from 'eslint-plugin-storybook';
export default [
// add more generic rulesets here, such as:
// js.configs.recommended,
...storybook.configs['flat/recommended'],
// something ...
];
In case you are using utility functions from tools like tseslint, you might need to set the plugin a little differently:
import storybook from 'eslint-plugin-storybook';
import somePlugin from 'some-plugin';
import tseslint from 'typescript-eslint';
export default tseslint.config(
somePlugin,
storybook.configs['flat/recommended'] // notice that it is not destructured
);
Optionally, you can override, add or disable rules settings. You likely don't want these settings to be applied in every file, so make sure that you add a flat config section in your eslint.config.[m|c]?js file that applies the overrides only to your stories files.
import storybook from 'eslint-plugin-storybook';
export default [
// ...
...storybook.configs['flat/recommended'],
{
files: ['**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: {
// example of overriding a rule
'storybook/hierarchy-separator': 'error',
// example of disabling a rule
'storybook/default-exports': 'off',
},
},
// something ...
];
This plugin does not support MDX files.
Key: 🔧 = fixable
Configurations: csf, csf-strict, addon-interactions, recommended
| Name | Description | 🔧 | Included in configurations |
|---|---|---|---|
storybook/await-interactions | Interactions should be awaited | 🔧 |
|
storybook/context-in-play-function | Pass a context when invoking play function of another story |
| |
storybook/csf-component | The component property should be set |
| |
storybook/default-exports | Story files should have a default export | 🔧 |
|
storybook/hierarchy-separator | Deprecated hierarchy separator in title property | 🔧 |
|
storybook/meta-inline-properties | Meta should only have inline properties | N/A | |
storybook/meta-satisfies-type | Meta should use satisfies Meta | 🔧 | N/A |
storybook/no-redundant-story-name | A story should not have a redundant name property | 🔧 |
|
storybook/no-stories-of | storiesOf is deprecated and should not be used |
| |
storybook/no-title-property-in-meta | Do not define a title in meta | 🔧 |
|
storybook/no-uninstalled-addons | This rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name. |
| |
storybook/prefer-pascal-case | Stories should use PascalCase | 🔧 |
|
storybook/story-exports | A story file must contain at least one story export |
| |
storybook/use-storybook-expect | Use expect from @storybook/test, storybook/test or @storybook/jest | 🔧 |
|
storybook/use-storybook-testing-library | Do not use testing-library directly on stories | 🔧 |
|
Looking into improving this plugin? That would be awesome! Please refer to the contributing guidelines for steps to contributing.
Learn more about Storybook at storybook.js.org.
This package provides ESLint rules for React applications. It includes rules that help prevent common issues in React code. While it is not specific to Storybook, it can be used alongside eslint-plugin-storybook to enforce best practices in React components that are showcased in Storybook.
This package contains ESLint rules for accessibility in JSX elements. It helps ensure that UI components are accessible to all users, including those using assistive technologies. It complements eslint-plugin-storybook by focusing on accessibility concerns, which are also important when developing components in Storybook.
Similar to eslint-plugin-react but for Vue.js applications, this package provides a collection of ESLint rules specific to Vue.js. It helps maintain code quality and adhere to Vue.js best practices. When using Storybook with Vue.js projects, eslint-plugin-vue can be used in conjunction with eslint-plugin-storybook to ensure high-quality component code.
FAQs
Storybook ESLint Plugin: Best practice rules for writing stories
The npm package eslint-plugin-storybook receives a total of 4,039,329 weekly downloads. As such, eslint-plugin-storybook popularity was classified as popular.
We found that eslint-plugin-storybook demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.