eslint-plugin-zod 1.3.0 → 3.0.0
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/LICENSE +19 -22
- package/README.md +84 -56
- package/dist/index.cjs +71 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +68 -0
- package/dist/meta.cjs +13 -0
- package/dist/meta.d.cts +3 -0
- package/dist/meta.d.ts +3 -0
- package/dist/meta.js +8 -0
- package/dist/rules/array-style.cjs +99 -0
- package/dist/rules/array-style.d.cts +10 -0
- package/dist/rules/array-style.d.ts +10 -0
- package/dist/rules/array-style.js +96 -0
- package/dist/rules/consistent-import-source.cjs +73 -0
- package/dist/rules/consistent-import-source.d.cts +10 -0
- package/dist/rules/consistent-import-source.d.ts +10 -0
- package/dist/rules/consistent-import-source.js +70 -0
- package/dist/rules/consistent-object-schema-type.cjs +83 -0
- package/dist/rules/consistent-object-schema-type.d.cts +11 -0
- package/dist/rules/consistent-object-schema-type.d.ts +11 -0
- package/dist/rules/consistent-object-schema-type.js +80 -0
- package/dist/rules/no-any-schema.cjs +66 -0
- package/dist/rules/no-any-schema.d.cts +4 -0
- package/dist/rules/no-any-schema.d.ts +4 -0
- package/dist/rules/no-any-schema.js +63 -0
- package/dist/rules/no-empty-custom-schema.cjs +40 -0
- package/dist/rules/no-empty-custom-schema.d.cts +4 -0
- package/dist/rules/no-empty-custom-schema.d.ts +4 -0
- package/dist/rules/no-empty-custom-schema.js +37 -0
- package/dist/rules/no-number-schema-with-int.cjs +78 -0
- package/dist/rules/no-number-schema-with-int.d.cts +4 -0
- package/dist/rules/no-number-schema-with-int.d.ts +4 -0
- package/dist/rules/no-number-schema-with-int.js +75 -0
- package/dist/rules/no-optional-and-default-together.cjs +80 -0
- package/dist/rules/no-optional-and-default-together.d.cts +11 -0
- package/dist/rules/no-optional-and-default-together.d.ts +11 -0
- package/dist/rules/no-optional-and-default-together.js +77 -0
- package/dist/rules/no-throw-in-refine.cjs +84 -0
- package/dist/rules/no-throw-in-refine.d.cts +4 -0
- package/dist/rules/no-throw-in-refine.d.ts +4 -0
- package/dist/rules/no-throw-in-refine.js +81 -0
- package/dist/rules/no-unknown-schema.cjs +35 -0
- package/dist/rules/no-unknown-schema.d.cts +4 -0
- package/dist/rules/no-unknown-schema.d.ts +4 -0
- package/dist/rules/no-unknown-schema.js +32 -0
- package/dist/rules/prefer-enum-over-literal-union.cjs +72 -0
- package/dist/rules/prefer-enum-over-literal-union.d.cts +4 -0
- package/dist/rules/prefer-enum-over-literal-union.d.ts +4 -0
- package/dist/rules/prefer-enum-over-literal-union.js +69 -0
- package/dist/rules/prefer-meta-last.cjs +71 -0
- package/dist/rules/prefer-meta-last.d.cts +4 -0
- package/dist/rules/prefer-meta-last.d.ts +4 -0
- package/dist/rules/prefer-meta-last.js +68 -0
- package/dist/rules/prefer-meta.cjs +48 -0
- package/dist/rules/prefer-meta.d.cts +4 -0
- package/dist/rules/prefer-meta.d.ts +4 -0
- package/dist/rules/prefer-meta.js +45 -0
- package/dist/rules/prefer-namespace-import.cjs +145 -0
- package/dist/rules/prefer-namespace-import.d.cts +4 -0
- package/dist/rules/prefer-namespace-import.d.ts +4 -0
- package/dist/rules/prefer-namespace-import.js +142 -0
- package/dist/rules/require-brand-type-parameter.cjs +60 -0
- package/dist/rules/require-brand-type-parameter.d.cts +4 -0
- package/dist/rules/require-brand-type-parameter.d.ts +4 -0
- package/dist/rules/require-brand-type-parameter.js +57 -0
- package/dist/rules/require-error-message.cjs +101 -0
- package/dist/rules/require-error-message.d.cts +4 -0
- package/dist/rules/require-error-message.d.ts +4 -0
- package/dist/rules/require-error-message.js +98 -0
- package/dist/rules/require-schema-suffix.cjs +73 -0
- package/dist/rules/require-schema-suffix.d.cts +8 -0
- package/dist/rules/require-schema-suffix.d.ts +8 -0
- package/dist/rules/require-schema-suffix.js +70 -0
- package/dist/rules/schema-error-property-style.cjs +106 -0
- package/dist/rules/schema-error-property-style.d.cts +9 -0
- package/dist/rules/schema-error-property-style.d.ts +9 -0
- package/dist/rules/schema-error-property-style.js +100 -0
- package/dist/utils/detect-zod-schema-root-node.cjs +104 -0
- package/dist/utils/detect-zod-schema-root-node.d.cts +10 -0
- package/dist/utils/detect-zod-schema-root-node.d.ts +10 -0
- package/dist/utils/detect-zod-schema-root-node.js +101 -0
- package/dist/utils/get-outermost-call.cjs +14 -0
- package/dist/utils/get-outermost-call.d.cts +2 -0
- package/dist/utils/get-outermost-call.d.ts +2 -0
- package/dist/utils/get-outermost-call.js +11 -0
- package/dist/utils/is-zod-expression.cjs +14 -0
- package/dist/utils/is-zod-expression.d.cts +2 -0
- package/dist/utils/is-zod-expression.d.ts +2 -0
- package/dist/utils/is-zod-expression.js +11 -0
- package/dist/utils/is-zod-import-source.cjs +6 -0
- package/dist/utils/is-zod-import-source.d.cts +1 -0
- package/dist/utils/is-zod-import-source.d.ts +1 -0
- package/dist/utils/is-zod-import-source.js +3 -0
- package/dist/utils/track-zod-schema-imports.cjs +61 -0
- package/dist/utils/track-zod-schema-imports.d.cts +13 -0
- package/dist/utils/track-zod-schema-imports.d.ts +13 -0
- package/dist/utils/track-zod-schema-imports.js +58 -0
- package/package.json +82 -38
- package/dist/src/index.d.ts +0 -31
- package/dist/src/index.js +0 -14
- package/dist/src/rules/requireStrict.d.ts +0 -24
- package/dist/src/rules/requireStrict.js +0 -69
- package/tsconfig.json +0 -28
package/package.json
CHANGED
|
@@ -1,50 +1,94 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"name": "eslint-plugin-zod",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": "^20 || ^22 || >=24"
|
|
6
8
|
},
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
10
|
-
"@semantic-release/github": "^8.0.6",
|
|
11
|
-
"@semantic-release/npm": "^9.0.1",
|
|
12
|
-
"@types/mocha": "^10.0.0",
|
|
13
|
-
"@types/node": "^18.11.9",
|
|
14
|
-
"eslint": "^8.27.0",
|
|
15
|
-
"eslint-config-canonical": "37.0.3",
|
|
16
|
-
"gitdown": "^3.1.5",
|
|
17
|
-
"glob": "^8.0.3",
|
|
18
|
-
"lodash": "^4.17.21",
|
|
19
|
-
"mocha": "^10.1.0",
|
|
20
|
-
"semantic-release": "^19.0.5",
|
|
21
|
-
"tsx": "^3.12.1",
|
|
22
|
-
"typescript": "^4.9.3"
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
23
11
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.cts",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/marcalexiei/eslint-plugin-zod#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/marcalexiei/eslint-plugin-zod/issues"
|
|
26
25
|
},
|
|
27
26
|
"keywords": [
|
|
28
27
|
"eslint",
|
|
29
|
-
"
|
|
28
|
+
"eslintplugin",
|
|
29
|
+
"eslint-plugin",
|
|
30
30
|
"zod"
|
|
31
31
|
],
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"author": "Marco Pasqualetti @marcalexiei",
|
|
36
|
+
"license": "MIT",
|
|
38
37
|
"repository": {
|
|
39
38
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
39
|
+
"url": "https://github.com/marcalexiei/eslint-plugin-zod"
|
|
40
|
+
},
|
|
41
|
+
"zshy": {
|
|
42
|
+
"exports": "./src/index.ts"
|
|
43
|
+
},
|
|
44
|
+
"prettier": "@marcalexiei/prettier-config",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@typescript-eslint/utils": "^8.50.0",
|
|
47
|
+
"esquery": "^1.6.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"eslint": "^9",
|
|
51
|
+
"zod": "^4"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"zod": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@changesets/changelog-github": "0.5.2",
|
|
60
|
+
"@changesets/cli": "2.29.8",
|
|
61
|
+
"@marcalexiei/eslint-config": "5.0.0",
|
|
62
|
+
"@marcalexiei/prettier-config": "1.1.4",
|
|
63
|
+
"@types/esquery": "1.5.4",
|
|
64
|
+
"@types/node": "24.10.1",
|
|
65
|
+
"@typescript-eslint/rule-tester": "8.51.0",
|
|
66
|
+
"@vitest/eslint-plugin": "1.6.4",
|
|
67
|
+
"dedent": "1.7.1",
|
|
68
|
+
"eslint": "9.39.2",
|
|
69
|
+
"eslint-doc-generator": "3.0.2",
|
|
70
|
+
"eslint-plugin-eslint-plugin": "7.2.0",
|
|
71
|
+
"eslint-plugin-n": "17.23.1",
|
|
72
|
+
"knip": "5.79.0",
|
|
73
|
+
"prettier": "3.7.4",
|
|
74
|
+
"typescript": "5.9.3",
|
|
75
|
+
"typescript-eslint": "8.51.0",
|
|
76
|
+
"vitest": "4.0.16",
|
|
77
|
+
"zshy": "0.7.0"
|
|
41
78
|
},
|
|
42
79
|
"scripts": {
|
|
43
|
-
"build": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"lint": "eslint
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
"build": "zshy",
|
|
81
|
+
"build:docs": "pnpm run build && eslint-doc-generator",
|
|
82
|
+
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:knip",
|
|
83
|
+
"lint:js": "eslint .",
|
|
84
|
+
"lint:js:fix": "eslint . --fix",
|
|
85
|
+
"lint:docs": "eslint-doc-generator --check",
|
|
86
|
+
"lint:knip": "knip",
|
|
87
|
+
"format": "prettier . --check",
|
|
88
|
+
"format:fix": "prettier . --write",
|
|
89
|
+
"test": "vitest",
|
|
90
|
+
"test:dev": "vitest --typecheck=false",
|
|
91
|
+
"release": "pnpm run build && changeset publish",
|
|
92
|
+
"check-all": "pnpm run \"/^(lint|format|typecheck|build)$/\" && pnpm run test --run"
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
rules: {
|
|
3
|
-
'require-strict': {
|
|
4
|
-
create: (context: any) => {
|
|
5
|
-
CallExpression(node: any): void;
|
|
6
|
-
};
|
|
7
|
-
meta: {
|
|
8
|
-
docs: {
|
|
9
|
-
description: string;
|
|
10
|
-
url: string;
|
|
11
|
-
};
|
|
12
|
-
fixable: string;
|
|
13
|
-
schema: {
|
|
14
|
-
additionalProperties: boolean;
|
|
15
|
-
properties: {
|
|
16
|
-
allowPassthrough: {
|
|
17
|
-
default: boolean;
|
|
18
|
-
type: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
type: string;
|
|
22
|
-
}[];
|
|
23
|
-
type: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
rulesConfig: {
|
|
28
|
-
'require-strict': number;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export = _default;
|
package/dist/src/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const requireStrict_1 = __importDefault(require("./rules/requireStrict"));
|
|
6
|
-
const rules = {
|
|
7
|
-
'require-strict': requireStrict_1.default,
|
|
8
|
-
};
|
|
9
|
-
module.exports = {
|
|
10
|
-
rules,
|
|
11
|
-
rulesConfig: {
|
|
12
|
-
'require-strict': 0,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
create: (context: any) => {
|
|
3
|
-
CallExpression(node: any): void;
|
|
4
|
-
};
|
|
5
|
-
meta: {
|
|
6
|
-
docs: {
|
|
7
|
-
description: string;
|
|
8
|
-
url: string;
|
|
9
|
-
};
|
|
10
|
-
fixable: string;
|
|
11
|
-
schema: {
|
|
12
|
-
additionalProperties: boolean;
|
|
13
|
-
properties: {
|
|
14
|
-
allowPassthrough: {
|
|
15
|
-
default: boolean;
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
type: string;
|
|
20
|
-
}[];
|
|
21
|
-
type: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export = _default;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const defaultOptions = {
|
|
3
|
-
allowPassthrough: true,
|
|
4
|
-
};
|
|
5
|
-
const create = (context) => {
|
|
6
|
-
return {
|
|
7
|
-
CallExpression(node) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
9
|
-
if (((_a = node.callee.object) === null || _a === void 0 ? void 0 : _a.name) !== 'z') {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (node.callee.property.name !== 'object') {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const { allowPassthrough, } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : defaultOptions;
|
|
16
|
-
if (!node.parent.property) {
|
|
17
|
-
context.report({
|
|
18
|
-
fix: (fixer) => {
|
|
19
|
-
return fixer.insertTextAfter(node, '.strict()');
|
|
20
|
-
},
|
|
21
|
-
message: 'Add a strict() call to the schema.',
|
|
22
|
-
node,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else if (
|
|
26
|
-
// z.object().strict()
|
|
27
|
-
((_d = (_c = node.parent) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.name) !== 'strict' &&
|
|
28
|
-
// z.object().merge().strict()
|
|
29
|
-
((_h = (_g = (_f = (_e = node.parent) === null || _e === void 0 ? void 0 : _e.parent) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.property) === null || _h === void 0 ? void 0 : _h.name) !== 'strict') {
|
|
30
|
-
if (((_k = (_j = node.parent) === null || _j === void 0 ? void 0 : _j.property) === null || _k === void 0 ? void 0 : _k.name) === 'passthrough' && allowPassthrough) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (((_m = (_l = node.parent) === null || _l === void 0 ? void 0 : _l.property) === null || _m === void 0 ? void 0 : _m.name) === 'and') {
|
|
34
|
-
// Ignore .and() calls
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// As far as I can think, in cases where the property name is not-strict,
|
|
38
|
-
// e.g. passthrough, we should not add a strict() call.
|
|
39
|
-
context.report({
|
|
40
|
-
message: 'Add a strict() call to the schema.',
|
|
41
|
-
node,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
module.exports = {
|
|
48
|
-
create,
|
|
49
|
-
meta: {
|
|
50
|
-
docs: {
|
|
51
|
-
description: 'Requires that objects are initialized with .strict().',
|
|
52
|
-
url: 'https://github.com/gajus/eslint-plugin-zod#eslint-plugin-zod-rules-require-strict',
|
|
53
|
-
},
|
|
54
|
-
fixable: 'code',
|
|
55
|
-
schema: [
|
|
56
|
-
{
|
|
57
|
-
additionalProperties: false,
|
|
58
|
-
properties: {
|
|
59
|
-
allowPassthrough: {
|
|
60
|
-
default: true,
|
|
61
|
-
type: 'boolean',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
type: 'object',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
type: 'problem',
|
|
68
|
-
},
|
|
69
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"allowSyntheticDefaultImports": true,
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"esModuleInterop": true,
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"lib": [
|
|
8
|
-
"es2021"
|
|
9
|
-
],
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"noImplicitAny": false,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"useUnknownInCatchVariables": false,
|
|
14
|
-
"outDir": "dist",
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"strict": true,
|
|
17
|
-
"target": "es2018"
|
|
18
|
-
},
|
|
19
|
-
"exclude": [
|
|
20
|
-
"dist",
|
|
21
|
-
"node_modules"
|
|
22
|
-
],
|
|
23
|
-
"include": [
|
|
24
|
-
"bin",
|
|
25
|
-
"src",
|
|
26
|
-
"test"
|
|
27
|
-
]
|
|
28
|
-
}
|