Home

Awesome

RefactorEx

RefactorEx is a powerful Visual Studio Code extension that simplifies and accelerates code refactoring for Elixir projects. It introduces intuitive code actions to help you refactor Elixir code efficiently and confidently.

With RefactorEx, you can perform common refactorings like extracting functions, renaming variables, and more — all within a few clicks.

Example

Available refactorings

ScopeRefactoringTarget
aliasExpand aliasesselection
aliasExtract aliasselection
aliasInline aliasselection
aliasMerge aliasesselection
aliasSort nested aliasesline
constantExtract constantselection
constantInline constantselection
constantRename constantselection
functionExpand anonymous functionselection
functionExtract anonymous functionselection
functionExtract functionselection
functionCollapse anonymous functionselection
functionInline functionselection
functionRename functionselection
functionUnderscore unused argsline
functionUse keyword syntaxline
functionUse regular syntaxline
guardExtract guardselection
guardInline guardselection
guardRename guardselection
if elseUse keyword syntaxline
if elseUse regular syntaxline
pipelineIntroduce IO.inspectselection
pipelineIntroduce pipeline
pipelineRemove IO.inspectline
pipelineRemove pipeline
variableExtract variableselection
variableInline variableselection
variableRename variableselection

How to use each refactoring

Alias: expand aliases

DescriptionExpand nested aliases to their full names
TargetSelection of nested alias, group of nested aliases or alias with nesting
Inverse ofMerge aliases
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Alias: extract alias

DescriptionExtract the module full name into an alias and use it
TargetSelection of module full name
Inverse ofInline alias
ExampleExample

▲ top

<br>

Alias: inline alias

DescriptionReplace the alias usage by the module full name
TargetSelection of alias usage
Inverse ofExtract alias
Notes1. alias must be declared on the same module <br> 2. alias declaration will not be removed
ExampleExample

▲ top

<br>

Alias: merge aliases

DescriptionMerge the group of aliases into a nested alias
TargetSelection of two or more mergeable aliases
Inverse ofExpand aliases
ExampleExample

▲ top

<br>

Alias: sort nested aliases

DescriptionSort all nested aliases alphabetically
TargetLine of alias with unsorted nested aliases
ExampleExample

▲ top

<br>

Constant: extract constant

DescriptionExtract a piece of code into a constant
TargetSelection of any code without variables
Inverse ofInline constant
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Constant: inline constant

DescriptionReplace a constant usage by its value
TargetSelection of constant
Inverse ofExtract constant
Notes1. constant must be declared on the same module <br> 2. constant declaration will not be removed
ExampleExample

▲ top

<br>

Constant: rename constant

DescriptionReplace the name of constant in all its usages
TargetSelection of (or cursor over) constant
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Function: collapse anonymous function

DescriptionCollapse a fn function into a & function
TargetSelection of fn function
Inverse ofExpand anonymous function
ExampleExample

▲ top

<br>

Function: extract anonymous function

DescriptionExtract a & or fn function into a function
TargetSelection of & or fn function
Inverse ofInline function
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Function: expand anonymous function

DescriptionExpand a & function into a fn function
TargetSelection of & function
Inverse ofCollapse anonymous function
ExampleExample

▲ top

<br>

Function: extract function

DescriptionExtract a piece of code into a function
TargetSelection of any code
Inverse ofInline function
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Function: inline function

DescriptionReplace a function call by its body
TargetSelection of function call
Inverse ofExtract anonymous function, Extract function
Read moreCatalog of Elixir refactorings
Notes1. function must be defined on the same module <br> 2. function definition will not be removed
ExampleExample

▲ top

<br>

Function: rename function

DescriptionReplace the name of function in all its calls
TargetSelection of (or cursor over) function name
Read moreCatalog of Elixir refactorings
Notes⚠️ Renaming a public function only affects the current file
ExampleExample

▲ top

<br>

Function: underscore unused args

DescriptionPlaces a _ in front of args not used
TargetLine of function definition with unused args
ExampleExample

▲ top

<br>

Function: use keyword syntax

DescriptionRewrite the function using keyword syntax
TargetLine of function definition using regular syntax
Inverse ofUse regular syntax
Notesfunction body must have a single statement
ExampleExample

▲ top

<br>

Function: use regular syntax

DescriptionRewrite the function using regular syntax
TargetLine of function definition using keyword syntax
Inverse ofUse keyword syntax
ExampleExample

▲ top

<br>

Guard: extract guard

DescriptionExtract a when statement into a guard
TargetSelection of when statement or part of one
Inverse ofInline guard
ExampleExample

▲ top

<br>

Guard: inline guard

DescriptionReplace a guard call by its when statement
TargetSelection of guard call
Inverse ofExtract guard
Notes1. guard must be defined on the same module <br> 2. guard definition will not be removed
ExampleExample

▲ top

<br>

Guard: rename guard

DescriptionReplace the name of guard in all its calls
TargetSelection of (or cursor over) guard name
Read moreCatalog of Elixir refactorings
Notes⚠️ Renaming a public guard only affects the current file
ExampleExample

▲ top

<br>

If else: use keyword syntax

DescriptionRewrite the if else using keyword syntax
TargetLine of if using regular syntax
Inverse ofUse regular syntax
NotesClauses must have a single statement
ExampleExample

▲ top

<br>

If else: use regular syntax

DescriptionRewrite the if else using regular syntax
TargetLine of if using keyword syntax
Inverse ofUse keyword syntax
ExampleExample

▲ top

<br>

Pipeline: introduce IO.inspect

DescriptionPipe a piece of code into an IO.inspect
TargetSelection of any code
Inverse ofRemove IO.inspect
ExampleExample

▲ top

<br>

Pipeline: introduce pipe

DescriptionPipe the first arg into function call or case condition
TargetLine of function call or case condition
Inverse ofRemove pipe
ExampleExample

▲ top

<br>

Pipeline: remove IO.inspect

DescriptionRemove IO.inspect call
TargetLine of IO.inspect call
Inverse ofIntroduce IO.inspect
ExampleExample

▲ top

<br>

Pipeline: remove pipe

DescriptionRemove |> from function call or case condition
TargetLine of pipe (|>)
Inverse ofIntroduce pipe
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Variable: extract variable

DescriptionExtract a piece of code into a variable
TargetSelection of any code
Inverse ofInline variable
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Variable: inline variable

DescriptionReplace all usages of variable by its value
TargetSelection of variable declaration or assignment
Inverse ofExtract variable
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>

Variable: rename variable

DescriptionReplace the name of variable in all its usages
TargetSelection of (or cursor over) variable assignment
Read moreCatalog of Elixir refactorings
ExampleExample

▲ top

<br>