From 6ff65bae9ef57ad56ef112bb2e6087e2d3743d38 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Thu, 8 Aug 2019 15:57:51 -0700 Subject: [PATCH] Add null check in `new-module-imports` rule (again) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes this test case: ``` new-module-imports › valid › for (let i = 0; i < 10; i++) { } TypeError: pp.body.some is not a function Occurred while linting :1 162 | } 163 | > 164 | return pp.body.some(n => { | ^ 165 | function containsInitSpecifier(specifiers) { 166 | return specifiers.some(s => { 167 | return s.local.name === name; at some (lib/utils/new-module.js:164:18) at isInitImportedFrom (lib/rules/new-module-imports.js:59:44) ``` --- lib/utils/new-module.js | 2 +- tests/lib/rules/new-module-imports.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils/new-module.js b/lib/utils/new-module.js index 16e8f074ea..5d2a73b15c 100644 --- a/lib/utils/new-module.js +++ b/lib/utils/new-module.js @@ -157,7 +157,7 @@ function isInitImportedFrom(node, module) { const { name } = node.init; const pp = node.parent.parent; - if (!pp || !pp.body) { + if (!pp || !pp.body || !pp.body.some) { return false; } diff --git a/tests/lib/rules/new-module-imports.js b/tests/lib/rules/new-module-imports.js index 2ef09b362a..391fa5a0f1 100644 --- a/tests/lib/rules/new-module-imports.js +++ b/tests/lib/rules/new-module-imports.js @@ -53,6 +53,10 @@ eslintTester.run('new-module-imports', rule, { code: `export const Ember = 1;`, parserOptions: { ecmaVersion: 6, sourceType: 'module' }, }, + { + code: `for (let i = 0; i < 10; i++) { }`, + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + }, ], invalid: [ {