ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Java​Script Refactor

by s-a ST2/ST3

A Sublime Text Refactor Plugin for Javascript Code

Details

  • 2016.12.16.08.43.23
  • github.​com
  • github.​com
  • 4 months ago
  • 24 minutes ago
  • 4 years ago

Installs

  • Total 33K
  • Win 16K
  • OS X 10K
  • Linux 6K
Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11
Windows 7 20 5 8 3 6 23 6 7 5 7 10 6 8 19 16 9 11 15 13 11 6 5 8 4 7 14 8 16 11 6 6 14 15 13 19 10 6 9 12 9 17 13 12 9 6
OS X 4 6 5 1 2 4 9 1 7 2 4 4 5 3 8 3 3 3 10 11 7 2 3 3 4 5 3 8 5 4 0 1 5 6 5 5 3 4 3 5 7 7 6 5 1 0
Linux 4 3 0 0 3 3 3 1 2 0 2 2 3 4 2 2 3 2 1 2 1 2 4 3 2 1 2 2 4 6 1 3 1 3 5 6 3 1 5 3 3 2 8 5 4 0

Readme

Source
raw.​githubusercontent.​com

Javascript Refactor plugin for Sublime Text 2 and 3

Package Control Donate

Overview

  • Goto definition of a variable or function
  • Rename variable or function respecting its current scope
  • Introduce variable
  • Extract selected source to a new method

Preview

http://www.youtube.com/watch?v=P9K7mxWItPw

Installation

Use the Sublime Package Control and search for: “JavaScript Refactor”
or
Clone or download the git repository into your packages folder. In Sublime Text use “Preferences/Browse Packages” menu item to open this folder. The shorter way of doing this is:

Linux

git clone https://github.com/s-a/sublime-text-refactor.git ~/.config/sublime-text-2/Packages/sublime-text-refactor

Mac

git clone https://github.com/s-a/sublime-text-refactor.git ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/sublime-text-refactor

Windows

In an elevated command prompt or powershell (as Admin): git clone https://github.com/s-a/sublime-text-refactor.git "%APPDATA%\Sublime Text 2\Packages\sublime-text-refactor“ for Sublime Text 3: git clone https://github.com/s-a/sublime-text-refactor.git "%APPDATA%\Sublime Text 3\Packages\sublime-text-refactor

Dependencies

  • This Plugin makes heavy usage of Node.js. So it needs a local installation of http://nodejs.org
  • mocha (only for testing)

Usage

Goto Definition:
Select a keyword via double click or point the cursor to the keyword and choose “Goto Definition” from context menu.

Rename:
Select a keyword via double click or point the cursor to the keyword and choose “Rename” from context menu. The plugin will select all variables or function calls occurring in the source code including its declaration. After that you rename them all on the fly. The logic respects the variables or functions scope. So it should be safe to rename them all without thinking ;) .

Introduce Variable:
Select an Expression from source code or point the cursor to the desired position and choose “Introduce Variable” from context menu.

Extract Method:
Select the source code you want to extract into a new method and choose “Refactor / Extract methode” from context menu. This will extract the source code instantly to a new methode aka function. The plugin will manage undeclared variable usages and pass them within a single bundled JSON parameter to the new function. It also generates a sample function call at the bottom of the new methode. The plugin marks all variables occurring in the source code so you can rename them on the fly.

Run the tests

Goto Pluginfolder and type npm test

You can find current test cases here
https://github.com/s-a/sublime-text-refactor/blob/master/js/test/

Troubleshoot

  • Node not found
    • Choose Preferences: Refactor Settings – User from context menu and configure the nodePath setup. (Default Value is node)

{ "nodePath" : "node" }

Todo

  • Extract method
  • Define exceptions of global scoped variable names like jQuery or $.
  • Do not pass variables available in current Scope (optional).
  • Let the user choose a function name before or after extraction.
  • Let the user choose a custom position to insert extracted methode code and indent it correctly.

License

MIT and GPL license.

Copyright © 2013 Stephan Ahlf stephan@ahlf-it.de

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.