@tcy/eslint-rules 1.5.0 → 1.6.1
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/coverage/clover.xml +35 -4
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/index.html +17 -17
- 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/index.html +1 -1
- package/coverage/lcov-report/src/back/recommended.js.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/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 +23 -8
- 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 +370 -0
- package/coverage/lcov-report/src/plugin.js.html +8 -2
- package/coverage/lcov-report/src/recommended.js.html +20 -2
- 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 +65 -0
- package/decl/back/recommended.d.ts +6 -0
- package/decl/client/client.d.ts +1 -0
- package/decl/client/recommended.d.ts +6 -0
- package/decl/jsx-ref-string-exists.d.ts +17 -0
- package/decl/plugin.d.ts +16 -0
- package/decl/recommended.d.ts +6 -0
- package/package.json +5 -5
- package/src/client/client.js +1 -0
- package/src/jsx-ref-string-exists.js +95 -0
- package/src/plugin.js +2 -0
- package/src/recommended.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tcy/eslint-rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
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,11 +41,11 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/core": "^7.29.0",
|
|
44
|
-
"@babel/preset-env": "^7.29.
|
|
44
|
+
"@babel/preset-env": "^7.29.5",
|
|
45
45
|
"@types/jest": "^30.0.0",
|
|
46
|
-
"@types/node": "^25.
|
|
47
|
-
"babel-jest": "^30.
|
|
48
|
-
"jest": "^30.
|
|
46
|
+
"@types/node": "^25.7.0",
|
|
47
|
+
"babel-jest": "^30.4.1",
|
|
48
|
+
"jest": "^30.4.2",
|
|
49
49
|
"rimraf": "^6.1.3",
|
|
50
50
|
"typescript": "^6.0.3"
|
|
51
51
|
}
|
package/src/client/client.js
CHANGED
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
'tcy/array-elements-per-line': 'error',
|
|
14
14
|
'tcy/jsx-expression-string-literals': 'error',
|
|
15
15
|
'tcy/jsx-boolean-shorthand': 'error',
|
|
16
|
+
'tcy/jsx-ref-string-exists': 'error',
|
|
16
17
|
'tcy/enforce-tailwind-important': 'error',
|
|
17
18
|
'tcy/v-model-name-match': 'error',
|
|
18
19
|
'tcy/vuejs-define-component': 'error',
|
|
@@ -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
|
@@ -3,6 +3,7 @@ import arrayElementsPerLineRule from './array-elements-per-line.js';
|
|
|
3
3
|
import exportSpecifiersPerLineRule from './export-specifiers-per-line.js';
|
|
4
4
|
import jsxBooleanShorthand from './jsx-boolean-shorthand.js'
|
|
5
5
|
import jsxExpressionStringLiterals from './jsx-expression-string-literals.js';
|
|
6
|
+
import jsxRefStringExists from './jsx-ref-string-exists.js';
|
|
6
7
|
import enforceTailwindImportant from './enforce-tailwind-important.js';
|
|
7
8
|
import vModelNameMatch from './v-model-name-match.js';
|
|
8
9
|
import decoratorTypeEnforcement from './decorator-type-enforcement.js'
|
|
@@ -15,6 +16,7 @@ export default {
|
|
|
15
16
|
'export-specifiers-per-line': exportSpecifiersPerLineRule,
|
|
16
17
|
'jsx-boolean-shorthand': jsxBooleanShorthand,
|
|
17
18
|
'jsx-expression-string-literals': jsxExpressionStringLiterals,
|
|
19
|
+
'jsx-ref-string-exists': jsxRefStringExists,
|
|
18
20
|
'enforce-tailwind-important': enforceTailwindImportant,
|
|
19
21
|
'v-model-name-match': vModelNameMatch,
|
|
20
22
|
'decorator-type-enforcement': decoratorTypeEnforcement,
|