From 991d9045d8a4e9b7170ce8a330176fd18e46ae38 Mon Sep 17 00:00:00 2001 From: Nathaniel Furniss Date: Wed, 30 Aug 2017 16:36:00 -0700 Subject: [PATCH] Guard propertyName in no-jquery-methods --- lib/rules/no-jquery-methods.js | 4 ++++ tests/lib/rules/no-jquery-methods.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/rules/no-jquery-methods.js b/lib/rules/no-jquery-methods.js index 45886d5..ca22f8a 100644 --- a/lib/rules/no-jquery-methods.js +++ b/lib/rules/no-jquery-methods.js @@ -62,6 +62,10 @@ module.exports = { MemberExpression(node) { let propertyName = get(node, 'property.name'); + // If the node doesn't have a name, return early. + if (!propertyName) { + return; + } let blackListName = BLACKLIST.includes(propertyName) ? propertyName : false; let isThisExpression = get(node, 'object.type').includes('ThisExpression'); diff --git a/tests/lib/rules/no-jquery-methods.js b/tests/lib/rules/no-jquery-methods.js index fc95342..8d501d4 100644 --- a/tests/lib/rules/no-jquery-methods.js +++ b/tests/lib/rules/no-jquery-methods.js @@ -74,6 +74,24 @@ ruleTester.run('no-jquery-methods', rule, { } });`, options: [] + }, + { + code: ` + export default Ember.Component({ + init() { + const myVar = this[this.myProp]; + } + });`, + options: [BLACKLISTMETHOD] + }, + { + code: ` + export default Ember.Component({ + init() { + const q = this[\`\${myVar}\`]; + } + });`, + options: [BLACKLISTMETHOD] } ], invalid: [