diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js index 53be62e68a3..2b5e908c1c2 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 !== "BlockStatement" && + isInvalid(name) + ); } /** @@ -101,21 +104,21 @@ module.exports = { // 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); } } - // Properties have their own rules + // Properties have their own rules } else if (node.parent.type === "Property") { if (shouldReport(effectiveParent, name)) { 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..3d3dd344d5c 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -65,6 +65,10 @@ ruleTester.run("id-blacklist", rule, { code: "var obj = { key: foo.bar };", options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"] }, + { + code: "{foo: bar}", + options: ["foo"] + }, { code: "var arr = [foo.bar];", options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"] @@ -176,6 +180,13 @@ ruleTester.run("id-blacklist", rule, { error ] }, + { + code: "{foo: bar}", + options: ["foo", "bar"], + errors: [ + error + ] + }, { code: "var arr = [foo.bar];", options: ["arr"],