For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/eslint/no-return-assign.md.
close

no-return-assign

Added in v0.5.0

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-return-assign': 'error',
    },
  },
]);

Rule Details

This rule aims to eliminate assignments from return statements, because it is difficult to tell whether the author intended an assignment or a mistyped comparison.

Examples of incorrect code for this rule:

function doSomething() {
  return foo = bar + 2;
}

function doSomethingElse() {
  return foo += 2;
}

const foo = (a, b) => a = b;

const bar = (a, b, c) => (a = b, c == b);

function doSomethingMore() {
  return foo = bar && foo > 0;
}

Examples of correct code for this rule:

function doSomething() {
  return foo == bar + 2;
}

function doSomethingMore() {
  return (foo = bar + 2);
}

const foo = (a, b) => (a = b);

const bar = (a, b, c) => ((a = b), c == b);

function doAnotherThing() {
  return (foo = bar) && foo > 0;
}

Options

This rule takes a single string option:

  • "except-parens" (default) — disallow assignments in return statements unless they are enclosed in parentheses.
  • "always" — disallow all assignments in return statements, even when parenthesised.

Examples of incorrect code for this rule with "always":

{ "no-return-assign": ["error", "always"] }
function doSomething() {
  return foo = bar + 2;
}

function doSomethingMore() {
  return (foo = bar + 2);
}

Examples of correct code for this rule with "always":

{ "no-return-assign": ["error", "always"] }
function doSomething() {
  return foo == bar + 2;
}

Original Documentation