Socket
Socket
Sign inDemoInstall

eslint-plugin-storybook

Package Overview
Dependencies
129
Maintainers
2
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-storybook

Best practice rules for Storybook


Version published
Maintainers
2
Weekly downloads
1,985,279
decreased by-17.73%
Install size
5.01 MB

Weekly downloads

Package description

What is eslint-plugin-storybook?

The eslint-plugin-storybook npm package is designed to help enforce best practices and conventions for writing stories in Storybook, which is a tool for developing UI components in isolation. It provides a set of ESLint rules specifically tailored for Storybook files.

What are eslint-plugin-storybook's main functionalities?

Enforce consistent naming for story files

This rule ensures that the names of the stories are consistent with the file name.

"storybook/consistent-story-name": "error"

Require or disallow a specific structure in story files

This rule can enforce a specific structure for story exports, such as allowing only default or named exports in story files.

"storybook/story-exports": ["error", { "allow": ["default", "named"] }]

Enforce the use of Storybook's controls

This rule ensures that stories use Storybook's controls feature to allow for live customization of component props.

"storybook/use-storybook-controls": "error"

Other packages similar to eslint-plugin-storybook

Readme

Source

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.

Usage

Use .eslintrc.* file to configure rules. See also: https://eslint.org/docs/user-guide/configuring

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

MDX Support

This plugin does not support MDX files.

Supported Rules and configurations

Key: 🔧 = fixable

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

NameDescription🔧Included in configurations
storybook/await-interactionsInteractions should be awaited🔧
  • addon-interactions
  • recommended
storybook/context-in-play-functionPass a context when invoking play function of another story
  • recommended
  • addon-interactions
storybook/csf-componentThe component property should be set
  • csf
storybook/default-exportsStory files should have a default export🔧
  • csf
  • recommended
storybook/hierarchy-separatorDeprecated hierarchy separator in title property🔧
  • csf
  • recommended
storybook/no-redundant-story-nameA story should not have a redundant name property🔧
  • csf
  • recommended
storybook/no-stories-ofstoriesOf is deprecated and should not be used
  • csf-strict
storybook/no-title-property-in-metaDo not define a title in meta🔧
  • csf-strict
storybook/no-uninstalled-addonsThis rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name.
  • recommended
storybook/prefer-pascal-caseStories should use PascalCase🔧
  • recommended
storybook/story-exportsA story file must contain at least one story export
  • recommended
  • csf
storybook/use-storybook-expectUse expect from @storybook/jest🔧
  • addon-interactions
  • recommended
storybook/use-storybook-testing-libraryDo not use testing-library directly on stories🔧
  • addon-interactions
  • recommended

Contributors

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

License

MIT

Keywords

FAQs

Last updated on 16 Feb 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc