Skip to content

Commit

Permalink
fix(no-hover-event): handle undefined variables properly
Browse files Browse the repository at this point in the history
if a variable cannot be resolved, null is returned. '(null).type' caused
an error while running the rule.
  • Loading branch information
david-at-frog committed Sep 3, 2019
1 parent 6347d8b commit 09a3637
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/rules/no-hover-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/lib/rules/jquery-compat/no-hover-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 09a3637

Please sign in to comment.