Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: no-param-reassign parameter in ternary operator (fixes #11236) (#…
  • Loading branch information
lpaladin authored and not-an-aardvark committed Jan 4, 2019
1 parent 258b654 commit bfff77a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rules/no-param-reassign.js
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-param-reassign.js
Expand Up @@ -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"] }] },
Expand Down Expand Up @@ -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 }],
Expand Down

0 comments on commit bfff77a

Please sign in to comment.