Code Actions
All 83 code actions in P42 (refactorings, quick fixes, and cleanups).
Increase the readability of long numbers and uncommon number formats by adding underscore separators.
Convert arrow function expression body into a block body.
Add {...}
to JSX attribute string literal value.
Convert an empty JSX tag into a self-closing tag.
Shorten object properties when the property name is the same as the property value.
Convert condition && aFunction();
and similar expression statements into if statements.
Replace .apply()
calls with the spread operator ...
Replace array.indexOf()
checks with array.includes()
.
Convert a conditional expression to an if-else statement.
Replace function expressions with arrow functions, a more concise syntax.
Convert property assignments with functions to method declarations.
Convert an if
-else
return or assignment expression into a conditional expression.
Convert if-else statement chain with equality comparisons to switch statement.
Replace let
declarations that have no re-assignment with const
declarations.
Replace regular for
loops with .forEach()
loops.
Replace for..of
with a regular for
loop that has an index variable.
Replace regular for
loops and anArray.forEach
loops with for...of
loops.
Use the exponentiation operator **
instead of Math.pow()
.
Converts a named function to a const declaration with a function expression.
Convert dot notation property access o.a
into bracket notation property access o['a']
.
Convert bracket notation property access o['a']
into dot notation property access o.a
.
Replace || value === 'aString'
and && value !== 'aString'
chains with array.includes()
.
Convert a string to a basic template literal without expressions.
Convert a simple template literal without expressions into a string.
Convert a variable declaration that accesses an object property to a destructuring assignment.
Replace various guard expressions with the optional chaining operator (?.
).
Replace var
with block-scoped variables let
and const
.
Expand a self-closing JSX tag.
Expand a shorthand object property (e.g. { a }
) to a regular property (e.g. { a: a }
).
Extract JSX element or fragment into a React Function Component.
Extract the selected text (including expressions from template literals) into a const
variable.
Extract one or more occurrences of an expression into a const
variable.
Swap the left and right operands and update the operator if necessary.
Inline a string or a basic template literal into an outer template literal.
Convert a variable assignment to a return
statement.
Inline a variable value into its references.
Insert a 'console.log' statement for a selected variable when possible.
Negate the condition of an if-statement or conditional expression and swap its content.
Replace default value assignment expressions with default parameter values.
Combine an object destructuring assignment with its preceding sibling.
Nested single if
statements inside else
blocks can be combined into else if
statements.
Combine two nested if
statements without additional operations into a single if
-statement, using &&
to combine the conditions.
Merge string and template literal concatenation into a single template literal or string.
Convert the initial assignment of a variable into its declaration initializer.
Move a first statement that appears in both the if and the else block out of the if-else statement.
Move a last statement that appears in both the if and the else block out of the if-else statement.
Move an operator out of an assignment into a binary expression.
Move the not-operator (!
) out of a binary expression.
Push the not-operator (!
) into an expression and negate it.
Move an operator from a binary expression into an assignment operator, e.g., +=
.
Push a parameter of an immediately-invoked function expressions (IIFEs) or an immediately-invoked arrow functions (IIAFs) into the function body.
Remove console.log statement.
Remove double negation (!!
) expressions.
Remove an empty 'else' block from an 'if' statement.
Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.
Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.
Remove redundant else-if conditions and unreachable else statements.
Replace a conditional expression with its condition or its result.
Lift the else content of an if
-else
with a return statement to the outer indentation level.
Remove an expression statement that has no side-effects.
Replace JSX Fragments <></>
that only contain a single child with that child.
Simplify a template literal with a single inner expression and no prefix or suffix.
Remove a variable that is not read or written.
Convert an arrow function block body into an expression body.
Remove {...}
from a JSX attribute expression value that contains a string literal.
Replace Lodash _.each
and _.forEach
with array.forEach
.
Replace Lodash _.every
with array.every
.
Replace Lodash _.filter
with array.filter
.
Replace Lodash _.map
with array.map
.
Replace _.noop
with () => undefined
.
Replace Lodash _.some
with array.some
.
Replace void 0
and other constant void
expressions with undefined
.
Separate a repeated sub-condition that is fully covered into a nested if-else.
Replace binary expression with simpler equivalent expression
Split the condition of an if statement on ||
or &&
when possible.
Separate the variable initialization from its declaration.
Convert declarations with multiple variables into separate declarations for each variable.
Wrap JSX elements in a JSX fragment <>...</>
.
Surround a sequence of statements in a try…catch
block.
Replace different of nullish checks with == null
.
Replace default value expression with nullish coalescing operator (??
) expressions.
string.endsWith()
checks if a string ends with another string.
string.startsWith()
checks if a string starts with another string.