eslint-plugin-storybook icon indicating copy to clipboard operation
eslint-plugin-storybook copied to clipboard

Add rule to prevent adding argType annotations matching actions.argTypesRegex

Open DamienCassou opened this issue 3 years ago • 0 comments

When the user specifies a value for actions.argTypesRegex such as this one (copy/pasted from the actions addon documentation):

// .storybook/preview.js

export const parameters = {
  actions: { argTypesRegex: '^on.*' }
}

then there is no need to also specify actions matching the regular expression:

// MyButton.stories.js

export default {
  title: 'Button',
  component: Button,
  argTypes: {
    onClick: { action: 'onClick' } // unnecessary because it matches `argTypesRegex`
  }
};

What about adding a rule to detect and fix such cases?

Should the rule contain a configuration argument to flag/ignore an action whose name doesn't match the parameter name such as in:

// MyButton.stories.js

export default {
  title: 'Button',
  component: Button,
  argTypes: {
    onClick: { action: 'clicked' } // clicked ≠ onClick
  }
};

DamienCassou avatar Feb 18 '22 12:02 DamienCassou