@tcy/eslint-rules 1.9.1 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +59 -62
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/index.html +19 -19
- package/coverage/lcov-report/src/array-elements-per-line.js.html +1 -1
- package/coverage/lcov-report/src/back/back.js.html +1 -1
- package/coverage/lcov-report/src/back/http.js.html +1 -1
- package/coverage/lcov-report/src/back/index.html +1 -1
- package/coverage/lcov-report/src/back/recommended.js.html +1 -1
- package/coverage/lcov-report/src/bin/eslint-cache-guard.js.html +1 -1
- package/coverage/lcov-report/src/bin/index.html +1 -1
- package/coverage/lcov-report/src/client/client.js.html +1 -1
- package/coverage/lcov-report/src/client/index.html +1 -1
- package/coverage/lcov-report/src/client/recommended.js.html +1 -1
- package/coverage/lcov-report/src/decorator-type-enforcement.js.html +1 -1
- package/coverage/lcov-report/src/enforce-tailwind-important.js.html +116 -125
- package/coverage/lcov-report/src/export-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/src/import-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/src/index.html +20 -20
- package/coverage/lcov-report/src/index.js.html +1 -1
- package/coverage/lcov-report/src/jsx-boolean-shorthand.js.html +1 -1
- package/coverage/lcov-report/src/jsx-expression-string-literals.js.html +1 -1
- package/coverage/lcov-report/src/jsx-ref-string-exists.js.html +1 -1
- package/coverage/lcov-report/src/no-static-key-in-map.js.html +1 -1
- package/coverage/lcov-report/src/plugin.js.html +1 -1
- package/coverage/lcov-report/src/recommended.js.html +1 -1
- package/coverage/lcov-report/src/require-fragment-key.js.html +1 -1
- package/coverage/lcov-report/src/route-dto-required.js.html +1 -1
- package/coverage/lcov-report/src/v-model-name-match.js.html +1 -1
- package/coverage/lcov-report/src/vuejs-define-component.js.html +1 -1
- package/coverage/lcov-report/src/vuejs-define-workspace.js.html +1 -1
- package/coverage/lcov.info +123 -135
- package/package.json +3 -3
- package/src/enforce-tailwind-important.js +13 -16
- package/tests/enforce-tailwind-important.spec.js +100 -1
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
131
131
|
Code coverage generated by
|
|
132
132
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
133
|
-
at 2026-09-
|
|
133
|
+
at 2026-09-17T13:27:07.234Z
|
|
134
134
|
</div>
|
|
135
135
|
<script src="../prettify.js"></script>
|
|
136
136
|
<script>
|
|
@@ -772,7 +772,7 @@ export default {
|
|
|
772
772
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
773
773
|
Code coverage generated by
|
|
774
774
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
775
|
-
at 2026-09-
|
|
775
|
+
at 2026-09-17T13:27:07.234Z
|
|
776
776
|
</div>
|
|
777
777
|
<script src="../prettify.js"></script>
|
|
778
778
|
<script>
|
|
@@ -298,7 +298,7 @@ export default {
|
|
|
298
298
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
299
299
|
Code coverage generated by
|
|
300
300
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
301
|
-
at 2026-09-
|
|
301
|
+
at 2026-09-17T13:27:07.234Z
|
|
302
302
|
</div>
|
|
303
303
|
<script src="../prettify.js"></script>
|
|
304
304
|
<script>
|
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
290
290
|
Code coverage generated by
|
|
291
291
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
292
|
-
at 2026-09-
|
|
292
|
+
at 2026-09-17T13:27:07.234Z
|
|
293
293
|
</div>
|
|
294
294
|
<script src="../prettify.js"></script>
|
|
295
295
|
<script>
|
|
@@ -328,7 +328,7 @@ export default {
|
|
|
328
328
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
329
329
|
Code coverage generated by
|
|
330
330
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
331
|
-
at 2026-09-
|
|
331
|
+
at 2026-09-17T13:27:07.234Z
|
|
332
332
|
</div>
|
|
333
333
|
<script src="../prettify.js"></script>
|
|
334
334
|
<script>
|
|
@@ -265,7 +265,7 @@ export default {
|
|
|
265
265
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
266
266
|
Code coverage generated by
|
|
267
267
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
268
|
-
at 2026-09-
|
|
268
|
+
at 2026-09-17T13:27:07.234Z
|
|
269
269
|
</div>
|
|
270
270
|
<script src="../prettify.js"></script>
|
|
271
271
|
<script>
|
package/coverage/lcov.info
CHANGED
|
@@ -134,53 +134,49 @@ FN:91,buildFixedTemplateText
|
|
|
134
134
|
FN:92,(anonymous_11)
|
|
135
135
|
FN:99,(anonymous_12)
|
|
136
136
|
FN:112,processExpression
|
|
137
|
-
FN:
|
|
138
|
-
FN:
|
|
139
|
-
FN:
|
|
140
|
-
FN:
|
|
141
|
-
FN:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
FNDA:
|
|
147
|
-
FNDA:
|
|
148
|
-
FNDA:
|
|
149
|
-
FNDA:
|
|
150
|
-
FNDA:
|
|
151
|
-
FNDA:
|
|
152
|
-
FNDA:
|
|
153
|
-
FNDA:
|
|
154
|
-
FNDA:0,(anonymous_8)
|
|
155
|
-
FNDA:0,(anonymous_9)
|
|
137
|
+
FN:128,(anonymous_14)
|
|
138
|
+
FN:136,(anonymous_15)
|
|
139
|
+
FN:148,(anonymous_16)
|
|
140
|
+
FN:177,(anonymous_17)
|
|
141
|
+
FN:192,(anonymous_18)
|
|
142
|
+
FNF:19
|
|
143
|
+
FNH:14
|
|
144
|
+
FNDA:35,(anonymous_0)
|
|
145
|
+
FNDA:9,(anonymous_1)
|
|
146
|
+
FNDA:34,(anonymous_2)
|
|
147
|
+
FNDA:13,(anonymous_3)
|
|
148
|
+
FNDA:9,(anonymous_4)
|
|
149
|
+
FNDA:26,(anonymous_5)
|
|
150
|
+
FNDA:14,reportIfMissing
|
|
151
|
+
FNDA:16,(anonymous_7)
|
|
152
|
+
FNDA:10,(anonymous_8)
|
|
153
|
+
FNDA:9,(anonymous_9)
|
|
156
154
|
FNDA:0,buildFixedTemplateText
|
|
157
155
|
FNDA:0,(anonymous_11)
|
|
158
156
|
FNDA:0,(anonymous_12)
|
|
159
|
-
FNDA:
|
|
160
|
-
FNDA:
|
|
157
|
+
FNDA:29,processExpression
|
|
158
|
+
FNDA:1,(anonymous_14)
|
|
161
159
|
FNDA:0,(anonymous_15)
|
|
162
160
|
FNDA:0,(anonymous_16)
|
|
163
|
-
FNDA:
|
|
164
|
-
FNDA:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
DA:4,9
|
|
168
|
-
DA:6,1
|
|
161
|
+
FNDA:9,(anonymous_17)
|
|
162
|
+
FNDA:9,(anonymous_18)
|
|
163
|
+
DA:4,35
|
|
164
|
+
DA:6,9
|
|
169
165
|
DA:16,1
|
|
170
|
-
DA:28,
|
|
171
|
-
DA:31,
|
|
172
|
-
DA:58,
|
|
173
|
-
DA:60,
|
|
174
|
-
DA:63,
|
|
175
|
-
DA:69,
|
|
176
|
-
DA:70,
|
|
177
|
-
DA:73,
|
|
178
|
-
DA:74,
|
|
179
|
-
DA:77,
|
|
180
|
-
DA:78,
|
|
181
|
-
DA:83,
|
|
182
|
-
DA:84,
|
|
183
|
-
DA:86,
|
|
166
|
+
DA:28,34
|
|
167
|
+
DA:31,13
|
|
168
|
+
DA:58,9
|
|
169
|
+
DA:60,9
|
|
170
|
+
DA:63,26
|
|
171
|
+
DA:69,16
|
|
172
|
+
DA:70,14
|
|
173
|
+
DA:73,14
|
|
174
|
+
DA:74,5
|
|
175
|
+
DA:77,10
|
|
176
|
+
DA:78,9
|
|
177
|
+
DA:83,9
|
|
178
|
+
DA:84,9
|
|
179
|
+
DA:86,9
|
|
184
180
|
DA:92,0
|
|
185
181
|
DA:93,0
|
|
186
182
|
DA:95,0
|
|
@@ -193,60 +189,57 @@ DA:104,0
|
|
|
193
189
|
DA:105,0
|
|
194
190
|
DA:108,0
|
|
195
191
|
DA:109,0
|
|
196
|
-
DA:113,
|
|
192
|
+
DA:113,29
|
|
197
193
|
DA:114,0
|
|
198
|
-
DA:117,
|
|
199
|
-
DA:
|
|
200
|
-
DA:
|
|
201
|
-
DA:
|
|
202
|
-
DA:
|
|
203
|
-
DA:
|
|
204
|
-
DA:
|
|
205
|
-
DA:
|
|
206
|
-
DA:
|
|
207
|
-
DA:
|
|
208
|
-
DA:
|
|
209
|
-
DA:
|
|
210
|
-
DA:137,0
|
|
211
|
-
DA:139,0
|
|
212
|
-
DA:140,0
|
|
194
|
+
DA:117,29
|
|
195
|
+
DA:120,14
|
|
196
|
+
DA:121,13
|
|
197
|
+
DA:123,14
|
|
198
|
+
DA:125,2
|
|
199
|
+
DA:126,2
|
|
200
|
+
DA:128,1
|
|
201
|
+
DA:129,1
|
|
202
|
+
DA:130,1
|
|
203
|
+
DA:133,1
|
|
204
|
+
DA:135,0
|
|
205
|
+
DA:136,0
|
|
213
206
|
DA:141,0
|
|
214
|
-
DA:
|
|
215
|
-
DA:
|
|
216
|
-
DA:
|
|
217
|
-
DA:
|
|
218
|
-
DA:
|
|
219
|
-
DA:
|
|
220
|
-
DA:
|
|
221
|
-
DA:
|
|
222
|
-
DA:
|
|
223
|
-
DA:
|
|
224
|
-
DA:
|
|
225
|
-
DA:
|
|
226
|
-
DA:
|
|
227
|
-
DA:
|
|
228
|
-
DA:
|
|
229
|
-
DA:
|
|
230
|
-
DA:
|
|
207
|
+
DA:142,0
|
|
208
|
+
DA:145,0
|
|
209
|
+
DA:149,0
|
|
210
|
+
DA:151,0
|
|
211
|
+
DA:154,0
|
|
212
|
+
DA:157,1
|
|
213
|
+
DA:158,1
|
|
214
|
+
DA:159,1
|
|
215
|
+
DA:163,10
|
|
216
|
+
DA:164,2
|
|
217
|
+
DA:166,10
|
|
218
|
+
DA:167,10
|
|
219
|
+
DA:169,1
|
|
220
|
+
DA:176,9
|
|
221
|
+
DA:178,9
|
|
222
|
+
DA:179,9
|
|
223
|
+
DA:181,9
|
|
224
|
+
DA:182,9
|
|
225
|
+
DA:184,9
|
|
231
226
|
DA:185,0
|
|
232
|
-
DA:
|
|
233
|
-
DA:
|
|
234
|
-
DA:
|
|
235
|
-
DA:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
BRDA:
|
|
241
|
-
BRDA:28,0,1,7
|
|
242
|
-
BRDA:33,1,0,4
|
|
227
|
+
DA:186,9
|
|
228
|
+
DA:187,9
|
|
229
|
+
DA:193,9
|
|
230
|
+
DA:201,0
|
|
231
|
+
LF:68
|
|
232
|
+
LH:45
|
|
233
|
+
BRDA:28,0,0,34
|
|
234
|
+
BRDA:28,0,1,25
|
|
235
|
+
BRDA:33,1,0,13
|
|
243
236
|
BRDA:33,1,1,1
|
|
244
|
-
BRDA:33,1,2,
|
|
245
|
-
BRDA:73,2,0,
|
|
246
|
-
BRDA:73,2,1,
|
|
247
|
-
BRDA:77,3,0,
|
|
248
|
-
BRDA:77,3,1,
|
|
249
|
-
BRDA:84,4,0,
|
|
237
|
+
BRDA:33,1,2,12
|
|
238
|
+
BRDA:73,2,0,5
|
|
239
|
+
BRDA:73,2,1,9
|
|
240
|
+
BRDA:77,3,0,9
|
|
241
|
+
BRDA:77,3,1,1
|
|
242
|
+
BRDA:84,4,0,9
|
|
250
243
|
BRDA:84,4,1,0
|
|
251
244
|
BRDA:99,5,0,0
|
|
252
245
|
BRDA:99,5,1,0
|
|
@@ -257,51 +250,46 @@ BRDA:104,7,1,0
|
|
|
257
250
|
BRDA:104,8,0,0
|
|
258
251
|
BRDA:104,8,1,0
|
|
259
252
|
BRDA:113,9,0,0
|
|
260
|
-
BRDA:113,9,1,
|
|
261
|
-
BRDA:117,10,0,
|
|
262
|
-
BRDA:117,10,1,
|
|
263
|
-
BRDA:117,10,2,
|
|
253
|
+
BRDA:113,9,1,29
|
|
254
|
+
BRDA:117,10,0,14
|
|
255
|
+
BRDA:117,10,1,2
|
|
256
|
+
BRDA:117,10,2,1
|
|
264
257
|
BRDA:117,10,3,0
|
|
265
|
-
BRDA:117,10,4,
|
|
266
|
-
BRDA:117,10,5,
|
|
267
|
-
BRDA:
|
|
268
|
-
BRDA:
|
|
269
|
-
BRDA:
|
|
270
|
-
BRDA:
|
|
271
|
-
BRDA:129,
|
|
272
|
-
BRDA:129,13,1
|
|
273
|
-
BRDA:
|
|
274
|
-
BRDA:
|
|
275
|
-
BRDA:
|
|
276
|
-
BRDA:
|
|
277
|
-
BRDA:
|
|
278
|
-
BRDA:
|
|
279
|
-
BRDA:
|
|
280
|
-
BRDA:
|
|
281
|
-
BRDA:
|
|
282
|
-
BRDA:
|
|
283
|
-
BRDA:
|
|
284
|
-
BRDA:
|
|
285
|
-
BRDA:
|
|
286
|
-
BRDA:
|
|
287
|
-
BRDA:
|
|
288
|
-
BRDA:
|
|
289
|
-
BRDA:
|
|
290
|
-
BRDA:
|
|
291
|
-
BRDA:
|
|
292
|
-
BRDA:
|
|
293
|
-
BRDA:
|
|
294
|
-
BRDA:
|
|
295
|
-
BRDA:
|
|
296
|
-
BRDA:
|
|
297
|
-
BRDA:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
BRDA:197,26,3,0
|
|
301
|
-
BRDA:197,26,4,0
|
|
302
|
-
BRDA:197,26,5,0
|
|
303
|
-
BRF:63
|
|
304
|
-
BRH:5
|
|
258
|
+
BRDA:117,10,4,1
|
|
259
|
+
BRDA:117,10,5,10
|
|
260
|
+
BRDA:117,10,6,1
|
|
261
|
+
BRDA:120,11,0,13
|
|
262
|
+
BRDA:120,11,1,1
|
|
263
|
+
BRDA:129,12,0,1
|
|
264
|
+
BRDA:129,12,1,0
|
|
265
|
+
BRDA:129,13,0,1
|
|
266
|
+
BRDA:129,13,1,1
|
|
267
|
+
BRDA:141,14,0,0
|
|
268
|
+
BRDA:141,14,1,0
|
|
269
|
+
BRDA:163,15,0,2
|
|
270
|
+
BRDA:163,15,1,8
|
|
271
|
+
BRDA:178,16,0,0
|
|
272
|
+
BRDA:178,16,1,9
|
|
273
|
+
BRDA:179,17,0,0
|
|
274
|
+
BRDA:179,17,1,9
|
|
275
|
+
BRDA:182,18,0,0
|
|
276
|
+
BRDA:182,18,1,9
|
|
277
|
+
BRDA:184,19,0,0
|
|
278
|
+
BRDA:184,19,1,9
|
|
279
|
+
BRDA:184,20,0,9
|
|
280
|
+
BRDA:184,20,1,0
|
|
281
|
+
BRDA:186,21,0,9
|
|
282
|
+
BRDA:186,21,1,0
|
|
283
|
+
BRDA:193,22,0,0
|
|
284
|
+
BRDA:193,22,1,9
|
|
285
|
+
BRDA:194,23,0,9
|
|
286
|
+
BRDA:194,23,1,9
|
|
287
|
+
BRDA:194,23,2,9
|
|
288
|
+
BRDA:194,23,3,0
|
|
289
|
+
BRDA:194,23,4,0
|
|
290
|
+
BRDA:194,23,5,0
|
|
291
|
+
BRF:58
|
|
292
|
+
BRH:34
|
|
305
293
|
end_of_record
|
|
306
294
|
TN:
|
|
307
295
|
SF:src/export-specifiers-per-line.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tcy/eslint-rules",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "```typescript import { plugin as customRules } from 'tcy@eslint-rules/src/index.mjs';",
|
|
5
5
|
"homepage": "https://github.com/tcastelly/eslint-rules#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"test": "jest"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "^8.0.
|
|
51
|
-
"@babel/preset-env": "^8.0.
|
|
50
|
+
"@babel/core": "^8.0.5",
|
|
51
|
+
"@babel/preset-env": "^8.0.5",
|
|
52
52
|
"@types/jest": "^30.0.0",
|
|
53
53
|
"@types/node": "^26.5.0",
|
|
54
54
|
"babel-jest": "^30.5.1",
|
|
@@ -116,24 +116,13 @@ export default {
|
|
|
116
116
|
|
|
117
117
|
switch (node.type) {
|
|
118
118
|
case 'Literal':
|
|
119
|
-
|
|
119
|
+
// skip non-string literals, e.g. `cond && 0`
|
|
120
|
+
if (typeof node.value === 'string') {
|
|
121
|
+
reportIfMissing(node, node.value);
|
|
122
|
+
}
|
|
120
123
|
break;
|
|
121
124
|
case 'ArrayExpression':
|
|
122
|
-
node.elements.forEach(
|
|
123
|
-
if (!el) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (el.type === 'Literal') {
|
|
128
|
-
reportIfMissing(el, el.value);
|
|
129
|
-
} else if (el.type === 'ObjectExpression') {
|
|
130
|
-
el.properties.forEach((p) => {
|
|
131
|
-
if (p.key?.type === 'Literal' && typeof p.key.value === 'string') {
|
|
132
|
-
reportIfMissing(p.key, p.key.value);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
});
|
|
125
|
+
node.elements.forEach(processExpression);
|
|
137
126
|
break;
|
|
138
127
|
case 'ObjectExpression':
|
|
139
128
|
node.properties.forEach((p) => {
|
|
@@ -168,6 +157,14 @@ export default {
|
|
|
168
157
|
processExpression(node.consequent);
|
|
169
158
|
processExpression(node.alternate);
|
|
170
159
|
break;
|
|
160
|
+
case 'LogicalExpression':
|
|
161
|
+
// `cond && 'cls'`: only the right side is a class
|
|
162
|
+
// `cls || 'cls'` / `cls ?? 'cls'`: both sides can be classes
|
|
163
|
+
if (node.operator !== '&&') {
|
|
164
|
+
processExpression(node.left);
|
|
165
|
+
}
|
|
166
|
+
processExpression(node.right);
|
|
167
|
+
break;
|
|
171
168
|
default:
|
|
172
169
|
break;
|
|
173
170
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
import rule, {
|
|
2
3
|
DEFAULT_IGNORED_CLASSES,
|
|
3
4
|
isMissingImportant,
|
|
4
5
|
resolveIgnored,
|
|
@@ -54,3 +55,101 @@ describe('GIVEN "enforce-tailwind-important"', () => {
|
|
|
54
55
|
});
|
|
55
56
|
});
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
// ─── rule (end-to-end) ──────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/** Run the rule on `code`, return reported classes and the auto-fixed source. */
|
|
62
|
+
const lint = (code, options = []) => {
|
|
63
|
+
const ast = parse(code, { sourceType: 'module', plugins: ['jsx', 'estree'] });
|
|
64
|
+
const reports = [];
|
|
65
|
+
const context = {
|
|
66
|
+
options,
|
|
67
|
+
getSourceCode: () => ({ getText: (node) => code.slice(node.start, node.end) }),
|
|
68
|
+
report: (r) => reports.push(r),
|
|
69
|
+
};
|
|
70
|
+
const visitors = rule.create(context);
|
|
71
|
+
|
|
72
|
+
const walk = (node) => {
|
|
73
|
+
if (!node || typeof node.type !== 'string') return;
|
|
74
|
+
visitors[node.type]?.(node);
|
|
75
|
+
Object.keys(node).forEach((key) => {
|
|
76
|
+
const value = node[key];
|
|
77
|
+
if (Array.isArray(value)) value.forEach(walk);
|
|
78
|
+
else if (value && typeof value.type === 'string') walk(value);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
walk(ast.program);
|
|
82
|
+
|
|
83
|
+
// apply fixes from the end so offsets stay valid
|
|
84
|
+
let output = code;
|
|
85
|
+
reports
|
|
86
|
+
.map((r) => r.fix({ replaceText: (node, text) => ({ node, text }) }))
|
|
87
|
+
.sort((a, b) => b.node.start - a.node.start)
|
|
88
|
+
.forEach(({ node, text }) => {
|
|
89
|
+
output = output.slice(0, node.start) + text + output.slice(node.end);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return { reports, output };
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
describe('GIVEN "enforce-tailwind-important" / logical expressions', () => {
|
|
96
|
+
it('THEN `cond && "cls"` is flagged and fixed', () => {
|
|
97
|
+
const { reports, output } = lint("const x = <div class={readonly && 'hidden'} />;");
|
|
98
|
+
|
|
99
|
+
expect(reports).toHaveLength(1);
|
|
100
|
+
expect(output).toBe("const x = <div class={readonly && 'hidden!'} />;");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('THEN only the missing classes are fixed', () => {
|
|
104
|
+
const { output } = lint("const x = <div className={readonly && 'something! else'} />;");
|
|
105
|
+
|
|
106
|
+
expect(output).toBe("const x = <div className={readonly && 'something! else!'} />;");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('THEN already-important classes are not flagged', () => {
|
|
110
|
+
const { reports } = lint("const x = <div class={readonly && 'something! else!'} />;");
|
|
111
|
+
|
|
112
|
+
expect(reports).toHaveLength(0);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('THEN both sides of `||` / `??` are checked', () => {
|
|
116
|
+
const { output } = lint("const x = <div class={(a || 'flex') ?? 'grid'} />;");
|
|
117
|
+
|
|
118
|
+
expect(output).toBe("const x = <div class={(a || 'flex!') ?? 'grid!'} />;");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('THEN the left side of `&&` is not treated as a class', () => {
|
|
122
|
+
const { reports } = lint("const x = <div class={'foo' && 'bar!'} />;");
|
|
123
|
+
|
|
124
|
+
expect(reports).toHaveLength(0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('THEN nested ternary / logical expressions are checked', () => {
|
|
128
|
+
const { output } = lint("const x = <div class={a ? b && 'p-2' : 'm-2'} />;");
|
|
129
|
+
|
|
130
|
+
expect(output).toBe("const x = <div class={a ? b && 'p-2!' : 'm-2!'} />;");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('THEN logical expressions inside an array are checked', () => {
|
|
134
|
+
const { reports, output } = lint(
|
|
135
|
+
"const x = <div class={[readonly && 'hidden', 'something', 'else']} />;",
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
expect(reports).toHaveLength(3);
|
|
139
|
+
expect(output).toBe(
|
|
140
|
+
"const x = <div class={[readonly && 'hidden!', 'something!', 'else!']} />;",
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('THEN array elements that are already important are not flagged', () => {
|
|
145
|
+
const { reports } = lint(
|
|
146
|
+
"const x = <div class={[readonly && 'hidden!', 'something!', { 'p-2!': a }]} />;",
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
expect(reports).toHaveLength(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('THEN non-string literals do not crash', () => {
|
|
153
|
+
expect(() => lint('const x = <div class={count && 0} />;')).not.toThrow();
|
|
154
|
+
});
|
|
155
|
+
});
|