Skip to content

Commit

Permalink
Merge pull request #1244 from jseminck/no-array-index-key-bug
Browse files Browse the repository at this point in the history
[Fix] Treat "key" without value as a valid case instead for "no-array-index-key"
  • Loading branch information
ljharb authored Jun 7, 2017
2 parents e28b9d2 + a9d2cf7 commit d77a205
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d77a205

Please sign in to comment.