Skip to content

Some codemod scripts to transform code for good styling

License

Notifications You must be signed in to change notification settings

yangshun/js-codemods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

js-codemods

This repository contains a collection of codemod scripts for use with JSCodeshift.

Setup & Run

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

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.

jscodeshift -t js-codemods/transforms/jsx-conditional-rendering-operator.js <file>

Before:

<div>
  {this.state.showAlert ? <Alert /> : null}
  {this.state.hideAlert ? null : <Alert />}
</div>

After:

<div>
  {this.state.showAlert && <Alert />}
  {!this.state.hideAlert && <Alert />}
</div>

jsxattribute-expression-to-literal

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

jscodeshift -t js-codemods/transforms/jsxattribute-expression-to-literal.js <file>

Before:

<Foo header={"Lorem Ipsum"} message={'dolor sit amet'} />

After:

<Foo header="Lorem Ipsum" message="dolor sit amet" />

About

Some codemod scripts to transform code for good styling

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published