Commit 57bfbb5
committed
Allow underscore prefix to bypass noUnusedLocals warning
This PR continues [Allow leading underscore for
types...](#58884),
taking into account feedback from https://github.com/microsoft/TypeScript/pull/58884/files#r1643108204.
The initial commit on this PR is original work by @a-tarasyuk. The second
commit enhances the test suite and reverts the change to checker.ts to
get a new baseline on the test suite for easier comparison with the
changes. The third commit changes checker.ts to allow any unused local if
it is prefixed with an underscore. This has the effect of newly allowing
the following unused declarations:
```ts
// Variables were previously allowed only in destructuring and for-loops
const _unusedVar = 2;
let _unusedLet = 4;
var _unusedVar2 = 6;
function _unusedFunc() { }
const _unusedArrow = () => { };
class _UnusedClass { }
interface _UnusedInterface { }
type _UnusedType = string;
enum _UnusedEnum { A }
namespace _UnusedNamespace { ... }
```
As far as I can tell, enum members and properties are not checked in the
checkUnusedLocalsAndParameters function, and we do not need to special-case
them.
Closes #585611 parent 8b41116 commit 57bfbb5
File tree
3 files changed
+4
-60
lines changed- src/compiler
- tests/baselines/reference
3 files changed
+4
-60
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44409 | 44409 | | |
44410 | 44410 | | |
44411 | 44411 | | |
44412 | | - | |
44413 | | - | |
44414 | | - | |
44415 | | - | |
44416 | | - | |
44417 | | - | |
44418 | | - | |
44419 | | - | |
44420 | | - | |
44421 | | - | |
44422 | | - | |
44423 | | - | |
44424 | | - | |
44425 | | - | |
44426 | | - | |
44427 | 44412 | | |
44428 | 44413 | | |
44429 | 44414 | | |
| |||
44438 | 44423 | | |
44439 | 44424 | | |
44440 | 44425 | | |
44441 | | - | |
| 44426 | + | |
| 44427 | + | |
44442 | 44428 | | |
44443 | 44429 | | |
44444 | 44430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 4 | | |
9 | 5 | | |
10 | | - | |
| 6 | + | |
11 | 7 | | |
12 | 8 | | |
13 | 9 | | |
| |||
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
26 | | - | |
27 | | - | |
28 | 22 | | |
29 | | - | |
30 | | - | |
31 | 23 | | |
32 | | - | |
33 | | - | |
34 | 24 | | |
35 | 25 | | |
36 | 26 | | |
37 | 27 | | |
38 | | - | |
39 | | - | |
40 | 28 | | |
41 | 29 | | |
Lines changed: 1 addition & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | | - | |
5 | 3 | | |
6 | | - | |
7 | 4 | | |
8 | | - | |
9 | 5 | | |
10 | | - | |
11 | 6 | | |
12 | | - | |
13 | 7 | | |
14 | | - | |
15 | 8 | | |
16 | | - | |
17 | 9 | | |
18 | | - | |
19 | 10 | | |
20 | 11 | | |
21 | 12 | | |
22 | | - | |
23 | 13 | | |
24 | 14 | | |
25 | 15 | | |
| |||
36 | 26 | | |
37 | 27 | | |
38 | 28 | | |
39 | | - | |
| 29 | + | |
40 | 30 | | |
41 | 31 | | |
42 | 32 | | |
43 | 33 | | |
44 | 34 | | |
45 | | - | |
46 | | - | |
47 | 35 | | |
48 | 36 | | |
49 | 37 | | |
50 | 38 | | |
51 | 39 | | |
52 | | - | |
53 | | - | |
54 | 40 | | |
55 | 41 | | |
56 | 42 | | |
57 | 43 | | |
58 | 44 | | |
59 | | - | |
60 | | - | |
61 | 45 | | |
62 | 46 | | |
63 | 47 | | |
64 | 48 | | |
65 | 49 | | |
66 | 50 | | |
67 | | - | |
68 | | - | |
69 | 51 | | |
70 | 52 | | |
71 | 53 | | |
72 | 54 | | |
73 | 55 | | |
74 | | - | |
75 | | - | |
76 | 56 | | |
77 | 57 | | |
78 | 58 | | |
79 | 59 | | |
80 | 60 | | |
81 | 61 | | |
82 | | - | |
83 | | - | |
84 | 62 | | |
85 | 63 | | |
86 | 64 | | |
87 | 65 | | |
88 | 66 | | |
89 | 67 | | |
90 | | - | |
91 | | - | |
92 | 68 | | |
93 | 69 | | |
94 | 70 | | |
95 | 71 | | |
96 | 72 | | |
97 | 73 | | |
98 | | - | |
99 | | - | |
100 | 74 | | |
101 | 75 | | |
102 | 76 | | |
103 | 77 | | |
104 | 78 | | |
105 | 79 | | |
106 | | - | |
107 | | - | |
108 | 80 | | |
109 | 81 | | |
110 | 82 | | |
| |||
123 | 95 | | |
124 | 96 | | |
125 | 97 | | |
126 | | - | |
127 | | - | |
128 | 98 | | |
129 | 99 | | |
130 | 100 | | |
| |||
0 commit comments