Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mukeshsoni/codemods

code modifiers scripts which work with jscodeshift
https://github.com/mukeshsoni/codemods

Last synced: 24 days ago
JSON representation

code modifiers scripts which work with jscodeshift

Awesome Lists containing this project

README

        

# codemods

This repository contains a collection of codemod scripts for use with [JSCodeshift](https://github.com/facebook/jscodeshift) that transform your source code in useful ways.

### Setup & Run

1. `npm install -g jscodeshift`
1. `git clone https://github.com/mukeshsoni/codemods.git` or download a zip file from `https://github.com/mukeshsoni/codemods/archive/master.zip`
1. `jscodeshift -t `
* `codemod-script` - path to the transform file, see available scripts below;
* `path` - files or directory to transform;
* use the `-d` option for a dry-run and use `-p` to print the output for comparison;
* use the `--extensions` option if your files have different extensions than `.js` (for example, `--extensions js,jsx`);
* if you use flowtype, you might also need to use `--parser=flow`;
* see all available [jscodeshift options](https://github.com/facebook/jscodeshift#usage-cli).

### Included Scripts

#### `jsx-add-data-test-id-attribute.js`

Adds a `data-test-id` attribute to all jsx html elements. Helpful for test writers to grab an element and simulate some action/event on it.
It does not add the attribute to custom components. Also, doesn't add the attribute if it already exists on an element.

```sh
jscodeshift -t codemods/transforms/jsx-add-data-test-id-attribute.js
```

E.g. - converts

```

Beautiful

```

to

```

Beautiful

```