Skip to content

Commit

Permalink
Treat key without value as a valid case instead of crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Seminck committed Jun 7, 2017
1 parent e28b9d2 commit a9d2cf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/no-array-index-key.js
Expand Up @@ -177,8 +177,8 @@ module.exports = {
}

var value = node.value;
if (value.type !== 'JSXExpressionContainer') {
// key='foo'
if (!value || value.type !== 'JSXExpressionContainer') {
// key='foo' or just simply 'key'
return;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/no-array-index-key.js
Expand Up @@ -30,6 +30,7 @@ ruleTester.run('no-array-index-key', rule, {
valid: [
{code: '<Foo key="foo" />;'},
{code: '<Foo key={i} />;'},
{code: '<Foo key />;'},
{code: '<Foo key={`foo-${i}`} />;'},
{code: '<Foo key={\'foo-\' + i} />;'},

Expand Down Expand Up @@ -71,6 +72,10 @@ ruleTester.run('no-array-index-key', rule, {
].join('\n')
},

{
code: 'foo.map((baz, i) => <Foo key />)'
},

{
code: 'foo.reduce((a, b) => a.concat(<Foo key={b.id} />), [])'
},
Expand Down

0 comments on commit a9d2cf7

Please sign in to comment.