storybookjs / eslint-plugin-storybook

🎗Official ESLint plugin for Storybook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

csf-strict config not scoped to story files

ahutchings opened this issue · comments

Describe the bug

I enabled the csf-strict config in my project by adding plugin:storybook/csf-strict to the extends array in .eslintrc.js.

When running ESLint, it fails with an exception:

TypeError: Cannot use 'in' operator to search for 'name' in undefined
Occurred while linting <snip>/packages/<snip>/src/index.js:12
    at <snip>/node_modules/eslint-plugin-storybook/dist/rules/no-title-property-in-meta.js:35:127
    at Array.find (<anonymous>)
    at ExportDefaultDeclaration (<snip>/node_modules/eslint-plugin-storybook/dist/rules/no-title-property-in-meta.js:35:51)
    at <snip>/node_modules/eslint/lib/util/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (<snip>/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (<snip>/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (<snip>/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (<snip>/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (<snip>/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)

This filename (src/index.js) doesn't match the patterns used by other configs (like in the csf config) so the csf-strict config must not be inheriting the scoping logic when it extends csf.

To Reproduce
Not sure exactly what syntax repros the error, but to confirm that the csf-strict config runs in non-story files, you can:

  1. Create a project with ESLint and eslint-plugin-storybook, extending the csf-strict config.
  2. Create a file in the project that does match a story file name (example: src/index.js)
  3. Export an anonymous object containing a title field.
  4. See an error due to the failing no-title-property-in-meta rule.

Expected behavior
No failing ESLint rules.

Screenshots
n/a

Additional context

eslint-plugin-storybook version 0.6.12