Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Fix: Mark qualified name type annotations as used (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothykang authored and JamesHenry committed Nov 23, 2017
1 parent 5e3999d commit 29bd53c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/rules/no-unused-vars.js
Expand Up @@ -69,15 +69,26 @@ module.exports = {
const annotation = node.typeAnnotation || node;

switch (annotation.type) {
case "Identifier": {
markVariableAsUsed(context, annotation.name);
break;
}
case "TSArrayType": {
markTypeAnnotationAsUsed(annotation.elementType);
break;
}
case "TSQualifiedName": {
markTypeAnnotationAsUsed(annotation.left);
markTypeAnnotationAsUsed(annotation.right);
break;
}
case "TSTypeReference": {
if (annotation.typeName.type === "TSArrayType") {
markTypeAnnotationAsUsed(
annotation.typeName.elementType
);
} else if (annotation.typeName.type === "TSQualifiedName") {
markTypeAnnotationAsUsed(annotation.typeName);
} else {
markVariableAsUsed(context, annotation.typeName.name);
if (
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -434,6 +434,22 @@ ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
"}"
].join("\n"),
parser
},
{
code: [
"import Foo from 'foo'",
"const bar: Foo.Bar = null",
"console.log(bar)"
].join("\n"),
parser
},
{
code: [
"import Foo from 'foo'",
"const baz: Foo.Bar.Baz = null",
"console.log(baz)"
].join("\n"),
parser
}
],

Expand Down

0 comments on commit 29bd53c

Please sign in to comment.