Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/uber-web/uber-codemods

Because Code Changes and Evolves
https://github.com/uber-web/uber-codemods

codemod javascript jscodeshift

Last synced: 3 months ago
JSON representation

Because Code Changes and Evolves

Awesome Lists containing this project

README

        

# uber-codemods
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

> A collection of code-changing [JSCodeshift's](https://github.com/facebook/jscodeshift) for JavaScript.

## Install

```
npm install -g jscodeshift
npm install uber-codemods
jscodeshift -t node_modules/uber-codemods/
```

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](https://github.com/uber/r-dom) with React's `createElement()`. After this conversion, you can optionally use the [create-element-to-jsx codemod](https://github.com/reactjs/react-codemod#create-element-to-jsx) to generate jsx.

##### Usage

```sh
jscodeshift -t node_modules/uber-codemods/src/r-dom-to-react-create-element.js
```

##### Code Examples

[Before](src/__testfixtures__/r-dom-to-react-create-element.input.js)

[After](src/__testfixtures__/r-dom-to-react-create-element.output.js)

### `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

```sh
jscodeshift -t node_modules/uber-codemods/src/replace-require.js --toReplace="object.omit" --replaceWith="just-omit"
```

##### Code Examples

[Before](src/__testfixtures__/replace-require.input.js)

[After](src/__testfixtures__/replace-require.output.js)

### `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

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

### `xtend-to-spread`

Replaces all uses of [`xtend`](https://github.com/Raynos/xtend) with the es6 spread operator.

##### Usage

```sh
jscodeshift -t node_modules/uber-codemods/src/xtend-to-spread.js
```

##### Code Examples

[Before](src/__testfixtures__/xtend-to-spread.input.js)

[After](src/__testfixtures__/xtend-to-spread.output.js)

## License

MIT © [Uber](https://uber.com)

[npm-image]: https://badge.fury.io/js/uber-codemods.svg
[npm-url]: https://npmjs.org/package/uber-codemods
[travis-image]: https://travis-ci.org/uber-web/uber-codemods.svg?branch=master
[travis-url]: https://travis-ci.org/uber-web/uber-codemods