Skip to content

Commit

Permalink
Fix prefer-negative-index crash on not enough arguments (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Feb 16, 2020
1 parent 027fb84 commit 50e038c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rules/prefer-negative-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function parse(node) {

if (isApply) {
const [, secondArgument] = originalArguments;
if (secondArgument.type !== 'ArrayExpression') {
if (!secondArgument || secondArgument.type !== 'ArrayExpression') {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion test/prefer-negative-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ ruleTester.run('prefer-negative-index', rule, {
// Foo[bar++]
'foo[bar++].slice(foo[bar++].length - 1)',
// Foo['bar'] & foo["bar"]
'foo[\'bar\'].slice(foo["bar"].length - 1)'
'foo[\'bar\'].slice(foo["bar"].length - 1)',
// Should not crash
// https://github.com/gatsbyjs/gatsby/blob/e720d8efe58eba0f6fae9f26ec8879128967d0b5/packages/gatsby/src/bootstrap/log-line-function.js#L9
'function foo() {return [].slice.apply(arguments);}'
],
invalid: [
// Docs example (1)
Expand Down

0 comments on commit 50e038c

Please sign in to comment.