Skip to content

Commit

Permalink
prefer-query-selector: Fix crash on calling without argument (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 24, 2020
1 parent 8335d41 commit 36908da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rules/prefer-query-selector.js
Expand Up @@ -105,6 +105,11 @@ const create = context => {
return;
}

const [firstArgument] = node.arguments;
if (node.arguments.length !== 1 || firstArgument.type === 'SpreadElement') {
return;
}

const report = {
node,
messageId: MESSAGE_ID,
Expand Down
5 changes: 5 additions & 0 deletions test/prefer-query-selector.js
Expand Up @@ -7,6 +7,11 @@ const createError = (method, replacement) => ({

test({
valid: [
// More or less arguments
'document.getElementById();',
'document.getElementsByClassName("foo", "bar");',
'document.getElementById(...["id"]);',

'document.querySelector("#foo");',
'document.querySelector(".bar");',
'document.querySelector("main #foo .bar");',
Expand Down

0 comments on commit 36908da

Please sign in to comment.