@@ -13,6 +13,7 @@ const ruleTester = new RuleTester({
13
13
parser : '@angular-eslint/template-parser' ,
14
14
} ) ;
15
15
const messageId : MessageIds = 'eqeqeq' ;
16
+ const suggestStrictEquality : MessageIds = 'suggestStrictEquality' ;
16
17
17
18
ruleTester . run ( RULE_NAME , rule , {
18
19
valid : [
@@ -31,7 +32,7 @@ ruleTester.run(RULE_NAME, rule, {
31
32
description :
32
33
'it should fail if the operation is not strict within interpolation' ,
33
34
annotatedSource : `
34
- {{ test == 'null' }}
35
+ {{ 'null' == test }}
35
36
~~~~~~~~~~~~~~
36
37
` ,
37
38
messageId,
@@ -40,15 +41,15 @@ ruleTester.run(RULE_NAME, rule, {
40
41
expectedOperation : '===' ,
41
42
} ,
42
43
annotatedOutput : `
43
- {{ test === 'null' }}
44
+ {{ 'null' === test }}
44
45
~~~~~~~~~~~~~~~
45
46
` ,
46
47
} ) ,
47
48
convertAnnotatedSourceToFailureCase ( {
48
49
description :
49
50
'it should fail if the operation is not strict within attribute directive' ,
50
51
annotatedSource : `
51
- <div [attr.disabled]="test != 'undefined' && null == 3 "></div>
52
+ <div [attr.disabled]="test != 'undefined' && null == '3' "></div>
52
53
~~~~~~~~~~~~~~~~~~~
53
54
` ,
54
55
messageId,
@@ -58,7 +59,7 @@ ruleTester.run(RULE_NAME, rule, {
58
59
} ,
59
60
options : [ { allowNullOrUndefined : true } ] ,
60
61
annotatedOutput : `
61
- <div [attr.disabled]="test !== 'undefined' && null == 3 "></div>
62
+ <div [attr.disabled]="test !== 'undefined' && null == '3' "></div>
62
63
~~~~~~~~~~~~~~~~~~~~
63
64
` ,
64
65
} ) ,
@@ -74,27 +75,45 @@ ruleTester.run(RULE_NAME, rule, {
74
75
actualOperation : '==' ,
75
76
expectedOperation : '===' ,
76
77
} ,
77
- annotatedOutput : `
78
+ suggestions : [
79
+ {
80
+ messageId : suggestStrictEquality ,
81
+ output : `
78
82
<div *ngIf="test === true || test1 !== undefined"></div>
79
- ~~~~~~~~~~~~~
80
- ` ,
83
+
84
+ ` ,
85
+ data : {
86
+ actualOperation : '==' ,
87
+ expectedOperation : '===' ,
88
+ } ,
89
+ } ,
90
+ ] ,
81
91
} ) ,
82
92
convertAnnotatedSourceToFailureCase ( {
83
93
description :
84
94
'it should fail if the operation is not strict within conditional' ,
85
95
annotatedSource : `
86
- {{ one != two ? c > d : 'hey!' }}
87
- ~~~~~~~~~~
96
+ {{ one != '02' ? c > d : 'hey!' }}
97
+ ~~~~~~~~~~~
88
98
` ,
89
99
messageId,
90
100
data : {
91
101
actualOperation : '!=' ,
92
102
expectedOperation : '!==' ,
93
103
} ,
94
- annotatedOutput : `
95
- {{ one !== two ? c > d : 'hey!' }}
96
- ~~~~~~~~~~~
97
- ` ,
104
+ suggestions : [
105
+ {
106
+ messageId : suggestStrictEquality ,
107
+ output : `
108
+ {{ one !== '02' ? c > d : 'hey!' }}
109
+
110
+ ` ,
111
+ data : {
112
+ actualOperation : '!=' ,
113
+ expectedOperation : '!==' ,
114
+ } ,
115
+ } ,
116
+ ] ,
98
117
} ) ,
99
118
convertAnnotatedSourceToFailureCase ( {
100
119
description :
@@ -108,10 +127,19 @@ ruleTester.run(RULE_NAME, rule, {
108
127
actualOperation : '==' ,
109
128
expectedOperation : '===' ,
110
129
} ,
111
- annotatedOutput : `
130
+ suggestions : [
131
+ {
132
+ messageId : suggestStrictEquality ,
133
+ output : `
112
134
{{ a === b && 1 === b ? c > d : 'hey!' }}
113
- ~~~~~~~
114
- ` ,
135
+
136
+ ` ,
137
+ data : {
138
+ actualOperation : '==' ,
139
+ expectedOperation : '===' ,
140
+ } ,
141
+ } ,
142
+ ] ,
115
143
} ) ,
116
144
convertAnnotatedSourceToFailureCase ( {
117
145
description :
@@ -125,45 +153,72 @@ ruleTester.run(RULE_NAME, rule, {
125
153
actualOperation : '!=' ,
126
154
expectedOperation : '!==' ,
127
155
} ,
128
- annotatedOutput : `
156
+ suggestions : [
157
+ {
158
+ messageId : suggestStrictEquality ,
159
+ output : `
129
160
{{ c > d ? a !== b : 'hey!' }}
130
- ~~~~~~~
131
- ` ,
161
+
162
+ ` ,
163
+ data : {
164
+ actualOperation : '!=' ,
165
+ expectedOperation : '!==' ,
166
+ } ,
167
+ } ,
168
+ ] ,
132
169
} ) ,
133
170
convertAnnotatedSourceToFailureCase ( {
134
171
description :
135
172
'it should fail if the operation is not strict within conditional (falseExp)' ,
136
173
annotatedSource : `
137
- {{ c > d ? 'hey!' : a == b }}
138
- ~~~~~~
174
+ {{ c > d ? 'hey!' : a == false }}
175
+ ~~~~~~~~~~
139
176
` ,
140
177
messageId,
141
178
data : {
142
179
actualOperation : '==' ,
143
180
expectedOperation : '===' ,
144
181
} ,
145
- annotatedOutput : `
146
- {{ c > d ? 'hey!' : a === b }}
147
- ~~~~~~~
148
- ` ,
182
+ suggestions : [
183
+ {
184
+ messageId : suggestStrictEquality ,
185
+ output : `
186
+ {{ c > d ? 'hey!' : a === false }}
187
+
188
+ ` ,
189
+ data : {
190
+ actualOperation : '==' ,
191
+ expectedOperation : '===' ,
192
+ } ,
193
+ } ,
194
+ ] ,
149
195
} ) ,
150
196
convertAnnotatedSourceToFailureCase ( {
151
197
description :
152
198
'it should fail if the operation is not strict within recursive conditional' ,
153
199
annotatedSource : `
154
- {{ undefined == test1 && a === b ? (c > d ? d != 3 : v === 4) : 'hey!' }}
155
- ~~~~~~
200
+ {{ undefined == test1 && a === b ? (c > d ? d != '0' : v === 4) : 'hey!' }}
201
+ ~~~~~~~~
156
202
` ,
157
203
messageId,
158
204
options : [ { allowNullOrUndefined : true } ] ,
159
205
data : {
160
206
actualOperation : '!=' ,
161
207
expectedOperation : '!==' ,
162
208
} ,
163
- annotatedOutput : `
164
- {{ undefined == test1 && a === b ? (c > d ? d !== 3 : v === 4) : 'hey!' }}
165
- ~~~~~~~
166
- ` ,
209
+ suggestions : [
210
+ {
211
+ messageId : suggestStrictEquality ,
212
+ output : `
213
+ {{ undefined == test1 && a === b ? (c > d ? d !== '0' : v === 4) : 'hey!' }}
214
+
215
+ ` ,
216
+ data : {
217
+ actualOperation : '!=' ,
218
+ expectedOperation : '!==' ,
219
+ } ,
220
+ } ,
221
+ ] ,
167
222
} ) ,
168
223
convertAnnotatedSourceToFailureCase ( {
169
224
description :
@@ -177,10 +232,19 @@ ruleTester.run(RULE_NAME, rule, {
177
232
actualOperation : '!=' ,
178
233
expectedOperation : '!==' ,
179
234
} ,
180
- annotatedOutput : `
235
+ suggestions : [
236
+ {
237
+ messageId : suggestStrictEquality ,
238
+ output : `
181
239
{{ undefined !== test1 }}
182
- ~~~~~~~~~~~~~~~~~~~
183
- ` ,
240
+
241
+ ` ,
242
+ data : {
243
+ actualOperation : '!=' ,
244
+ expectedOperation : '!==' ,
245
+ } ,
246
+ } ,
247
+ ] ,
184
248
} ) ,
185
249
] ,
186
250
} ) ;
0 commit comments