
17 Code Cleanups
Code cleanups remove unnecessary code. Such code can result from code churn, e.g., by applying other refactorings, adding new features, or fixing bugs. The JS Assistant shows hints and automates the cleanup for the following situations:
- Flatten array rest/spread property
Merge a ...[] expression into the outer array literal or destructuring expression.
- Remove console.log
Remove console.log statement.
- Remove double negation
Remove double negation (
!!
) expressions. - Remove empty else block
Remove an empty 'else' block from an 'if' statement.
- Remove empty if block
Remove an empty 'if' block from an 'if' statement. Replaces it with the 'else' block when available.
- Remove IIFE/IIAF
Remove immediately-invoked function expressions (IIFEs) and immediately-invoked arrow functions (IIAFs) without parameters.
- Remove redundant else if
Remove redundant else-if conditions and unreachable else statements.
- Remove trailing array destructuring holes
Remove trailing array destructuring holes and empty array destructuring expressions.
- Remove unnecessary conditional expression
Replace a conditional expression with its condition or its result.
- Remove unnecessary else
Lift the else content of an
if
-else
with a return statement to the outer indentation level. - Remove unnecessary expression statement
Remove an expression statement that has no side-effects.
- Remove unnecessary JSX fragment
Replace JSX Fragments
<></>
that only contain a single child with that child. - Remove unnecessary template literal
Simplify a template literal with a single inner expression and no prefix or suffix.
- Remove unused variable
Remove a variable that is not read or written.
- Replace void 0 with undefined
Replace
void 0
and other constantvoid
expressions withundefined
. - Simplify binary expression
Replace binary expression with a more straightforward equivalent expression.
- Simplify switch statement
Remove an unnecessary switch statement or replace it with its content.