Repository: nzakas/eslint-plugin-typescript
Pull request #84 (2017-10-08 17:07:47)

Destructured param type annotation not marked used
Here is a failing seemingly valid test code.

mightyiam: @weirdpattern and @j-f1 I have fixed the issues you brought up. A space and the function call.

Your turn to fix the bug :laughing:.
weirdpattern: Thank you @mightyiam I will take a look at this tomorrow
weirdpattern: Ok, I submitted a PR in @mightyiam to update his branch, and finally this PR.
This should take care of #82 

Patch:
diff --git a/lib/rules/no-triple-slash-reference.js b/lib/rules/no-triple-slash-reference.js
index c010343..49e8c32 100644
--- a/lib/rules/no-triple-slash-reference.js
+++ b/lib/rules/no-triple-slash-reference.js
@@ -35,9 +35,9 @@ module.exports = {
          * @private
          */
         function checkTripleSlashReference(program) {
-            const leading = sourceCode.getComments(program).leading;
+            const commentsBefore = sourceCode.getCommentsBefore(program);
 
-            leading.forEach(comment => {
+            commentsBefore.forEach(comment => {
                 if (comment.type !== "Line") {
                     return;
                 }
diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js
index 0f6aef8..3995024 100644
--- a/lib/rules/no-unused-vars.js
+++ b/lib/rules/no-unused-vars.js
@@ -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 => {
@@ -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);
diff --git a/lib/rules/type-annotation-spacing.js b/lib/rules/type-annotation-spacing.js
index dd61c66..8a8aeb2 100644
--- a/lib/rules/type-annotation-spacing.js
+++ b/lib/rules/type-annotation-spacing.js
@@ -45,6 +45,7 @@ module.exports = {
     },
 
     create(context) {
+        const punctuators = [":", "=>"];
         const sourceCode = context.getSourceCode();
         const options = context.options[0] || {};
 
@@ -78,12 +79,16 @@ module.exports = {
             const nextToken = typeAnnotation;
             const punctuatorToken = sourceCode.getTokenBefore(nextToken);
             const previousToken = sourceCode.getTokenBefore(punctuatorToken);
+            const type = punctuatorToken.value;
+
+            if (punctuators.indexOf(type) === -1) {
+                return;
+            }
 
             const previousDelta =
                 punctuatorToken.range[0] - previousToken.range[1];
             const nextDelta = nextToken.range[0] - punctuatorToken.range[1];
 
-            const type = punctuatorToken.value;
             const before =
                 type === ":" ? colonOptions.before : arrowOptions.before;
             const after =
@@ -159,9 +164,7 @@ module.exports = {
                 }
             },
             TypeAnnotation(node) {
-                if (node.parent.type !== "TSAsExpression") {
-                    checkTypeAnnotationSpacing(node.typeAnnotation);
-                }
+                checkTypeAnnotationSpacing(node.typeAnnotation);
             },
             FunctionDeclaration: checkFunctionReturnTypeSpacing,
             FunctionExpression: checkFunctionReturnTypeSpacing,


Test patch:
diff --git a/tests/lib/rules/no-triple-slash-reference.js b/tests/lib/rules/no-triple-slash-reference.js
index 9656fc6..dd0a11f 100644
--- a/tests/lib/rules/no-triple-slash-reference.js
+++ b/tests/lib/rules/no-triple-slash-reference.js
@@ -39,6 +39,20 @@ ruleTester.run("no-triple-slash-reference", rule, {
                     column: 1
                 }
             ]
+        },
+        {
+            code: `
+/// <reference path="Animal" />
+let a
+            `,
+            parser: "typescript-eslint-parser",
+            errors: [
+                {
+                    message: "Do not use a triple slash reference",
+                    line: 2,
+                    column: 1
+                }
+            ]
         }
     ]
 });
diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js
index fbc5937..a737b3d 100644
--- a/tests/lib/rules/no-unused-vars.js
+++ b/tests/lib/rules/no-unused-vars.js
@@ -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'",
diff --git a/tests/lib/rules/type-annotation-spacing.js b/tests/lib/rules/type-annotation-spacing.js
index 2400ea1..bd6b5d5 100644
--- a/tests/lib/rules/type-annotation-spacing.js
+++ b/tests/lib/rules/type-annotation-spacing.js
@@ -19,6 +19,14 @@ const ruleTester = new RuleTester();
 
 ruleTester.run("type-annotation-spacing", rule, {
     valid: [
+        {
+            code: `
+interface resolve {
+    resolver: (() => PromiseLike<T>) | PromiseLike<T>;
+}
+            `,
+            parser: "typescript-eslint-parser"
+        },
         {
             code: "const foo = {} as Foo;",
             parser: "typescript-eslint-parser"
@@ -1175,6 +1183,18 @@ class Foo {
             `,
             options: [{ before: true }],
             parser: "typescript-eslint-parser"
+        },
+        {
+            code: "let resolver: (() => PromiseLike<T>) | PromiseLike<T>;",
+            parser: "typescript-eslint-parser"
+        },
+        {
+            code: `
+interface resolve {
+    resolver: (() => PromiseLike<T>) | PromiseLike<T>;
+}
+            `,
+            parser: "typescript-eslint-parser"
         }
     ],
     invalid: [