npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-storybook

v0.11.1

Published

Best practice rules for Storybook

Downloads

12,697,715

Readme

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

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-interactionsflat/addon-interactionsrecommendedflat/recommended | | storybook/context-in-play-function | Pass a context when invoking play function of another story | | recommendedflat/recommendedaddon-interactionsflat/addon-interactions | | storybook/csf-component | The component property should be set | | csfflat/csfcsf-strictflat/csf-strict | | storybook/default-exports | Story files should have a default export | 🔧 | csfflat/csfrecommendedflat/recommendedcsf-strictflat/csf-strict | | storybook/hierarchy-separator | Deprecated hierarchy separator in title property | 🔧 | csfflat/csfrecommendedflat/recommendedcsf-strictflat/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 | 🔧 | csfflat/csfrecommendedflat/recommendedcsf-strictflat/csf-strict | | storybook/no-stories-of | storiesOf is deprecated and should not be used | | csf-strictflat/csf-strict | | storybook/no-title-property-in-meta | Do not define a title in meta | 🔧 | csf-strictflat/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. | | recommendedflat/recommended | | storybook/prefer-pascal-case | Stories should use PascalCase | 🔧 | recommendedflat/recommended | | storybook/story-exports | A story file must contain at least one story export | | recommendedflat/recommendedcsfflat/csfcsf-strictflat/csf-strict | | storybook/use-storybook-expect | Use expect from @storybook/test or @storybook/jest | 🔧 | addon-interactionsflat/addon-interactionsrecommendedflat/recommended | | storybook/use-storybook-testing-library | Do not use testing-library directly on stories | 🔧 | addon-interactionsflat/addon-interactionsrecommendedflat/recommended |

Contributors

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

License

MIT