Skip to content

Commit

Permalink
Handle unresolved js import when type is exported with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Ryzhikov authored and ljharb committed Aug 31, 2017
1 parent 4c92c47 commit 5358a57
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ExportMap.js
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/rules/named.js
Expand Up @@ -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}'`);
}
}
});
Expand Down
16 changes: 16 additions & 0 deletions tests/src/rules/named.js
Expand Up @@ -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({
Expand Down

0 comments on commit 5358a57

Please sign in to comment.