@tcy/eslint-rules 1.12.1 → 1.13.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.
- package/README.md +64 -11
- package/coverage/clover.xml +330 -174
- package/coverage/coverage-final.json +2 -1
- package/coverage/lcov-report/index.html +19 -19
- package/coverage/lcov-report/src/array-elements-per-line.js.html +1 -1
- package/coverage/lcov-report/src/back/back.js.html +1 -1
- package/coverage/lcov-report/src/back/http.js.html +1 -1
- package/coverage/lcov-report/src/back/index.html +1 -1
- package/coverage/lcov-report/src/back/recommended.js.html +1 -1
- package/coverage/lcov-report/src/bin/eslint-cache-guard.js.html +1 -1
- package/coverage/lcov-report/src/bin/index.html +1 -1
- package/coverage/lcov-report/src/client/client.js.html +5 -2
- package/coverage/lcov-report/src/client/index.html +1 -1
- package/coverage/lcov-report/src/client/recommended.js.html +1 -1
- package/coverage/lcov-report/src/consistent-const-scoping.js.html +1 -1
- package/coverage/lcov-report/src/decorator-type-enforcement.js.html +1 -1
- package/coverage/lcov-report/src/enforce-tailwind-important.js.html +1 -1
- package/coverage/lcov-report/src/export-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/src/import-specifiers-per-line.js.html +1 -1
- package/coverage/lcov-report/src/index.html +35 -20
- package/coverage/lcov-report/src/index.js.html +1 -1
- package/coverage/lcov-report/src/jsx-boolean-shorthand.js.html +1 -1
- package/coverage/lcov-report/src/jsx-expression-string-literals.js.html +1 -1
- package/coverage/lcov-report/src/jsx-ref-string-exists.js.html +1 -1
- package/coverage/lcov-report/src/jsx-ref-type-match.js.html +865 -0
- package/coverage/lcov-report/src/no-static-key-in-map.js.html +1 -1
- package/coverage/lcov-report/src/no-unused-setup-return.js.html +359 -17
- package/coverage/lcov-report/src/no-v-model-on-prop.js.html +1 -1
- package/coverage/lcov-report/src/plugin.js.html +8 -2
- package/coverage/lcov-report/src/recommended.js.html +1 -1
- package/coverage/lcov-report/src/require-fragment-key.js.html +1 -1
- package/coverage/lcov-report/src/route-dto-required.js.html +1 -1
- package/coverage/lcov-report/src/v-model-name-match.js.html +1 -1
- package/coverage/lcov-report/src/vuejs-define-component.js.html +1 -1
- package/coverage/lcov-report/src/vuejs-define-workspace.js.html +1 -1
- package/coverage/lcov.info +739 -362
- package/decl/back/back.d.ts +20 -0
- package/decl/client/client.d.ts +21 -0
- package/decl/jsx-ref-type-match.d.ts +34 -0
- package/decl/no-unused-setup-return.d.ts +2 -0
- package/decl/plugin.d.ts +20 -0
- package/package.json +1 -1
- package/src/client/client.js +1 -0
- package/src/jsx-ref-type-match.js +260 -0
- package/src/no-unused-setup-return.js +120 -6
- package/src/plugin.js +2 -0
- package/tests/jsx-ref-type-match.spec.js +118 -0
- package/tests/no-unused-setup-return.spec.js +17 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
import {
|
|
3
|
+
getInstanceTypeNames, getTagName, isAnyOrUnknown, isIntrinsicTag, isStringRef, isUntyped,
|
|
4
|
+
} from '../src/jsx-ref-type-match';
|
|
5
|
+
|
|
6
|
+
// ─── helpers ────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
const openingOf = (jsx) => {
|
|
9
|
+
const ast = parse(jsx, { sourceType: 'module', plugins: ['jsx', 'typescript'] });
|
|
10
|
+
return ast.program.body[0].expression.openingElement;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// babel uses `StringLiteral`, ESTree (typescript-eslint) uses `Literal`
|
|
14
|
+
const toEstree = (attr) => (attr.value?.type === 'StringLiteral'
|
|
15
|
+
? { ...attr, value: { ...attr.value, type: 'Literal' } }
|
|
16
|
+
: attr);
|
|
17
|
+
|
|
18
|
+
// minimal checker / types: intrinsic types are recognized by their printed name
|
|
19
|
+
const checker = {
|
|
20
|
+
typeToString: (t) => (t.isUnion() ? t.types.map((u) => u.name).join(' | ') : t.name),
|
|
21
|
+
};
|
|
22
|
+
const single = (name) => ({ name, isUnion: () => false });
|
|
23
|
+
const type = (...names) => (names.length === 1
|
|
24
|
+
? single(names[0])
|
|
25
|
+
: { isUnion: () => true, types: names.map(single) });
|
|
26
|
+
|
|
27
|
+
// ─── isStringRef ────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
describe('GIVEN "jsx-ref-type-match" / isStringRef', () => {
|
|
30
|
+
it.each([
|
|
31
|
+
['<div ref="root" />', true],
|
|
32
|
+
['<div ref={root} />', false],
|
|
33
|
+
['<div ref={"root"} />', false],
|
|
34
|
+
['<div id="root" />', false],
|
|
35
|
+
])('THEN %s → %s', (jsx, expected) => {
|
|
36
|
+
expect(isStringRef(toEstree(openingOf(jsx).attributes[0]))).toBe(expected);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ─── getTagName ─────────────────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
describe('GIVEN "jsx-ref-type-match" / getTagName', () => {
|
|
43
|
+
it.each([
|
|
44
|
+
['<div />', 'div'],
|
|
45
|
+
['<BaseInput />', 'BaseInput'],
|
|
46
|
+
['<Foo.Bar />', 'Foo.Bar'],
|
|
47
|
+
['<A.B.C />', 'A.B.C'],
|
|
48
|
+
['<svg:rect />', null],
|
|
49
|
+
])('THEN %s → %s', (jsx, expected) => {
|
|
50
|
+
expect(getTagName(openingOf(jsx))).toBe(expected);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ─── isIntrinsicTag ─────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
describe('GIVEN "jsx-ref-type-match" / isIntrinsicTag', () => {
|
|
57
|
+
it.each([
|
|
58
|
+
['div', true],
|
|
59
|
+
['svg', true],
|
|
60
|
+
['my-element', true],
|
|
61
|
+
['BaseInput', false],
|
|
62
|
+
['Component', false],
|
|
63
|
+
['icons.Check', false],
|
|
64
|
+
])('THEN %s → %s', (tag, expected) => {
|
|
65
|
+
expect(isIntrinsicTag(tag)).toBe(expected);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// ─── getInstanceTypeNames ───────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
describe('GIVEN "jsx-ref-type-match" / getInstanceTypeNames', () => {
|
|
72
|
+
it.each([
|
|
73
|
+
// `export default defineComponent(...)` in BaseInput.ts
|
|
74
|
+
['default', '/src/form/BaseInput.ts', 'BaseInput', ['BaseInput']],
|
|
75
|
+
// imported under another name: the file name wins over the tag
|
|
76
|
+
['default', '/src/form/BaseInput.ts', 'Input', ['BaseInput', 'Input']],
|
|
77
|
+
// named export
|
|
78
|
+
['VDropdown', '/src/dropdown/index.ts', 'VDropdown', ['VDropdown', 'index']],
|
|
79
|
+
['default', '/src/a/Foo.tsx', 'Foo', ['Foo']],
|
|
80
|
+
['default', '/src/a/Foo.d.ts', 'Foo', ['Foo']],
|
|
81
|
+
['default', '/src/a/Foo.ts', 'NS.Foo', ['Foo']],
|
|
82
|
+
])('THEN (%s, %s, %s) → %j', (exportName, fileName, tag, expected) => {
|
|
83
|
+
expect(getInstanceTypeNames(exportName, fileName, tag)).toEqual(expected);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ─── isUntyped ──────────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
describe('GIVEN "jsx-ref-type-match" / isUntyped', () => {
|
|
90
|
+
it.each([
|
|
91
|
+
[['any'], true], // ref()
|
|
92
|
+
[['unknown'], true],
|
|
93
|
+
[['null'], true], // ref(null)
|
|
94
|
+
[['undefined'], true],
|
|
95
|
+
[['null', 'undefined'], true],
|
|
96
|
+
[['void'], true],
|
|
97
|
+
[['HTMLDivElement'], false], // ref<HTMLDivElement>() unwrapped
|
|
98
|
+
[['HTMLDivElement', 'undefined'], false],
|
|
99
|
+
[['BaseInput', 'null'], false],
|
|
100
|
+
[['string'], false],
|
|
101
|
+
[['anything'], false], // the name must match exactly
|
|
102
|
+
])('THEN %j → %s', (names, expected) => {
|
|
103
|
+
expect(isUntyped(type(...names), checker)).toBe(expected);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ─── isAnyOrUnknown ─────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
describe('GIVEN "jsx-ref-type-match" / isAnyOrUnknown', () => {
|
|
110
|
+
it.each([
|
|
111
|
+
['any', true],
|
|
112
|
+
['unknown', true],
|
|
113
|
+
['null', false],
|
|
114
|
+
['VDropdown', false],
|
|
115
|
+
])('THEN %s → %s', (name, expected) => {
|
|
116
|
+
expect(isAnyOrUnknown(single(name), checker)).toBe(expected);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {
|
|
5
|
-
getKeyName, getWholeContextUsage, isComponentFileName, isComposableFile, isImportedElsewhere, readImportedRenders, isUsed, stripComments, usesWholeContext,
|
|
5
|
+
getKeyName, getWholeContextUsage, isComponentFileName, isComposableFile, isImportedElsewhere, isPublicComment, readImportedRenders, isUsed, stripComments, usesWholeContext,
|
|
6
6
|
} from '../src/no-unused-setup-return';
|
|
7
7
|
|
|
8
8
|
describe('GIVEN "no-unused-setup-return" / isComposableFile', () => {
|
|
@@ -134,3 +134,19 @@ describe('GIVEN "no-unused-setup-return" / readImportedRenders', () => {
|
|
|
134
134
|
expect(readImportedRenders("import render from '@/x/render';", '/tmp')).toEqual([]);
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
|
+
|
|
138
|
+
describe('GIVEN "no-unused-setup-return" / isPublicComment', () => {
|
|
139
|
+
it.each([
|
|
140
|
+
// comment values, as given by ESLint (without the delimiters)
|
|
141
|
+
['* @public ', true], // /** @public */
|
|
142
|
+
[' @public', true], // // @public
|
|
143
|
+
[' @public called by the parent', true],
|
|
144
|
+
['*\n * Focus the input\n * @public\n ', true], // multi-line JSDoc
|
|
145
|
+
[' public', false],
|
|
146
|
+
[' @publicApi', false],
|
|
147
|
+
[' not @public-ish', false],
|
|
148
|
+
[' foo@public', false],
|
|
149
|
+
])('THEN %j → %s', (text, expected) => {
|
|
150
|
+
expect(isPublicComment(text)).toBe(expected);
|
|
151
|
+
});
|
|
152
|
+
});
|