@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.
Files changed (34) hide show
  1. package/coverage/clover.xml +59 -62
  2. package/coverage/coverage-final.json +1 -1
  3. package/coverage/lcov-report/index.html +19 -19
  4. package/coverage/lcov-report/src/array-elements-per-line.js.html +1 -1
  5. package/coverage/lcov-report/src/back/back.js.html +1 -1
  6. package/coverage/lcov-report/src/back/http.js.html +1 -1
  7. package/coverage/lcov-report/src/back/index.html +1 -1
  8. package/coverage/lcov-report/src/back/recommended.js.html +1 -1
  9. package/coverage/lcov-report/src/bin/eslint-cache-guard.js.html +1 -1
  10. package/coverage/lcov-report/src/bin/index.html +1 -1
  11. package/coverage/lcov-report/src/client/client.js.html +1 -1
  12. package/coverage/lcov-report/src/client/index.html +1 -1
  13. package/coverage/lcov-report/src/client/recommended.js.html +1 -1
  14. package/coverage/lcov-report/src/decorator-type-enforcement.js.html +1 -1
  15. package/coverage/lcov-report/src/enforce-tailwind-important.js.html +116 -125
  16. package/coverage/lcov-report/src/export-specifiers-per-line.js.html +1 -1
  17. package/coverage/lcov-report/src/import-specifiers-per-line.js.html +1 -1
  18. package/coverage/lcov-report/src/index.html +20 -20
  19. package/coverage/lcov-report/src/index.js.html +1 -1
  20. package/coverage/lcov-report/src/jsx-boolean-shorthand.js.html +1 -1
  21. package/coverage/lcov-report/src/jsx-expression-string-literals.js.html +1 -1
  22. package/coverage/lcov-report/src/jsx-ref-string-exists.js.html +1 -1
  23. package/coverage/lcov-report/src/no-static-key-in-map.js.html +1 -1
  24. package/coverage/lcov-report/src/plugin.js.html +1 -1
  25. package/coverage/lcov-report/src/recommended.js.html +1 -1
  26. package/coverage/lcov-report/src/require-fragment-key.js.html +1 -1
  27. package/coverage/lcov-report/src/route-dto-required.js.html +1 -1
  28. package/coverage/lcov-report/src/v-model-name-match.js.html +1 -1
  29. package/coverage/lcov-report/src/vuejs-define-component.js.html +1 -1
  30. package/coverage/lcov-report/src/vuejs-define-workspace.js.html +1 -1
  31. package/coverage/lcov.info +123 -135
  32. package/package.json +3 -3
  33. package/src/enforce-tailwind-important.js +13 -16
  34. 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-10T16:53:24.460Z
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-10T16:53:24.460Z
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-10T16:53:24.460Z
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-10T16:53:24.460Z
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-10T16:53:24.460Z
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-10T16:53:24.460Z
268
+ at 2026-09-17T13:27:07.234Z
269
269
  </div>
270
270
  <script src="../prettify.js"></script>
271
271
  <script>
@@ -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:122,(anonymous_14)
138
- FN:130,(anonymous_15)
139
- FN:139,(anonymous_16)
140
- FN:147,(anonymous_17)
141
- FN:159,(anonymous_18)
142
- FN:180,(anonymous_19)
143
- FN:195,(anonymous_20)
144
- FNF:21
145
- FNH:3
146
- FNDA:9,(anonymous_0)
147
- FNDA:0,(anonymous_1)
148
- FNDA:8,(anonymous_2)
149
- FNDA:4,(anonymous_3)
150
- FNDA:0,(anonymous_4)
151
- FNDA:0,(anonymous_5)
152
- FNDA:0,reportIfMissing
153
- FNDA:0,(anonymous_7)
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:0,processExpression
160
- FNDA:0,(anonymous_14)
157
+ FNDA:29,processExpression
158
+ FNDA:1,(anonymous_14)
161
159
  FNDA:0,(anonymous_15)
162
160
  FNDA:0,(anonymous_16)
163
- FNDA:0,(anonymous_17)
164
- FNDA:0,(anonymous_18)
165
- FNDA:0,(anonymous_19)
166
- FNDA:0,(anonymous_20)
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,8
171
- DA:31,4
172
- DA:58,0
173
- DA:60,0
174
- DA:63,0
175
- DA:69,0
176
- DA:70,0
177
- DA:73,0
178
- DA:74,0
179
- DA:77,0
180
- DA:78,0
181
- DA:83,0
182
- DA:84,0
183
- DA:86,0
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,0
192
+ DA:113,29
197
193
  DA:114,0
198
- DA:117,0
199
- DA:119,0
200
- DA:120,0
201
- DA:122,0
202
- DA:123,0
203
- DA:124,0
204
- DA:127,0
205
- DA:128,0
206
- DA:129,0
207
- DA:130,0
208
- DA:131,0
209
- DA:132,0
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:144,0
215
- DA:146,0
216
- DA:147,0
217
- DA:152,0
218
- DA:153,0
219
- DA:156,0
220
- DA:160,0
221
- DA:162,0
222
- DA:165,0
223
- DA:168,0
224
- DA:169,0
225
- DA:170,0
226
- DA:172,0
227
- DA:179,0
228
- DA:181,0
229
- DA:182,0
230
- DA:184,0
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:187,0
233
- DA:188,0
234
- DA:189,0
235
- DA:190,0
236
- DA:196,0
237
- DA:204,0
238
- LF:71
239
- LH:5
240
- BRDA:28,0,0,8
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,3
245
- BRDA:73,2,0,0
246
- BRDA:73,2,1,0
247
- BRDA:77,3,0,0
248
- BRDA:77,3,1,0
249
- BRDA:84,4,0,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,0
261
- BRDA:117,10,0,0
262
- BRDA:117,10,1,0
263
- BRDA:117,10,2,0
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,0
266
- BRDA:117,10,5,0
267
- BRDA:123,11,0,0
268
- BRDA:123,11,1,0
269
- BRDA:127,12,0,0
270
- BRDA:127,12,1,0
271
- BRDA:129,13,0,0
272
- BRDA:129,13,1,0
273
- BRDA:131,14,0,0
274
- BRDA:131,14,1,0
275
- BRDA:131,15,0,0
276
- BRDA:131,15,1,0
277
- BRDA:140,16,0,0
278
- BRDA:140,16,1,0
279
- BRDA:140,17,0,0
280
- BRDA:140,17,1,0
281
- BRDA:152,18,0,0
282
- BRDA:152,18,1,0
283
- BRDA:181,19,0,0
284
- BRDA:181,19,1,0
285
- BRDA:182,20,0,0
286
- BRDA:182,20,1,0
287
- BRDA:185,21,0,0
288
- BRDA:185,21,1,0
289
- BRDA:187,22,0,0
290
- BRDA:187,22,1,0
291
- BRDA:187,23,0,0
292
- BRDA:187,23,1,0
293
- BRDA:189,24,0,0
294
- BRDA:189,24,1,0
295
- BRDA:196,25,0,0
296
- BRDA:196,25,1,0
297
- BRDA:197,26,0,0
298
- BRDA:197,26,1,0
299
- BRDA:197,26,2,0
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.1",
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.1",
51
- "@babel/preset-env": "^8.0.2",
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
- reportIfMissing(node, node.value);
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((el) => {
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
+ });