Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-storybook

storybookjs8.8mMIT0.11.2TypeScript support: included

Best practice rules for Storybook

eslint, eslintplugin, eslint-plugin, storybook

readme

Storybook

Build bulletproof UI components faster


Storybook Community Backers on Open Collective Sponsors on Open Collective Official Twitter Handle

eslint-plugin-storybook

Best practice rules for Storybook

Installation

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'],
  },
]

ESLint compatibility

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

Usage

Configuration (.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.

Overriding/disabling rules

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',
      }
    }
  ]
}

Configuration (eslint.config.[c|m]?js)

Use eslint.config.[c|m]?js file to configure rules. 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 ...
]

Overriding/disabling rules

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 ...
]

MDX Support

This plugin does not support MDX files.

Supported Rules and configurations

Key: 🔧 = fixable

Configurations: csf, csf-strict, addon-interactions, recommended

Name Description 🔧 Included in configurations
storybook/await-interactions Interactions should be awaited 🔧
  • addon-interactions
  • flat/addon-interactions
  • recommended
  • flat/recommended
storybook/context-in-play-function Pass a context when invoking play function of another story |
  • recommended
  • flat/recommended
  • addon-interactions
  • flat/addon-interactions
storybook/csf-component The component property should be set |
  • csf
  • flat/csf
  • csf-strict
  • flat/csf-strict
storybook/default-exports Story files should have a default export 🔧
  • csf
  • flat/csf
  • recommended
  • flat/recommended
  • csf-strict
  • flat/csf-strict
storybook/hierarchy-separator Deprecated hierarchy separator in title property 🔧
  • csf
  • flat/csf
  • recommended
  • flat/recommended
  • csf-strict
  • flat/csf-strict
storybook/meta-inline-properties Meta should only have inline properties | N/A
storybook/no-redundant-story-name A story should not have a redundant name property 🔧
  • csf
  • flat/csf
  • recommended
  • flat/recommended
  • csf-strict
  • flat/csf-strict
storybook/no-stories-of storiesOf is deprecated and should not be used |
  • csf-strict
  • flat/csf-strict
storybook/no-title-property-in-meta Do not define a title in meta 🔧
  • csf-strict
  • flat/csf-strict
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. |
  • recommended
  • flat/recommended
storybook/prefer-pascal-case Stories should use PascalCase 🔧
  • recommended
  • flat/recommended
storybook/story-exports A story file must contain at least one story export |
  • recommended
  • flat/recommended
  • csf
  • flat/csf
  • csf-strict
  • flat/csf-strict
storybook/use-storybook-expect Use expect from @storybook/test or @storybook/jest 🔧
  • addon-interactions
  • flat/addon-interactions
  • recommended
  • flat/recommended
storybook/use-storybook-testing-library Do not use testing-library directly on stories 🔧
  • addon-interactions
  • flat/addon-interactions
  • recommended
  • flat/recommended

Contributors

Looking into improving this plugin? That would be awesome! Please refer to the contributing guidelines for steps to contributing.

License

MIT

changelog

v0.11.2 (Thu Jan 02 2025)

🐛 Bug Fix

Authors: 2


v0.11.1 (Tue Nov 19 2024)

🐛 Bug Fix

Authors: 1


v0.11.0 (Mon Nov 04 2024)

🚀 Enhancement

  • Generate Typescript types for flat configs #180 (@yannbf)

🐛 Bug Fix

  • Update docs to be more clear about extended categories #179 (@yannbf)
  • chore: Update the link for eslintignore doc #163 (@tunawasabi)

Authors: 2


v0.10.2 (Fri Nov 01 2024)

🐛 Bug Fix

  • Fix: Bring back non-categorized rules #176 (@yannbf)
  • Build: Refactor, fix issues reported by eslint and format md files #175 (@yannbf)

Authors: 1


v0.10.1 (Mon Oct 21 2024)

🐛 Bug Fix

Authors: 1


v0.10.0 (Mon Oct 21 2024)

🚀 Enhancement

Authors: 3


v0.9.0 (Thu Sep 26 2024)

🚀 Enhancement

  • use-storybook-expect: remove auto fix suggestion #165 (@yannbf)

🐛 Bug Fix

Authors: 3


v0.8.0 (Fri Feb 16 2024)

🚀 Enhancement

🐛 Bug Fix

Authors: 1


v0.7.0 (Fri Feb 16 2024)

🚀 Enhancement

Authors: 1


v0.6.15 (Sun Oct 08 2023)

🐛 Bug Fix

  • no-uninstalled-addons: support satisfies operator and default reexport #139 (@hjoelh)

Authors: 1


v0.6.14 (Wed Sep 20 2023)

🐛 Bug Fix

  • use-storybook-expect: allow storybook/test imports #141 (@yannbf)

Authors: 1


v0.6.13 (Thu Jul 20 2023)

⚠️ Pushed to main

Authors: 1


v0.6.12 (Wed May 03 2023)

🐛 Bug Fix

📝 Documentation

Authors: 3


v0.6.11 (Tue Feb 21 2023)

🐛 Bug Fix

Authors: 2


v0.6.10 (Tue Jan 10 2023)

🐛 Bug Fix

Authors: 2


v0.6.9 (Tue Jan 10 2023)

🐛 Bug Fix

Authors: 1


v0.6.8 (Mon Dec 05 2022)

🐛 Bug Fix

Authors: 2


v0.6.7 (Tue Nov 01 2022)

🐛 Bug Fix

Authors: 2


v0.6.6 (Tue Oct 11 2022)

🐛 Bug Fix

Authors: 2


v0.6.5 (Mon Oct 10 2022)

Release Notes

story-exports: provide better feedback when using filters (#107)

The story-exports rule now detects whether you are using includeStories/excludeStories and provides a more helpful message in case there are not exported stories. A possible scenario is you have a typo in your includeStories which will result in Storybook not including it:

export default {
  title: 'Button',
  includeStories: ['myStory'], // <-- notice the lowercase m, which won't match with the story name
}

export const MyStory = {}

🐛 Bug Fix

  • story-exports: provide better feedback when using filters #107 (@yannbf)

Authors: 1


v0.6.4 (Mon Aug 08 2022)

🐛 Bug Fix

  • no-uninstalled-addons: improve local addons filter #105 (@yannbf)

Authors: 1


v0.6.3 (Wed Aug 03 2022)

🐛 Bug Fix

Authors: 1


v0.6.2 (Tue Aug 02 2022)

Release Notes

feat(no-uninstalled-addons): add option for a custom package.json location (#102)

feat(no-uninstalled-addons): add option for a custom package.json location (#102)


🐛 Bug Fix

Authors: 2


v0.6.1 (Tue Jul 12 2022)

🐛 Bug Fix

  • fix(no-uninstalled-addons): ignore local addons #98 (@yannbf)

Authors: 1


v0.6.0 (Sun Jul 10 2022)

🚀 Enhancement

Authors: 2


v0.5.13 (Fri Jun 24 2022)

⚠️ Pushed to main

  • docs(CONTRIBUTING): add more test instructions [skip-ci] (@yannbf)

Authors: 1


v0.5.12 (Tue May 17 2022)

🐛 Bug Fix

Authors: 1


v0.5.11 (Wed Apr 20 2022)

🐛 Bug Fix

Authors: 1


v0.5.10 (Sat Apr 16 2022)

🐛 Bug Fix

  • feat(default-exports): add autofix even if component name is not found #90 (@yannbf)
  • fix(story-exports): stop highlighting the entire code on error #91 (@yannbf)

Authors: 1


v0.5.9 (Fri Apr 15 2022)

🐛 Bug Fix

Authors: 2


v0.5.8 (Thu Apr 07 2022)

🐛 Bug Fix

Authors: 1


v0.5.7 (Thu Feb 17 2022)

🐛 Bug Fix

📝 Documentation

  • fix syntax of code example in docs: hierarchy-separator #79 (@aurmer)

Authors: 2


v0.5.6 (Wed Jan 19 2022)

🐛 Bug Fix

📝 Documentation

Authors: 2


v0.5.5 (Mon Dec 20 2021)

🐛 Bug Fix

  • no-redundant-story-name: use same naming algorithm as storybook #69 (@yannbf)
  • fix: gracefully handle dynamic values in non-story exports configuration #68 (@yannbf)

Authors: 1


v0.5.4 (Mon Dec 20 2021)

🐛 Bug Fix

  • story-exports: Support stories that are function declarations. #66 (@etlovett)
  • chore: add linear to gh actions #64 (@yannbf)

⚠️ Pushed to main

  • Update linear-export.yml (@yannbf)

Authors: 2


v0.5.3 (Fri Dec 03 2021)

🐛 Bug Fix

Authors: 2


v0.5.2 (Thu Dec 02 2021)

🐛 Bug Fix

Authors: 2


v0.5.1 (Mon Nov 29 2021)

🐛 Bug Fix

  • Fix: define hasSuggestions to all fixable rules #55 (@yannbf)

Authors: 1


v0.5.0 (Tue Nov 23 2021)

🚀 Enhancement

  • Rule: pass context when invoking play #53 (@yannbf)

Authors: 1


v0.4.2 (Fri Nov 19 2021)

🐛 Bug Fix

Authors: 2


v0.4.1 (Sat Nov 13 2021)

🐛 Bug Fix

  • Unify documentation to use @storybook/jest #46 (@IanVS)

Authors: 1


v0.4.0 (Fri Nov 12 2021)

🚀 Enhancement

🐛 Bug Fix

  • docs(README): add overrides section #43 (@yannbf)

Authors: 1


v0.3.5 (Thu Nov 11 2021)

🐛 Bug Fix

Authors: 1


v0.3.4 (Thu Nov 11 2021)

🐛 Bug Fix

Authors: 1


v0.3.2 (Thu Nov 11 2021)

🐛 Bug Fix

  • ignore storiesOf in default-export and prefer-pascal-case #39 (@yannbf)
  • prefer-pascal-case: ignore stories that start with underscore #38 (@yannbf)

Authors: 1


v0.3.1 (Thu Nov 11 2021)

🐛 Bug Fix

  • hierarchy-separator: remove dot from checkings #37 (@yannbf)

Authors: 1


v0.3.0 (Thu Nov 11 2021)

🚀 Enhancement

  • Add autofix heuristics for default-exports rule #36 (@shilman)

🐛 Bug Fix

⚠️ Pushed to main

Authors: 4