@tcy/eslint-rules 1.8.0 → 1.9.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 (40) hide show
  1. package/coverage/clover.xml +50 -4
  2. package/coverage/coverage-final.json +1 -0
  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 +5 -2
  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 +1 -1
  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 +24 -9
  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 +631 -0
  24. package/coverage/lcov-report/src/plugin.js.html +8 -2
  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 +115 -0
  32. package/decl/back/back.d.ts +16 -0
  33. package/decl/client/client.d.ts +17 -0
  34. package/decl/no-static-key-in-map.d.ts +66 -0
  35. package/decl/plugin.d.ts +16 -0
  36. package/package.json +1 -1
  37. package/src/client/client.js +1 -0
  38. package/src/no-static-key-in-map.js +182 -0
  39. package/src/plugin.js +2 -0
  40. package/tests/no-static-key-in-map.spec.js +186 -0
@@ -92,7 +92,11 @@
92
92
  <a name='L27'></a><a href='#L27'>27</a>
93
93
  <a name='L28'></a><a href='#L28'>28</a>
94
94
  <a name='L29'></a><a href='#L29'>29</a>
95
- <a name='L30'></a><a href='#L30'>30</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
95
+ <a name='L30'></a><a href='#L30'>30</a>
96
+ <a name='L31'></a><a href='#L31'>31</a>
97
+ <a name='L32'></a><a href='#L32'>32</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
98
+ <span class="cline-any cline-neutral">&nbsp;</span>
99
+ <span class="cline-any cline-neutral">&nbsp;</span>
96
100
  <span class="cline-any cline-neutral">&nbsp;</span>
97
101
  <span class="cline-any cline-neutral">&nbsp;</span>
98
102
  <span class="cline-any cline-neutral">&nbsp;</span>
@@ -134,6 +138,7 @@ import vuejsDefineComponent from './vuejs-define-component.js'
134
138
  import vuejsDefineWorkspace from './vuejs-define-workspace.js'
135
139
  import routeDtoRequired from './route-dto-required.js'
136
140
  import requireFragmentKey from './require-fragment-key.js'
141
+ import noStaticKeyInMap from './no-static-key-in-map.js'
137
142
  &nbsp;
138
143
  export default {
139
144
  'import-specifiers-per-line': importSpecifiersPerLineRule,
@@ -149,6 +154,7 @@ export default {
149
154
  'vuejs-define-workspace': vuejsDefineWorkspace,
150
155
  'route-dto-required': routeDtoRequired,
151
156
  'require-fragment-key': requireFragmentKey,
157
+ 'no-static-key-in-map': noStaticKeyInMap,
152
158
  }
153
159
  &nbsp;</pre></td></tr></table></pre>
154
160
 
@@ -157,7 +163,7 @@ export default {
157
163
  <div class='footer quiet pad2 space-top1 center small'>
158
164
  Code coverage generated by
159
165
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
160
- at 2026-09-08T14:12:35.933Z
166
+ at 2026-09-08T15:20:28.268Z
161
167
  </div>
162
168
  <script src="../prettify.js"></script>
163
169
  <script>
@@ -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-08T14:12:35.933Z
133
+ at 2026-09-08T15:20:28.268Z
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-08T14:12:35.933Z
775
+ at 2026-09-08T15:20:28.268Z
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-08T14:12:35.933Z
301
+ at 2026-09-08T15:20:28.268Z
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-08T14:12:35.933Z
292
+ at 2026-09-08T15:20:28.268Z
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-08T14:12:35.933Z
331
+ at 2026-09-08T15:20:28.268Z
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-08T14:12:35.933Z
268
+ at 2026-09-08T15:20:28.268Z
269
269
  </div>
270
270
  <script src="../prettify.js"></script>
271
271
  <script>
@@ -554,6 +554,121 @@ BRF:18
554
554
  BRH:0
555
555
  end_of_record
556
556
  TN:
557
+ SF:src/no-static-key-in-map.js
558
+ FN:61,(anonymous_0)
559
+ FN:76,(anonymous_1)
560
+ FN:80,(anonymous_2)
561
+ FN:97,(anonymous_3)
562
+ FN:113,(anonymous_4)
563
+ FN:136,(anonymous_5)
564
+ FN:162,(anonymous_6)
565
+ FN:165,(anonymous_7)
566
+ FNF:8
567
+ FNH:6
568
+ FNDA:21,(anonymous_0)
569
+ FNDA:32,(anonymous_1)
570
+ FNDA:28,(anonymous_2)
571
+ FNDA:10,(anonymous_3)
572
+ FNDA:18,(anonymous_4)
573
+ FNDA:23,(anonymous_5)
574
+ FNDA:0,(anonymous_6)
575
+ FNDA:0,(anonymous_7)
576
+ DA:28,1
577
+ DA:30,1
578
+ DA:39,1
579
+ DA:47,1
580
+ DA:61,1
581
+ DA:62,21
582
+ DA:63,21
583
+ DA:64,15
584
+ DA:65,10
585
+ DA:66,9
586
+ DA:76,1
587
+ DA:77,32
588
+ DA:79,32
589
+ DA:80,28
590
+ DA:84,32
591
+ DA:86,28
592
+ DA:88,28
593
+ DA:89,28
594
+ DA:90,11
595
+ DA:93,17
596
+ DA:97,1
597
+ DA:98,10
598
+ DA:99,10
599
+ DA:113,1
600
+ DA:114,18
601
+ DA:116,18
602
+ DA:117,26
603
+ DA:118,8
604
+ DA:119,8
605
+ DA:121,18
606
+ DA:125,10
607
+ DA:128,8
608
+ DA:130,0
609
+ DA:136,1
610
+ DA:137,23
611
+ DA:138,23
612
+ DA:139,15
613
+ DA:163,0
614
+ DA:165,0
615
+ DA:166,0
616
+ DA:167,0
617
+ DA:169,0
618
+ DA:178,0
619
+ LF:43
620
+ LH:36
621
+ BRDA:62,0,0,0
622
+ BRDA:62,0,1,21
623
+ BRDA:63,1,0,6
624
+ BRDA:63,1,1,15
625
+ BRDA:64,2,0,5
626
+ BRDA:64,2,1,10
627
+ BRDA:65,3,0,1
628
+ BRDA:65,3,1,9
629
+ BRDA:77,4,0,0
630
+ BRDA:77,4,1,32
631
+ BRDA:77,5,0,32
632
+ BRDA:77,5,1,32
633
+ BRDA:80,6,0,28
634
+ BRDA:80,6,1,28
635
+ BRDA:80,6,2,28
636
+ BRDA:84,7,0,4
637
+ BRDA:84,7,1,28
638
+ BRDA:88,8,0,0
639
+ BRDA:88,8,1,28
640
+ BRDA:89,9,0,11
641
+ BRDA:89,9,1,17
642
+ BRDA:90,10,0,3
643
+ BRDA:90,10,1,8
644
+ BRDA:93,11,0,17
645
+ BRDA:93,11,1,0
646
+ BRDA:99,12,0,10
647
+ BRDA:99,12,1,10
648
+ BRDA:99,12,2,10
649
+ BRDA:99,12,3,10
650
+ BRDA:99,12,4,10
651
+ BRDA:99,12,5,10
652
+ BRDA:117,13,0,8
653
+ BRDA:117,13,1,18
654
+ BRDA:121,14,0,10
655
+ BRDA:121,14,1,8
656
+ BRDA:122,15,0,18
657
+ BRDA:122,15,1,8
658
+ BRDA:138,16,0,8
659
+ BRDA:138,16,1,15
660
+ BRDA:139,17,0,9
661
+ BRDA:139,17,1,6
662
+ BRDA:167,18,0,0
663
+ BRDA:167,18,1,0
664
+ BRDA:167,19,0,0
665
+ BRDA:167,19,1,0
666
+ BRDA:173,20,0,0
667
+ BRDA:173,20,1,0
668
+ BRF:47
669
+ BRH:37
670
+ end_of_record
671
+ TN:
557
672
  SF:src/plugin.js
558
673
  FNF:0
559
674
  FNH:0
@@ -218,6 +218,22 @@ declare const _default: {
218
218
  JSXElement: (node: any) => void;
219
219
  };
220
220
  };
221
+ 'no-static-key-in-map': {
222
+ meta: {
223
+ type: string;
224
+ docs: {
225
+ description: string;
226
+ recommended: boolean;
227
+ };
228
+ schema: never[];
229
+ messages: {
230
+ staticKeyInIterator: string;
231
+ };
232
+ };
233
+ create(context: any): {
234
+ JSXElement: (node: any) => void;
235
+ };
236
+ };
221
237
  };
222
238
  };
223
239
  };
@@ -218,6 +218,22 @@ declare const _default: {
218
218
  JSXElement: (node: any) => void;
219
219
  };
220
220
  };
221
+ 'no-static-key-in-map': {
222
+ meta: {
223
+ type: string;
224
+ docs: {
225
+ description: string;
226
+ recommended: boolean;
227
+ };
228
+ schema: never[];
229
+ messages: {
230
+ staticKeyInIterator: string;
231
+ };
232
+ };
233
+ create(context: any): {
234
+ JSXElement: (node: any) => void;
235
+ };
236
+ };
221
237
  };
222
238
  };
223
239
  };
@@ -235,6 +251,7 @@ declare const _default: {
235
251
  'tcy/vuejs-define-component': string;
236
252
  'tcy/vuejs-define-workspace': string;
237
253
  'tcy/require-fragment-key': string;
254
+ 'tcy/no-static-key-in-map': string;
238
255
  };
239
256
  };
240
257
  export default _default;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @fileoverview no-static-key-in-map
3
+ *
4
+ * Reports a JSX list item whose `key` is a *static* value (a string / number /
5
+ * boolean literal, or a template literal with no interpolation) when that
6
+ * element is the root returned from an iterator callback:
7
+ *
8
+ * list.map(() => <Row key="row" />) // ✗ same key every item
9
+ * list.map(() => <Fragment key="rows">…</Fragment>) // ✗
10
+ * list.map((r) => r.ok && <Row key="row" />) // ✗ (conditional in .map)
11
+ * list.flatMap(() => [<A key="a" />, <B key="b" />]) // ✗ (array returned from .map)
12
+ *
13
+ * A constant key on every sibling is worse than no key: Vue / React build a
14
+ * key → index map where later duplicates overwrite earlier ones, so on
15
+ * insert / remove / reorder the diff patches the wrong node (misplaced DOM,
16
+ * lost child-component state) and dev builds warn about duplicate keys.
17
+ *
18
+ * It stays silent when:
19
+ *
20
+ * - the key is derived from the item or the index — `key={r.id}`, `key={i}`,
21
+ * `` key={`row-${i}`} ``
22
+ * - the element is NOT the list-item root — a static key on a nested element
23
+ * (`<ul>{rows.map(() => <li key="only" />)}</ul>` inside a keyed root) is
24
+ * scoped to its own parent's children, not the iterated list
25
+ * - there is no `key` at all — that is `react/jsx-key` / `require-fragment-key`
26
+ */
27
+ /** A value with no runtime input — a bare literal or a `${…}`-free template. */
28
+ export declare const isStaticExpression: (node: any) => any;
29
+ /**
30
+ * The `key` attribute of a JSXElement when it is present *and* static.
31
+ * `<>…</>` can never carry a key, so only JSXElement is inspected
32
+ * (`<Fragment key="…">` included).
33
+ *
34
+ * @returns the `key` JSXAttribute node, or `null`
35
+ */
36
+ export declare const getStaticKeyAttr: (node: any) => any;
37
+ /** Is `fnNode` the first argument of a `.map()` / `.flatMap()` call? */
38
+ export declare const isIteratorCallback: (fnNode: any) => boolean;
39
+ /**
40
+ * Walk outward from `node` through transparent wrappers and conditional
41
+ * operators. `node` is a list-item root when the first structural ancestor
42
+ * reached is an iterator callback; it is NOT when a JSX element / fragment is
43
+ * reached first (the element is nested, its key scoped to that parent).
44
+ */
45
+ export declare const isListItemRoot: (node: any) => boolean;
46
+ /**
47
+ * @returns {'staticKeyInIterator' | null}
48
+ */
49
+ export declare const analyzeElement: (node: any) => 'staticKeyInIterator' | null;
50
+ declare const _default: {
51
+ meta: {
52
+ type: string;
53
+ docs: {
54
+ description: string;
55
+ recommended: boolean;
56
+ };
57
+ schema: never[];
58
+ messages: {
59
+ staticKeyInIterator: string;
60
+ };
61
+ };
62
+ create(context: any): {
63
+ JSXElement: (node: any) => void;
64
+ };
65
+ };
66
+ export default _default;
package/decl/plugin.d.ts CHANGED
@@ -215,5 +215,21 @@ declare const _default: {
215
215
  JSXElement: (node: any) => void;
216
216
  };
217
217
  };
218
+ 'no-static-key-in-map': {
219
+ meta: {
220
+ type: string;
221
+ docs: {
222
+ description: string;
223
+ recommended: boolean;
224
+ };
225
+ schema: never[];
226
+ messages: {
227
+ staticKeyInIterator: string;
228
+ };
229
+ };
230
+ create(context: any): {
231
+ JSXElement: (node: any) => void;
232
+ };
233
+ };
218
234
  };
219
235
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tcy/eslint-rules",
3
- "version": "1.8.0",
3
+ "version": "1.9.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": {
@@ -19,5 +19,6 @@ export default {
19
19
  'tcy/vuejs-define-component': 'error',
20
20
  'tcy/vuejs-define-workspace': 'error',
21
21
  'tcy/require-fragment-key': 'error',
22
+ 'tcy/no-static-key-in-map': 'error',
22
23
  }
23
24
  }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * @fileoverview no-static-key-in-map
3
+ *
4
+ * Reports a JSX list item whose `key` is a *static* value (a string / number /
5
+ * boolean literal, or a template literal with no interpolation) when that
6
+ * element is the root returned from an iterator callback:
7
+ *
8
+ * list.map(() => <Row key="row" />) // ✗ same key every item
9
+ * list.map(() => <Fragment key="rows">…</Fragment>) // ✗
10
+ * list.map((r) => r.ok && <Row key="row" />) // ✗ (conditional in .map)
11
+ * list.flatMap(() => [<A key="a" />, <B key="b" />]) // ✗ (array returned from .map)
12
+ *
13
+ * A constant key on every sibling is worse than no key: Vue / React build a
14
+ * key → index map where later duplicates overwrite earlier ones, so on
15
+ * insert / remove / reorder the diff patches the wrong node (misplaced DOM,
16
+ * lost child-component state) and dev builds warn about duplicate keys.
17
+ *
18
+ * It stays silent when:
19
+ *
20
+ * - the key is derived from the item or the index — `key={r.id}`, `key={i}`,
21
+ * `` key={`row-${i}`} ``
22
+ * - the element is NOT the list-item root — a static key on a nested element
23
+ * (`<ul>{rows.map(() => <li key="only" />)}</ul>` inside a keyed root) is
24
+ * scoped to its own parent's children, not the iterated list
25
+ * - there is no `key` at all — that is `react/jsx-key` / `require-fragment-key`
26
+ */
27
+
28
+ const ITERATOR_METHODS = new Set(['map', 'flatMap']);
29
+
30
+ const LITERAL_TYPES = new Set([
31
+ 'Literal', // espree: string / number / boolean / null / regex
32
+ 'StringLiteral', // @babel/parser
33
+ 'NumericLiteral',
34
+ 'BooleanLiteral',
35
+ 'BigIntLiteral',
36
+ 'NullLiteral',
37
+ ]);
38
+
39
+ const UNWRAP_TYPES = new Set([
40
+ 'ParenthesizedExpression',
41
+ 'TSAsExpression',
42
+ 'TSNonNullExpression',
43
+ 'TSSatisfiesExpression',
44
+ ]);
45
+
46
+ /** Transparent wrappers we walk *through* on the way out to the callback. */
47
+ const TRANSPARENT_ANCESTORS = new Set([
48
+ 'JSXExpressionContainer',
49
+ 'ParenthesizedExpression',
50
+ 'TSAsExpression',
51
+ 'TSNonNullExpression',
52
+ 'TSSatisfiesExpression',
53
+ 'BlockStatement',
54
+ 'ReturnStatement',
55
+ 'ArrayExpression',
56
+ 'LogicalExpression',
57
+ 'ConditionalExpression',
58
+ ]);
59
+
60
+ /** A value with no runtime input — a bare literal or a `${…}`-free template. */
61
+ export const isStaticExpression = (node) => {
62
+ if (!node) return false;
63
+ if (LITERAL_TYPES.has(node.type)) return true;
64
+ if (node.type === 'TemplateLiteral') return node.expressions.length === 0;
65
+ if (UNWRAP_TYPES.has(node.type)) return isStaticExpression(node.expression);
66
+ return false;
67
+ };
68
+
69
+ /**
70
+ * The `key` attribute of a JSXElement when it is present *and* static.
71
+ * `<>…</>` can never carry a key, so only JSXElement is inspected
72
+ * (`<Fragment key="…">` included).
73
+ *
74
+ * @returns the `key` JSXAttribute node, or `null`
75
+ */
76
+ export const getStaticKeyAttr = (node) => {
77
+ if (!node || node.type !== 'JSXElement') return null;
78
+
79
+ const attr = node.openingElement.attributes.find(
80
+ (a) => a.type === 'JSXAttribute'
81
+ && a.name.type === 'JSXIdentifier'
82
+ && a.name.name === 'key',
83
+ );
84
+ if (!attr) return null;
85
+
86
+ const { value } = attr;
87
+ // `key` with no value (`<X key />`) — treat as static, it is never dynamic
88
+ if (!value) return attr;
89
+ if (value.type === 'JSXExpressionContainer') {
90
+ return isStaticExpression(value.expression) ? attr : null;
91
+ }
92
+ // a plain JSX string attribute: `key="row"`
93
+ return LITERAL_TYPES.has(value.type) ? attr : null;
94
+ };
95
+
96
+ /** Is `fnNode` the first argument of a `.map()` / `.flatMap()` call? */
97
+ export const isIteratorCallback = (fnNode) => {
98
+ const call = fnNode.parent;
99
+ return !!call
100
+ && call.type === 'CallExpression'
101
+ && call.arguments[0] === fnNode
102
+ && call.callee.type === 'MemberExpression'
103
+ && call.callee.property.type === 'Identifier'
104
+ && ITERATOR_METHODS.has(call.callee.property.name);
105
+ };
106
+
107
+ /**
108
+ * Walk outward from `node` through transparent wrappers and conditional
109
+ * operators. `node` is a list-item root when the first structural ancestor
110
+ * reached is an iterator callback; it is NOT when a JSX element / fragment is
111
+ * reached first (the element is nested, its key scoped to that parent).
112
+ */
113
+ export const isListItemRoot = (node) => {
114
+ let node_ = node.parent;
115
+
116
+ while (node_) {
117
+ if (TRANSPARENT_ANCESTORS.has(node_.type)) {
118
+ node_ = node_.parent;
119
+ continue;
120
+ }
121
+ if (
122
+ node_.type === 'ArrowFunctionExpression'
123
+ || node_.type === 'FunctionExpression'
124
+ ) {
125
+ return isIteratorCallback(node_);
126
+ }
127
+ // JSXElement / JSXFragment / anything else → not a direct list item
128
+ return false;
129
+ }
130
+ return false;
131
+ };
132
+
133
+ /**
134
+ * @returns {'staticKeyInIterator' | null}
135
+ */
136
+ export const analyzeElement = (node) => {
137
+ const keyAttr = getStaticKeyAttr(node);
138
+ if (!keyAttr) return null;
139
+ return isListItemRoot(node) ? 'staticKeyInIterator' : null;
140
+ };
141
+
142
+ export default {
143
+ meta: {
144
+ type: 'problem',
145
+ docs: {
146
+ description:
147
+ 'Disallow a static `key` (string / number / template-without-interpolation) '
148
+ + 'on the root element returned from `.map()` / `.flatMap()` — every item would '
149
+ + 'get the same key.',
150
+ recommended: false,
151
+ },
152
+ schema: [],
153
+ messages: {
154
+ staticKeyInIterator:
155
+ 'Static `key={{keyText}}` on a `.map()` list item — every iteration renders the '
156
+ + 'same key, so Vue diffs the list by position and can mismatch nodes on '
157
+ + 'insert / remove / reorder. Derive it from the item (`key={item.id}`) or, '
158
+ + 'failing that, the index (`key={i}`).',
159
+ },
160
+ },
161
+
162
+ create(context) {
163
+ const { sourceCode } = context;
164
+
165
+ const check = (node) => {
166
+ const keyAttr = getStaticKeyAttr(node);
167
+ if (!keyAttr || !isListItemRoot(node)) return;
168
+
169
+ context.report({
170
+ node: keyAttr,
171
+ messageId: 'staticKeyInIterator',
172
+ data: {
173
+ keyText: keyAttr.value ? sourceCode.getText(keyAttr.value) : '(none)',
174
+ },
175
+ });
176
+ };
177
+
178
+ return {
179
+ JSXElement: check,
180
+ };
181
+ },
182
+ };
package/src/plugin.js CHANGED
@@ -11,6 +11,7 @@ import vuejsDefineComponent from './vuejs-define-component.js'
11
11
  import vuejsDefineWorkspace from './vuejs-define-workspace.js'
12
12
  import routeDtoRequired from './route-dto-required.js'
13
13
  import requireFragmentKey from './require-fragment-key.js'
14
+ import noStaticKeyInMap from './no-static-key-in-map.js'
14
15
 
15
16
  export default {
16
17
  'import-specifiers-per-line': importSpecifiersPerLineRule,
@@ -26,4 +27,5 @@ export default {
26
27
  'vuejs-define-workspace': vuejsDefineWorkspace,
27
28
  'route-dto-required': routeDtoRequired,
28
29
  'require-fragment-key': requireFragmentKey,
30
+ 'no-static-key-in-map': noStaticKeyInMap,
29
31
  }