@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,88 @@
1
+ import {
2
+ getKeyName, getWholeContextUsage, isComponentFileName, isComposableFile, isUsed, stripComments, usesWholeContext,
3
+ } from '../src/no-unused-setup-return';
4
+
5
+ describe('GIVEN "no-unused-setup-return" / isComposableFile', () => {
6
+ it.each([
7
+ ['/a/useFoo.ts', true],
8
+ ['/a/useFoo2.ts', true],
9
+ ['/a/useRender.tsx', false],
10
+ ['/a/useFoo.spec.ts', false],
11
+ ['/a/Foo.ts', false],
12
+ ['/a/user.ts', false],
13
+ ])('THEN %s → %s', (file, expected) => {
14
+ expect(isComposableFile(file)).toBe(expected);
15
+ });
16
+ });
17
+
18
+ describe('GIVEN "no-unused-setup-return" / isUsed', () => {
19
+ it.each([
20
+ ['series', 'c.series.value', true],
21
+ ['series', 'const { series } = c;', true],
22
+ ['series', 'c.seriesCount', false],
23
+ ['series', 'c.allseries', false],
24
+ ['series', 'c.$series', false],
25
+ ['grid', '<GGrid ref="grid" />', true],
26
+ ['a.b', 'axb', false],
27
+ ])('THEN %s in %s → %s', (name, text, expected) => {
28
+ expect(isUsed(name, [text])).toBe(expected);
29
+ });
30
+ });
31
+
32
+ describe('GIVEN "no-unused-setup-return" / stripComments', () => {
33
+ it('THEN a commented use does not count', () => {
34
+ const text = stripComments('// c.foo\n/* c.bar */\nc.baz; const u = "http://x";');
35
+ expect(isUsed('foo', [text])).toBe(false);
36
+ expect(isUsed('bar', [text])).toBe(false);
37
+ expect(isUsed('baz', [text])).toBe(true);
38
+ expect(text).toContain('http://x');
39
+ });
40
+ });
41
+
42
+ describe('GIVEN "no-unused-setup-return" / usesWholeContext', () => {
43
+ it.each([
44
+ ['export default function (c: Foo) { return <A {...c} />; }', true],
45
+ ['export default function (c: Foo) { return <A>{render(c)}</A>; }', true],
46
+ ['export default function (c: Foo) { return <A>{render(a, c)}</A>; }', true],
47
+ ['export default function (c: Foo) { return <A v={c.a} />; }', false],
48
+ ['export default function (c: Foo) { return <A v={fn(c.a, c.b)} />; }', false],
49
+ ['export default function ({ a }: Foo) { return <A v={a} />; }', false],
50
+ ])('THEN %s → %s', (text, expected) => {
51
+ expect(usesWholeContext(text)).toBe(expected);
52
+ });
53
+ });
54
+
55
+ describe('GIVEN "no-unused-setup-return" / getKeyName', () => {
56
+ it.each([
57
+ [{ type: 'Property', computed: false, key: { type: 'Identifier', name: 'a' } }, 'a'],
58
+ [{ type: 'Property', computed: false, key: { type: 'Literal', value: 'b' } }, 'b'],
59
+ [{ type: 'Property', computed: true, key: { type: 'Identifier', name: 'c' } }, null],
60
+ [{ type: 'SpreadElement' }, null],
61
+ ])('THEN %j → %s', (prop, expected) => {
62
+ expect(getKeyName(prop)).toBe(expected);
63
+ });
64
+ });
65
+
66
+ describe('GIVEN "no-unused-setup-return" / getWholeContextUsage', () => {
67
+ it.each([
68
+ ['export default function (c: Foo) { return <A {...c} />; }', { spread: true, callees: [] }],
69
+ ['export default function (c: Foo) { return <A>{render(c)}</A>; }', { spread: false, callees: ['render'] }],
70
+ ['export default function (c: Foo) { return <A>{f(value, row, c)}</A>; }', { spread: false, callees: ['f'] }],
71
+ ['export default function (c: Foo) { return <A v={c.a} />; }', { spread: false, callees: [] }],
72
+ ])('THEN %s → %j', (text, expected) => {
73
+ expect(getWholeContextUsage(text)).toEqual(expected);
74
+ });
75
+ });
76
+
77
+ describe('GIVEN "no-unused-setup-return" / isComponentFileName', () => {
78
+ it.each([
79
+ ['/a/DailyPL.ts', true],
80
+ ['/a/WorkspaceFoo.ts', true],
81
+ ['/a/useDailyPL.ts', false],
82
+ ['/a/useRender.tsx', false],
83
+ ['/a/DailyPL.spec.ts', false],
84
+ ['/a/types.d.ts', false],
85
+ ])('THEN %s → %s', (file, expected) => {
86
+ expect(isComponentFileName(file)).toBe(expected);
87
+ });
88
+ });
@@ -0,0 +1,47 @@
1
+ import { parse } from '@babel/parser';
2
+ import { getModelTarget, getVModelAttrName } from '../src/no-v-model-on-prop';
3
+
4
+ // ─── helpers ────────────────────────────────────────────────────────────────
5
+
6
+ /** First JSX attribute of `<A {attr} />` */
7
+ const attrOf = (attr) => {
8
+ const ast = parse(`<A ${attr} />`, { sourceType: 'module', plugins: ['jsx', 'typescript'] });
9
+ return ast.program.body[0].expression.openingElement.attributes[0];
10
+ };
11
+
12
+ // babel uses `StringLiteral` / `OptionalMemberExpression`, close enough to ESTree here
13
+ const target = (attr) => {
14
+ const t = getModelTarget(attrOf(attr).value.expression);
15
+ return t && { object: t.object.name, name: t.name, nested: t.nested };
16
+ };
17
+
18
+ // ─── getVModelAttrName ──────────────────────────────────────────────────────
19
+
20
+ describe('GIVEN "no-v-model-on-prop" / getVModelAttrName', () => {
21
+ it.each([
22
+ ['v-model={c.value}', 'v-model'],
23
+ ['v-model:selected={c.selected}', 'v-model:selected'],
24
+ ['value={c.value}', null],
25
+ ['onUpdate:value={c.set}', null],
26
+ ])('THEN %s → %s', (attr, expected) => {
27
+ expect(getVModelAttrName(attrOf(attr))).toBe(expected);
28
+ });
29
+ });
30
+
31
+ // ─── getModelTarget ─────────────────────────────────────────────────────────
32
+
33
+ describe('GIVEN "no-v-model-on-prop" / getModelTarget', () => {
34
+ it.each([
35
+ ['v-model={c.value}', { object: 'c', name: 'value', nested: false }],
36
+ ['v-model={c.row.recTp}', { object: 'c', name: 'row', nested: true }],
37
+ ['v-model={c.searchFilter.a.b}', { object: 'c', name: 'searchFilter', nested: true }],
38
+ ['v-model={c["value"]}', { object: 'c', name: 'value', nested: false }],
39
+ ['v-model={c.value!}', { object: 'c', name: 'value', nested: false }],
40
+ ['v-model={c.value as string}', { object: 'c', name: 'value', nested: false }],
41
+ ['v-model={value}', null],
42
+ ['v-model={c[key]}', null],
43
+ ['v-model={getC().value}', null],
44
+ ])('THEN %s → %j', (attr, expected) => {
45
+ expect(target(attr)).toEqual(expected);
46
+ });
47
+ });