Skip to content

Commit

Permalink
Fix no-array-index-key rule exception
Browse files Browse the repository at this point in the history
  • Loading branch information
wKich authored and ljharb committed Jan 14, 2017
1 parent a33db3b commit 941a67d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rules/no-array-index-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ module.exports = {
}

props.properties.forEach(function (prop) {
if (prop.key.name !== 'key') {
if (!prop.key || prop.key.name !== 'key') {
// { ...foo }
// { foo: bar }
return;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/lib/rules/no-array-index-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var RuleTester = require('eslint').RuleTester;
var parserOptions = {
ecmaVersion: 6,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true
}
};
Expand Down Expand Up @@ -61,6 +62,11 @@ ruleTester.run('no-array-index-key', rule, {
parserOptions: parserOptions
},

{
code: 'foo.map((baz, i) => React.cloneElement(someChild, { ...someChild.props }))',
parserOptions: parserOptions
},

{
code: [
'foo.map((item, i) => {',
Expand All @@ -69,7 +75,6 @@ ruleTester.run('no-array-index-key', rule, {
' })',
'})'
].join('\n'),
errors: [{message: 'Do not use Array index in keys'}],
parserOptions: parserOptions
},

Expand Down Expand Up @@ -131,6 +136,12 @@ ruleTester.run('no-array-index-key', rule, {
parserOptions: parserOptions
},

{
code: 'foo.map((baz, i) => React.cloneElement(someChild, { ...someChild.props, key: i }))',
errors: [{message: 'Do not use Array index in keys'}],
parserOptions: parserOptions
},

{
code: [
'foo.map((item, i) => {',
Expand Down

0 comments on commit 941a67d

Please sign in to comment.