GithubHelp home page GithubHelp logo

uber-codemods's Introduction

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

uber-codemods's People

Contributors

dawsbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

uber-codemods's Issues

๐Ÿ› replace-require data-type failure

It's understood that this comes from an assumption about the data-type of an underlying literal. Assuming it's a string when it's not, there are string operations which are called on the data type. Should be fixable with an additional filter.

 ERR /var/folders/tv/fdtq5cgn6zq4bj1_lzvrhl7h0000gn/T/3848786987-<module-name>-<version>/package/test/tasks/version-assets.js Transformation error
Error: {value: [object Object], parentPath: [object Object], name: init, __childCache: null} does not match type Printable
    at Type.Tp.assert (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:60:19)
    at genericPrintNoParens (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:219:26)
    at genericPrint (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:164:9)
    at printRootGenerically (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:105:15)
    at maybeReprint (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:97:16)
    at print (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:75:29)
    at exports.printComments (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/comments.js:324:22)
    at printWithComments (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:61:16)
    at FastPath.call (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/fast-path.js:113:18)
    at genericPrintNoParens (/Users/dawsonbotsford/.config/yarn/global/node_modules/jscodeshift/node_modules/recast/lib/printer.js:867:18)

replace-require sub-paths

When calling replace-require() for thing -> replaceme on require('thing/sub'), it should create require('replaceme/sub'). Instead, it creates require('thing/sub').

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.