Skip to content
Sarj Code Standards

no-mutating-input-with-result

Return replacement object values instead of writing input fields in result-returning functions.

Why

A result-returning function that also writes a caller-owned object changes aliases outside the returned value, hiding its mutation contract.

Fix

Return a fresh replacement and update the caller to use it, or expose an explicit in-place command returning void. Do not add a dummy return or discard the operation.

Examples

Before — flagged A result does not undo the caller-visible write
src/config.ts
interface Config {
enabled: boolean;
}
function enable(config: Config): Config {
config.enabled = true;
return config;
}
After — preferred Return the replacement explicitly
src/config.ts
interface Config {
enabled: boolean;
}
function enable(config: Config): Config {
return { ...config, enabled: true };
}