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: 3 months ago
JSON representation
Some codemod scripts to transform code for good styling
- Host: GitHub
- URL: https://github.com/yangshun/js-codemods
- Owner: yangshun
- License: mit
- Created: 2017-04-14T09:18:45.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-21T15:12:28.000Z (almost 8 years ago)
- Last Synced: 2024-08-02T07:14:26.699Z (7 months ago)
- Topics: codemod, es6, javascript, jscodeshift
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codemods - js-codemods - Some codemod scripts to transform code for good styling. (JavaScript)
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
```