diff --git a/lib/rules/no-param-reassign.js b/lib/rules/no-param-reassign.js index 243bb6412cf..349345c148a 100644 --- a/lib/rules/no-param-reassign.js +++ b/lib/rules/no-param-reassign.js @@ -107,6 +107,14 @@ module.exports = { break; + // EXCLUDES: e.g. (foo ? a : b).c = bar; + case "ConditionalExpression": + if (parent.test === node) { + return false; + } + + break; + // no default } diff --git a/tests/lib/rules/no-param-reassign.js b/tests/lib/rules/no-param-reassign.js index 5d009c338f3..40156f481ec 100644 --- a/tests/lib/rules/no-param-reassign.js +++ b/tests/lib/rules/no-param-reassign.js @@ -32,6 +32,8 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { bar(a.b).c = 0; }", options: [{ props: true }] }, { code: "function foo(a) { data[a.b] = 0; }", options: [{ props: true }] }, { code: "function foo(a) { +a.b; }", options: [{ props: true }] }, + { code: "function foo(a) { (a ? [] : [])[0] = 1; }", options: [{ props: true }] }, + { code: "function foo(a) { (a.b ? [] : [])[0] = 1; }", options: [{ props: true }] }, { code: "function foo(a) { a.b = 0; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, { code: "function foo(a) { ++a.b; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, { code: "function foo(a) { delete a.b; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, @@ -87,6 +89,11 @@ ruleTester.run("no-param-reassign", rule, { options: [{ props: true }], errors: [{ message: "Assignment to property of function parameter 'bar'." }] }, + { + code: "function foo(bar) { (bar ? bar : [])[0] = 1; }", + options: [{ props: true }], + errors: [{ message: "Assignment to property of function parameter 'bar'." }] + }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true }],