@tcy/eslint-rules 1.4.5 → 1.6.0

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 +44 -4
  2. package/coverage/coverage-final.json +2 -0
  3. package/coverage/lcov-report/index.html +17 -17
  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/index.html +1 -1
  7. package/coverage/lcov-report/src/back/recommended.js.html +1 -1
  8. package/coverage/lcov-report/src/client/client.js.html +8 -2
  9. package/coverage/lcov-report/src/client/index.html +1 -1
  10. package/coverage/lcov-report/src/client/recommended.js.html +1 -1
  11. package/coverage/lcov-report/src/decorator-type-enforcement.js.html +1 -1
  12. package/coverage/lcov-report/src/enforce-tailwind-important.js.html +1 -1
  13. package/coverage/lcov-report/src/export-specifiers-per-line.js.html +1 -1
  14. package/coverage/lcov-report/src/import-specifiers-per-line.js.html +1 -1
  15. package/coverage/lcov-report/src/index.html +38 -8
  16. package/coverage/lcov-report/src/index.js.html +1 -1
  17. package/coverage/lcov-report/src/jsx-boolean-shorthand.js.html +187 -0
  18. package/coverage/lcov-report/src/jsx-expression-string-literals.js.html +1 -1
  19. package/coverage/lcov-report/src/jsx-ref-string-exists.js.html +370 -0
  20. package/coverage/lcov-report/src/plugin.js.html +14 -2
  21. package/coverage/lcov-report/src/recommended.js.html +1 -1
  22. package/coverage/lcov-report/src/v-model-name-match.js.html +1 -1
  23. package/coverage/lcov-report/src/vuejs-define-component.js.html +1 -1
  24. package/coverage/lcov-report/src/vuejs-define-workspace.js.html +1 -1
  25. package/coverage/lcov.info +96 -0
  26. package/decl/client/client.d.ts +2 -0
  27. package/decl/jsx-boolean-shorthand.d.ts +14 -0
  28. package/decl/jsx-ref-string-exists.d.ts +17 -0
  29. package/decl/plugin.d.ts +29 -0
  30. package/package.json +3 -3
  31. package/src/client/client.js +2 -0
  32. package/src/jsx-boolean-shorthand.js +35 -0
  33. package/src/jsx-ref-string-exists.js +95 -0
  34. package/src/plugin.js +4 -0
@@ -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-04-15T09:33:48.761Z
331
+ at 2026-05-05T09:28:14.346Z
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-04-15T09:33:48.761Z
268
+ at 2026-05-05T09:28:14.346Z
269
269
  </div>
270
270
  <script src="../prettify.js"></script>
271
271
  <script>
@@ -426,6 +426,37 @@ BRF:0
426
426
  BRH:0
427
427
  end_of_record
428
428
  TN:
429
+ SF:src/jsx-boolean-shorthand.js
430
+ FN:10,(anonymous_0)
431
+ FN:12,(anonymous_1)
432
+ FN:25,(anonymous_2)
433
+ FNF:3
434
+ FNH:0
435
+ FNDA:0,(anonymous_0)
436
+ FNDA:0,(anonymous_1)
437
+ FNDA:0,(anonymous_2)
438
+ DA:11,0
439
+ DA:14,0
440
+ DA:15,0
441
+ DA:18,0
442
+ DA:19,0
443
+ DA:27,0
444
+ LF:6
445
+ LH:0
446
+ BRDA:14,0,0,0
447
+ BRDA:14,0,1,0
448
+ BRDA:14,1,0,0
449
+ BRDA:14,1,1,0
450
+ BRDA:18,2,0,0
451
+ BRDA:18,2,1,0
452
+ BRDA:18,3,0,0
453
+ BRDA:18,3,1,0
454
+ BRDA:23,4,0,0
455
+ BRDA:23,4,1,0
456
+ BRF:10
457
+ BRH:0
458
+ end_of_record
459
+ TN:
429
460
  SF:src/jsx-expression-string-literals.js
430
461
  FN:12,(anonymous_0)
431
462
  FN:14,(anonymous_1)
@@ -458,6 +489,71 @@ BRF:8
458
489
  BRH:0
459
490
  end_of_record
460
491
  TN:
492
+ SF:src/jsx-ref-string-exists.js
493
+ FN:17,(anonymous_0)
494
+ FN:22,(anonymous_1)
495
+ FN:33,(anonymous_2)
496
+ FN:72,isStringRef
497
+ FN:87,getAllEnclosingFunctions
498
+ FNF:5
499
+ FNH:0
500
+ FNDA:0,(anonymous_0)
501
+ FNDA:0,(anonymous_1)
502
+ FNDA:0,(anonymous_2)
503
+ FNDA:0,isStringRef
504
+ FNDA:0,getAllEnclosingFunctions
505
+ DA:18,0
506
+ DA:20,0
507
+ DA:21,0
508
+ DA:23,0
509
+ DA:24,0
510
+ DA:30,0
511
+ DA:32,0
512
+ DA:34,0
513
+ DA:36,0
514
+ DA:39,0
515
+ DA:40,0
516
+ DA:43,0
517
+ DA:44,0
518
+ DA:45,0
519
+ DA:47,0
520
+ DA:48,0
521
+ DA:49,0
522
+ DA:51,0
523
+ DA:53,0
524
+ DA:57,0
525
+ DA:73,0
526
+ DA:81,0
527
+ DA:88,0
528
+ DA:89,0
529
+ DA:90,0
530
+ DA:91,0
531
+ DA:92,0
532
+ DA:94,0
533
+ LF:28
534
+ LH:0
535
+ BRDA:20,0,0,0
536
+ BRDA:20,0,1,0
537
+ BRDA:23,1,0,0
538
+ BRDA:23,1,1,0
539
+ BRDA:34,2,0,0
540
+ BRDA:34,2,1,0
541
+ BRDA:40,3,0,0
542
+ BRDA:40,3,1,0
543
+ BRDA:45,4,0,0
544
+ BRDA:45,4,1,0
545
+ BRDA:51,5,0,0
546
+ BRDA:51,5,1,0
547
+ BRDA:74,6,0,0
548
+ BRDA:74,6,1,0
549
+ BRDA:74,6,2,0
550
+ BRDA:74,6,3,0
551
+ BRDA:91,7,0,0
552
+ BRDA:91,7,1,0
553
+ BRF:18
554
+ BRH:0
555
+ end_of_record
556
+ TN:
461
557
  SF:src/plugin.js
462
558
  FNF:0
463
559
  FNH:0
@@ -11,6 +11,8 @@ declare namespace _default {
11
11
  'tcy/export-specifiers-per-line': string;
12
12
  'tcy/array-elements-per-line': string;
13
13
  'tcy/jsx-expression-string-literals': string;
14
+ 'tcy/jsx-boolean-shorthand': string;
15
+ 'tcy/jsx-ref-string-exists': string;
14
16
  'tcy/enforce-tailwind-important': string;
15
17
  'tcy/v-model-name-match': string;
16
18
  'tcy/vuejs-define-component': string;
@@ -0,0 +1,14 @@
1
+ declare namespace _default {
2
+ namespace meta {
3
+ let type: string;
4
+ namespace docs {
5
+ let description: string;
6
+ }
7
+ let fixable: string;
8
+ let schema: never[];
9
+ }
10
+ function create(context: any): {
11
+ JSXAttribute(node: any): void;
12
+ };
13
+ }
14
+ export default _default;
@@ -0,0 +1,17 @@
1
+ declare namespace _default {
2
+ namespace meta {
3
+ let type: string;
4
+ namespace docs {
5
+ let description: string;
6
+ }
7
+ namespace messages {
8
+ let missingRef: string;
9
+ let noServices: string;
10
+ }
11
+ let schema: never[];
12
+ }
13
+ function create(context: any): {
14
+ JSXAttribute(node: any): void;
15
+ };
16
+ }
17
+ export default _default;
package/decl/plugin.d.ts CHANGED
@@ -53,6 +53,19 @@ declare const _default: {
53
53
  ExportNamedDeclaration(node: any): void;
54
54
  };
55
55
  };
56
+ 'jsx-boolean-shorthand': {
57
+ meta: {
58
+ type: string;
59
+ docs: {
60
+ description: string;
61
+ };
62
+ fixable: string;
63
+ schema: never[];
64
+ };
65
+ create(context: any): {
66
+ JSXAttribute(node: any): void;
67
+ };
68
+ };
56
69
  'jsx-expression-string-literals': {
57
70
  meta: {
58
71
  type: string;
@@ -66,6 +79,22 @@ declare const _default: {
66
79
  JSXAttribute(node: any): void;
67
80
  };
68
81
  };
82
+ 'jsx-ref-string-exists': {
83
+ meta: {
84
+ type: string;
85
+ docs: {
86
+ description: string;
87
+ };
88
+ messages: {
89
+ missingRef: string;
90
+ noServices: string;
91
+ };
92
+ schema: never[];
93
+ };
94
+ create(context: any): {
95
+ JSXAttribute(node: any): void;
96
+ };
97
+ };
69
98
  'enforce-tailwind-important': {
70
99
  meta: {
71
100
  type: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tcy/eslint-rules",
3
- "version": "1.4.5",
3
+ "version": "1.6.0",
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": {
@@ -41,12 +41,12 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.29.0",
44
- "@babel/preset-env": "^7.29.2",
44
+ "@babel/preset-env": "^7.29.3",
45
45
  "@types/jest": "^30.0.0",
46
46
  "@types/node": "^25.6.0",
47
47
  "babel-jest": "^30.3.0",
48
48
  "jest": "^30.3.0",
49
49
  "rimraf": "^6.1.3",
50
- "typescript": "^6.0.2"
50
+ "typescript": "^6.0.3"
51
51
  }
52
52
  }
@@ -12,6 +12,8 @@ export default {
12
12
  'tcy/export-specifiers-per-line': 'error',
13
13
  'tcy/array-elements-per-line': 'error',
14
14
  'tcy/jsx-expression-string-literals': 'error',
15
+ 'tcy/jsx-boolean-shorthand': 'error',
16
+ 'tcy/jsx-ref-string-exists': 'error',
15
17
  'tcy/enforce-tailwind-important': 'error',
16
18
  'tcy/v-model-name-match': 'error',
17
19
  'tcy/vuejs-define-component': 'error',
@@ -0,0 +1,35 @@
1
+ export default {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: 'Enforce shorthand boolean syntax in JSX props',
6
+ },
7
+ fixable: 'code',
8
+ schema: [],
9
+ },
10
+ create(context) {
11
+ return {
12
+ JSXAttribute(node) {
13
+ // Only check boolean values in JSX
14
+ if (node.value && node.value.type === 'JSXExpressionContainer') {
15
+ const expression = node.value.expression;
16
+
17
+ // Check if the value is a boolean literal 'true'
18
+ if (expression.type === 'Literal' && expression.value === true) {
19
+ context.report({
20
+ node,
21
+ message: 'Use shorthand boolean syntax instead of {{value}}',
22
+ data: {
23
+ value: node.value.raw || node.value.expression.raw,
24
+ },
25
+ fix(fixer) {
26
+ // Remove the expression container and just keep the attribute name
27
+ return fixer.replaceText(node, node.name.name);
28
+ },
29
+ });
30
+ }
31
+ }
32
+ },
33
+ };
34
+ },
35
+ };
@@ -0,0 +1,95 @@
1
+ export default {
2
+ meta: {
3
+ type: 'problem',
4
+ docs: {
5
+ description:
6
+ 'Ensure string refs in TSX (ref="name") exist as properties on the render function\'s first parameter type.',
7
+ },
8
+ messages: {
9
+ missingRef: 'Ref "{{ref}}" does not exist on type "{{types}}".',
10
+ noServices:
11
+ 'ref-string-exists requires TypeScript type information. ' +
12
+ 'Set parserOptions.projectService (or project) in your ESLint config.',
13
+ },
14
+ schema: [],
15
+ },
16
+
17
+ create(context) {
18
+ const services = context.sourceCode.parserServices;
19
+
20
+ if (!services?.program) {
21
+ return {
22
+ JSXAttribute(node) {
23
+ if (isStringRef(node)) {
24
+ context.report({ node, messageId: 'noServices' });
25
+ }
26
+ },
27
+ };
28
+ }
29
+
30
+ const checker = services.program.getTypeChecker();
31
+
32
+ return {
33
+ JSXAttribute(node) {
34
+ if (!isStringRef(node)) return;
35
+
36
+ const refName = node.value.value;
37
+
38
+ // Collect ALL enclosing functions, nearest first
39
+ const fns = getAllEnclosingFunctions(node);
40
+ if (!fns.length) return;
41
+
42
+ // Check each function's first param — pass if ANY of them has the ref
43
+ const checkedTypes = [];
44
+ for (const fn of fns) {
45
+ if (!fn.params?.length) continue;
46
+
47
+ const tsNode = services.esTreeNodeToTSNodeMap.get(fn.params[0]);
48
+ const type = checker.getTypeAtLocation(tsNode);
49
+ const prop = checker.getPropertyOfType(type, refName);
50
+
51
+ if (prop) return; // ✅ found in at least one scope
52
+
53
+ checkedTypes.push(checker.typeToString(type));
54
+ }
55
+
56
+ // None of the enclosing functions had it
57
+ context.report({
58
+ node,
59
+ messageId: 'missingRef',
60
+ data: {
61
+ ref: refName,
62
+ types: checkedTypes.join(' | '),
63
+ },
64
+ });
65
+ },
66
+ };
67
+ },
68
+ };
69
+
70
+ // ─── helpers ────────────────────────────────────────────────────────────────
71
+
72
+ function isStringRef(node) {
73
+ return (
74
+ node.name?.type === 'JSXIdentifier' &&
75
+ node.name.name === 'ref' &&
76
+ node.value?.type === 'Literal' &&
77
+ typeof node.value.value === 'string'
78
+ );
79
+ }
80
+
81
+ const FUNCTION_TYPES = new Set([
82
+ 'FunctionDeclaration',
83
+ 'FunctionExpression',
84
+ 'ArrowFunctionExpression',
85
+ ]);
86
+
87
+ function getAllEnclosingFunctions(node) {
88
+ const fns = [];
89
+ let current = node.parent;
90
+ while (current) {
91
+ if (FUNCTION_TYPES.has(current.type)) fns.push(current);
92
+ current = current.parent;
93
+ }
94
+ return fns;
95
+ }
package/src/plugin.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import importSpecifiersPerLineRule from './import-specifiers-per-line.js';
2
2
  import arrayElementsPerLineRule from './array-elements-per-line.js';
3
3
  import exportSpecifiersPerLineRule from './export-specifiers-per-line.js';
4
+ import jsxBooleanShorthand from './jsx-boolean-shorthand.js'
4
5
  import jsxExpressionStringLiterals from './jsx-expression-string-literals.js';
6
+ import jsxRefStringExists from './jsx-ref-string-exists.js';
5
7
  import enforceTailwindImportant from './enforce-tailwind-important.js';
6
8
  import vModelNameMatch from './v-model-name-match.js';
7
9
  import decoratorTypeEnforcement from './decorator-type-enforcement.js'
@@ -12,7 +14,9 @@ export default {
12
14
  'import-specifiers-per-line': importSpecifiersPerLineRule,
13
15
  'array-elements-per-line': arrayElementsPerLineRule,
14
16
  'export-specifiers-per-line': exportSpecifiersPerLineRule,
17
+ 'jsx-boolean-shorthand': jsxBooleanShorthand,
15
18
  'jsx-expression-string-literals': jsxExpressionStringLiterals,
19
+ 'jsx-ref-string-exists': jsxRefStringExists,
16
20
  'enforce-tailwind-important': enforceTailwindImportant,
17
21
  'v-model-name-match': vModelNameMatch,
18
22
  'decorator-type-enforcement': decoratorTypeEnforcement,