@tcy/eslint-rules 1.10.1 → 1.12.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 (47) hide show
  1. package/README.md +63 -0
  2. package/coverage/clover.xml +196 -4
  3. package/coverage/coverage-final.json +2 -0
  4. package/coverage/lcov-report/index.html +18 -18
  5. package/coverage/lcov-report/src/array-elements-per-line.js.html +1 -1
  6. package/coverage/lcov-report/src/back/back.js.html +1 -1
  7. package/coverage/lcov-report/src/back/http.js.html +1 -1
  8. package/coverage/lcov-report/src/back/index.html +1 -1
  9. package/coverage/lcov-report/src/back/recommended.js.html +1 -1
  10. package/coverage/lcov-report/src/bin/eslint-cache-guard.js.html +1 -1
  11. package/coverage/lcov-report/src/bin/index.html +1 -1
  12. package/coverage/lcov-report/src/client/client.js.html +8 -2
  13. package/coverage/lcov-report/src/client/index.html +1 -1
  14. package/coverage/lcov-report/src/client/recommended.js.html +1 -1
  15. package/coverage/lcov-report/src/consistent-const-scoping.js.html +1 -1
  16. package/coverage/lcov-report/src/decorator-type-enforcement.js.html +1 -1
  17. package/coverage/lcov-report/src/enforce-tailwind-important.js.html +1 -1
  18. package/coverage/lcov-report/src/export-specifiers-per-line.js.html +1 -1
  19. package/coverage/lcov-report/src/import-specifiers-per-line.js.html +1 -1
  20. package/coverage/lcov-report/src/index.html +39 -9
  21. package/coverage/lcov-report/src/index.js.html +1 -1
  22. package/coverage/lcov-report/src/jsx-boolean-shorthand.js.html +1 -1
  23. package/coverage/lcov-report/src/jsx-expression-string-literals.js.html +1 -1
  24. package/coverage/lcov-report/src/jsx-ref-string-exists.js.html +1 -1
  25. package/coverage/lcov-report/src/no-static-key-in-map.js.html +1 -1
  26. package/coverage/lcov-report/src/no-unused-setup-return.js.html +1009 -0
  27. package/coverage/lcov-report/src/no-v-model-on-prop.js.html +553 -0
  28. package/coverage/lcov-report/src/plugin.js.html +14 -2
  29. package/coverage/lcov-report/src/recommended.js.html +1 -1
  30. package/coverage/lcov-report/src/require-fragment-key.js.html +1 -1
  31. package/coverage/lcov-report/src/route-dto-required.js.html +1 -1
  32. package/coverage/lcov-report/src/v-model-name-match.js.html +1 -1
  33. package/coverage/lcov-report/src/vuejs-define-component.js.html +1 -1
  34. package/coverage/lcov-report/src/vuejs-define-workspace.js.html +1 -1
  35. package/coverage/lcov.info +458 -0
  36. package/decl/back/back.d.ts +71 -0
  37. package/decl/client/client.d.ts +73 -0
  38. package/decl/no-unused-setup-return.d.ts +64 -0
  39. package/decl/no-v-model-on-prop.d.ts +48 -0
  40. package/decl/plugin.d.ts +71 -0
  41. package/package.json +5 -5
  42. package/src/client/client.js +2 -0
  43. package/src/no-unused-setup-return.js +308 -0
  44. package/src/no-v-model-on-prop.js +156 -0
  45. package/src/plugin.js +4 -0
  46. package/tests/no-unused-setup-return.spec.js +88 -0
  47. package/tests/no-v-model-on-prop.spec.js +47 -0
@@ -0,0 +1,48 @@
1
+ declare const _default: {
2
+ meta: {
3
+ type: string;
4
+ docs: {
5
+ description: string;
6
+ };
7
+ messages: {
8
+ prop: string;
9
+ nestedProp: string;
10
+ };
11
+ schema: {
12
+ type: string;
13
+ properties: {
14
+ allowNested: {
15
+ type: string;
16
+ };
17
+ contextTypeName: {
18
+ type: string;
19
+ };
20
+ };
21
+ additionalProperties: boolean;
22
+ }[];
23
+ };
24
+ create(context: any): {
25
+ JSXAttribute?: undefined;
26
+ } | {
27
+ JSXAttribute(node: any): void;
28
+ };
29
+ };
30
+ export default _default;
31
+ /** `v-model` / `v-model:selected` → attribute name, otherwise null */
32
+ export declare const getVModelAttrName: (attr: any) => string | null;
33
+ /**
34
+ * Root member of the v-model expression:
35
+ * c.value → { object: c, name: 'value', nested: false }
36
+ * c.row.recTp → { object: c, name: 'row', nested: true }
37
+ * value / foo() → null
38
+ */
39
+ export declare const getModelTarget: (expr: any) => {
40
+ object: any;
41
+ name: any;
42
+ nested: boolean;
43
+ } | null;
44
+ /**
45
+ * `Props` from a `Context<typeof setup, Props>` type, either used directly
46
+ * or through an alias (`type Foo = Context<typeof setup, Props>`)
47
+ */
48
+ export declare const getPropsType: (checker: any, type: any, contextTypeName: any) => any;
package/decl/plugin.d.ts CHANGED
@@ -272,5 +272,76 @@ declare const _default: {
272
272
  VariableDeclarator(node: any): void;
273
273
  };
274
274
  };
275
+ 'no-v-model-on-prop': {
276
+ meta: {
277
+ type: string;
278
+ docs: {
279
+ description: string;
280
+ };
281
+ messages: {
282
+ prop: string;
283
+ nestedProp: string;
284
+ };
285
+ schema: {
286
+ type: string;
287
+ properties: {
288
+ allowNested: {
289
+ type: string;
290
+ };
291
+ contextTypeName: {
292
+ type: string;
293
+ };
294
+ };
295
+ additionalProperties: boolean;
296
+ }[];
297
+ };
298
+ create(context: any): {
299
+ JSXAttribute?: undefined;
300
+ } | {
301
+ JSXAttribute(node: any): void;
302
+ };
303
+ };
304
+ 'no-unused-setup-return': {
305
+ meta: {
306
+ type: string;
307
+ docs: {
308
+ description: string;
309
+ };
310
+ messages: {
311
+ unused: string;
312
+ };
313
+ schema: {
314
+ type: string;
315
+ properties: {
316
+ ignore: {
317
+ type: string;
318
+ items: {
319
+ type: string;
320
+ };
321
+ };
322
+ };
323
+ additionalProperties: boolean;
324
+ }[];
325
+ };
326
+ create(context: any): {
327
+ Program?: undefined;
328
+ FunctionDeclaration?: undefined;
329
+ 'FunctionDeclaration:exit'?: undefined;
330
+ FunctionExpression?: undefined;
331
+ 'FunctionExpression:exit'?: undefined;
332
+ ArrowFunctionExpression?: undefined;
333
+ 'ArrowFunctionExpression:exit'?: undefined;
334
+ ReturnStatement?: undefined;
335
+ } | {
336
+ Program(program: any): void;
337
+ FunctionDeclaration: (node: any) => void;
338
+ 'FunctionDeclaration:exit': () => void;
339
+ FunctionExpression: (node: any) => void;
340
+ 'FunctionExpression:exit': () => void;
341
+ ArrowFunctionExpression(node: any): void;
342
+ 'ArrowFunctionExpression:exit': () => void;
343
+ ReturnStatement(node: any): void;
344
+ };
345
+ };
275
346
  };
276
347
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tcy/eslint-rules",
3
- "version": "1.10.1",
3
+ "version": "1.12.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": {
@@ -47,13 +47,13 @@
47
47
  "test": "jest"
48
48
  },
49
49
  "devDependencies": {
50
- "@babel/core": "^8.0.6",
51
- "@babel/preset-env": "^8.0.6",
50
+ "@babel/core": "^8.1.2",
51
+ "@babel/preset-env": "^8.0.7",
52
52
  "@types/jest": "^30.0.0",
53
- "@types/node": "^26.6.4",
53
+ "@types/node": "^26.6.6",
54
54
  "babel-jest": "^30.5.2",
55
55
  "jest": "^30.5.2",
56
- "rimraf": "^6.1.3",
56
+ "rimraf": "^6.1.4",
57
57
  "typescript": "^7.0.2"
58
58
  }
59
59
  }
@@ -21,5 +21,7 @@ export default {
21
21
  'tcy/require-fragment-key': 'error',
22
22
  'tcy/no-static-key-in-map': 'error',
23
23
  'tcy/consistent-const-scoping': 'error',
24
+ 'tcy/no-v-model-on-prop': 'error',
25
+ 'tcy/no-unused-setup-return': 'error',
24
26
  }
25
27
  }
@@ -0,0 +1,308 @@
1
+ // Disallow a key returned by a composition function (`useXxx.ts`) or by the `setup` of `Component.ts`
2
+ // that nothing else of the component reads:
3
+ //
4
+ // Component.ts defineComponent + setup, spreads the composables in a single object
5
+ // useComponent.ts composable ← the rule runs here, on the returned object
6
+ // Component.ts the `setup` returned object is checked too
7
+ // useComponent2.ts other composable
8
+ // useRender.tsx render, reads the keys through `c.key`
9
+ //
10
+ // A returned key is used when its name is found in another file of the same directory (or of its
11
+ // sub-directories, a child can read it through the context type): the render,
12
+ // `Component.ts` or another composable (`useGridConfig(p, { columnFilteredName })`). A key used only
13
+ // by a composable is not reported, it can be a value shared between compositions, not rendered.
14
+ //
15
+ // The check is by name, on purpose: it can miss an unused key sharing its name with something else,
16
+ // but never reports a used one. `ref="name"` is a use too.
17
+ //
18
+ // The directory is skipped when:
19
+ // - it has no `Component.ts` (a file calling `defineComponent`) importing the composable:
20
+ // a composable shared by many components, or used through inject / by a parent
21
+ // - a render file spreads (`...c`), or passes the whole context to a function (`foo(c)`) that
22
+ // can't be resolved (relative import): any key can be read. A resolved function is searched too
23
+
24
+ import fs from 'node:fs';
25
+ import path from 'node:path';
26
+
27
+ export default {
28
+ meta: {
29
+ type: 'suggestion',
30
+ docs: {
31
+ description: 'Disallow a key returned by a composable that is not used by the component (render or other compositions).',
32
+ },
33
+ messages: {
34
+ unused: '"{{name}}" is returned by the setup but not used by the render or by another composition of the component.',
35
+ },
36
+ schema: [{
37
+ type: 'object',
38
+ properties: {
39
+ // keys that are never reported
40
+ ignore: { type: 'array', items: { type: 'string' } },
41
+ },
42
+ additionalProperties: false,
43
+ }],
44
+ },
45
+
46
+ create(context) {
47
+ const filename = context.filename ?? context.getFilename();
48
+
49
+ // `Component.ts` (`setup`) or a composable (`useXxx.ts`, default export)
50
+ const isComposable = isComposableFile(filename);
51
+ if (!isComposable && !isComponentFileName(filename)) return {};
52
+
53
+ const { ignore = [] } = context.options[0] || {};
54
+
55
+ const siblings = readSiblings(filename);
56
+ if (!siblings) return {};
57
+
58
+ // the composable is part of the setup of the component of its directory,
59
+ // otherwise it is shared (inject, parent, ...) and the keys are read from elsewhere
60
+ const base = path.basename(filename).replace(EXT, '');
61
+ if (isComposable) {
62
+ const component = siblings.find((s) => !s.inner && isComponentFile(s));
63
+ if (!component || !new RegExp(`from\\s+['"]\\./${escapeRegExp(base)}['"]`).test(component.text)) return {};
64
+ } else if (!/\bdefineComponent\s*\(/.test(context.sourceCode.text)) {
65
+ return {};
66
+ }
67
+ const isTarget = (fn, names) => (isComposable ? isExported(fn, names) : isSetup(fn));
68
+
69
+ const texts = siblings.map((s) => s.text);
70
+
71
+ // the render passes its whole context: `...c` hides the keys that are read, `foo(c)` is
72
+ // resolved and the file of `foo` is searched too (not resolvable: every key can be used)
73
+ for (const s of siblings) {
74
+ if (!s.isRender || s.inner) continue;
75
+
76
+ const { spread, callees } = getWholeContextUsage(s.text);
77
+ if (spread) return {};
78
+
79
+ for (const callee of callees) {
80
+ const imported = readImported(callee, s.text, path.dirname(filename));
81
+ if (imported === null) return {};
82
+ texts.push(imported);
83
+ }
84
+ }
85
+
86
+ // function stack, only the exported function counts
87
+ const stack = [];
88
+ const enter = (node) => { stack.push(node); };
89
+ const leave = () => { stack.pop(); };
90
+
91
+ const exportedNames = new Set();
92
+
93
+ return {
94
+ Program(program) {
95
+ for (const node of program.body) {
96
+ if (node.type === 'ExportDefaultDeclaration' && node.declaration.type === 'Identifier') {
97
+ exportedNames.add(node.declaration.name);
98
+ }
99
+ }
100
+ },
101
+
102
+ FunctionDeclaration: enter,
103
+ 'FunctionDeclaration:exit': leave,
104
+ FunctionExpression: enter,
105
+ 'FunctionExpression:exit': leave,
106
+ ArrowFunctionExpression(node) {
107
+ enter(node);
108
+ // `=> ({ a, b })`
109
+ if (node.body.type === 'ObjectExpression' && isTarget(node, exportedNames)) {
110
+ check(context, node.body, texts, ignore);
111
+ }
112
+ },
113
+ 'ArrowFunctionExpression:exit': leave,
114
+
115
+ ReturnStatement(node) {
116
+ if (node.argument?.type !== 'ObjectExpression') return;
117
+ const fn = stack[stack.length - 1];
118
+ if (!fn || !isTarget(fn, exportedNames)) return;
119
+ check(context, node.argument, texts, ignore);
120
+ },
121
+ };
122
+ },
123
+ };
124
+
125
+ // ─── helpers ────────────────────────────────────────────────────────────────
126
+
127
+ const EXT = /\.(ts|tsx|js|jsx)$/;
128
+
129
+ /** `useXxx.ts`, but not the render function */
130
+ export const isComposableFile = (filename) => {
131
+ const base = path.basename(filename);
132
+ return /^use[A-Z].*\.(ts|js)$/.test(base) && !/^useRender\./.test(base) && !/\.(spec|test)\./.test(base);
133
+ };
134
+
135
+ const isComponentFile = (sibling) => !sibling.isComposable && /\bdefineComponent\s*\(/.test(sibling.text);
136
+
137
+ const cache = new Map();
138
+
139
+ /** Other files of the directory, `null` if it can't be read */
140
+ const readSiblings = (filename) => {
141
+ const dir = path.dirname(filename);
142
+ let names;
143
+ try {
144
+ names = fs.readdirSync(dir, { withFileTypes: true });
145
+ } catch {
146
+ return null;
147
+ }
148
+
149
+ const result = [];
150
+ walk(dir, filename, 0, result);
151
+ return result;
152
+ };
153
+
154
+ const MAX_DEPTH = 4;
155
+
156
+ // files of the directory, `inner` the ones of its sub-directories: a child component can read
157
+ // the keys through the context type
158
+ const walk = (dir, self, depth, result) => {
159
+ let entries;
160
+ try {
161
+ entries = fs.readdirSync(dir, { withFileTypes: true });
162
+ } catch {
163
+ return;
164
+ }
165
+
166
+ for (const entry of entries) {
167
+ const file = path.join(dir, entry.name);
168
+
169
+ if (entry.isDirectory()) {
170
+ if (depth < MAX_DEPTH && entry.name !== 'node_modules') walk(file, self, depth + 1, result);
171
+ continue;
172
+ }
173
+
174
+ const { name } = entry;
175
+ if (file === self || !EXT.test(name) || /\.(spec|test)\./.test(name) || /\.d\.ts$/.test(name)) continue;
176
+
177
+ try {
178
+ const { mtimeMs } = fs.statSync(file);
179
+ const hit = cache.get(file);
180
+ if (hit?.mtimeMs === mtimeMs) {
181
+ result.push(hit.sibling);
182
+ continue;
183
+ }
184
+
185
+ const sibling = {
186
+ name,
187
+ inner: depth > 0,
188
+ isRender: /^useRender\./.test(name),
189
+ isComposable: /^use[A-Z]/.test(name),
190
+ text: stripComments(fs.readFileSync(file, 'utf8')),
191
+ };
192
+ cache.set(file, { mtimeMs, sibling });
193
+ result.push(sibling);
194
+ } catch {
195
+ // unreadable file, ignored
196
+ }
197
+ }
198
+ };
199
+
200
+ export const stripComments = (text) => text
201
+ .replace(/\/\*[\s\S]*?\*\//g, '')
202
+ .replace(/(^|[^:'"`])\/\/.*$/gm, '$1');
203
+
204
+ const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
205
+
206
+ /** `name` found as a whole word in one of the texts */
207
+ export const isUsed = (name, texts) => {
208
+ const re = new RegExp(`(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
209
+ return texts.some((t) => re.test(t));
210
+ };
211
+
212
+ /** Name of the first parameter of the render function, `null` if destructured / not found */
213
+ const getContextName = (text) => {
214
+ const m = /(?:function\s*\w*\s*|=\s*)\(\s*(?:\{[^}]*\}|(\w+))\s*(?::[^)]*)?\)/.exec(text);
215
+ return m ? { name: m[1] ?? null, rest: text.slice(m.index + m[0].length) } : null;
216
+ };
217
+
218
+ /**
219
+ * How the render uses its whole context (`c`):
220
+ * - `{ spread: true }` `...c`: any key can be read
221
+ * - `{ callees: [...] }` `foo(a, c)`: the names of the called functions, they read keys of `c`
222
+ */
223
+ export const getWholeContextUsage = (text) => {
224
+ const ctx = getContextName(text);
225
+ if (!ctx?.name) return { spread: false, callees: [] };
226
+
227
+ const n = escapeRegExp(ctx.name);
228
+ if (new RegExp(`\\.\\.\\.${n}(?![\\w$])`).test(ctx.rest)) return { spread: true, callees: [] };
229
+
230
+ const callees = [];
231
+ const call = new RegExp(`([\\w$]+)\\s*\\(([^()]*,\\s*)?${n}\\s*[,)]`, 'g');
232
+ for (const m of ctx.rest.matchAll(call)) callees.push(m[1]);
233
+ // a bare `(c)` / `, c)` not matched above: unknown callee
234
+ const bare = new RegExp(`[(,]\\s*${n}\\s*[,)]`, 'g');
235
+ const unknown = [...ctx.rest.matchAll(bare)].length > callees.length;
236
+ return { spread: unknown, callees };
237
+ };
238
+
239
+ /** `usesWholeContext`: the render hides the keys it reads */
240
+ export const usesWholeContext = (text) => {
241
+ const { spread, callees } = getWholeContextUsage(text);
242
+ return spread || callees.length > 0;
243
+ };
244
+
245
+ const RESOLVE_EXT = ['.ts', '.tsx', '.js', '/index.ts', '/index.tsx', '/index.js'];
246
+
247
+ /** Text of the file imported as `name` with a relative path, `null` if not resolvable */
248
+ export const readImported = (name, text, dir) => {
249
+ const n = escapeRegExp(name);
250
+ const m = new RegExp(`import\\s+${n}\\s+from\\s+['"](\\.[^'"]*)['"]|import\\s*\\{[^}]*\\b${n}\\b[^}]*\\}\\s*from\\s*['"](\\.[^'"]*)['"]`).exec(text);
251
+ const rel = m && (m[1] ?? m[2]);
252
+ if (!rel) return null;
253
+
254
+ for (const ext of RESOLVE_EXT) {
255
+ const file = path.resolve(dir, rel + ext);
256
+ try {
257
+ return stripComments(fs.readFileSync(file, 'utf8'));
258
+ } catch {
259
+ // next candidate
260
+ }
261
+ }
262
+ return null;
263
+ };
264
+
265
+ /** `Component.ts`: not a composable, not the render */
266
+ export const isComponentFileName = (filename) => {
267
+ const base = path.basename(filename);
268
+ return /\.(ts|js)$/.test(base) && !/^use[A-Z]/.test(base) && !/\.(spec|test|d)\./.test(base);
269
+ };
270
+
271
+ /** `const setup = () => {}` or `defineComponent({ setup() {}, setup: () => {} })` */
272
+ const isSetup = (fn) => {
273
+ const { parent } = fn;
274
+ if (parent?.type === 'VariableDeclarator') return parent.id.type === 'Identifier' && parent.id.name === 'setup';
275
+ if (fn.type === 'FunctionDeclaration') return fn.id?.name === 'setup';
276
+ if (parent?.type === 'Property' || parent?.type === 'MethodDefinition') {
277
+ return !parent.computed && parent.key.type === 'Identifier' && parent.key.name === 'setup';
278
+ }
279
+ return false;
280
+ };
281
+
282
+ const isExported = (fn, exportedNames) => {
283
+ const { parent } = fn;
284
+ if (parent?.type === 'ExportDefaultDeclaration') return true;
285
+ if (fn.type === 'FunctionDeclaration' && fn.id && exportedNames.has(fn.id.name)) return true;
286
+ if (parent?.type === 'VariableDeclarator' && parent.id.type === 'Identifier' && exportedNames.has(parent.id.name)) {
287
+ return true;
288
+ }
289
+ return false;
290
+ };
291
+
292
+ export const getKeyName = (prop) => {
293
+ if (prop.type !== 'Property' || prop.computed) return null;
294
+ if (prop.key.type === 'Identifier') return prop.key.name;
295
+ if (prop.key.type === 'Literal' && typeof prop.key.value === 'string') return prop.key.value;
296
+ return null;
297
+ };
298
+
299
+ const check = (context, objectNode, texts, ignore) => {
300
+ for (const prop of objectNode.properties) {
301
+ const name = getKeyName(prop);
302
+ if (!name || ignore.includes(name)) continue;
303
+
304
+ if (!isUsed(name, texts)) {
305
+ context.report({ node: prop, messageId: 'unused', data: { name } });
306
+ }
307
+ }
308
+ };
@@ -0,0 +1,156 @@
1
+ // Disallow `v-model` bound to a component prop in a render function:
2
+ //
3
+ // export type Foo = Context<typeof setup, Props>;
4
+ // export default function (c: Foo) {
5
+ // return <Input v-model={c.value} />; // `value` is in `Props`
6
+ // }
7
+ //
8
+ // Props are readonly: the update is dropped (with a Vue warning). For a nested field (`c.row.recTp`)
9
+ // Vue doesn't complain, but the object belongs to the parent component.
10
+ //
11
+ // `Props` is read from the second type argument of `Context`. A prop and a setup value can't share
12
+ // a name, so being a key of `Props` is enough to know `c.x` is a prop.
13
+
14
+ export default {
15
+ meta: {
16
+ type: 'problem',
17
+ docs: {
18
+ description: 'Disallow `v-model` bound to a component prop (`c.x` where `x` is in `Props`).',
19
+ },
20
+ messages: {
21
+ prop: '`{{attr}}` is bound to the prop "{{name}}". Props are readonly, emit an update event instead.',
22
+ nestedProp: '`{{attr}}` mutates the prop "{{name}}" ({{expr}}), which belongs to the parent component.',
23
+ },
24
+ schema: [{
25
+ type: 'object',
26
+ properties: {
27
+ // allow `v-model={c.row.field}` when `row` is a prop
28
+ allowNested: { type: 'boolean' },
29
+ // name of the context type, `Context<typeof setup, Props>`
30
+ contextTypeName: { type: 'string' },
31
+ },
32
+ additionalProperties: false,
33
+ }],
34
+ },
35
+
36
+ create(context) {
37
+ const services = context.sourceCode.parserServices;
38
+
39
+ // type information is required
40
+ if (!services?.program) {
41
+ return {};
42
+ }
43
+
44
+ const { allowNested = false, contextTypeName = 'Context' } = context.options[0] || {};
45
+ const checker = services.program.getTypeChecker();
46
+
47
+ // cache by type: the same `c` is used by every v-model of a render function
48
+ const propsCache = new Map();
49
+ const getProps = (identifier) => {
50
+ const type = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(identifier));
51
+ if (!propsCache.has(type)) {
52
+ propsCache.set(type, getPropsType(checker, type, contextTypeName));
53
+ }
54
+ return propsCache.get(type);
55
+ };
56
+
57
+ return {
58
+ JSXAttribute(node) {
59
+ const attr = getVModelAttrName(node);
60
+ if (!attr) return;
61
+
62
+ const target = getModelTarget(node.value?.expression);
63
+ if (!target) return;
64
+
65
+ if (target.nested && allowNested) return;
66
+
67
+ const propsType = getProps(target.object);
68
+ if (!propsType || !checker.getPropertyOfType(propsType, target.name)) return;
69
+
70
+ context.report({
71
+ node: node.value,
72
+ messageId: target.nested ? 'nestedProp' : 'prop',
73
+ data: {
74
+ attr,
75
+ name: target.name,
76
+ expr: context.sourceCode.getText(node.value.expression),
77
+ },
78
+ });
79
+ },
80
+ };
81
+ },
82
+ };
83
+
84
+ // ─── helpers ────────────────────────────────────────────────────────────────
85
+
86
+ /** `v-model` / `v-model:selected` → attribute name, otherwise null */
87
+ export const getVModelAttrName = (attr) => {
88
+ if (attr.name.type === 'JSXIdentifier') {
89
+ return attr.name.name === 'v-model' ? 'v-model' : null;
90
+ }
91
+ if (attr.name.type === 'JSXNamespacedName' && attr.name.namespace.name === 'v-model') {
92
+ return `v-model:${attr.name.name.name}`;
93
+ }
94
+ return null;
95
+ };
96
+
97
+ const getStaticPropertyName = (member) => {
98
+ if (!member.computed && member.property.type === 'Identifier') return member.property.name;
99
+ if (member.computed && member.property.type === 'Literal' && typeof member.property.value === 'string') {
100
+ return member.property.value;
101
+ }
102
+ // babel AST (tests)
103
+ if (member.computed && member.property.type === 'StringLiteral') return member.property.value;
104
+ return null;
105
+ };
106
+
107
+ /**
108
+ * Root member of the v-model expression:
109
+ * c.value → { object: c, name: 'value', nested: false }
110
+ * c.row.recTp → { object: c, name: 'row', nested: true }
111
+ * value / foo() → null
112
+ */
113
+ export const getModelTarget = (expr) => {
114
+ let e = expr;
115
+ // `c.value!` / `c.value as T`
116
+ while (e && ['TSNonNullExpression', 'TSAsExpression'].includes(e.type)) e = e.expression;
117
+
118
+ if (e?.type !== 'MemberExpression') return null;
119
+
120
+ let root = e;
121
+ while (root.object.type === 'MemberExpression') root = root.object;
122
+
123
+ if (root.object.type !== 'Identifier') return null;
124
+
125
+ const name = getStaticPropertyName(root);
126
+ if (!name) return null;
127
+
128
+ return {
129
+ object: root.object,
130
+ name,
131
+ nested: root !== e,
132
+ };
133
+ };
134
+
135
+ /**
136
+ * `Props` from a `Context<typeof setup, Props>` type, either used directly
137
+ * or through an alias (`type Foo = Context<typeof setup, Props>`)
138
+ */
139
+ export const getPropsType = (checker, type, contextTypeName) => {
140
+ const alias = type.aliasSymbol;
141
+ if (!alias) return null;
142
+
143
+ if (alias.name === contextTypeName) {
144
+ return type.aliasTypeArguments?.[1] ?? null;
145
+ }
146
+
147
+ for (const decl of alias.declarations ?? []) {
148
+ const ref = decl.type;
149
+ const refName = ref?.typeName?.escapedText ?? ref?.typeName?.right?.escapedText;
150
+ if (refName === contextTypeName && ref.typeArguments?.length >= 2) {
151
+ return checker.getTypeFromTypeNode(ref.typeArguments[1]);
152
+ }
153
+ }
154
+
155
+ return null;
156
+ };
package/src/plugin.js CHANGED
@@ -13,6 +13,8 @@ import routeDtoRequired from './route-dto-required.js'
13
13
  import requireFragmentKey from './require-fragment-key.js'
14
14
  import noStaticKeyInMap from './no-static-key-in-map.js'
15
15
  import consistentConstScoping from './consistent-const-scoping.js'
16
+ import noVModelOnProp from './no-v-model-on-prop.js'
17
+ import noUnusedSetupReturn from './no-unused-setup-return.js'
16
18
 
17
19
  export default {
18
20
  'import-specifiers-per-line': importSpecifiersPerLineRule,
@@ -30,4 +32,6 @@ export default {
30
32
  'require-fragment-key': requireFragmentKey,
31
33
  'no-static-key-in-map': noStaticKeyInMap,
32
34
  'consistent-const-scoping': consistentConstScoping,
35
+ 'no-v-model-on-prop': noVModelOnProp,
36
+ 'no-unused-setup-return': noUnusedSetupReturn,
33
37
  }