wix-incubator / vscode-glean

The extension provides refactoring tools for your React codebase
MIT License
1.46k stars 56 forks source link
clean-code extract jsx react refactoring vscode vscode-extension

VSCode Glean

The extension provides refactoring tools for your React codebase

Build Status

The extension provides refactoring tools for your React codebase: extract JSX into a new component, convert Class Components to Functional Components, wrapping with Hooks and more!

Highlights

Installation

Go to the link below and click Install.

Visual Studio Code Market Place: Glean

Features

Extracting JSX into a new Component

Glean allows easy extraction of JSX into new React components (in the same or other file). Just select the JSX to extract, and Glean will handle all the rest:

Example of JSX extraction

Converting Class Component to Functional Component

Glean seamlesly automates convertion of class components to functional component, while take care of all the complexity:

WARNING!!! If You are using React version older than 16.8.0, This refactoring will delete all Lifecycle methods and setState calls!

Example of Hooks Support

Converting Functional Component to Class Component

Example of Stateless to Stateful Component Conversion

Rename State Variable

Rename any state variable and let Glean rename its setter accordingly for You!

Example of Rename State

Wrap with Hook (useMemo, useCallback or useEffect)

Example of Rename State

Render Conditionally

Example of Render Conditionally

Extract to file

Select text and either VSCode's code suggestion (aka "Lightbulb") or Command Pallet ('Extract to File' command) to extract the text.

Example of Javascript Extraction

Configuration Options

glean.jsModuleSystem (Default: 'esm')

Determines how the selected code will be exported/imported. Valid options are 'esm' and 'commonjs'.

glean.jsFilesExtensions (Default: [ "js", "jsx", "ts", "tsx" ])

List of extensions of files that should be treated as javascript files. This determines whether or not the snippet will be exported and imported. The snippet will be treated as javascript only if the extension of both origin and target files appears in this list.

glean.switchToTarget (Default: false)

Determines whether VSCode should switch to target file after extracting.

glean.experiments (Default: [])

A list of enabled experimental features. Available experimental features:

glean.showConversionWarning (Default: true)

Determines whether VSCode should show conversion warning when converting Class Component to Functional Component.

Contribute

Feel free to open issues or PRs!

Getting started

In order to start working all you need to do is:

$ git clone git@github.com:wix/vscode-glean.git
$ cd vscode-glean
$ npm install
$ code .

Running Extension

Running Tests

Commit messages

Please refer to to the following guide.