eslint-plugin-zod 4.5.1 → 4.5.3
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,8 +1,7 @@
|
|
|
1
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
-
let
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_throw_in_refine = require("@eslint-zod/utils/rule-builders/no-throw-in-refine");
|
|
4
4
|
//#region src/rules/no-throw-in-refine.ts
|
|
5
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodImportScope);
|
|
6
5
|
const noThrowInRefine = require_create_plugin_rule.createZodPluginRule({
|
|
7
6
|
name: "no-throw-in-refine",
|
|
8
7
|
meta: {
|
|
@@ -12,55 +11,7 @@ const noThrowInRefine = require_create_plugin_rule.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 _typescript_eslint_utils.AST_NODE_TYPES.ThrowStatement:
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "noThrowInRefine"
|
|
24
|
-
});
|
|
25
|
-
break;
|
|
26
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.BlockStatement:
|
|
27
|
-
node.body.forEach(checkNode);
|
|
28
|
-
break;
|
|
29
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.IfStatement:
|
|
30
|
-
checkNode(node.consequent);
|
|
31
|
-
if (node.alternate) checkNode(node.alternate);
|
|
32
|
-
break;
|
|
33
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForStatement:
|
|
34
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForInStatement:
|
|
35
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ForOfStatement:
|
|
36
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.WhileStatement:
|
|
37
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.DoWhileStatement:
|
|
38
|
-
checkNode(node.body);
|
|
39
|
-
break;
|
|
40
|
-
case _typescript_eslint_utils.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 _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression:
|
|
46
|
-
case _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
47
|
-
case _typescript_eslint_utils.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 === _typescript_eslint_utils.AST_NODE_TYPES.ArrowFunctionExpression || callback.type === _typescript_eslint_utils.AST_NODE_TYPES.FunctionExpression) checkNode(callback.body);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_throw_in_refine.buildNoThrowInRefineCreate)(_eslint_zod_utils.zodImportScope)
|
|
64
15
|
});
|
|
65
16
|
//#endregion
|
|
66
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,17 +1,12 @@
|
|
|
1
1
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
2
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
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");
|
|
4
5
|
//#region src/rules/no-transform-in-record-key.ts
|
|
5
|
-
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.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
|
+
..._eslint_zod_utils.ZOD_MUTATING_CHECK_NAMES,
|
|
10
8
|
"transform",
|
|
11
|
-
"map"
|
|
12
|
-
"trim",
|
|
13
|
-
"toLowerCase",
|
|
14
|
-
"toUpperCase"
|
|
9
|
+
"map"
|
|
15
10
|
];
|
|
16
11
|
const noTransformInRecordKey = require_create_plugin_rule.createZodPluginRule({
|
|
17
12
|
name: "no-transform-in-record-key",
|
|
@@ -22,29 +17,10 @@ const noTransformInRecordKey = require_create_plugin_rule.createZodPluginRule({
|
|
|
22
17
|
schema: []
|
|
23
18
|
},
|
|
24
19
|
defaultOptions: [],
|
|
25
|
-
create(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
function hasTransformMethods(schema) {
|
|
31
|
-
if (schema.type === _typescript_eslint_utils.AST_NODE_TYPES.SpreadElement) return false;
|
|
32
|
-
if (schema.type === _typescript_eslint_utils.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: (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
|
+
} })
|
|
48
24
|
});
|
|
49
25
|
//#endregion
|
|
50
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.3",
|
|
4
4
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@typescript-eslint/utils": "^8.57.0",
|
|
42
|
-
"@eslint-zod/utils": "2.
|
|
42
|
+
"@eslint-zod/utils": "2.1.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@marcalexiei/prettier-config": "2.0.0",
|