Skip to content

Commit

Permalink
Merge pull request #1106 from syymza/flow-types-fix
Browse files Browse the repository at this point in the history
Fixed flow types imports
  • Loading branch information
ljharb authored Jun 30, 2018
2 parents 3b04d5f + 1d9ae51 commit 37554fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ module.exports = {
node.specifiers.forEach(function (im) {
if (im.type !== type) return

// ignore type imports
if (im.importKind === 'type') return

const deepLookup = imports.hasDeep(im[key].name)

if (!deepLookup.found) {
Expand Down
3 changes: 3 additions & 0 deletions tests/files/flowtypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export type MyType = {
export interface MyInterface {}

export class MyClass {}

export opaque type MyOpaqueType: string = string;

14 changes: 14 additions & 0 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ ruleTester.run('named', rule, {
code: 'import type { MissingType } from "./flowtypes"',
parser: 'babel-eslint',
}),
test({
code: 'import type { MyOpaqueType } from "./flowtypes"',
parser: 'babel-eslint',
}),
test({
code: 'import { type MyOpaqueType, MyClass } from "./flowtypes"',
parser: 'babel-eslint',
}),

// TypeScript
test({
Expand Down Expand Up @@ -262,6 +270,12 @@ ruleTester.run('named', rule, {
}],
}),

test({
code: 'import { type MyOpaqueType, MyMissingClass } from "./flowtypes"',
parser: 'babel-eslint',
errors: ["MyMissingClass not found in './flowtypes'"],
}),

// jsnext
test({
code: '/*jsnext*/ import { createSnorlax } from "redux"',
Expand Down

0 comments on commit 37554fe

Please sign in to comment.