Skip to content

uber-web/uber-codemods

Repository files navigation

uber-codemods

NPM version Build Status

A collection of code-changing JSCodeshift's for JavaScript.

Install

npm install -g jscodeshift
npm install uber-codemods
jscodeshift -t node_modules/uber-codemods/<codemod-name> <transform-path>

Use the -d option for a dry-run and use -p to print the output for comparison.

Included mods

r-dom-to-react-create-element

Replaces all uses of r-dom with React's createElement(). After this conversion, you can optionally use the create-element-to-jsx codemod to generate jsx.

Usage
jscodeshift -t node_modules/uber-codemods/src/r-dom-to-react-create-element.js <transform-path>
Code Examples

Before

After

replace-require

Replaces all requires and imports of toReplace with replaceWith. Takes two options via the cli. Also replaces sub-paths in your require/import statements.

Usage
jscodeshift -t node_modules/uber-codemods/src/replace-require.js <transform-path> --toReplace="object.omit" --replaceWith="just-omit"
Code Examples

Before

After

replace-require-absolute-path

Replaces all requires and imports of toReplace with the relative path to replaceWith. Takes two options via the cli. The reason this is needed as a separate mod from replace-require is because the relative path to replaceWith changes relative to the current file being evaluated by jscodeshift.

Usage
jscodeshift -t node_modules/uber-codemods/src/replace-require-absolute-path.js <transform-path> --toReplace="object.omit" --replaceWith=$(pwd)/just-omit

xtend-to-spread

Replaces all uses of xtend with the es6 spread operator.

Usage
jscodeshift -t node_modules/uber-codemods/src/xtend-to-spread.js <transform-path>
Code Examples

Before

After

License

MIT © Uber