Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/files/with-flow-typed/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"dependencies": {}
"dependencies": {
"myflowtyped": "1.0.0"
}
}
8 changes: 8 additions & 0 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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"' }),
Expand Down Expand Up @@ -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({
Expand Down