JS CodeFormer is a JS refactoring and code automation extension for VS Code. Born from the ashes of JS Refactor, JS CodeFormer answers a new question. Instead of asking "can a JS refactoring tool be made for VS Code", this project aims to answer "how can better tools help to create better software?"
JS CodeFormer is a suite of tools purpose built to simplify the process of creating and editing software in a JavaScript environment.
JS CodeFormer is an extension for Visual Studio Code. Install it from the Visual Studio Marketplace:
Make a selection or place your cursor on the code you are working with, then either:
ctrl+alt+.
-- Windowsshift+cmd+alt+.
-- MacJS CodeFormer is not just a code refactoring and automation extension, it is an extension which is built upon these core principles:
None of these principles can be treated as "set it and forget it". Every new behavior, and every improvement receives serious thought as to how it will serve, and impact the developer using this tool.
A goal in this project is to have it "just work". In other words, in any situation where it seems it should work, it does work. Since nobody is able to see the future, this is something which will need to be addressed as new situations arise.
Currently, JS CodeFormer quietly works in files which reach beyond what is generally considered "standard JavaScript/TypeScript environments". Many extensions do not work in a LiveShare session, but JS CodeFormer is built to support a rich editing experience in an environment where many extensions are disabled.
JS CodeFormer does the following so support "it just works":
The core languages in this list have been tested through active production use of the extension. Frameworks have been, at the least, smoke-tested on example production code.
Languages:
Frameworks:
Framework-specific formats:
Experimental framework support:
Currently settings are limited to just one: "Use Semicolons"
There are folks who use them and folks who don't. In order to better serve people, semicolons in generated code can be turned on or off. They are on by default -- this is the TC39 recommendation.
JS CodeFormer has a number of automated code actions you can take. They are separated into the following categories:
JS CodeFormer can suggest refactorings, conversions, and actions based on your current selection -- which is how I prefer to work. This reduces hotkey overload by giving you access to actions you can take without memorizing a bunch of key combinations.
ctrl+alt+.
cmd+shift+alt+.
Important note: this is not wired into the refactoring menu in order to ensure JS CodeFormer is available to you even if you are in a Live Share session.
JS CodeFormer automated refactorings are built upon years of experience to be stable and reliable. Though the project is new, and issues will inevitably arise, the tools in this project are used to support the project itself. In essence, JS CodeFormer is a self-dogfooding project.
Current refactorings:
Conversions may or may not introduce a different behavior. This means they are in a class of their own. The following conversions are currently available:
Not everything we want to do with our code is a refactoring. That doesn't mean we can't automate it. Actions aim to pair with the supported refactorings in order to provide a smooth development experience.
Current Actions:
VS Code comes with a number of basic snippets for generating common code. JS CodeFormer adds a few while trying to limit snippet overlap. This means the snippet selection will be enhanced rather than repeated. The list of snippets is long, and constantly improving, so listing all snippets is unreasonable here.
Current snippets support:
ctrl+shift+j, m
cmd+shift+j, m
ctrl+shift+j, p
cmd+shift+j, p
ctrl+shift+j, v
cmd+shift+j, v
ctrl+shift+j, i
cmd+shift+j, i
ctrl+shift+j, n
cmd+shift+j, n
ctrl+shift+j, t
cmd+shift+j, t
ctrl+shift+j, r
cmd+shift+j, r
ctrl+shift+j, w
cmd+shift+j, w
Suggested Actions
Get action suggestions based on your current selection:
Extract Method
Using extract method in old jQuery, embedded in HTML:
Using extract method in a JSX block:
Extract Variable
Extract variable in a Vue single-file component:
Extract to Parameter
Extract to parameter in old jQuery, embedded in HTML:
Inline Variable
Inline variable in old jQuery, embedded in HTML:
Rename
Rename in a Vue single-file component:
Code contributions help introduce new behaviors and improve existing behaviors materially. I'd like to thank these contributors for their code contributions:
It's important to understand that not all contributions to a project are, or can be committed to the source repository. With that in mind, the following are people who have provided help and insights which might not have a name on a commit:
Also, every person who submitted a bug or enhancement on JS Refactor, and those who offer them on this project!
The best place to find me is on Twitter: @cm_stead You can also find me on the web: ChrisStead.net
Rename:
Convert Ternary to If/Else Statement:
Convert Selected Functions to Class