diff --git a/src/rules/named.js b/src/rules/named.js index aa17dfb40..7c2c4f624 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -18,6 +18,8 @@ module.exports = { return // no named imports/exports } + if (isTypeFromPackage(node)) return + const imports = Exports.get(node.source.value, context) if (imports == null) return @@ -47,6 +49,14 @@ module.exports = { }) } + function isTypeFromPackage(node) { + return node.importKind === 'type' && !hasRelativePath(node.source) + } + + function hasRelativePath(source) { + return source.value.match(/^\.\//) + } + return { 'ImportDeclaration': checkSpecifiers.bind( null , 'imported' diff --git a/tests/files/with-flow-typed/flow-typed/npm/myflowtyped_v1.x.x.js b/tests/files/with-flow-typed/flow-typed/npm/myflowtyped_v1.x.x.js index 2917b03f5..8ef42f3d2 100644 --- a/tests/files/with-flow-typed/flow-typed/npm/myflowtyped_v1.x.x.js +++ b/tests/files/with-flow-typed/flow-typed/npm/myflowtyped_v1.x.x.js @@ -1,4 +1,6 @@ // flow-typed signature: ____ // flow-typed version: ____/myflowtyped_v1.x.x/flow_>=v0.33.x -declare module 'myflowtyped' {} +declare module 'myflowtyped' { + declare export type MyType = boolean; +} diff --git a/tests/files/with-flow-typed/node_modules/myflowtyped/index.js b/tests/files/with-flow-typed/node_modules/myflowtyped/index.js new file mode 100644 index 000000000..382cd024a --- /dev/null +++ b/tests/files/with-flow-typed/node_modules/myflowtyped/index.js @@ -0,0 +1 @@ +export const MyFlowTyped = {}; diff --git a/tests/files/with-flow-typed/node_modules/myflowtyped/package.json b/tests/files/with-flow-typed/node_modules/myflowtyped/package.json new file mode 100644 index 000000000..c23601c33 --- /dev/null +++ b/tests/files/with-flow-typed/node_modules/myflowtyped/package.json @@ -0,0 +1,5 @@ +{ + "name": "myflowtyped", + "version": "1.0.0", + "main": "index.js" +} diff --git a/tests/files/with-flow-typed/package.json b/tests/files/with-flow-typed/package.json index 18a1e415e..b4151a4a4 100644 --- a/tests/files/with-flow-typed/package.json +++ b/tests/files/with-flow-typed/package.json @@ -1,3 +1,5 @@ { - "dependencies": {} + "dependencies": { + "myflowtyped": "1.0.0" + } } diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index 2364c74ed..e02cb455c 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -1,4 +1,5 @@ import { test, SYNTAX_CASES } from '../utils' +import * as path from 'path' import { RuleTester } from 'eslint' import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve' @@ -12,6 +13,8 @@ function error(name, module) { , type: 'Identifier' } } +const packageDirWithFlowTyped = path.join(__dirname, '../../files/with-flow-typed') + ruleTester.run('named', rule, { valid: [ test({ code: 'import "./malformed.js"' }), @@ -80,6 +83,11 @@ ruleTester.run('named', rule, { code: 'import type { MyClass } from "./flowtypes"', 'parser': 'babel-eslint', }), + test({ + filename: packageDirWithFlowTyped + '/foo.js', + code: 'import type { MyType } from "myflowtyped"', + 'parser': 'babel-eslint', + }), // TypeScript test({