Forbid the use of Object.assign()
with a variable as first argument
Object.assign()
is a method that mutates its first argument. In order to use this method as a non-mutating method, the first element may not be a variable (even if declared using const
), and should therefore be a static value, such as an object expression.
var a = {foo: 1, bar: 2};
var b = {bar: 3};
Object.assign(a, b);
var a = {foo: 1, bar: 2};
var b = {bar: 3};
Object.assign({}, a, b);
Object.assign({foo: 1, bar: 2}, b);
Object.assign(function foo() {}, {propTypes: {}});