storybookjs / eslint-plugin-storybook

🎗Official ESLint plugin for Storybook
MIT License
245 stars 52 forks source link

CSF default export with spreaded-in properties throws error #78

Closed sbolz closed 1 year ago

sbolz commented 2 years ago

Describe the bug When spreading in an object into the default export of a stories-file, I noticed that at least the title property must be set directly, or else the eslint process will throw an error: Cannot read property 'name' of undefined and the whole linting process is terminated.

To Reproduce A minimal reproduction can be achieved by exporting the default export like this:

const storyTemplate = {
  title: "My Component",
  component: "my-component", // this line is not even necessary
};

export default {
  ...storyTemplate,
};

When running eslint, this will throw an error: Cannot read property 'name' of undefined (pointing to the line of the default export).

Linting will not break if you add in the "title" field:

export default {
  title: storyTemplate.title, // without this line, eslint rules for storybook will break
  ...storyTemplate,
};

Linting will also break, if the above title line is added after the spreaded-in ...storyTemplate:

export default {
  ...storyTemplate,
  title: storyTemplate.title, // this will break
};

Expected behavior Linting should not throw an Error

Additional context I'm using Storybook 6.4.9 for web-components and eslint-plugin-storybook 0.5.6

yannbf commented 1 year ago

This issue was fixed in v0.5.7. Thanks for reporting it!