eslint-plugin-zod 4.5.0 → 4.5.2
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/meta.cjs +0 -1
- package/dist/rules/array-style.cjs +0 -1
- package/dist/rules/consistent-import-source.cjs +2 -26
- package/dist/rules/consistent-import-source.mjs +2 -25
- package/dist/rules/consistent-import.cjs +3 -80
- package/dist/rules/consistent-import.mjs +3 -79
- package/dist/rules/consistent-object-schema-type.cjs +2 -41
- package/dist/rules/consistent-object-schema-type.mjs +3 -41
- package/dist/rules/consistent-schema-output-type-style.cjs +3 -42
- package/dist/rules/consistent-schema-output-type-style.mjs +4 -42
- package/dist/rules/consistent-schema-var-name.cjs +2 -26
- package/dist/rules/consistent-schema-var-name.mjs +3 -26
- package/dist/rules/no-any-schema.cjs +2 -41
- package/dist/rules/no-any-schema.mjs +3 -41
- package/dist/rules/no-empty-custom-schema.cjs +2 -18
- package/dist/rules/no-empty-custom-schema.mjs +3 -18
- package/dist/rules/no-native-enum.cjs +0 -1
- package/dist/rules/no-number-schema-with-finite.cjs +0 -1
- package/dist/rules/no-number-schema-with-int.cjs +0 -1
- package/dist/rules/no-number-schema-with-is-finite.cjs +0 -1
- package/dist/rules/no-number-schema-with-is-int.cjs +0 -1
- package/dist/rules/no-number-schema-with-safe.cjs +0 -1
- package/dist/rules/no-number-schema-with-step.cjs +0 -1
- package/dist/rules/no-optional-and-default-together.cjs +0 -1
- package/dist/rules/no-promise-schema.cjs +0 -1
- package/dist/rules/no-schema-with-is-nullable.cjs +0 -1
- package/dist/rules/no-schema-with-is-optional.cjs +0 -1
- package/dist/rules/no-string-schema-with-uuid.cjs +0 -1
- package/dist/rules/no-throw-in-refine.cjs +2 -52
- package/dist/rules/no-throw-in-refine.mjs +3 -52
- package/dist/rules/no-transform-in-record-key.cjs +7 -32
- package/dist/rules/no-transform-in-record-key.mjs +8 -32
- package/dist/rules/no-unknown-schema.cjs +2 -14
- package/dist/rules/no-unknown-schema.mjs +3 -14
- package/dist/rules/prefer-enum-over-literal-union.cjs +2 -2
- package/dist/rules/prefer-enum-over-literal-union.mjs +2 -1
- package/dist/rules/prefer-loose-object.cjs +0 -1
- package/dist/rules/prefer-meta-last.cjs +0 -1
- package/dist/rules/prefer-meta.cjs +0 -1
- package/dist/rules/prefer-strict-object.cjs +0 -1
- package/dist/rules/prefer-string-schema-with-trim.cjs +0 -1
- package/dist/rules/prefer-top-level-string-formats.cjs +0 -1
- package/dist/rules/prefer-trim-before-string-length-checks.cjs +0 -1
- package/dist/rules/require-brand-type-parameter.cjs +2 -28
- package/dist/rules/require-brand-type-parameter.mjs +3 -28
- package/dist/rules/require-error-message.cjs +2 -62
- package/dist/rules/require-error-message.mjs +3 -62
- package/dist/rules/schema-error-property-style.cjs +2 -59
- package/dist/rules/schema-error-property-style.mjs +3 -58
- package/dist/utils/create-plugin-rule.cjs +0 -1
- package/package.json +2 -4
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
-
let
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_any_schema = require("@eslint-zod/utils/rule-builders/no-any-schema");
|
|
5
4
|
//#region src/rules/no-any-schema.ts
|
|
6
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
7
5
|
const noAnySchema = require_create_plugin_rule.createZodPluginRule({
|
|
8
6
|
name: "no-any-schema",
|
|
9
7
|
meta: {
|
|
@@ -17,44 +15,7 @@ const noAnySchema = require_create_plugin_rule.createZodPluginRule({
|
|
|
17
15
|
schema: []
|
|
18
16
|
},
|
|
19
17
|
defaultOptions: [],
|
|
20
|
-
create(
|
|
21
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
22
|
-
return {
|
|
23
|
-
ImportDeclaration: importDeclarationListener,
|
|
24
|
-
CallExpression(node) {
|
|
25
|
-
if (detectZodSchemaRootNode(node)?.schemaType !== "any") return;
|
|
26
|
-
const { callee } = node;
|
|
27
|
-
if (callee.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
messageId: "noZAny"
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (callee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression) {
|
|
35
|
-
const [{ node: schemaMethod }] = collectZodChainMethods(node);
|
|
36
|
-
const schemaMethodCallee = schemaMethod.callee;
|
|
37
|
-
if (schemaMethodCallee.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && schemaMethodCallee.property.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier) {
|
|
38
|
-
context.report({
|
|
39
|
-
node,
|
|
40
|
-
messageId: "noZAny",
|
|
41
|
-
suggest: [{
|
|
42
|
-
messageId: "useUnknown",
|
|
43
|
-
fix(fixer) {
|
|
44
|
-
return fixer.replaceText(schemaMethodCallee.property, "unknown");
|
|
45
|
-
}
|
|
46
|
-
}]
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
context.report({
|
|
51
|
-
node,
|
|
52
|
-
messageId: "noZAny"
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
18
|
+
create: (0, _eslint_zod_utils_rule_builders_no_any_schema.buildNoAnySchemaCreate)(_eslint_zod_utils.zodImportScope)
|
|
58
19
|
});
|
|
59
20
|
//#endregion
|
|
60
21
|
exports.noAnySchema = noAnySchema;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoAnySchemaCreate } from "@eslint-zod/utils/rule-builders/no-any-schema";
|
|
4
4
|
//#region src/rules/no-any-schema.ts
|
|
5
|
-
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
6
5
|
const noAnySchema = createZodPluginRule({
|
|
7
6
|
name: "no-any-schema",
|
|
8
7
|
meta: {
|
|
@@ -16,44 +15,7 @@ const noAnySchema = createZodPluginRule({
|
|
|
16
15
|
schema: []
|
|
17
16
|
},
|
|
18
17
|
defaultOptions: [],
|
|
19
|
-
create(
|
|
20
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
21
|
-
return {
|
|
22
|
-
ImportDeclaration: importDeclarationListener,
|
|
23
|
-
CallExpression(node) {
|
|
24
|
-
if (detectZodSchemaRootNode(node)?.schemaType !== "any") return;
|
|
25
|
-
const { callee } = node;
|
|
26
|
-
if (callee.type === AST_NODE_TYPES.Identifier) {
|
|
27
|
-
context.report({
|
|
28
|
-
node,
|
|
29
|
-
messageId: "noZAny"
|
|
30
|
-
});
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (callee.type === AST_NODE_TYPES.MemberExpression) {
|
|
34
|
-
const [{ node: schemaMethod }] = collectZodChainMethods(node);
|
|
35
|
-
const schemaMethodCallee = schemaMethod.callee;
|
|
36
|
-
if (schemaMethodCallee.type === AST_NODE_TYPES.MemberExpression && schemaMethodCallee.property.type === AST_NODE_TYPES.Identifier) {
|
|
37
|
-
context.report({
|
|
38
|
-
node,
|
|
39
|
-
messageId: "noZAny",
|
|
40
|
-
suggest: [{
|
|
41
|
-
messageId: "useUnknown",
|
|
42
|
-
fix(fixer) {
|
|
43
|
-
return fixer.replaceText(schemaMethodCallee.property, "unknown");
|
|
44
|
-
}
|
|
45
|
-
}]
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
context.report({
|
|
50
|
-
node,
|
|
51
|
-
messageId: "noZAny"
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
18
|
+
create: buildNoAnySchemaCreate(zodImportScope)
|
|
57
19
|
});
|
|
58
20
|
//#endregion
|
|
59
21
|
export { noAnySchema };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_empty_custom_schema = require("@eslint-zod/utils/rule-builders/no-empty-custom-schema");
|
|
4
4
|
//#region src/rules/no-empty-custom-schema.ts
|
|
5
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
6
5
|
const noEmptyCustomSchema = require_create_plugin_rule.createZodPluginRule({
|
|
7
6
|
name: "no-empty-custom-schema",
|
|
8
7
|
meta: {
|
|
@@ -13,22 +12,7 @@ const noEmptyCustomSchema = require_create_plugin_rule.createZodPluginRule({
|
|
|
13
12
|
schema: []
|
|
14
13
|
},
|
|
15
14
|
defaultOptions: [],
|
|
16
|
-
create(
|
|
17
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
18
|
-
return {
|
|
19
|
-
ImportDeclaration: importDeclarationListener,
|
|
20
|
-
CallExpression(node) {
|
|
21
|
-
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
22
|
-
if (!zodSchemaMeta) return;
|
|
23
|
-
if (zodSchemaMeta.schemaType !== "custom") return;
|
|
24
|
-
const customCallNode = collectZodChainMethods(node).find((method) => method.name === "custom")?.node;
|
|
25
|
-
if (customCallNode?.arguments.length === 0) context.report({
|
|
26
|
-
node: customCallNode,
|
|
27
|
-
messageId: "noEmptyCustomSchema"
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_builders_no_empty_custom_schema.buildNoEmptyCustomSchemaCreate)(_eslint_zod_utils.zodImportScope)
|
|
32
16
|
});
|
|
33
17
|
//#endregion
|
|
34
18
|
exports.noEmptyCustomSchema = noEmptyCustomSchema;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoEmptyCustomSchemaCreate } from "@eslint-zod/utils/rule-builders/no-empty-custom-schema";
|
|
3
4
|
//#region src/rules/no-empty-custom-schema.ts
|
|
4
|
-
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
5
5
|
const noEmptyCustomSchema = createZodPluginRule({
|
|
6
6
|
name: "no-empty-custom-schema",
|
|
7
7
|
meta: {
|
|
@@ -12,22 +12,7 @@ const noEmptyCustomSchema = createZodPluginRule({
|
|
|
12
12
|
schema: []
|
|
13
13
|
},
|
|
14
14
|
defaultOptions: [],
|
|
15
|
-
create(
|
|
16
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
17
|
-
return {
|
|
18
|
-
ImportDeclaration: importDeclarationListener,
|
|
19
|
-
CallExpression(node) {
|
|
20
|
-
const zodSchemaMeta = detectZodSchemaRootNode(node);
|
|
21
|
-
if (!zodSchemaMeta) return;
|
|
22
|
-
if (zodSchemaMeta.schemaType !== "custom") return;
|
|
23
|
-
const customCallNode = collectZodChainMethods(node).find((method) => method.name === "custom")?.node;
|
|
24
|
-
if (customCallNode?.arguments.length === 0) context.report({
|
|
25
|
-
node: customCallNode,
|
|
26
|
-
messageId: "noEmptyCustomSchema"
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
15
|
+
create: buildNoEmptyCustomSchemaCreate(zodImportScope)
|
|
31
16
|
});
|
|
32
17
|
//#endregion
|
|
33
18
|
export { noEmptyCustomSchema };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
-
let
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_throw_in_refine = require("@eslint-zod/utils/rule-builders/no-throw-in-refine");
|
|
5
4
|
//#region src/rules/no-throw-in-refine.ts
|
|
6
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
7
5
|
const noThrowInRefine = require_create_plugin_rule.createZodPluginRule({
|
|
8
6
|
name: "no-throw-in-refine",
|
|
9
7
|
meta: {
|
|
@@ -13,55 +11,7 @@ const noThrowInRefine = require_create_plugin_rule.createZodPluginRule({
|
|
|
13
11
|
schema: []
|
|
14
12
|
},
|
|
15
13
|
defaultOptions: [],
|
|
16
|
-
create(
|
|
17
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
18
|
-
function checkNode(node) {
|
|
19
|
-
if (!node) return;
|
|
20
|
-
switch (node.type) {
|
|
21
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ThrowStatement:
|
|
22
|
-
context.report({
|
|
23
|
-
node,
|
|
24
|
-
messageId: "noThrowInRefine"
|
|
25
|
-
});
|
|
26
|
-
break;
|
|
27
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement:
|
|
28
|
-
node.body.forEach(checkNode);
|
|
29
|
-
break;
|
|
30
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.IfStatement:
|
|
31
|
-
checkNode(node.consequent);
|
|
32
|
-
if (node.alternate) checkNode(node.alternate);
|
|
33
|
-
break;
|
|
34
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForStatement:
|
|
35
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForInStatement:
|
|
36
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForOfStatement:
|
|
37
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.WhileStatement:
|
|
38
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.DoWhileStatement:
|
|
39
|
-
checkNode(node.body);
|
|
40
|
-
break;
|
|
41
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.TryStatement:
|
|
42
|
-
checkNode(node.block);
|
|
43
|
-
if (node.handler) checkNode(node.handler.body);
|
|
44
|
-
if (node.finalizer) checkNode(node.finalizer);
|
|
45
|
-
break;
|
|
46
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression:
|
|
47
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
48
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.FunctionDeclaration: return;
|
|
49
|
-
default:
|
|
50
|
-
if ("body" in node && Array.isArray(node.body)) node.body.forEach(checkNode);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
ImportDeclaration: importDeclarationListener,
|
|
56
|
-
CallExpression(node) {
|
|
57
|
-
if (!detectZodSchemaRootNode(node)) return;
|
|
58
|
-
const refineMethod = collectZodChainMethods(node).find((it) => it.name === "refine");
|
|
59
|
-
if (!refineMethod) return;
|
|
60
|
-
const [callback] = refineMethod.node.arguments;
|
|
61
|
-
if (callback.type === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression || callback.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression) checkNode(callback.body);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_throw_in_refine.buildNoThrowInRefineCreate)(_eslint_zod_utils.zodImportScope)
|
|
65
15
|
});
|
|
66
16
|
//#endregion
|
|
67
17
|
exports.noThrowInRefine = noThrowInRefine;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoThrowInRefineCreate } from "@eslint-zod/utils/rule-builders/no-throw-in-refine";
|
|
4
4
|
//#region src/rules/no-throw-in-refine.ts
|
|
5
|
-
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
6
5
|
const noThrowInRefine = createZodPluginRule({
|
|
7
6
|
name: "no-throw-in-refine",
|
|
8
7
|
meta: {
|
|
@@ -12,55 +11,7 @@ const noThrowInRefine = createZodPluginRule({
|
|
|
12
11
|
schema: []
|
|
13
12
|
},
|
|
14
13
|
defaultOptions: [],
|
|
15
|
-
create(
|
|
16
|
-
const { importDeclarationListener, detectZodSchemaRootNode, collectZodChainMethods } = trackZodSchemaImports();
|
|
17
|
-
function checkNode(node) {
|
|
18
|
-
if (!node) return;
|
|
19
|
-
switch (node.type) {
|
|
20
|
-
case AST_NODE_TYPES.ThrowStatement:
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "noThrowInRefine"
|
|
24
|
-
});
|
|
25
|
-
break;
|
|
26
|
-
case AST_NODE_TYPES.BlockStatement:
|
|
27
|
-
node.body.forEach(checkNode);
|
|
28
|
-
break;
|
|
29
|
-
case AST_NODE_TYPES.IfStatement:
|
|
30
|
-
checkNode(node.consequent);
|
|
31
|
-
if (node.alternate) checkNode(node.alternate);
|
|
32
|
-
break;
|
|
33
|
-
case AST_NODE_TYPES.ForStatement:
|
|
34
|
-
case AST_NODE_TYPES.ForInStatement:
|
|
35
|
-
case AST_NODE_TYPES.ForOfStatement:
|
|
36
|
-
case AST_NODE_TYPES.WhileStatement:
|
|
37
|
-
case AST_NODE_TYPES.DoWhileStatement:
|
|
38
|
-
checkNode(node.body);
|
|
39
|
-
break;
|
|
40
|
-
case AST_NODE_TYPES.TryStatement:
|
|
41
|
-
checkNode(node.block);
|
|
42
|
-
if (node.handler) checkNode(node.handler.body);
|
|
43
|
-
if (node.finalizer) checkNode(node.finalizer);
|
|
44
|
-
break;
|
|
45
|
-
case AST_NODE_TYPES.FunctionExpression:
|
|
46
|
-
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
47
|
-
case AST_NODE_TYPES.FunctionDeclaration: return;
|
|
48
|
-
default:
|
|
49
|
-
if ("body" in node && Array.isArray(node.body)) node.body.forEach(checkNode);
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
ImportDeclaration: importDeclarationListener,
|
|
55
|
-
CallExpression(node) {
|
|
56
|
-
if (!detectZodSchemaRootNode(node)) return;
|
|
57
|
-
const refineMethod = collectZodChainMethods(node).find((it) => it.name === "refine");
|
|
58
|
-
if (!refineMethod) return;
|
|
59
|
-
const [callback] = refineMethod.node.arguments;
|
|
60
|
-
if (callback.type === AST_NODE_TYPES.ArrowFunctionExpression || callback.type === AST_NODE_TYPES.FunctionExpression) checkNode(callback.body);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
14
|
+
create: buildNoThrowInRefineCreate(zodImportScope)
|
|
64
15
|
});
|
|
65
16
|
//#endregion
|
|
66
17
|
export { noThrowInRefine };
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
3
|
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
4
|
+
let _eslint_zod_utils_rule_builders_no_transform_in_record_key = require("@eslint-zod/utils/rule-builders/no-transform-in-record-key");
|
|
5
5
|
//#region src/rules/no-transform-in-record-key.ts
|
|
6
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
7
|
-
/**
|
|
8
|
-
* Methods that mutate/transform the value and should not be used in z.record() key schemas
|
|
9
|
-
*/
|
|
10
6
|
const TRANSFORM_METHODS = [
|
|
7
|
+
..._eslint_zod_utils.ZOD_MUTATING_CHECK_NAMES,
|
|
11
8
|
"transform",
|
|
12
|
-
"map"
|
|
13
|
-
"trim",
|
|
14
|
-
"toLowerCase",
|
|
15
|
-
"toUpperCase"
|
|
9
|
+
"map"
|
|
16
10
|
];
|
|
17
11
|
const noTransformInRecordKey = require_create_plugin_rule.createZodPluginRule({
|
|
18
12
|
name: "no-transform-in-record-key",
|
|
@@ -23,29 +17,10 @@ const noTransformInRecordKey = require_create_plugin_rule.createZodPluginRule({
|
|
|
23
17
|
schema: []
|
|
24
18
|
},
|
|
25
19
|
defaultOptions: [],
|
|
26
|
-
create(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
function hasTransformMethods(schema) {
|
|
32
|
-
if (schema.type === _typescript_eslint_utils.AST_NODE_TYPES.SpreadElement) return false;
|
|
33
|
-
if (schema.type === _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return collectZodChainMethods(schema).some((method) => TRANSFORM_METHODS.includes(method.name));
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
ImportDeclaration: importDeclarationListener,
|
|
38
|
-
CallExpression(node) {
|
|
39
|
-
if (detectZodSchemaRootNode(node)?.schemaType !== "record") return;
|
|
40
|
-
const keySchemaArg = node.arguments.at(0);
|
|
41
|
-
if (!keySchemaArg) return;
|
|
42
|
-
if (hasTransformMethods(keySchemaArg)) context.report({
|
|
43
|
-
node: keySchemaArg,
|
|
44
|
-
messageId: "noTransformInRecordKey"
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
20
|
+
create: (0, _eslint_zod_utils_rule_builders_no_transform_in_record_key.buildNoTransformInRecordKeyCreate)(_eslint_zod_utils.zodImportScope, { findTransformNode(keySchema, { collectZodChainMethods }) {
|
|
21
|
+
if (keySchema.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return null;
|
|
22
|
+
return collectZodChainMethods(keySchema).some((method) => TRANSFORM_METHODS.includes(method.name)) ? keySchema : null;
|
|
23
|
+
} })
|
|
49
24
|
});
|
|
50
25
|
//#endregion
|
|
51
26
|
exports.noTransformInRecordKey = noTransformInRecordKey;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ZOD_MUTATING_CHECK_NAMES, zodImportScope } from "@eslint-zod/utils";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
import { buildNoTransformInRecordKeyCreate } from "@eslint-zod/utils/rule-builders/no-transform-in-record-key";
|
|
4
5
|
//#region src/rules/no-transform-in-record-key.ts
|
|
5
|
-
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
6
|
-
/**
|
|
7
|
-
* Methods that mutate/transform the value and should not be used in z.record() key schemas
|
|
8
|
-
*/
|
|
9
6
|
const TRANSFORM_METHODS = [
|
|
7
|
+
...ZOD_MUTATING_CHECK_NAMES,
|
|
10
8
|
"transform",
|
|
11
|
-
"map"
|
|
12
|
-
"trim",
|
|
13
|
-
"toLowerCase",
|
|
14
|
-
"toUpperCase"
|
|
9
|
+
"map"
|
|
15
10
|
];
|
|
16
11
|
const noTransformInRecordKey = createZodPluginRule({
|
|
17
12
|
name: "no-transform-in-record-key",
|
|
@@ -22,29 +17,10 @@ const noTransformInRecordKey = createZodPluginRule({
|
|
|
22
17
|
schema: []
|
|
23
18
|
},
|
|
24
19
|
defaultOptions: [],
|
|
25
|
-
create(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
function hasTransformMethods(schema) {
|
|
31
|
-
if (schema.type === AST_NODE_TYPES.SpreadElement) return false;
|
|
32
|
-
if (schema.type === AST_NODE_TYPES.CallExpression) return collectZodChainMethods(schema).some((method) => TRANSFORM_METHODS.includes(method.name));
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
ImportDeclaration: importDeclarationListener,
|
|
37
|
-
CallExpression(node) {
|
|
38
|
-
if (detectZodSchemaRootNode(node)?.schemaType !== "record") return;
|
|
39
|
-
const keySchemaArg = node.arguments.at(0);
|
|
40
|
-
if (!keySchemaArg) return;
|
|
41
|
-
if (hasTransformMethods(keySchemaArg)) context.report({
|
|
42
|
-
node: keySchemaArg,
|
|
43
|
-
messageId: "noTransformInRecordKey"
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
20
|
+
create: buildNoTransformInRecordKeyCreate(zodImportScope, { findTransformNode(keySchema, { collectZodChainMethods }) {
|
|
21
|
+
if (keySchema.type !== AST_NODE_TYPES.CallExpression) return null;
|
|
22
|
+
return collectZodChainMethods(keySchema).some((method) => TRANSFORM_METHODS.includes(method.name)) ? keySchema : null;
|
|
23
|
+
} })
|
|
48
24
|
});
|
|
49
25
|
//#endregion
|
|
50
26
|
export { noTransformInRecordKey };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_unknown_schema = require("@eslint-zod/utils/rule-builders/no-unknown-schema");
|
|
4
4
|
//#region src/rules/no-unknown-schema.ts
|
|
5
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
6
5
|
const noUnknownSchema = require_create_plugin_rule.createZodPluginRule({
|
|
7
6
|
name: "no-unknown-schema",
|
|
8
7
|
meta: {
|
|
@@ -12,18 +11,7 @@ const noUnknownSchema = require_create_plugin_rule.createZodPluginRule({
|
|
|
12
11
|
schema: []
|
|
13
12
|
},
|
|
14
13
|
defaultOptions: [],
|
|
15
|
-
create(
|
|
16
|
-
const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
|
|
17
|
-
return {
|
|
18
|
-
ImportDeclaration: importDeclarationListener,
|
|
19
|
-
CallExpression(node) {
|
|
20
|
-
if (detectZodSchemaRootNode(node)?.schemaType === "unknown") context.report({
|
|
21
|
-
node,
|
|
22
|
-
messageId: "noZUnknown"
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_unknown_schema.buildNoUnknownSchemaCreate)(_eslint_zod_utils.zodImportScope)
|
|
27
15
|
});
|
|
28
16
|
//#endregion
|
|
29
17
|
exports.noUnknownSchema = noUnknownSchema;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoUnknownSchemaCreate } from "@eslint-zod/utils/rule-builders/no-unknown-schema";
|
|
3
4
|
//#region src/rules/no-unknown-schema.ts
|
|
4
|
-
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodImportScope);
|
|
5
5
|
const noUnknownSchema = createZodPluginRule({
|
|
6
6
|
name: "no-unknown-schema",
|
|
7
7
|
meta: {
|
|
@@ -11,18 +11,7 @@ const noUnknownSchema = createZodPluginRule({
|
|
|
11
11
|
schema: []
|
|
12
12
|
},
|
|
13
13
|
defaultOptions: [],
|
|
14
|
-
create(
|
|
15
|
-
const { importDeclarationListener, detectZodSchemaRootNode } = trackZodSchemaImports();
|
|
16
|
-
return {
|
|
17
|
-
ImportDeclaration: importDeclarationListener,
|
|
18
|
-
CallExpression(node) {
|
|
19
|
-
if (detectZodSchemaRootNode(node)?.schemaType === "unknown") context.report({
|
|
20
|
-
node,
|
|
21
|
-
messageId: "noZUnknown"
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
14
|
+
create: buildNoUnknownSchemaCreate(zodImportScope)
|
|
26
15
|
});
|
|
27
16
|
//#endregion
|
|
28
17
|
export { noUnknownSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_prefer_enum_over_literal_union = require("@eslint-zod/utils/rule-builders/prefer-enum-over-literal-union");
|
|
4
4
|
//#region src/rules/prefer-enum-over-literal-union.ts
|
|
5
5
|
const preferEnumOverLiteralUnion = require_create_plugin_rule.createZodPluginRule({
|
|
6
6
|
name: "prefer-enum-over-literal-union",
|
|
@@ -12,7 +12,7 @@ const preferEnumOverLiteralUnion = require_create_plugin_rule.createZodPluginRul
|
|
|
12
12
|
schema: []
|
|
13
13
|
},
|
|
14
14
|
defaultOptions: [],
|
|
15
|
-
create: (0,
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_builders_prefer_enum_over_literal_union.buildPreferEnumOverLiteralUnionCreate)(_eslint_zod_utils.zodImportScope)
|
|
16
16
|
});
|
|
17
17
|
//#endregion
|
|
18
18
|
exports.preferEnumOverLiteralUnion = preferEnumOverLiteralUnion;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createZodPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildPreferEnumOverLiteralUnionCreate } from "@eslint-zod/utils/rule-builders/prefer-enum-over-literal-union";
|
|
3
4
|
//#region src/rules/prefer-enum-over-literal-union.ts
|
|
4
5
|
const preferEnumOverLiteralUnion = createZodPluginRule({
|
|
5
6
|
name: "prefer-enum-over-literal-union",
|