storybookjs / eslint-plugin-storybook

🎗Official ESLint plugin for Storybook
MIT License
238 stars 42 forks source link

Use string literal names rule #117

Open Dschungelabenteuer opened 1 year ago

Dschungelabenteuer commented 1 year ago

Issue: #111

What Changed

Documentation and any plain english content may need to be rephrased.

Checklist

Check the ones applicable to your change:

Change Type

Indicate the type of change your pull request is:

yannbf commented 1 year ago

This is fantastic @Dschungelabenteuer ! I made a few tweaks and added a few more test cases which we need to support. Can you take a look?

Dschungelabenteuer commented 1 year ago

@yannbf It looks good to me, should I go green? I'll work something out :)

Dschungelabenteuer commented 1 year ago

Sorry for being that long to address these cases @yannbf, I've been a bit busy lately!

While taking a look at some other issues (including #28 and #67 you mentioned on Discord), I ended up being a bit more ambitious than just addressing the original issue and its test cases.

I definitely wanted to have a generic, easy and re-usable way of restricting validation logic to stories and their properties. I came up with some wrapper function which abstracts the whole process of "figuring out whether we're in a Story context" and exposes a very simple API to get stories and story properties. You can even filter them, which can come handy as illustrated by the use-string-literal-names rule, which specifically targets both name and storyName properties. A few notes:

I believe this could make writing new rules much easier, and bring in a bit of confidence about what's going on under the hood. The rule I've wrote to address the original issue now just holds in <50 LOC! However, I could not come up with any good approach on how to unit test the wrapper, which kind of upsets me!

I'd love to get your insight!