storybookjs / eslint-plugin-storybook

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

context-in-play-function support only "context" as a variable name #118

Closed beaussan closed 1 year ago

beaussan commented 1 year ago

Describe the bug Context in play function only support only "context" as a variable names. Any other variable names gives a lint error.

To Reproduce Given this code :

const Story1 = Template.bind({});
Story1.play = async (ctx) => {
...
}

const Story2 = Template.bind({});
Story2.play = async (ctx) => {
    await Story1.play(ctx)
}

the lint should not fail since we are passing the context, but with a different variable name

Expected behavior There should not have any lint errors since it respects the lint rule.

yannbf commented 1 year ago

Thanks for opening this issue @beaussan! That makes total sense. Are you willing to make a PR for this? This is the place where you'd need to touch: https://github.com/storybookjs/eslint-plugin-storybook/blob/main/lib/rules/context-in-play-function.ts#L70

beaussan commented 1 year ago

I'll try yes ! I saw the file when I opened the issue and I should have some time today to at least give it a try.

I have a bit of ast / eslint knoledge, but the thing I don't know how to achieve is how to get the the name of the argument of the current function.

My first idea is to try to go up the ast tree to get the function itself, but that maybe flaky

yannbf commented 1 year ago

I always recommend trying https://astexplorer.net/ out, it helps you immensely when figuring out AST structures! And from there you can start playing around 🎡

Dschungelabenteuer commented 1 year ago

@beaussan LMK if you need any help from a french fellow

beaussan commented 1 year ago

Thanks to the both of you !

I finally got some time to work on this, and made a PR :tada:

yannbf commented 1 year ago

A fix for this was released in v0.6.11 🚀

Thanks @beaussan !!