From 9a064263867a7d266402de9ffccab3094d21bb12 Mon Sep 17 00:00:00 2001 From: futpib Date: Fri, 23 Jun 2017 18:51:32 +0300 Subject: [PATCH] Fix flow interface imports giving false-negative with `named` rule This fixes #708 without ignoring all type imports. --- src/ExportMap.js | 3 ++- tests/files/flowtypes.js | 4 ++++ tests/src/rules/named.js | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index 02b723837..e5e772914 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -155,7 +155,7 @@ export default class ExportMap { const d = dep() // CJS / ignored dependencies won't exist (#717) if (d == null) return - + d.forEach((v, n) => n !== 'default' && callback.call(thisArg, v, n, this)) }) @@ -406,6 +406,7 @@ ExportMap.parse = function (path, content, context) { case 'FunctionDeclaration': case 'ClassDeclaration': case 'TypeAlias': // flowtype with babel-eslint parser + case 'InterfaceDeclaration': m.namespace.set(n.declaration.id.name, captureDoc(docStyleParsers, n)) break case 'VariableDeclaration': diff --git a/tests/files/flowtypes.js b/tests/files/flowtypes.js index e4bbb0fd8..7ada3482b 100644 --- a/tests/files/flowtypes.js +++ b/tests/files/flowtypes.js @@ -6,3 +6,7 @@ export type MyType = { firstName: string, lastName: string }; + +export interface MyInterface {} + +export class MyClass {} diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index f027a5b3d..8cee0c731 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -72,6 +72,14 @@ ruleTester.run('named', rule, { code: 'import type { MyType } from "./flowtypes"', 'parser': 'babel-eslint', }), + test({ + code: 'import type { MyInterface } from "./flowtypes"', + 'parser': 'babel-eslint', + }), + test({ + code: 'import type { MyClass } from "./flowtypes"', + 'parser': 'babel-eslint', + }), // jsnext test({