eslint-plugin-th-rules 3.1.7 → 3.1.8
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/configs/core/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,eAAO,MAAM,cAAc,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/configs/core/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,eAAO,MAAM,cAAc,EAAE,iBAAiB,EAoB7C,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas-in-schemas-file.d.ts","sourceRoot":"","sources":["../../src/rules/schemas-in-schemas-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas-in-schemas-file.d.ts","sourceRoot":"","sources":["../../src/rules/schemas-in-schemas-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAEtF,QAAA,MAAM,oBAAoB;;;;;;CAmIxB,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
2
|
+
/* eslint-disable new-cap */
|
|
1
3
|
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
|
|
2
4
|
const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/schemas-in-schemas-file.md')({
|
|
3
5
|
name: 'schemas-in-schemas-file',
|
|
@@ -13,7 +15,6 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
|
|
|
13
15
|
allowedSuffixes: {
|
|
14
16
|
type: 'array',
|
|
15
17
|
items: { type: 'string', minLength: 1 },
|
|
16
|
-
minItems: 1,
|
|
17
18
|
},
|
|
18
19
|
onlyWhenAssigned: { type: 'boolean' },
|
|
19
20
|
allowInTests: { type: 'boolean' },
|
|
@@ -32,25 +33,24 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
|
|
|
32
33
|
allowInTests: false,
|
|
33
34
|
},
|
|
34
35
|
],
|
|
35
|
-
create(context, [
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
create(context, [rawOptions]) {
|
|
37
|
+
const options = {
|
|
38
|
+
allowedSuffixes: rawOptions?.allowedSuffixes ?? ['.schemas.ts'],
|
|
39
|
+
onlyWhenAssigned: rawOptions?.onlyWhenAssigned ?? false,
|
|
40
|
+
allowInTests: rawOptions?.allowInTests ?? false,
|
|
41
|
+
};
|
|
39
42
|
const zodIdentifiers = new Set();
|
|
40
43
|
function filenameAllowed(filename) {
|
|
41
44
|
if (!filename || filename === '<input>') {
|
|
42
45
|
return false;
|
|
43
46
|
}
|
|
44
|
-
if (allowInTests && /\.(test|spec)\.[jt]sx?$/.test(filename)) {
|
|
47
|
+
if (options.allowInTests && /\.(test|spec)\.[jt]sx?$/.test(filename)) {
|
|
45
48
|
return true;
|
|
46
49
|
}
|
|
47
|
-
return allowedSuffixes.some((suffix) => filename.endsWith(suffix));
|
|
48
|
-
}
|
|
49
|
-
function isZodModuleImport(node) {
|
|
50
|
-
return node.source.value === 'zod';
|
|
50
|
+
return options.allowedSuffixes.some((suffix) => filename.endsWith(suffix));
|
|
51
51
|
}
|
|
52
52
|
function collectZodIdentifiersFromImport(node) {
|
|
53
|
-
if (
|
|
53
|
+
if (node.source.value !== 'zod') {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
for (const spec of node.specifiers) {
|
|
@@ -64,53 +64,37 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
|
|
|
64
64
|
}
|
|
65
65
|
function isZodBuilderCall(node) {
|
|
66
66
|
const { callee } = node;
|
|
67
|
-
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
const { object } = callee;
|
|
71
|
-
const { property } = callee;
|
|
72
|
-
return object.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(object.name) && property.type === AST_NODE_TYPES.Identifier;
|
|
67
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(callee.object.name);
|
|
73
68
|
}
|
|
74
69
|
function isZodChainedBuilderCall(node) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
let current = callee.object;
|
|
80
|
-
while (current.type === AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
70
|
+
let current = node.callee;
|
|
71
|
+
while (current?.type === AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
81
72
|
current = current.object;
|
|
82
73
|
}
|
|
83
|
-
return current
|
|
74
|
+
return current?.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(current.name);
|
|
84
75
|
}
|
|
85
|
-
function
|
|
86
|
-
const { parent } =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
if (parent.type === AST_NODE_TYPES.AssignmentExpression && parent.left.type === AST_NODE_TYPES.Identifier) {
|
|
91
|
-
return parent.left.name;
|
|
92
|
-
}
|
|
76
|
+
function getAssignmentTarget(node) {
|
|
77
|
+
const { parent } = node;
|
|
78
|
+
return ((parent?.type === AST_NODE_TYPES.VariableDeclarator && parent.id.type === AST_NODE_TYPES.Identifier) ||
|
|
79
|
+
(parent?.type === AST_NODE_TYPES.AssignmentExpression && parent.left.type === AST_NODE_TYPES.Identifier));
|
|
93
80
|
}
|
|
94
81
|
function report(node) {
|
|
95
82
|
if (filenameAllowed(context.filename)) {
|
|
96
83
|
return;
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
if (onlyWhenAssigned && !targetName) {
|
|
85
|
+
if (options.onlyWhenAssigned && !getAssignmentTarget(node)) {
|
|
100
86
|
return;
|
|
101
87
|
}
|
|
102
88
|
context.report({
|
|
103
89
|
node,
|
|
104
90
|
messageId: 'moveSchema',
|
|
105
91
|
data: {
|
|
106
|
-
suffixes: allowedSuffixes.join(' or '),
|
|
92
|
+
suffixes: options.allowedSuffixes.join(' or ') || '.schemas.ts',
|
|
107
93
|
},
|
|
108
94
|
});
|
|
109
95
|
}
|
|
110
96
|
return {
|
|
111
|
-
ImportDeclaration
|
|
112
|
-
collectZodIdentifiersFromImport(node);
|
|
113
|
-
},
|
|
97
|
+
ImportDeclaration: collectZodIdentifiersFromImport,
|
|
114
98
|
CallExpression(node) {
|
|
115
99
|
if (zodIdentifiers.size === 0) {
|
|
116
100
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-th-rules",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "A List of custom ESLint rules created by Tomer Horowitz",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -25,10 +25,6 @@
|
|
|
25
25
|
"@babel/eslint-parser": "^7.28.6",
|
|
26
26
|
"@eslint/eslintrc": "^3.3.3",
|
|
27
27
|
"@leancodepl/resolve-eslint-flat-config": "^9.7.0",
|
|
28
|
-
"@typescript-eslint/eslint-plugin": "^8.53.0",
|
|
29
|
-
"@typescript-eslint/parser": "^8.53.0",
|
|
30
|
-
"@typescript-eslint/rule-tester": "^8.53.0",
|
|
31
|
-
"@typescript-eslint/utils": "^8.53.0",
|
|
32
28
|
"eslint-config-jsdoc": "^15.4.0",
|
|
33
29
|
"eslint-config-prettier": "^10.1.8",
|
|
34
30
|
"eslint-config-xo": "^0.49.0",
|
|
@@ -67,6 +63,10 @@
|
|
|
67
63
|
"@types/node": "^25.0.9",
|
|
68
64
|
"@types/requireindex": "^1.2.4",
|
|
69
65
|
"@types/xo": "^0.39.9",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "8.53.0",
|
|
67
|
+
"@typescript-eslint/parser": "8.53.0",
|
|
68
|
+
"@typescript-eslint/rule-tester": "8.53.0",
|
|
69
|
+
"@typescript-eslint/utils": "8.53.0",
|
|
70
70
|
"bun-types": "latest",
|
|
71
71
|
"eslint": "^9.39.2",
|
|
72
72
|
"eslint-doc-generator": "^3.0.2",
|