diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js index 53be62e68a3..e5dcdc63091 100644 --- a/lib/rules/id-blacklist.js +++ b/lib/rules/id-blacklist.js @@ -61,9 +61,12 @@ module.exports = { * @returns {boolean} whether an error should be reported or not */ function shouldReport(effectiveParent, name) { - return effectiveParent.type !== "CallExpression" && + return ( + effectiveParent.type !== "CallExpression" && effectiveParent.type !== "NewExpression" && - isInvalid(name); + effectiveParent.parent.type !== "ObjectPattern" && + isInvalid(name) + ); } /** @@ -98,11 +101,11 @@ module.exports = { report(node); } - // Report AssignmentExpressions only if they are the left side of the assignment + // Report AssignmentExpressions only if they are the left side of the assignment } else if (effectiveParent.type === "AssignmentExpression" && (effectiveParent.right.type !== "MemberExpression" || - effectiveParent.left.type === "MemberExpression" && - effectiveParent.left.property.name === node.name)) { + effectiveParent.left.type === "MemberExpression" && + effectiveParent.left.property.name === node.name)) { if (isInvalid(name)) { report(node); } @@ -115,7 +118,7 @@ module.exports = { report(node); } - // Report anything that is a match and not a CallExpression + // Report anything that is a match and not a CallExpression } else if (shouldReport(effectiveParent, name)) { report(node); } diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js index f4380e2b86e..5e92a4d5b4a 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -65,6 +65,26 @@ ruleTester.run("id-blacklist", rule, { code: "var obj = { key: foo.bar };", options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"] }, + { + code: "const {foo: bar} = baz", + options: ["foo", "bar"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "const {foo: {bar: baz}} = qux", + options: ["foo", "bar", "baz"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "function foo({ bar: baz }) {}", + options: ["bar", "baz"], + parserOptions: { ecmaVersion: 6 } + }, + { + code: "function foo({ bar: {baz: qux} }) {}", + options: ["bar", "baz", "qux"], + parserOptions: { ecmaVersion: 6 } + }, { code: "var arr = [foo.bar];", options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]