From 3908e6d349f04b5726b09479f67f937783bb7c1b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 15 Jan 2020 12:17:30 -0800 Subject: [PATCH] [Fix] `extensions`: for invalid code where `name` does not exist, do not crash Fixes #1613 --- CHANGELOG.md | 2 ++ src/core/importType.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c5a0d26..96b12e157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [Unreleased] ### Fixed - [`import/external-module-folders` setting] now correctly works with directories containing modules symlinked from `node_modules` ([#1605], thanks [@skozin]) +- [`extensions`]: for invalid code where `name` does not exist, do not crash ([#1613], thanks [@ljharb]) ### Changed - [`import/external-module-folders` setting] behavior is more strict now: it will only match complete path segments ([#1605], thanks [@skozin]) @@ -641,6 +642,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#1613]: https://github.com/benmosher/eslint-plugin-import/issues/1613 [#1605]: https://github.com/benmosher/eslint-plugin-import/pull/1605 [#1589]: https://github.com/benmosher/eslint-plugin-import/issues/1589 [#1586]: https://github.com/benmosher/eslint-plugin-import/pull/1586 diff --git a/src/core/importType.js b/src/core/importType.js index d99f9a348..311fd1e28 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -17,7 +17,7 @@ export function isAbsolute(name) { // path is defined only when a resolver resolves to a non-standard path export function isBuiltIn(name, settings, path) { - if (path) return false + if (path || !name) return false const base = baseModule(name) const extras = (settings && settings['import/core-modules']) || [] return coreModules[base] || extras.indexOf(base) > -1 @@ -52,12 +52,12 @@ export function isExternalModuleMain(name, settings, path) { const scopedRegExp = /^@[^/]+\/?[^/]+/ export function isScoped(name) { - return scopedRegExp.test(name) + return name && scopedRegExp.test(name) } const scopedMainRegExp = /^@[^/]+\/?[^/]+$/ export function isScopedMain(name) { - return scopedMainRegExp.test(name) + return name && scopedMainRegExp.test(name) } function isInternalModule(name, settings, path) {