eslint-plugin-zod 3.5.3 → 3.5.4
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,6 +1,8 @@
|
|
|
1
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
|
+
const require_track_zod_schema_imports = require("../utils/track-zod-schema-imports.cjs");
|
|
3
|
+
const require_find_parent_schema_matching_condition = require("../utils/find-parent-schema-matching-condition.cjs");
|
|
2
4
|
//#region src/rules/prefer-string-schema-with-trim.ts
|
|
3
|
-
const { zodImportAllowedSource, trackZodSchemaImports } =
|
|
5
|
+
const { zodImportAllowedSource, trackZodSchemaImports } = require_track_zod_schema_imports.createZodSchemaImportTrack("zod");
|
|
4
6
|
const preferStringSchemaWithTrim = require_create_plugin_rule.createZodPluginRule({
|
|
5
7
|
name: "prefer-string-schema-with-trim",
|
|
6
8
|
meta: {
|
|
@@ -21,6 +23,10 @@ const preferStringSchemaWithTrim = require_create_plugin_rule.createZodPluginRul
|
|
|
21
23
|
CallExpression(node) {
|
|
22
24
|
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
23
25
|
if (zodSchemaMeta?.schemaType !== "string") return;
|
|
26
|
+
if (require_find_parent_schema_matching_condition.findParentSchemaMatchingCondition(zodSchemaMeta.node, {
|
|
27
|
+
schemaName: "record",
|
|
28
|
+
condition: (callParent) => callParent.arguments.length > 0 && callParent.arguments[0] === zodSchemaMeta.node
|
|
29
|
+
})) return;
|
|
24
30
|
const methods = collectZodChainMethods(zodSchemaMeta.node);
|
|
25
31
|
if (methods.some((it) => it.name === "trim")) return;
|
|
26
32
|
if (zodSchemaMeta.schemaDecl === "named") {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
2
|
import { createZodSchemaImportTrack } from "../utils/track-zod-schema-imports.mjs";
|
|
3
|
+
import { findParentSchemaMatchingCondition } from "../utils/find-parent-schema-matching-condition.mjs";
|
|
3
4
|
//#region src/rules/prefer-string-schema-with-trim.ts
|
|
4
5
|
const { zodImportAllowedSource, trackZodSchemaImports } = createZodSchemaImportTrack("zod");
|
|
5
6
|
const preferStringSchemaWithTrim = createZodPluginRule({
|
|
@@ -22,6 +23,10 @@ const preferStringSchemaWithTrim = createZodPluginRule({
|
|
|
22
23
|
CallExpression(node) {
|
|
23
24
|
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
24
25
|
if (zodSchemaMeta?.schemaType !== "string") return;
|
|
26
|
+
if (findParentSchemaMatchingCondition(zodSchemaMeta.node, {
|
|
27
|
+
schemaName: "record",
|
|
28
|
+
condition: (callParent) => callParent.arguments.length > 0 && callParent.arguments[0] === zodSchemaMeta.node
|
|
29
|
+
})) return;
|
|
25
30
|
const methods = collectZodChainMethods(zodSchemaMeta.node);
|
|
26
31
|
if (methods.some((it) => it.name === "trim")) return;
|
|
27
32
|
if (zodSchemaMeta.schemaDecl === "named") {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
3
|
+
//#region src/utils/find-parent-schema-matching-condition.ts
|
|
4
|
+
function findParentSchemaMatchingCondition(outermostNode, options) {
|
|
5
|
+
const { schemaName, condition } = options;
|
|
6
|
+
let current = outermostNode;
|
|
7
|
+
while (current.parent) {
|
|
8
|
+
const { parent } = current;
|
|
9
|
+
if (parent.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) {
|
|
10
|
+
const callParent = parent;
|
|
11
|
+
if (callParent.callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) {
|
|
12
|
+
const memberExpr = callParent.callee;
|
|
13
|
+
if ((memberExpr.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier ? memberExpr.property.name : null) === schemaName) return condition(callParent);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (parent.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) {
|
|
17
|
+
current = parent;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
current = parent;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.findParentSchemaMatchingCondition = findParentSchemaMatchingCondition;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
//#region src/utils/find-parent-schema-matching-condition.ts
|
|
3
|
+
function findParentSchemaMatchingCondition(outermostNode, options) {
|
|
4
|
+
const { schemaName, condition } = options;
|
|
5
|
+
let current = outermostNode;
|
|
6
|
+
while (current.parent) {
|
|
7
|
+
const { parent } = current;
|
|
8
|
+
if (parent.type === AST_NODE_TYPES.CallExpression) {
|
|
9
|
+
const callParent = parent;
|
|
10
|
+
if (callParent.callee.type === AST_NODE_TYPES.MemberExpression) {
|
|
11
|
+
const memberExpr = callParent.callee;
|
|
12
|
+
if ((memberExpr.property.type === AST_NODE_TYPES.Identifier ? memberExpr.property.name : null) === schemaName) return condition(callParent);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (parent.type === AST_NODE_TYPES.MemberExpression) {
|
|
16
|
+
current = parent;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
current = parent;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { findParentSchemaMatchingCondition };
|