Skip to content

Commit b59714e

Browse files
author
Paul van Brenk
committed
Add more testcases and simplify
1 parent d4b99d6 commit b59714e

File tree

7 files changed

+54
-66
lines changed

7 files changed

+54
-66
lines changed

src/services/codefixes/unusedIdentifierFixes.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ namespace ts.codefix {
5454
}
5555
}
5656

57-
case SyntaxKind.FunctionDeclaration:
58-
case SyntaxKind.ClassDeclaration:
59-
case SyntaxKind.InterfaceDeclaration:
60-
case SyntaxKind.MethodDeclaration:
61-
case SyntaxKind.ModuleDeclaration:
62-
case SyntaxKind.PropertyDeclaration:
63-
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
64-
6557
case SyntaxKind.TypeParameter:
6658
const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters;
6759
if (typeParameters.length === 1) {
@@ -105,6 +97,12 @@ namespace ts.codefix {
10597

10698
case SyntaxKind.EnumDeclaration:
10799
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
100+
101+
default:
102+
if (isDeclarationName(token)) {
103+
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
104+
}
105+
break;
108106
}
109107
break;
110108

tests/cases/fourslash/unusedClassInNamespace3.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@
55
//// [| namespace Validation {
66
//// class c1 {
77
////
8-
//// }/*1*/
9-
//// } |]
8+
//// }
9+
////
10+
//// export class c2 {
11+
////
12+
//// }
13+
////
14+
//// class c3 extends c1 {
15+
////
16+
//// }
17+
////} |]
1018

1119
verify.codeFixAtPosition(`namespace Validation {
12-
}`);
20+
class c1 {
21+
}
22+
23+
export class c2 {
24+
}
25+
}`);

tests/cases/fourslash/unusedClassInNamespace4.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
// @noUnusedLocals: true
44
// @noUnusedParameters:true
5-
65
//// [| namespace Validation {
76
//// class c1 {
87
////
@@ -11,9 +10,18 @@
1110
//// export class c2 {
1211
////
1312
//// }
14-
//// } |]
13+
////
14+
//// class c3 {
15+
//// public x: c1;
16+
//// }
17+
////} |]
1518

1619
verify.codeFixAtPosition(`namespace Validation {
20+
class c1 {
21+
22+
}
23+
1724
export class c2 {
25+
1826
}
1927
}`);

tests/cases/fourslash/unusedClassInNamespace5.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/cases/fourslash/unusedClassInNamespace6.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
//// [| namespace greeter {
5+
//// enum enum1 {
6+
//// Monday
7+
//// }
8+
//// } |]
9+
10+
verify.codeFixAtPosition(`namespace greeter {
11+
}`);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
//// [| namespace greeter {
5+
//// type hw = "Hello" |"world";
6+
//// export type nw = "No" | "Way";
7+
//// } |]
8+
9+
verify.codeFixAtPosition(`namespace greeter {
10+
export type nw = "No" | "Way";
11+
}`);

0 commit comments

Comments
 (0)