eslint-plugin-zod-utils 1.0.4 → 1.0.5
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/dist/index.cjs +91 -9
- package/dist/index.js +91 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
37
37
|
"boolean",
|
|
38
38
|
"cidrv4",
|
|
39
39
|
"cidrv6",
|
|
40
|
+
"codec",
|
|
40
41
|
"cuid",
|
|
41
42
|
"cuid2",
|
|
42
43
|
"custom",
|
|
@@ -46,38 +47,65 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
46
47
|
"email",
|
|
47
48
|
"emoji",
|
|
48
49
|
"enum",
|
|
50
|
+
"exactOptional",
|
|
49
51
|
"file",
|
|
52
|
+
"float32",
|
|
53
|
+
"float64",
|
|
50
54
|
"function",
|
|
51
55
|
"fromJSONSchema",
|
|
56
|
+
"guid",
|
|
57
|
+
"hash",
|
|
58
|
+
"hex",
|
|
59
|
+
"hostname",
|
|
60
|
+
"httpUrl",
|
|
52
61
|
"instanceof",
|
|
62
|
+
"int",
|
|
63
|
+
"int32",
|
|
64
|
+
"int64",
|
|
53
65
|
"intersection",
|
|
66
|
+
"invertCodec",
|
|
54
67
|
"ipv4",
|
|
55
68
|
"ipv6",
|
|
69
|
+
"json",
|
|
56
70
|
"jwt",
|
|
71
|
+
"keyof",
|
|
57
72
|
"ksuid",
|
|
58
73
|
"lazy",
|
|
59
74
|
"literal",
|
|
60
75
|
"looseObject",
|
|
76
|
+
"looseRecord",
|
|
77
|
+
"mac",
|
|
61
78
|
"map",
|
|
62
79
|
"nan",
|
|
63
80
|
"nanoid",
|
|
64
81
|
"nativeEnum",
|
|
65
82
|
"never",
|
|
83
|
+
"nonoptional",
|
|
66
84
|
"null",
|
|
67
85
|
"nullable",
|
|
86
|
+
"nullish",
|
|
68
87
|
"number",
|
|
69
88
|
"object",
|
|
70
89
|
"optional",
|
|
90
|
+
"partialRecord",
|
|
91
|
+
"pipe",
|
|
92
|
+
"prefault",
|
|
71
93
|
"preprocess",
|
|
72
94
|
"promise",
|
|
95
|
+
"readonly",
|
|
73
96
|
"record",
|
|
74
97
|
"set",
|
|
75
98
|
"string",
|
|
99
|
+
"stringFormat",
|
|
76
100
|
"stringbool",
|
|
77
101
|
"strictObject",
|
|
102
|
+
"success",
|
|
78
103
|
"symbol",
|
|
79
104
|
"templateLiteral",
|
|
105
|
+
"transform",
|
|
80
106
|
"tuple",
|
|
107
|
+
"uint32",
|
|
108
|
+
"uint64",
|
|
81
109
|
"undefined",
|
|
82
110
|
"union",
|
|
83
111
|
"unknown",
|
|
@@ -88,8 +116,19 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
88
116
|
"uuidv6",
|
|
89
117
|
"uuidv7",
|
|
90
118
|
"void",
|
|
119
|
+
"xor",
|
|
91
120
|
"xid"
|
|
92
121
|
]);
|
|
122
|
+
var ZOD_DIRECT_COMBINATOR_IMPORTS = /* @__PURE__ */ new Set([
|
|
123
|
+
"catchall",
|
|
124
|
+
"extend",
|
|
125
|
+
"merge",
|
|
126
|
+
"omit",
|
|
127
|
+
"partial",
|
|
128
|
+
"pick",
|
|
129
|
+
"required",
|
|
130
|
+
"safeExtend"
|
|
131
|
+
]);
|
|
93
132
|
var ZOD_NAMESPACE_IMPORTS = /* @__PURE__ */ new Set(["z", "coerce", "iso"]);
|
|
94
133
|
var ZOD_ISO_FACTORY_IMPORTS = /* @__PURE__ */ new Set(["date", "datetime", "duration", "time"]);
|
|
95
134
|
var ZOD_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -134,6 +173,15 @@ function findVariable(scope, name) {
|
|
|
134
173
|
}
|
|
135
174
|
return null;
|
|
136
175
|
}
|
|
176
|
+
function getStaticMemberName(node) {
|
|
177
|
+
if (!node.computed && node.property.type === "Identifier") {
|
|
178
|
+
return node.property.name;
|
|
179
|
+
}
|
|
180
|
+
if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string") {
|
|
181
|
+
return node.property.value;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
137
185
|
function getRootIdentifier(node) {
|
|
138
186
|
if (!node) {
|
|
139
187
|
return null;
|
|
@@ -165,8 +213,8 @@ function getRootMethodName(node) {
|
|
|
165
213
|
continue;
|
|
166
214
|
}
|
|
167
215
|
if (current.type === "MemberExpression") {
|
|
168
|
-
if (current.object.type === "Identifier"
|
|
169
|
-
rootMethodName = current
|
|
216
|
+
if (current.object.type === "Identifier") {
|
|
217
|
+
rootMethodName = getStaticMemberName(current);
|
|
170
218
|
}
|
|
171
219
|
current = current.object;
|
|
172
220
|
continue;
|
|
@@ -191,10 +239,11 @@ function getMemberPathFromRoot(node) {
|
|
|
191
239
|
continue;
|
|
192
240
|
}
|
|
193
241
|
if (current.type === "MemberExpression") {
|
|
194
|
-
|
|
242
|
+
const memberName = getStaticMemberName(current);
|
|
243
|
+
if (memberName === null) {
|
|
195
244
|
return null;
|
|
196
245
|
}
|
|
197
|
-
memberPath.unshift(
|
|
246
|
+
memberPath.unshift(memberName);
|
|
198
247
|
current = current.object;
|
|
199
248
|
continue;
|
|
200
249
|
}
|
|
@@ -203,8 +252,8 @@ function getMemberPathFromRoot(node) {
|
|
|
203
252
|
}
|
|
204
253
|
function getCallMethodName(node) {
|
|
205
254
|
const { callee } = node;
|
|
206
|
-
if (callee.type === "MemberExpression" &&
|
|
207
|
-
return callee
|
|
255
|
+
if (callee.type === "MemberExpression" && getStaticMemberName(callee) !== null) {
|
|
256
|
+
return getStaticMemberName(callee);
|
|
208
257
|
}
|
|
209
258
|
return null;
|
|
210
259
|
}
|
|
@@ -229,7 +278,7 @@ function getZodImportKind(node) {
|
|
|
229
278
|
if (ZOD_NAMESPACE_IMPORTS.has(importedName)) {
|
|
230
279
|
return { importedName, type: "namespace" };
|
|
231
280
|
}
|
|
232
|
-
if (ZOD_FACTORY_IMPORTS.has(importedName)) {
|
|
281
|
+
if (ZOD_FACTORY_IMPORTS.has(importedName) || ZOD_DIRECT_COMBINATOR_IMPORTS.has(importedName)) {
|
|
233
282
|
return { type: "factory" };
|
|
234
283
|
}
|
|
235
284
|
return null;
|
|
@@ -347,6 +396,37 @@ var noInlineZodSchema = import_utils.ESLintUtils.RuleCreator(
|
|
|
347
396
|
function isSchemaCreationCall(node) {
|
|
348
397
|
return isZodSchemaCall(node) || isTypedZodSchemaCombinatorCall(node);
|
|
349
398
|
}
|
|
399
|
+
function isInModuleInitializationPath(node) {
|
|
400
|
+
let current = node;
|
|
401
|
+
while (current) {
|
|
402
|
+
if (current.type === "Program") {
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
if (current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
if (current.type === "PropertyDefinition" && !current.static) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
current = current.parent;
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
function isFunctionExecutedDuringModuleInitialization(node) {
|
|
416
|
+
if (node.type === "FunctionDeclaration") {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
const parent = node.parent;
|
|
420
|
+
if (parent?.type === "CallExpression") {
|
|
421
|
+
if (parent.callee === node) {
|
|
422
|
+
return isInModuleInitializationPath(parent);
|
|
423
|
+
}
|
|
424
|
+
if (parent.arguments.includes(node)) {
|
|
425
|
+
return isInModuleInitializationPath(parent);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
350
430
|
function hasSchemaCreationCallAncestor(node) {
|
|
351
431
|
let current = node.parent;
|
|
352
432
|
while (current) {
|
|
@@ -361,7 +441,9 @@ var noInlineZodSchema = import_utils.ESLintUtils.RuleCreator(
|
|
|
361
441
|
let current = node.parent;
|
|
362
442
|
while (current) {
|
|
363
443
|
if (current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") {
|
|
364
|
-
|
|
444
|
+
if (!isFunctionExecutedDuringModuleInitialization(current)) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
365
447
|
}
|
|
366
448
|
if (current.type === "PropertyDefinition" && !current.static) {
|
|
367
449
|
return true;
|
|
@@ -398,7 +480,7 @@ var rules = {
|
|
|
398
480
|
var plugin = {
|
|
399
481
|
meta: {
|
|
400
482
|
name: "eslint-plugin-zod-utils",
|
|
401
|
-
version: "1.0.
|
|
483
|
+
version: "1.0.5"
|
|
402
484
|
},
|
|
403
485
|
rules,
|
|
404
486
|
configs: {}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
9
9
|
"boolean",
|
|
10
10
|
"cidrv4",
|
|
11
11
|
"cidrv6",
|
|
12
|
+
"codec",
|
|
12
13
|
"cuid",
|
|
13
14
|
"cuid2",
|
|
14
15
|
"custom",
|
|
@@ -18,38 +19,65 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
18
19
|
"email",
|
|
19
20
|
"emoji",
|
|
20
21
|
"enum",
|
|
22
|
+
"exactOptional",
|
|
21
23
|
"file",
|
|
24
|
+
"float32",
|
|
25
|
+
"float64",
|
|
22
26
|
"function",
|
|
23
27
|
"fromJSONSchema",
|
|
28
|
+
"guid",
|
|
29
|
+
"hash",
|
|
30
|
+
"hex",
|
|
31
|
+
"hostname",
|
|
32
|
+
"httpUrl",
|
|
24
33
|
"instanceof",
|
|
34
|
+
"int",
|
|
35
|
+
"int32",
|
|
36
|
+
"int64",
|
|
25
37
|
"intersection",
|
|
38
|
+
"invertCodec",
|
|
26
39
|
"ipv4",
|
|
27
40
|
"ipv6",
|
|
41
|
+
"json",
|
|
28
42
|
"jwt",
|
|
43
|
+
"keyof",
|
|
29
44
|
"ksuid",
|
|
30
45
|
"lazy",
|
|
31
46
|
"literal",
|
|
32
47
|
"looseObject",
|
|
48
|
+
"looseRecord",
|
|
49
|
+
"mac",
|
|
33
50
|
"map",
|
|
34
51
|
"nan",
|
|
35
52
|
"nanoid",
|
|
36
53
|
"nativeEnum",
|
|
37
54
|
"never",
|
|
55
|
+
"nonoptional",
|
|
38
56
|
"null",
|
|
39
57
|
"nullable",
|
|
58
|
+
"nullish",
|
|
40
59
|
"number",
|
|
41
60
|
"object",
|
|
42
61
|
"optional",
|
|
62
|
+
"partialRecord",
|
|
63
|
+
"pipe",
|
|
64
|
+
"prefault",
|
|
43
65
|
"preprocess",
|
|
44
66
|
"promise",
|
|
67
|
+
"readonly",
|
|
45
68
|
"record",
|
|
46
69
|
"set",
|
|
47
70
|
"string",
|
|
71
|
+
"stringFormat",
|
|
48
72
|
"stringbool",
|
|
49
73
|
"strictObject",
|
|
74
|
+
"success",
|
|
50
75
|
"symbol",
|
|
51
76
|
"templateLiteral",
|
|
77
|
+
"transform",
|
|
52
78
|
"tuple",
|
|
79
|
+
"uint32",
|
|
80
|
+
"uint64",
|
|
53
81
|
"undefined",
|
|
54
82
|
"union",
|
|
55
83
|
"unknown",
|
|
@@ -60,8 +88,19 @@ var ZOD_FACTORY_IMPORTS = /* @__PURE__ */ new Set([
|
|
|
60
88
|
"uuidv6",
|
|
61
89
|
"uuidv7",
|
|
62
90
|
"void",
|
|
91
|
+
"xor",
|
|
63
92
|
"xid"
|
|
64
93
|
]);
|
|
94
|
+
var ZOD_DIRECT_COMBINATOR_IMPORTS = /* @__PURE__ */ new Set([
|
|
95
|
+
"catchall",
|
|
96
|
+
"extend",
|
|
97
|
+
"merge",
|
|
98
|
+
"omit",
|
|
99
|
+
"partial",
|
|
100
|
+
"pick",
|
|
101
|
+
"required",
|
|
102
|
+
"safeExtend"
|
|
103
|
+
]);
|
|
65
104
|
var ZOD_NAMESPACE_IMPORTS = /* @__PURE__ */ new Set(["z", "coerce", "iso"]);
|
|
66
105
|
var ZOD_ISO_FACTORY_IMPORTS = /* @__PURE__ */ new Set(["date", "datetime", "duration", "time"]);
|
|
67
106
|
var ZOD_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -106,6 +145,15 @@ function findVariable(scope, name) {
|
|
|
106
145
|
}
|
|
107
146
|
return null;
|
|
108
147
|
}
|
|
148
|
+
function getStaticMemberName(node) {
|
|
149
|
+
if (!node.computed && node.property.type === "Identifier") {
|
|
150
|
+
return node.property.name;
|
|
151
|
+
}
|
|
152
|
+
if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string") {
|
|
153
|
+
return node.property.value;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
109
157
|
function getRootIdentifier(node) {
|
|
110
158
|
if (!node) {
|
|
111
159
|
return null;
|
|
@@ -137,8 +185,8 @@ function getRootMethodName(node) {
|
|
|
137
185
|
continue;
|
|
138
186
|
}
|
|
139
187
|
if (current.type === "MemberExpression") {
|
|
140
|
-
if (current.object.type === "Identifier"
|
|
141
|
-
rootMethodName = current
|
|
188
|
+
if (current.object.type === "Identifier") {
|
|
189
|
+
rootMethodName = getStaticMemberName(current);
|
|
142
190
|
}
|
|
143
191
|
current = current.object;
|
|
144
192
|
continue;
|
|
@@ -163,10 +211,11 @@ function getMemberPathFromRoot(node) {
|
|
|
163
211
|
continue;
|
|
164
212
|
}
|
|
165
213
|
if (current.type === "MemberExpression") {
|
|
166
|
-
|
|
214
|
+
const memberName = getStaticMemberName(current);
|
|
215
|
+
if (memberName === null) {
|
|
167
216
|
return null;
|
|
168
217
|
}
|
|
169
|
-
memberPath.unshift(
|
|
218
|
+
memberPath.unshift(memberName);
|
|
170
219
|
current = current.object;
|
|
171
220
|
continue;
|
|
172
221
|
}
|
|
@@ -175,8 +224,8 @@ function getMemberPathFromRoot(node) {
|
|
|
175
224
|
}
|
|
176
225
|
function getCallMethodName(node) {
|
|
177
226
|
const { callee } = node;
|
|
178
|
-
if (callee.type === "MemberExpression" &&
|
|
179
|
-
return callee
|
|
227
|
+
if (callee.type === "MemberExpression" && getStaticMemberName(callee) !== null) {
|
|
228
|
+
return getStaticMemberName(callee);
|
|
180
229
|
}
|
|
181
230
|
return null;
|
|
182
231
|
}
|
|
@@ -201,7 +250,7 @@ function getZodImportKind(node) {
|
|
|
201
250
|
if (ZOD_NAMESPACE_IMPORTS.has(importedName)) {
|
|
202
251
|
return { importedName, type: "namespace" };
|
|
203
252
|
}
|
|
204
|
-
if (ZOD_FACTORY_IMPORTS.has(importedName)) {
|
|
253
|
+
if (ZOD_FACTORY_IMPORTS.has(importedName) || ZOD_DIRECT_COMBINATOR_IMPORTS.has(importedName)) {
|
|
205
254
|
return { type: "factory" };
|
|
206
255
|
}
|
|
207
256
|
return null;
|
|
@@ -319,6 +368,37 @@ var noInlineZodSchema = ESLintUtils.RuleCreator(
|
|
|
319
368
|
function isSchemaCreationCall(node) {
|
|
320
369
|
return isZodSchemaCall(node) || isTypedZodSchemaCombinatorCall(node);
|
|
321
370
|
}
|
|
371
|
+
function isInModuleInitializationPath(node) {
|
|
372
|
+
let current = node;
|
|
373
|
+
while (current) {
|
|
374
|
+
if (current.type === "Program") {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
if (current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
if (current.type === "PropertyDefinition" && !current.static) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
current = current.parent;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
function isFunctionExecutedDuringModuleInitialization(node) {
|
|
388
|
+
if (node.type === "FunctionDeclaration") {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
const parent = node.parent;
|
|
392
|
+
if (parent?.type === "CallExpression") {
|
|
393
|
+
if (parent.callee === node) {
|
|
394
|
+
return isInModuleInitializationPath(parent);
|
|
395
|
+
}
|
|
396
|
+
if (parent.arguments.includes(node)) {
|
|
397
|
+
return isInModuleInitializationPath(parent);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
322
402
|
function hasSchemaCreationCallAncestor(node) {
|
|
323
403
|
let current = node.parent;
|
|
324
404
|
while (current) {
|
|
@@ -333,7 +413,9 @@ var noInlineZodSchema = ESLintUtils.RuleCreator(
|
|
|
333
413
|
let current = node.parent;
|
|
334
414
|
while (current) {
|
|
335
415
|
if (current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") {
|
|
336
|
-
|
|
416
|
+
if (!isFunctionExecutedDuringModuleInitialization(current)) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
337
419
|
}
|
|
338
420
|
if (current.type === "PropertyDefinition" && !current.static) {
|
|
339
421
|
return true;
|
|
@@ -370,7 +452,7 @@ var rules = {
|
|
|
370
452
|
var plugin = {
|
|
371
453
|
meta: {
|
|
372
454
|
name: "eslint-plugin-zod-utils",
|
|
373
|
-
version: "1.0.
|
|
455
|
+
version: "1.0.5"
|
|
374
456
|
},
|
|
375
457
|
rules,
|
|
376
458
|
configs: {}
|