Skip to content

Latest commit

 

History

History

rename-prop

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

rename-prop

This universal codemod provides possibility to replace any prop with a new one in any component

- <Component old="info" />
+ <Component new="info" />

It's likely that props might be assigned in a different manners, therefore this codemod accounts for several prop patterns.

<Component old="old" />
<Component old={"old"} />
<Component old={old} />
<Component {...props} />
<Component {...{ old: "old" }} />
<Component {...{ old }} />
<Component {...{ old: oldType }} />

If there is a pattern that you use that is not transformed, please file a feature request.

Usage

Components imported as a default import:

npx carbon-codemod rename-prop <target> <component-import-path> <old-prop> <new-prop>

npx carbon-codemod rename-prop src carbon-react/lib/components/button oldProp newProp

Components imported as a named import:

npx carbon-codemod rename-prop <target> <component-import-path> <old-prop> <new-prop> -i <component-import-name>

npx carbon-codemod rename-prop src carbon-react/lib/components/accordion oldProp newProp -i Accordion

Example

npx carbon-codemod rename-prop src carbon-react/lib/components/button buttonType variant

import Button from "carbon-react/lib/components/button";
- <Button buttonType="primary>Button</Button>
+ <Button variant="primary">Button</Button>