storybookjs/storybook

[Feature Request]: CSF3 Autofixer shouldn't hoist arg uses above declarations

Offen

#21.488 geöffnet am 08.03.2023

 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (10.058 Forks)batch import
bugcodemodshelp wantedsev:S3

Repository-Metriken

Stars
 (89.909 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 7T 22h) (184 gemergte PRs in 30 T)

Beschreibung

Is your feature request related to a problem? Please describe

When migrating a story defined like:

export const MyStory = (props) => <MyComponent {...props} />
const defaultArgs = { foo: 'bar'}
MyStory.args = defaultArgs

using the args is hoisted above the constant definition:

export const MyStory = {
  render: (props) => <MyComponent {...props} />,
  args: defaultArgs,
}
const defaultArgs = { foo: 'bar'}

Describe the solution you'd like

Ideally the codemod would move the constant declaration above where it was used:

const defaultArgs = { foo: 'bar'}
export const MyStory = {
  render: (props) => <MyComponent {...props} />,
  args: defaultArgs,
}

Describe alternatives you've considered

I looked, but there's not an autofixer for this in eslint or ts. I can check to see if theres an existing codemod that can help with this.

Are you able to assist to bring the feature to reality?

yes, I can

Additional context

No response

Contributor Guide