From 513a488ea7b5fdbd6b5b42386307ef9110a1bc00 Mon Sep 17 00:00:00 2001 From: Daniele Zanni Date: Fri, 18 May 2018 12:32:33 +1000 Subject: [PATCH 1/3] Fixed flow types imports --- src/rules/named.js | 3 +++ tests/files/flowtypes.js | 3 +++ tests/src/rules/named.js | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/src/rules/named.js b/src/rules/named.js index 8c2acd714..f0151a89d 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -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) { diff --git a/tests/files/flowtypes.js b/tests/files/flowtypes.js index 7ada3482b..2df247147 100644 --- a/tests/files/flowtypes.js +++ b/tests/files/flowtypes.js @@ -10,3 +10,6 @@ export type MyType = { export interface MyInterface {} export class MyClass {} + +export opaque type MyOpaqueType: string = string; + diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index 4fdd3434f..fce523093 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -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({ From 96500b84518f2e2802a79f673da35e5625bb8c3a Mon Sep 17 00:00:00 2001 From: Daniele Zanni Date: Fri, 18 May 2018 18:39:01 +1000 Subject: [PATCH 2/3] Added missing space --- src/rules/named.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/named.js b/src/rules/named.js index f0151a89d..57e4f1d9e 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -31,7 +31,7 @@ module.exports = { if (im.type !== type) return // ignore type imports - if(im.importKind === 'type') return + if (im.importKind === 'type') return const deepLookup = imports.hasDeep(im[key].name) From 1d9ae51f9f305ed54c9b36d1c6a883392ea94d8e Mon Sep 17 00:00:00 2001 From: syymza Date: Fri, 18 May 2018 22:34:05 +1000 Subject: [PATCH 3/3] Added test for mixed flow imports --- tests/src/rules/named.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index fce523093..cb1a5b843 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -270,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"',