From 5358a57680f7a84862c0fd3351cb674f9eff8d38 Mon Sep 17 00:00:00 2001 From: Alexander Ryzhikov Date: Thu, 31 Aug 2017 11:48:40 +0300 Subject: [PATCH] Handle unresolved js import when type is exported with the same name --- src/ExportMap.js | 7 +++++-- src/rules/named.js | 9 ++++++++- tests/src/rules/named.js | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index 215f3de716..416082a340 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -533,9 +533,12 @@ ExportMap.parse = function (path, content, context) { case 'TSTypeAliasDeclaration': case 'TSInterfaceDeclaration': case 'TSAbstractClassDeclaration': - case 'TSModuleDeclaration': - m.namespace.set(n.declaration.id.name, captureDoc(source, docStyleParsers, n)); + case 'TSModuleDeclaration': { + const meta = captureDoc(docStyleParsers, n); + meta.exportKind = n.exportKind; + m.namespace.set(n.declaration.id.name, meta); break; + } case 'VariableDeclaration': n.declaration.declarations.forEach((d) => recursivePatternCapture(d.id, diff --git a/src/rules/named.js b/src/rules/named.js index c4ce5ea915..95ae75bbca 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -50,7 +50,14 @@ module.exports = { `${im[key].name} not found via ${deepPath}`); } else { context.report(im[key], - im[key].name + ' not found in \'' + node.source.value + '\''); + `${im[key].name} not found in '${node.source.value}'`); + } + } else if (node.importKind === 'value') { + const meta = deepLookup.path[deepLookup.path.length - 1].namespace.get(im[key].name); + const wrongType = meta && meta.exportKind !== undefined && meta.exportKind !== 'value'; + if (wrongType) { + context.report(im[key], + `${im[key].name} not found in '${node.source.value}'`); } } }); diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index f09ee20595..84e3ebab8a 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -216,6 +216,22 @@ ruleTester.run('named', rule, { parser: require.resolve('babel-eslint'), errors: ["MyMissingClass not found in './flowtypes'"], }), + test({ + code: 'import { MyType } from "./flowtypes"', + parser: require.resolve('babel-eslint'), + errors: [{ + message: "MyType not found in './flowtypes'", + type: 'Identifier', + }], + }), + test({ + code: 'import type { MissingType } from "./flowtypes"', + parser: require.resolve('babel-eslint'), + errors: [{ + message: "MissingType not found in './flowtypes'", + type: 'Identifier', + }], + }), // jsnext test({