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

Commit

Permalink
Fix: Destructured param type annotation not marked used (fixes #82) (#84
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mightyiam authored and JamesHenry committed Nov 23, 2017
1 parent 2b197fd commit 5e3999d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/rules/no-unused-vars.js
Expand Up @@ -92,6 +92,15 @@ module.exports = {

break;
}
case "TSTypeLiteral": {
annotation.members.forEach(member => {
if (member.typeAnnotation) {
markTypeAnnotationAsUsed(member.typeAnnotation);
}
});

break;
}
case "TSUnionType":
case "TSIntersectionType":
annotation.types.forEach(type => {
Expand Down Expand Up @@ -257,6 +266,12 @@ module.exports = {
ClassDeclaration: markClassOptionsAsUsed,
ClassExpression: markClassOptionsAsUsed,

ObjectPattern(node) {
if (node.typeAnnotation) {
markTypeAnnotationAsUsed(node.typeAnnotation);
}
},

MethodDefinition(node) {
if (node.decorators) {
node.decorators.forEach(markDecoratorAsUsed);
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -373,6 +373,22 @@ ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
].join("\n"),
parser
},
{
code: [
"import { Nullable } from 'nullable'",
"const foo = ({ nullable }: Nullable) => nullable",
"foo({ nullable: null })"
].join("\n"),
parser
},
{
code: [
"import { ReproInterface } from 'ReproInterface'",
"const x = ({ a = null } : { a: ReproInterface }) => a",
"console.log(x)"
].join("\n"),
parser
},
{
code: [
"import { Nullable } from 'nullable'",
Expand Down

0 comments on commit 5e3999d

Please sign in to comment.