From 22c9237fd447d1bc44a838042799217942fcceb2 Mon Sep 17 00:00:00 2001 From: kamataryo Date: Fri, 22 Dec 2017 18:49:54 +0900 Subject: [PATCH] Add null avoidance --- lib/rules/require-optimization.js | 2 +- tests/lib/rules/require-optimization.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rules/require-optimization.js b/lib/rules/require-optimization.js index 49d44a4456..b1b85db3bc 100644 --- a/lib/rules/require-optimization.js +++ b/lib/rules/require-optimization.js @@ -106,7 +106,7 @@ module.exports = { let hasPR = false; if (node.value && node.value.elements) { for (let i = 0, l = node.value.elements.length; i < l; i++) { - if (node.value.elements[i].name === 'PureRenderMixin') { + if (node.value.elements[i] && node.value.elements[i].name === 'PureRenderMixin') { hasPR = true; break; } diff --git a/tests/lib/rules/require-optimization.js b/tests/lib/rules/require-optimization.js index b4c1bf7b4c..e66ee22b33 100644 --- a/tests/lib/rules/require-optimization.js +++ b/tests/lib/rules/require-optimization.js @@ -112,6 +112,10 @@ ruleTester.run('react-require-optimization', rule, { `, parser: 'babel-eslint', options: [{allowDecorators: ['renderPure', 'pureRender']}] + }, { + code: ` + const obj = { prop: [,,,,,] } + ` }], invalid: [{