JSPM

eslint-plugin-storybook

0.0.1-alpha.7
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4054363
  • Score
    100M100P100Q178987F
  • License MIT

Best practice rules for Storybook

Package Exports

  • eslint-plugin-storybook

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-storybook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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 i eslint --save-dev

Next, install eslint-plugin-storybook:

npm install eslint-plugin-storybook --save-dev

Usage

Add storybook to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["storybook"]
}

Then, define which rule configurations to extend in your eslint file. Before that, it's important to understand that Storybook linting rules should only be applied in your stories files. You don't want rules to affect your other files such as production or test code as the rules might conflict with rules from other ESLint plugins.

Run the plugin only against story files

We don't want eslint-plugin-storybook to run against your whole codebase. To run this plugin only against your stories files, you have the following options:

ESLint overrides

One way of restricting ESLint config by file patterns is by using ESLint overrides.

Assuming you are using the recommended .stories extension in your files, the following config would run eslint-plugin-storybook only against your stories files:

// .eslintrc
{
  // 1) Here we have our usual config which applies to the whole project, so we don't put storybook preset here.
  "extends": ["airbnb", "plugin:prettier/recommended"],

  // 2) We load eslint-plugin-storybook globally with other ESLint plugins.
  "plugins": ["react-hooks", "storybook"],

  "overrides": [
    {
      // 3) Now we enable eslint-plugin-storybook rules or preset only for matching files!
      // you can use the one defined in your main.js
      "files": ['src/**/*.stories.@(js|jsx|ts|tsx)'],
      "extends": ["plugin:storybook/recommended"],

      // 4) Optional: you can override specific rules here if you want. Else delete this
      "rules": {
        'storybook/no-redundant-story-name': 'error'
      }
    },
  ],
};

ESLint Cascading and Hierarchy

Another approach for customizing ESLint config by paths is through ESLint Cascading and Hierarchy. This is useful if all your stories are placed under the same folder, so you can place there another .eslintrc where you enable eslint-plugin-storybook for applying it only to the files under such folder, rather than enabling it on your global .eslintrc which would apply to your whole project.

Supported Rules

Key: 🔧 = fixable

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

Name Description 🔧 Included in configurations
storybook/await-interactions Interactions should be awaited 🔧 addon-interactions, recommended
storybook/csf-component The component property should be set csf
storybook/default-exports Story files should have a default export csf, recommended
storybook/hierarchy-separator Deprecated hierachy separator in title property 🔧 csf, recommended
storybook/no-redundant-story-name A story should not have a redundant name property 🔧 csf, recommended
storybook/no-stories-of storiesOf is deprecated and should not be used csf-strict
storybook/no-title-property-in-meta Do not define a title in meta 🔧 csf-strict
storybook/prefer-pascal-case Stories should use PascalCase 🔧 recommended
storybook/use-storybook-expect Use expect from @storybook/jest 🔧 addon-interactions, recommended
storybook/use-storybook-testing-library Do 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.