storybookjs/storybook

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

开放

#21,488 创建于 2023年3月8日

 (2 条评论) (0 个反应) (0 位负责人)TypeScript (10,058 个派生)batch import
bugcodemodshelp wantedsev:S3

仓库指标

星标
 (89,909 个星标)
PR 合并指标
 (平均合并 7天 22小时) (30 天内合并 184 个 PR)

描述

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

贡献者指南