Skip to content

JSCodeshift codemod to add default values to React components optional proptypes

License

Notifications You must be signed in to change notification settings

ricovitch/codemod-react-default-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codemods

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

Tools

Available types for writing codemods and manipulating AST with jscodeshift API are inherited from ast-types package, which implements Esprima API pionneered by Mozilla Parser API

Setup & Run

npm install -g jscodeshift
git clone [email protected]:ricovitch/codemod-react-default-props.git
jscodeshift -t <codemod-script> <file>

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

Included Scripts

default-props

Adds default values for optional proptypes (does nothing if defaultProps assignment exists already)

jscodeshift -t codemods/transforms/default-props.js <path>

TODOs

  • Use ReactUtils module from react-codemod package instead of copy-pasting
  • Extract reusable util method from default-props.js module
  • Support modules with multiple components and multiple propTypes definitions
  • Support functional components with HOCs / non arrow function declaration (componentName undefined)
  • Support modules with existing but incomplet defaultProps ?
  • Add trailing commas at end of lines (with option do deactivate ?) https://eslint.org/docs/rules/comma-dangle

About

JSCodeshift codemod to add default values to React components optional proptypes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published