From 592a7e1c37967f68e56b0b6d024196ad560aac36 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Thu, 14 Dec 2017 12:02:46 +1100 Subject: [PATCH] fix: handle exceptions from parse-package-name --- src/rules/no-internal-import.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rules/no-internal-import.js b/src/rules/no-internal-import.js index c0b3ef0..a450bc8 100644 --- a/src/rules/no-internal-import.js +++ b/src/rules/no-internal-import.js @@ -13,7 +13,7 @@ export const create = context => { const packages = getPackages(process.cwd()); return moduleVisitor(node => { - const { name, path: internalPath } = parse(node.value); + const { name, path: internalPath } = tryParse(node.value); if (internalPath && packages.find(pkg => pkg.name === name)) { context.report({ node, @@ -22,3 +22,11 @@ export const create = context => { } }, moduleUtilOptions); }; + +const tryParse = text => { + try { + return parse(text); + } catch (error) { + return { path: text, name: '' }; + } +};