Skip to content

Commit a9d2cf7

Browse files
author
Joachim Seminck
committed
Treat key without value as a valid case instead of crashing
1 parent e28b9d2 commit a9d2cf7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/rules/no-array-index-key.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ module.exports = {
177177
}
178178

179179
var value = node.value;
180-
if (value.type !== 'JSXExpressionContainer') {
181-
// key='foo'
180+
if (!value || value.type !== 'JSXExpressionContainer') {
181+
// key='foo' or just simply 'key'
182182
return;
183183
}
184184

tests/lib/rules/no-array-index-key.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ruleTester.run('no-array-index-key', rule, {
3030
valid: [
3131
{code: '<Foo key="foo" />;'},
3232
{code: '<Foo key={i} />;'},
33+
{code: '<Foo key />;'},
3334
{code: '<Foo key={`foo-${i}`} />;'},
3435
{code: '<Foo key={\'foo-\' + i} />;'},
3536

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

75+
{
76+
code: 'foo.map((baz, i) => <Foo key />)'
77+
},
78+
7479
{
7580
code: 'foo.reduce((a, b) => a.concat(<Foo key={b.id} />), [])'
7681
},

0 commit comments

Comments
 (0)