Skip to content

Commit

Permalink
fix: Remove no longer needed code for use-flow-type
Browse files Browse the repository at this point in the history
Since babel/babel-eslint#444 use-flow-type no
longer needs to check generic type annotations to suppress the
no-unused-vars rule.

This commit removes the unneeded code, and moves some test cases from
`VALID_WITH_USE_FLOW_TYPE` to `ALWAYS_VALID` so that the tests pass
again.
  • Loading branch information
lydell committed Aug 27, 2017
1 parent 675e5cd commit c1f444f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 81 deletions.
24 changes: 1 addition & 23 deletions src/rules/useFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};

Expand Down
70 changes: 12 additions & 58 deletions tests/rules/assertions/useFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: A>(): T {})',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type A from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'import type {A} from "a"; (function<T: A>(): T {})',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type {A} from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type {a as A} from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'type A = {}; function x<Y: A>(i: Y) { i }; x()',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'function x<Y: A>(i: Y) { i }; type A = {}; x()',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()',
// QualifiedTypeIdentifier -------^
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()',
// ^- QualifiedTypeIdentifier
errors: [
'\'A\' is defined but never used.'
]
}
];

Expand Down Expand Up @@ -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: A>(): T {})',
'(function<T: A>(): T {}); import type A from "a"',
'import type {A} from "a"; (function<T: A>(): T {})',
'(function<T: A>(): T {}); import type {A} from "a"',
'(function<T: A>(): T {}); import type {a as A} from "a"',
'type A = {}; function x<Y: A>(i: Y) { i }; x()',
'function x<Y: A>(i: Y) { i }; type A = {}; x()',
'type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()',
// QualifiedTypeIdentifier -------^
'function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()'
// ^- QualifiedTypeIdentifier
];

/**
Expand Down Expand Up @@ -187,4 +142,3 @@ export default {
})
]
};

0 comments on commit c1f444f

Please sign in to comment.