No Assign Then Return
Return expressions directly instead of assigning to an intermediate variable that is immediately returned.
Summary
The no-assign-then-return rule reports a return statement that returns an identifier when the immediately preceding statement is a const declaration of that same identifier.
It is recommended to return the expression directly.
Why Use This Rule?
- Removes unnecessary intermediate variables that add visual noise.
- Makes the return value immediately visible without scanning back to the declaration.
- Keeps functions concise by eliminating a redundant line.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
This rule provides automatic fixes. Run ESLint with the --fix flag:
npx eslint --fix . --rule '@cbnventures/nova/no-assign-then-return: error'
Troubleshooting
- Warning fires but the variable name is descriptive — It is recommended to return the expression directly. If a descriptive name is important, consider adding a comment above the return statement instead.
- Only
constdeclarations are checked — Reassignable variables (let) are skipped because they might be modified between declaration and return.