This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
/
test.ts.lint
178 lines (154 loc) · 4.33 KB
/
test.ts.lint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
if (2) {}
if (2 > 1) {}
if (2 < 1) {}
if (2 >= 1) {}
if (2 <= 1) {}
if (2 == 1) {}
if (2 === 1) {}
if (2 != 1) {}
if (2 !== 1) {}
if (2 > undefined) {}
~~~~~~~~~~~~~ [CANNOT_COMPARE % ("number", "undefined")]
if (undefined === 1) {}
if (2 > undefined) {}
~~~~~~~~~~~~~ [CANNOT_COMPARE % ("number", "undefined")]
if (true) {}
if (true > false) {}
~~~~~~~~~~~~ [CANNOT_USE % (">", "boolean")]
if (true < false) {}
~~~~~~~~~~~~ [CANNOT_USE % ("<", "boolean")]
if (true >= false) {}
~~~~~~~~~~~~~ [CANNOT_USE % (">=", "boolean")]
if (true <= false) {}
~~~~~~~~~~~~~ [CANNOT_USE % ("<=", "boolean")]
if (true == false) {}
if (true === false) {}
if (true != false) {}
if (true !== false) {}
if ('') {}
if ('' > '') {}
if ('' < '') {}
if ('' >= '') {}
if ('' <= '') {}
if ('' == '') {}
if ('' === '') {}
if ('' != '') {}
if ('' !== '') {}
if ({}) {}
if ({} > {}) {}
~~~~~~~ [CANNOT_USE % (">", "object")]
if ({} < {}) {}
~~~~~~~ [CANNOT_USE % ("<", "object")]
if ({} >= {}) {}
~~~~~~~~ [CANNOT_USE % (">=", "object")]
if ({} <= {}) {}
~~~~~~~~ [CANNOT_USE % ("<=", "object")]
if ({} == {}) {}
~~~~~~~~ [CANNOT_USE % ("==", "object")]
if ({} === {}) {}
~~~~~~~~~ [CANNOT_USE % ("===", "object")]
if ({} != {}) {}
~~~~~~~~ [CANNOT_USE % ("!=", "object")]
if ({} !== {}) {}
~~~~~~~~~ [CANNOT_USE % ("!==", "object")]
if ([] === []) {}
~~~~~~~~~ [CANNOT_USE % ("===", "object")]
if (3 > 2 || 2 > 1 && true === true) {}
if ('' > '' || 2 > 1 || {} > {}) {}
~~~~~~~ [CANNOT_USE % (">", "object")]
if ('' > '' && 2 > 1 && {} > {}) {}
~~~~~~~ [CANNOT_USE % (">", "object")]
if ({} === null) {}
if (null === {}) {}
if ({} === undefined) {}
if (undefined === {}) {}
function sameObject<T>(a: T, b: T): boolean {
return a === b;
~~~~~~~ [CANNOT_USE % ("===", "object")]
}
function sameObject<T>(a: any, b: any): boolean {
return a === b;
}
type myNumber = number;
const a1: myNumber = 1
const a2: myNumber = 2
if (a1 < a2) {}
if (a2 < a1) {}
type myString = string;
const b1: myString = ''
const b2: myString = ''
if (b1 === b2) {}
if (b2 === b1) {}
type myObject = Object;
const c1: myObject = {}
const c2: myObject = {}
if (c1 === c2) {}
~~~~~~~~~ [CANNOT_USE % ("===", "object")]
if (c2 === c1) {}
~~~~~~~~~ [CANNOT_USE % ("===", "object")]
const d1: any = 'string'
const d2: any = 2
if (d1 === d2) {}
if (d2 === d1) {}
enum TestNumericEnum {
One = 1,
Two = 2,
}
const e1: TestNumericEnum = TestNumericEnum.One
#if typescript > 2.1
if (e1 === TestNumericEnum.Two) {}
if (TestNumericEnum.Two === e1) {}
if (e1 > TestNumericEnum.Two) {}
if (TestNumericEnum.Two > e1) {}
const f1: TestNumericEnum | undefined
const f2: TestNumericEnum | undefined
if (f1 === f2) {}
if (f2 === f1) {}
enum TestStringEnum {
One = 'one',
Two = 'two',
}
const g1: TestStringEnum = TestStringEnum.One
if (g1 === TestStringEnum.Two) {}
if (TestStringEnum.Two === g1) {}
if (g1 > TestStringEnum.Two) {}
if (TestStringEnum.Two > g1) {}
#endif
const h1: string | number = Math.random() > 0.5 ? 'text' : 5;
const h2: string | number = Math.random() > 0.5 ? 'test' : 2;
if (h1 > h2) {}
if (h2 > h1) {}
if (h1 === h2) {}
if (h2 === h1) {}
if (undefined === null) {}
if (null !== undefined) {}
if (1 > null) {}
~~~~~~~~ [CANNOT_COMPARE % ("number", "null")]
if (null > 1) {}
~~~~~~~~ [CANNOT_COMPARE % ("null", "number")]
if (1 >= undefined) {}
~~~~~~~~~~~~~~ [CANNOT_COMPARE % ("number", "undefined")]
if (undefined >= 1) {}
~~~~~~~~~~~~~~ [CANNOT_COMPARE % ("undefined", "number")]
if (undefined <= null) {}
~~~~~~~~~~~~~~~~~ [CANNOT_COMPARE % ("undefined", "null")]
if (null >= undefined) {}
~~~~~~~~~~~~~~~~~ [CANNOT_COMPARE % ("null", "undefined")]
const func = (param?: boolean): boolean => {
return param === undefined ? false : param;
}
const func = (param?: boolean): boolean => {
return param === null ? false : true;
}
const func = (param: number): number => {
return param + 1;
}
const func = (arg1: number, arg2: number): boolean => {
return arg1 === arg2;
}
const func = (param: string | null = null) => {
if (param !== null) {}
if (param !== undefined) {}
}
[CANNOT_USE]: Cannot use '%s' comparator for type '%s'.
[CANNOT_COMPARE]: Cannot compare type '%s' to type '%s'.