Ecosyste.ms: Awesome

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

https://github.com/yangshun/js-codemods

Some codemod scripts to transform code for good styling
https://github.com/yangshun/js-codemods

codemod es6 javascript jscodeshift

Last synced: 11 days ago
JSON representation

Some codemod scripts to transform code for good styling

Lists

README

        

## js-codemods

This repository contains a collection of codemod scripts for use with
[JSCodeshift](https://github.com/facebook/jscodeshift).

### Setup & Run

```sh
npm install -g jscodeshift
git clone https://github.com/yangshun/js-codemods.git
jscodeshift -t path/to/codemod-script.js
```

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

### Included Scripts

#### `jsx-conditional-rendering-operator`

Transforms JSX inline If-Else with conditional operator rendering into inline if with logical `&&` operator rendering.

```sh
jscodeshift -t js-codemods/transforms/jsx-conditional-rendering-operator.js
```

**Before**:

```jsx


{this.state.showAlert ? : null}
{this.state.hideAlert ? null : }

```

**After**:

```jsx


{this.state.showAlert && }
{!this.state.hideAlert && }

```

#### `jsxattribute-expression-to-literal`

Transforms JSX attribute values which are string literals wrapped within `JSXExpressionContainers` to just the string literal itself.

```sh
jscodeshift -t js-codemods/transforms/jsxattribute-expression-to-literal.js
```

**Before**:

```jsx

```

**After**:

```jsx

```