diff --git a/src/rules/useFlowType.js b/src/rules/useFlowType.js index 185dad40..d1ff50c9 100644 --- a/src/rules/useFlowType.js +++ b/src/rules/useFlowType.js @@ -9,29 +9,7 @@ const create = (context) => { DeclareClass: markTypeAsUsed, DeclareFunction: markTypeAsUsed, DeclareModule: markTypeAsUsed, - DeclareVariable: markTypeAsUsed, - GenericTypeAnnotation (node) { - let typeId; - let scope; - let variable; - - if (node.id.type === 'Identifier') { - typeId = node.id; - } else if (node.id.type === 'QualifiedTypeIdentifier') { - typeId = node.id; - do { - typeId = typeId.qualification; - } while (typeId.qualification); - } - - for (scope = context.getScope(); scope; scope = scope.upper) { - variable = scope.set.get(typeId.name); - if (variable && variable.defs.length) { - context.markVariableAsUsed(typeId.name); - break; - } - } - } + DeclareVariable: markTypeAsUsed }; }; diff --git a/tests/rules/assertions/useFlowType.js b/tests/rules/assertions/useFlowType.js index cccdaba5..e2d1eccf 100644 --- a/tests/rules/assertions/useFlowType.js +++ b/tests/rules/assertions/useFlowType.js @@ -34,62 +34,6 @@ const VALID_WITH_USE_FLOW_TYPE = [ errors: [ '\'A\' is defined but never used.' ] - }, - { - code: 'import type A from "a"; (function(): T {})', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: '(function(): T {}); import type A from "a"', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: 'import type {A} from "a"; (function(): T {})', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: '(function(): T {}); import type {A} from "a"', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: '(function(): T {}); import type {a as A} from "a"', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: 'type A = {}; function x(i: Y) { i }; x()', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: 'function x(i: Y) { i }; type A = {}; x()', - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: 'type A = {}; function x(i: Y) { i }; x()', - // QualifiedTypeIdentifier -------^ - errors: [ - '\'A\' is defined but never used.' - ] - }, - { - code: 'function x(i: Y) { i }; type A = {}; x()', - // ^- QualifiedTypeIdentifier - errors: [ - '\'A\' is defined but never used.' - ] } ]; @@ -125,7 +69,18 @@ const ALWAYS_VALID = [ 'import type A from "a"; (function(): A {})', '(function(): A {}); import type A from "a";', 'declare interface A {}', - 'declare type A = {}' + 'declare type A = {}', + 'import type A from "a"; (function(): T {})', + '(function(): T {}); import type A from "a"', + 'import type {A} from "a"; (function(): T {})', + '(function(): T {}); import type {A} from "a"', + '(function(): T {}); import type {a as A} from "a"', + 'type A = {}; function x(i: Y) { i }; x()', + 'function x(i: Y) { i }; type A = {}; x()', + 'type A = {}; function x(i: Y) { i }; x()', + // QualifiedTypeIdentifier -------^ + 'function x(i: Y) { i }; type A = {}; x()' + // ^- QualifiedTypeIdentifier ]; /** @@ -187,4 +142,3 @@ export default { }) ] }; -