From a9d2cf7fb9650c106b638b93f8bcd83f5c50dbfe Mon Sep 17 00:00:00 2001 From: Joachim Seminck Date: Wed, 7 Jun 2017 10:36:10 +0300 Subject: [PATCH] Treat key without value as a valid case instead of crashing --- lib/rules/no-array-index-key.js | 4 ++-- tests/lib/rules/no-array-index-key.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-array-index-key.js b/lib/rules/no-array-index-key.js index 1e4602ad7f..d5e9241af8 100644 --- a/lib/rules/no-array-index-key.js +++ b/lib/rules/no-array-index-key.js @@ -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; } diff --git a/tests/lib/rules/no-array-index-key.js b/tests/lib/rules/no-array-index-key.js index 3bcd60488e..fbf41deb8b 100644 --- a/tests/lib/rules/no-array-index-key.js +++ b/tests/lib/rules/no-array-index-key.js @@ -30,6 +30,7 @@ ruleTester.run('no-array-index-key', rule, { valid: [ {code: ';'}, {code: ';'}, + {code: ';'}, {code: ';'}, {code: ';'}, @@ -71,6 +72,10 @@ ruleTester.run('no-array-index-key', rule, { ].join('\n') }, + { + code: 'foo.map((baz, i) => )' + }, + { code: 'foo.reduce((a, b) => a.concat(), [])' },