Permalink
Browse files

Fix: no-param-reassign parameter in ternary operator (fixes #11236) (#…

  • Loading branch information...
zhouhaoyu authored and not-an-aardvark committed Jan 4, 2019
1 parent 258b654 commit bfff77ad4eaa02e2e62481c986634df38d5db6e5
Showing with 15 additions and 0 deletions.
  1. +8 −0 lib/rules/no-param-reassign.js
  2. +7 −0 tests/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
}

@@ -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 }],

0 comments on commit bfff77a

Please sign in to comment.