Giter Club home page Giter Club logo

vscode-glean's Introduction

VSCode Glean

The extension provides refactoring tools for your React/Javascript/Typescript codebase

Build Status

The extension provides refactoring tools for your React codebase: extract JSX into a new component, convert Function to Stateful React Components and more! In addition, you can extract regular Javascript/Typescript code between files, while handling exporting the selected code from the old location and importing in the new one!

Highlights

  • Allows extracting JSX into new component as well as other React code refactoring options
  • Moving code between files
  • Typescript support
  • ES2015 modules support
  • CommonJS modules support
  • Plain Text support

Installation

Go to the link below and click Install.

Visual Studio Code Market Place: Glean

Features

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

JSX Support

Extracting JSX into a new Component

Glean allows easy extraction of JSX into new React components. Just select the JSX to extract, and Glean will handle all the rest:

  • Generate Stateful or Stateless Component, such that the extracted JSX will continue to function.
  • It will identify all inputs to the newly created component.
  • Replace extracted JSX will newly created component, while providing it with all the props.

Example of JSX extraction

Converting Functional Component to Stateful Component

Example of Stateless to Stateful Component Conversion

Converting Stateful Component to Functional Component

Example of Stateful to Stateless Component Conversion

WARNING!!! This refactoring will delete all Lifecycle methods and setState calls!

Render Conditionally

Example of Render Conditionally

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.

Contribute

Feel free to open issues or PRs!

Getting started

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

$ git clone [email protected]:wix/vscode-glean.git
$ cd vscode-glean
$ npm install
$ code .

Running Extension

  • Go to VSCode debug sidebar
  • Select Extension from the dropdown
  • Hit F5

Running Tests

  • Go to VSCode debug sidebar
  • Select Extension Tests from the dropdown
  • Hit F5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.