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

Commit

Permalink
Fix: Mark call expression type parameters as used (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothykang authored and JamesHenry committed Nov 23, 2017
1 parent 29bd53c commit 3284af4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rules/no-unused-vars.js
Expand Up @@ -271,6 +271,14 @@ module.exports = {
FunctionExpression: markFunctionReturnTypeAsUsed,
ArrowFunctionExpression: markFunctionReturnTypeAsUsed,

CallExpression(node) {
if (node.typeParameters && node.typeParameters.params) {
node.typeParameters.params.forEach(
markTypeAnnotationAsUsed
);
}
},

Decorator: markDecoratorAsUsed,
TSInterfaceHeritage: markExtendedInterfaceAsUsed,

Expand Down
45 changes: 45 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -184,6 +184,36 @@ ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
].join("\n"),
parser
},
{
code: [
"import { Foo } from 'foo'",
"function bar<T>() {}",
"bar<Foo>()"
].join("\n"),
parser
},
{
code: [
"import { Foo } from 'foo'",
"const bar = function <T>() {}",
"bar<Foo>()"
].join("\n"),
parser
},
{
code: [
"import { Foo } from 'foo'",
"const bar = <T>() => {}",
"bar<Foo>()"
].join("\n"),
parser
},
{
code: ["import { Foo } from 'foo'", "<Foo>(<T>() => {})()"].join(
"\n"
),
parser
},
{
code: [
"import { Nullable } from 'nullable'",
Expand Down Expand Up @@ -469,6 +499,21 @@ ruleTester.run("no-unused-vars", ruleNoUnusedVars, {
}
]
},
{
code: [
"import { Foo, Bar } from 'foo';",
"function baz<Foo>() {}",
"baz<Bar>()"
].join("\n"),
parser,
errors: [
{
message: "'Foo' is defined but never used.",
line: 1,
column: 10
}
]
},
{
code: [
"import { Nullable } from 'nullable';",
Expand Down

0 comments on commit 3284af4

Please sign in to comment.