From 09a3637eebe58328c5b05c8dfb84eca97077895a Mon Sep 17 00:00:00 2001 From: David Godfrey Date: Tue, 3 Sep 2019 14:34:28 +0100 Subject: [PATCH] fix(no-hover-event): handle undefined variables properly if a variable cannot be resolved, null is returned. '(null).type' caused an error while running the rule. --- lib/rules/no-hover-event.js | 4 +--- test/lib/rules/jquery-compat/no-hover-event.js | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-hover-event.js b/lib/rules/no-hover-event.js index 0729d47..0f79bdd 100644 --- a/lib/rules/no-hover-event.js +++ b/lib/rules/no-hover-event.js @@ -38,9 +38,7 @@ module.exports = { const args = node.arguments - const arg0 = args[0] && args[0].type === 'Identifier' - ? resolveIdentifier(args[0], context) - : args[0] + const arg0 = resolveIdentifier(args[0], context) || args[0] if (arg0.type !== 'Literal' || arg0.value !== 'hover') return diff --git a/test/lib/rules/jquery-compat/no-hover-event.js b/test/lib/rules/jquery-compat/no-hover-event.js index df90ac8..4cfdddb 100644 --- a/test/lib/rules/jquery-compat/no-hover-event.js +++ b/test/lib/rules/jquery-compat/no-hover-event.js @@ -11,6 +11,9 @@ ruleTester.run('jquery-compat/no-hover-event', rules['no-hover-event'], { }, { code: '$(".foo").hover()' + }, + { + code: 'foo.forEach(function(bar) { $quux.on(bar, baz) })' } ], invalid: [