eslint-plugin-zod-mini 0.1.0 → 1.0.1
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/README.md +35 -27
- package/dist/index.cjs +1 -5
- package/dist/index.mjs +1 -5
- package/dist/meta.cjs +2 -3
- package/dist/meta.mjs +2 -3
- package/dist/rules/consistent-import-source.cjs +3 -6
- package/dist/rules/consistent-import-source.mjs +4 -7
- package/dist/rules/consistent-import.cjs +7 -53
- package/dist/rules/consistent-import.mjs +4 -50
- package/dist/rules/consistent-object-schema-type.cjs +2 -5
- package/dist/rules/consistent-object-schema-type.mjs +3 -6
- package/dist/rules/consistent-schema-output-type-style.cjs +2 -5
- package/dist/rules/consistent-schema-output-type-style.mjs +3 -6
- package/dist/rules/consistent-schema-var-name.cjs +3 -25
- package/dist/rules/consistent-schema-var-name.mjs +4 -26
- package/dist/rules/no-any-schema.cjs +2 -5
- package/dist/rules/no-any-schema.mjs +3 -6
- package/dist/rules/no-empty-custom-schema.cjs +3 -5
- package/dist/rules/no-empty-custom-schema.mjs +3 -6
- package/dist/rules/no-unknown-schema.cjs +3 -5
- package/dist/rules/no-unknown-schema.mjs +3 -6
- package/dist/rules/prefer-meta.cjs +2 -5
- package/dist/rules/prefer-meta.mjs +3 -6
- package/dist/rules/require-brand-type-parameter.cjs +3 -5
- package/dist/rules/require-brand-type-parameter.mjs +3 -6
- package/dist/rules/require-error-message.cjs +2 -5
- package/dist/rules/require-error-message.mjs +3 -6
- package/dist/rules/schema-error-property-style.cjs +2 -5
- package/dist/rules/schema-error-property-style.mjs +3 -6
- package/package.json +38 -38
- package/dist/rules/prefer-namespace-import.cjs +0 -117
- package/dist/rules/prefer-namespace-import.mjs +0 -116
- package/dist/rules/require-schema-suffix.cjs +0 -69
- package/dist/rules/require-schema-suffix.mjs +0 -68
- package/dist/src/index.d.ts +0 -21
- package/dist/src/index.js +0 -56
- package/dist/src/meta.d.ts +0 -3
- package/dist/src/meta.js +0 -8
- package/dist/src/rules/consistent-import-source.d.ts +0 -11
- package/dist/src/rules/consistent-import-source.js +0 -64
- package/dist/src/rules/consistent-import-source.spec.d.ts +0 -1
- package/dist/src/rules/consistent-import-source.spec.js +0 -103
- package/dist/src/rules/consistent-import.d.ts +0 -12
- package/dist/src/rules/consistent-import.js +0 -176
- package/dist/src/rules/consistent-import.spec.d.ts +0 -1
- package/dist/src/rules/consistent-import.spec.js +0 -194
- package/dist/src/rules/consistent-object-schema-type.d.ts +0 -13
- package/dist/src/rules/consistent-object-schema-type.js +0 -82
- package/dist/src/rules/consistent-object-schema-type.spec.d.ts +0 -1
- package/dist/src/rules/consistent-object-schema-type.spec.js +0 -138
- package/dist/src/rules/consistent-schema-output-type-style.d.ts +0 -12
- package/dist/src/rules/consistent-schema-output-type-style.js +0 -81
- package/dist/src/rules/consistent-schema-output-type-style.spec.d.ts +0 -1
- package/dist/src/rules/consistent-schema-output-type-style.spec.js +0 -128
- package/dist/src/rules/consistent-schema-var-name.d.ts +0 -10
- package/dist/src/rules/consistent-schema-var-name.js +0 -86
- package/dist/src/rules/consistent-schema-var-name.spec.d.ts +0 -1
- package/dist/src/rules/consistent-schema-var-name.spec.js +0 -130
- package/dist/src/rules/no-any-schema.d.ts +0 -6
- package/dist/src/rules/no-any-schema.js +0 -65
- package/dist/src/rules/no-any-schema.spec.d.ts +0 -1
- package/dist/src/rules/no-any-schema.spec.js +0 -155
- package/dist/src/rules/no-empty-custom-schema.d.ts +0 -5
- package/dist/src/rules/no-empty-custom-schema.js +0 -43
- package/dist/src/rules/no-empty-custom-schema.spec.d.ts +0 -1
- package/dist/src/rules/no-empty-custom-schema.spec.js +0 -97
- package/dist/src/rules/no-unknown-schema.d.ts +0 -5
- package/dist/src/rules/no-unknown-schema.js +0 -33
- package/dist/src/rules/no-unknown-schema.spec.d.ts +0 -1
- package/dist/src/rules/no-unknown-schema.spec.js +0 -75
- package/dist/src/rules/prefer-meta.d.ts +0 -5
- package/dist/src/rules/prefer-meta.js +0 -51
- package/dist/src/rules/prefer-meta.spec.d.ts +0 -1
- package/dist/src/rules/prefer-meta.spec.js +0 -118
- package/dist/src/rules/prefer-namespace-import.d.ts +0 -5
- package/dist/src/rules/prefer-namespace-import.js +0 -146
- package/dist/src/rules/prefer-namespace-import.spec.d.ts +0 -1
- package/dist/src/rules/prefer-namespace-import.spec.js +0 -100
- package/dist/src/rules/require-brand-type-parameter.d.ts +0 -6
- package/dist/src/rules/require-brand-type-parameter.js +0 -58
- package/dist/src/rules/require-brand-type-parameter.spec.d.ts +0 -1
- package/dist/src/rules/require-brand-type-parameter.spec.js +0 -157
- package/dist/src/rules/require-error-message.d.ts +0 -5
- package/dist/src/rules/require-error-message.js +0 -103
- package/dist/src/rules/require-error-message.spec.d.ts +0 -1
- package/dist/src/rules/require-error-message.spec.js +0 -161
- package/dist/src/rules/require-schema-suffix.d.ts +0 -9
- package/dist/src/rules/require-schema-suffix.js +0 -79
- package/dist/src/rules/require-schema-suffix.spec.d.ts +0 -1
- package/dist/src/rules/require-schema-suffix.spec.js +0 -131
- package/dist/src/rules/schema-error-property-style.d.ts +0 -10
- package/dist/src/rules/schema-error-property-style.js +0 -102
- package/dist/src/rules/schema-error-property-style.spec.d.ts +0 -1
- package/dist/src/rules/schema-error-property-style.spec.js +0 -134
- package/dist/src/utils/create-plugin-rule.d.ts +0 -8
- package/dist/src/utils/create-plugin-rule.js +0 -3
- package/dist/tests/setup.d.ts +0 -1
- package/dist/tests/setup.js +0 -12
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/tsdown.config.d.ts +0 -2
- package/dist/tsdown.config.js +0 -11
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -7
package/README.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# eslint-plugin-zod-mini
|
|
2
2
|
|
|
3
|
-
[![CI][CIBadge]][CIURL]
|
|
3
|
+
[![CI Status][CIBadge]][CIURL]
|
|
4
4
|
[![Code style: prettier][CodeStyleBadge]][CodeStyleURL]
|
|
5
5
|
[![Lint: eslint][lintBadge]][lintURL]
|
|
6
|
-
[![
|
|
7
|
-
[![
|
|
6
|
+
[![Open on npmx][npmVersionBadge]][npmVersionURL]
|
|
7
|
+
[![Open issue tracker][issuesBadge]][issuesURL]
|
|
8
8
|
|
|
9
|
-
[CIBadge]: https://img.shields.io/github/actions/workflow/status/marcalexiei/eslint-
|
|
10
|
-
[CIURL]: https://github.com/marcalexiei/eslint-
|
|
9
|
+
[CIBadge]: https://img.shields.io/github/actions/workflow/status/marcalexiei/eslint-zod/ci.yml?style=for-the-badge&logo=github&event=push&label=CI
|
|
10
|
+
[CIURL]: https://github.com/marcalexiei/eslint-zod/actions/workflows/CI.yml/badge.svg
|
|
11
11
|
[CodeStyleBadge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge&logo=prettier
|
|
12
12
|
[CodeStyleURL]: https://prettier.io
|
|
13
13
|
[npmVersionBadge]: https://img.shields.io/npm/v/eslint-plugin-zod-mini.svg?style=for-the-badge&logo=npm
|
|
14
|
-
[npmVersionURL]: https://
|
|
14
|
+
[npmVersionURL]: https://npmx.dev/package/eslint-plugin-zod-mini
|
|
15
15
|
[lintBadge]: https://img.shields.io/badge/lint-eslint-3A33D1?logo=eslint&style=for-the-badge
|
|
16
16
|
[lintURL]: https://eslint.org
|
|
17
|
-
[issuesBadge]: https://img.shields.io/github/issues/marcalexiei/eslint-
|
|
18
|
-
[issuesURL]: https://github.com/marcalexiei/eslint-
|
|
17
|
+
[issuesBadge]: https://img.shields.io/github/issues/marcalexiei/eslint-zod.svg?style=for-the-badge
|
|
18
|
+
[issuesURL]: https://github.com/marcalexiei/eslint-zod/issues
|
|
19
19
|
|
|
20
20
|
[ESLint](https://eslint.org) plugin that adds custom linting rules to enforce best practices when using [Zod Mini](https://zod.dev/?id=zod-mini) (`zod/mini`).
|
|
21
21
|
|
|
@@ -29,25 +29,22 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
29
29
|
💼 Configurations enabled in.\
|
|
30
30
|
✅ Set in the `recommended` configuration.\
|
|
31
31
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
32
|
-
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
| [consistent-import](docs/rules/consistent-import.md)
|
|
38
|
-
| [consistent-
|
|
39
|
-
| [consistent-
|
|
40
|
-
| [consistent-schema-
|
|
41
|
-
| [
|
|
42
|
-
| [no-
|
|
43
|
-
| [no-
|
|
44
|
-
| [
|
|
45
|
-
| [
|
|
46
|
-
| [
|
|
47
|
-
| [
|
|
48
|
-
| [require-error-message](docs/rules/require-error-message.md) | Enforce that custom refinements include an error message | ✅ | 🔧 | | |
|
|
49
|
-
| [require-schema-suffix](docs/rules/require-schema-suffix.md) | Require schema suffix when declaring a Zod Mini schema | | | | ❌ |
|
|
50
|
-
| [schema-error-property-style](docs/rules/schema-error-property-style.md) | Enforce consistent style for error messages in Zod Mini schema validation (using ESQuery patterns) | | | | |
|
|
32
|
+
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
|
33
|
+
|
|
34
|
+
| Name | Description | 💼 | 🔧 | 💡 |
|
|
35
|
+
| :--------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :-- | :-- | :-- |
|
|
36
|
+
| [consistent-import](docs/rules/consistent-import.md) | Enforce a consistent import style for Zod Mini | ✅ | 🔧 | |
|
|
37
|
+
| [consistent-import-source](docs/rules/consistent-import-source.md) | Enforce consistent source from Zod Mini imports | | | 💡 |
|
|
38
|
+
| [consistent-object-schema-type](docs/rules/consistent-object-schema-type.md) | Enforce consistent usage of Zod Mini schema methods | | | 💡 |
|
|
39
|
+
| [consistent-schema-output-type-style](docs/rules/consistent-schema-output-type-style.md) | Enforce consistent use of z.infer or z.output for schema type inference | | 🔧 | |
|
|
40
|
+
| [consistent-schema-var-name](docs/rules/consistent-schema-var-name.md) | Enforce a consistent naming convention for Zod Mini schema variables | ✅ | | |
|
|
41
|
+
| [no-any-schema](docs/rules/no-any-schema.md) | Disallow usage of `z.any()` in Zod Mini schemas | ✅ | | 💡 |
|
|
42
|
+
| [no-empty-custom-schema](docs/rules/no-empty-custom-schema.md) | Disallow usage of `z.custom()` without arguments | ✅ | | |
|
|
43
|
+
| [no-unknown-schema](docs/rules/no-unknown-schema.md) | Disallow usage of `z.unknown()` in Zod Mini schemas | | | |
|
|
44
|
+
| [prefer-meta](docs/rules/prefer-meta.md) | Enforce usage of `z.meta()` over `z.describe()` | ✅ | 🔧 | |
|
|
45
|
+
| [require-brand-type-parameter](docs/rules/require-brand-type-parameter.md) | Require type parameter on `.brand()` functions | ✅ | | 💡 |
|
|
46
|
+
| [require-error-message](docs/rules/require-error-message.md) | Enforce that custom refinements include an error message | ✅ | 🔧 | |
|
|
47
|
+
| [schema-error-property-style](docs/rules/schema-error-property-style.md) | Enforce consistent style for error messages in Zod Mini schema validation (using ESQuery patterns) | | | |
|
|
51
48
|
|
|
52
49
|
<!-- end auto-generated rules list -->
|
|
53
50
|
|
|
@@ -147,3 +144,14 @@ export default defineConfig({
|
|
|
147
144
|
},
|
|
148
145
|
});
|
|
149
146
|
```
|
|
147
|
+
|
|
148
|
+
## Zod peer dependency version
|
|
149
|
+
|
|
150
|
+
`eslint-plugin-zod-mini` is designed for projects that use `zod@^4` (specifically `zod/mini`).
|
|
151
|
+
While the plugin analyzes Zod Mini schemas in your code,
|
|
152
|
+
it doesn't import or depend on Zod at runtime.
|
|
153
|
+
To document this relationship without forcing installation,
|
|
154
|
+
Zod is declared as an optional peer dependency in the plugin's `package.json`.
|
|
155
|
+
|
|
156
|
+
If your project uses Zod Mini, the plugin will automatically lint your schemas.
|
|
157
|
+
If you're not using Zod (for example, in a separate ESLint workspace), you don't need to install it.
|
package/dist/index.cjs
CHANGED
|
@@ -8,10 +8,8 @@ const require_no_any_schema = require("./rules/no-any-schema.cjs");
|
|
|
8
8
|
const require_no_empty_custom_schema = require("./rules/no-empty-custom-schema.cjs");
|
|
9
9
|
const require_no_unknown_schema = require("./rules/no-unknown-schema.cjs");
|
|
10
10
|
const require_prefer_meta = require("./rules/prefer-meta.cjs");
|
|
11
|
-
const require_prefer_namespace_import = require("./rules/prefer-namespace-import.cjs");
|
|
12
11
|
const require_require_brand_type_parameter = require("./rules/require-brand-type-parameter.cjs");
|
|
13
12
|
const require_require_error_message = require("./rules/require-error-message.cjs");
|
|
14
|
-
const require_require_schema_suffix = require("./rules/require-schema-suffix.cjs");
|
|
15
13
|
const require_schema_error_property_style = require("./rules/schema-error-property-style.cjs");
|
|
16
14
|
//#region src/index.ts
|
|
17
15
|
const eslintPluginZodMini = {
|
|
@@ -29,10 +27,8 @@ const eslintPluginZodMini = {
|
|
|
29
27
|
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
30
28
|
"no-unknown-schema": require_no_unknown_schema.noUnknownSchema,
|
|
31
29
|
"prefer-meta": require_prefer_meta.preferMeta,
|
|
32
|
-
"prefer-namespace-import": require_prefer_namespace_import.preferNamespaceImport,
|
|
33
30
|
"require-brand-type-parameter": require_require_brand_type_parameter.requireBrandTypeParameter,
|
|
34
31
|
"require-error-message": require_require_error_message.requireErrorMessage,
|
|
35
|
-
"require-schema-suffix": require_require_schema_suffix.requireSchemaSuffix,
|
|
36
32
|
"schema-error-property-style": require_schema_error_property_style.schemaErrorPropertyStyle
|
|
37
33
|
}
|
|
38
34
|
};
|
|
@@ -56,7 +52,7 @@ var src_default = {
|
|
|
56
52
|
};
|
|
57
53
|
/**
|
|
58
54
|
* why `satisfies`?
|
|
59
|
-
* @see https://github.com/marcalexiei/eslint-
|
|
55
|
+
* @see https://github.com/marcalexiei/eslint-zod/issues/49
|
|
60
56
|
*/
|
|
61
57
|
//#endregion
|
|
62
58
|
module.exports = src_default;
|
package/dist/index.mjs
CHANGED
|
@@ -8,10 +8,8 @@ import { noAnySchema } from "./rules/no-any-schema.mjs";
|
|
|
8
8
|
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
9
9
|
import { noUnknownSchema } from "./rules/no-unknown-schema.mjs";
|
|
10
10
|
import { preferMeta } from "./rules/prefer-meta.mjs";
|
|
11
|
-
import { preferNamespaceImport } from "./rules/prefer-namespace-import.mjs";
|
|
12
11
|
import { requireBrandTypeParameter } from "./rules/require-brand-type-parameter.mjs";
|
|
13
12
|
import { requireErrorMessage } from "./rules/require-error-message.mjs";
|
|
14
|
-
import { requireSchemaSuffix } from "./rules/require-schema-suffix.mjs";
|
|
15
13
|
import { schemaErrorPropertyStyle } from "./rules/schema-error-property-style.mjs";
|
|
16
14
|
//#region src/index.ts
|
|
17
15
|
const eslintPluginZodMini = {
|
|
@@ -29,10 +27,8 @@ const eslintPluginZodMini = {
|
|
|
29
27
|
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
30
28
|
"no-unknown-schema": noUnknownSchema,
|
|
31
29
|
"prefer-meta": preferMeta,
|
|
32
|
-
"prefer-namespace-import": preferNamespaceImport,
|
|
33
30
|
"require-brand-type-parameter": requireBrandTypeParameter,
|
|
34
31
|
"require-error-message": requireErrorMessage,
|
|
35
|
-
"require-schema-suffix": requireSchemaSuffix,
|
|
36
32
|
"schema-error-property-style": schemaErrorPropertyStyle
|
|
37
33
|
}
|
|
38
34
|
};
|
|
@@ -56,7 +52,7 @@ var src_default = {
|
|
|
56
52
|
};
|
|
57
53
|
/**
|
|
58
54
|
* why `satisfies`?
|
|
59
|
-
* @see https://github.com/marcalexiei/eslint-
|
|
55
|
+
* @see https://github.com/marcalexiei/eslint-zod/issues/49
|
|
60
56
|
*/
|
|
61
57
|
//#endregion
|
|
62
58
|
export { src_default as default };
|
package/dist/meta.cjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let node_fs = require("node:fs");
|
|
3
3
|
//#region src/meta.ts
|
|
4
|
-
const { name: PLUGIN_NAME, version: PLUGIN_VERSION,
|
|
5
|
-
const PLUGIN_HOMEPAGE = homepage.replace(/#[^#]*$/, "");
|
|
4
|
+
const { name: PLUGIN_NAME, version: PLUGIN_VERSION, repository } = JSON.parse((0, node_fs.readFileSync)(new URL("../package.json", require("url").pathToFileURL(__filename).href), "utf8"));
|
|
6
5
|
function getRuleURL(ruleID) {
|
|
7
|
-
return `${
|
|
6
|
+
return `${repository.url}/blob/HEAD/${repository.directory}/docs/rules/${ruleID}.md`;
|
|
8
7
|
}
|
|
9
8
|
//#endregion
|
|
10
9
|
exports.PLUGIN_NAME = PLUGIN_NAME;
|
package/dist/meta.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
//#region src/meta.ts
|
|
3
|
-
const { name: PLUGIN_NAME, version: PLUGIN_VERSION,
|
|
4
|
-
const PLUGIN_HOMEPAGE = homepage.replace(/#[^#]*$/, "");
|
|
3
|
+
const { name: PLUGIN_NAME, version: PLUGIN_VERSION, repository } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
5
4
|
function getRuleURL(ruleID) {
|
|
6
|
-
return `${
|
|
5
|
+
return `${repository.url}/blob/HEAD/${repository.directory}/docs/rules/${ruleID}.md`;
|
|
7
6
|
}
|
|
8
7
|
//#endregion
|
|
9
8
|
export { PLUGIN_NAME, PLUGIN_VERSION, getRuleURL };
|
|
@@ -7,10 +7,7 @@ const consistentImportSource = require_create_plugin_rule.createZodMiniPluginRul
|
|
|
7
7
|
meta: {
|
|
8
8
|
hasSuggestions: true,
|
|
9
9
|
type: "suggestion",
|
|
10
|
-
docs: {
|
|
11
|
-
zodImportAllowedSource: "zod-mini",
|
|
12
|
-
description: "Enforce consistent source from Zod Mini imports"
|
|
13
|
-
},
|
|
10
|
+
docs: { description: "Enforce consistent source from Zod Mini imports" },
|
|
14
11
|
messages: {
|
|
15
12
|
sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
|
|
16
13
|
replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
|
|
@@ -22,7 +19,7 @@ const consistentImportSource = require_create_plugin_rule.createZodMiniPluginRul
|
|
|
22
19
|
description: "An array of allowed Zod import sources.",
|
|
23
20
|
items: {
|
|
24
21
|
type: "string",
|
|
25
|
-
enum: [..._eslint_zod_utils.
|
|
22
|
+
enum: [..._eslint_zod_utils.zodMiniImportScope.sources]
|
|
26
23
|
},
|
|
27
24
|
minItems: 1,
|
|
28
25
|
uniqueItems: true
|
|
@@ -34,7 +31,7 @@ const consistentImportSource = require_create_plugin_rule.createZodMiniPluginRul
|
|
|
34
31
|
create(context, [{ sources }]) {
|
|
35
32
|
return { ImportDeclaration(node) {
|
|
36
33
|
const sourceValue = node.source.value;
|
|
37
|
-
if (!
|
|
34
|
+
if (!_eslint_zod_utils.zodMiniImportScope.isAllowed(sourceValue)) return;
|
|
38
35
|
if (sources.includes(sourceValue)) return;
|
|
39
36
|
context.report({
|
|
40
37
|
node,
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
3
|
//#region src/rules/consistent-import-source.ts
|
|
4
4
|
const consistentImportSource = createZodMiniPluginRule({
|
|
5
5
|
name: "consistent-import-source",
|
|
6
6
|
meta: {
|
|
7
7
|
hasSuggestions: true,
|
|
8
8
|
type: "suggestion",
|
|
9
|
-
docs: {
|
|
10
|
-
zodImportAllowedSource: "zod-mini",
|
|
11
|
-
description: "Enforce consistent source from Zod Mini imports"
|
|
12
|
-
},
|
|
9
|
+
docs: { description: "Enforce consistent source from Zod Mini imports" },
|
|
13
10
|
messages: {
|
|
14
11
|
sourceNotAllowed: "\"{{source}}\" is not allowed. Available values are: {{sources}}",
|
|
15
12
|
replaceSource: "Replace \"{{invalid}}\" with \"{{valid}}\""
|
|
@@ -21,7 +18,7 @@ const consistentImportSource = createZodMiniPluginRule({
|
|
|
21
18
|
description: "An array of allowed Zod import sources.",
|
|
22
19
|
items: {
|
|
23
20
|
type: "string",
|
|
24
|
-
enum: [...
|
|
21
|
+
enum: [...zodMiniImportScope.sources]
|
|
25
22
|
},
|
|
26
23
|
minItems: 1,
|
|
27
24
|
uniqueItems: true
|
|
@@ -33,7 +30,7 @@ const consistentImportSource = createZodMiniPluginRule({
|
|
|
33
30
|
create(context, [{ sources }]) {
|
|
34
31
|
return { ImportDeclaration(node) {
|
|
35
32
|
const sourceValue = node.source.value;
|
|
36
|
-
if (!
|
|
33
|
+
if (!zodMiniImportScope.isAllowed(sourceValue)) return;
|
|
37
34
|
if (sources.includes(sourceValue)) return;
|
|
38
35
|
context.report({
|
|
39
36
|
node,
|
|
@@ -1,58 +1,12 @@
|
|
|
1
1
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
3
3
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
|
-
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
4
|
//#region src/rules/consistent-import.ts
|
|
6
|
-
const IMPORT_SYNTAXES = ["namespace", "named"];
|
|
7
|
-
/**
|
|
8
|
-
* Determines whether the first import in a group is valid for a given import
|
|
9
|
-
* syntax (`named` or `namespace`), taking into account whether the group
|
|
10
|
-
* contains only type imports.
|
|
11
|
-
*
|
|
12
|
-
* Rules enforced:
|
|
13
|
-
* - For `named` syntax:
|
|
14
|
-
* - The first import must have exactly one specifier
|
|
15
|
-
* - That specifier must be a named import of identifier `z`
|
|
16
|
-
* - For `namespace` syntax:
|
|
17
|
-
* - The first import must have exactly one namespace specifier
|
|
18
|
-
* - If the group contains only type imports, the first import must explicitly
|
|
19
|
-
* be declared as `import type`
|
|
20
|
-
*
|
|
21
|
-
* @param group - Metadata describing the import group
|
|
22
|
-
* @param syntax - Expected import syntax for the group
|
|
23
|
-
* @returns `true` if the first import matches the expected syntax and type rules
|
|
24
|
-
*/
|
|
25
|
-
function isGroupFirstImportKindValidForSyntax(group, syntax) {
|
|
26
|
-
const { hasOnlyTypeImports, nodes } = group;
|
|
27
|
-
const [firstImportNode] = nodes;
|
|
28
|
-
const { specifiers, importKind } = firstImportNode;
|
|
29
|
-
if (specifiers.length !== 1) return false;
|
|
30
|
-
const [specifier] = specifiers;
|
|
31
|
-
if (!(syntax === "named" ? specifier.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && specifier.imported.name === "z" : specifier.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportNamespaceSpecifier)) return false;
|
|
32
|
-
if (hasOnlyTypeImports) return importKind === "type";
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
function shouldIdentifierBeRenamed(node) {
|
|
36
|
-
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportSpecifier) return false;
|
|
37
|
-
if (node.parent.type === _typescript_eslint_utils.AST_NODE_TYPES.MemberExpression && node.parent.object.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.parent.object.name !== node.name) return false;
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* From a given specifiers retrieve the most significant to use when creating an alias import
|
|
42
|
-
*/
|
|
43
|
-
function getNamespaceAliasNameFrom(node) {
|
|
44
|
-
if (node.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportDefaultSpecifier || node.type === _typescript_eslint_utils.AST_NODE_TYPES.ImportNamespaceSpecifier) return node.local.name;
|
|
45
|
-
if (node.imported.type === _typescript_eslint_utils.AST_NODE_TYPES.Identifier && node.imported.name === "z") return node.local.name;
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
5
|
const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
49
6
|
name: "consistent-import",
|
|
50
7
|
meta: {
|
|
51
8
|
type: "problem",
|
|
52
|
-
docs: {
|
|
53
|
-
zodImportAllowedSource: "zod-mini",
|
|
54
|
-
description: "Enforce a consistent import style for Zod Mini"
|
|
55
|
-
},
|
|
9
|
+
docs: { description: "Enforce a consistent import style for Zod Mini" },
|
|
56
10
|
fixable: "code",
|
|
57
11
|
messages: {
|
|
58
12
|
changeImportSyntax: "Use a {{syntax}} import for Zod Mini.",
|
|
@@ -64,7 +18,7 @@ const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
|
64
18
|
properties: { syntax: {
|
|
65
19
|
description: "Specifies the import syntax to use for Zod Mini.",
|
|
66
20
|
type: "string",
|
|
67
|
-
enum: IMPORT_SYNTAXES
|
|
21
|
+
enum: _eslint_zod_utils.IMPORT_SYNTAXES
|
|
68
22
|
} },
|
|
69
23
|
additionalProperties: false
|
|
70
24
|
}]
|
|
@@ -77,8 +31,8 @@ const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
|
77
31
|
return {
|
|
78
32
|
ImportDeclaration(node) {
|
|
79
33
|
const { source, importKind } = node;
|
|
80
|
-
if (!
|
|
81
|
-
|
|
34
|
+
if (!_eslint_zod_utils.zodMiniImportScope.isAllowed(source.value)) return;
|
|
35
|
+
importGroups[source.value] ??= {
|
|
82
36
|
hasOnlyTypeImports: true,
|
|
83
37
|
nodes: []
|
|
84
38
|
};
|
|
@@ -98,7 +52,7 @@ const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
|
98
52
|
let namespaceAliasName = null;
|
|
99
53
|
for (const specifier of nodes.flatMap((it) => it.specifiers)) {
|
|
100
54
|
if (!namespaceAliasName) {
|
|
101
|
-
namespaceAliasName = getNamespaceAliasNameFrom(specifier);
|
|
55
|
+
namespaceAliasName = (0, _eslint_zod_utils.getNamespaceAliasNameFrom)(specifier);
|
|
102
56
|
if (namespaceAliasName) continue;
|
|
103
57
|
}
|
|
104
58
|
nodesWithVariablesToUpdate.push(specifier);
|
|
@@ -110,7 +64,7 @@ const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
|
110
64
|
namespaceAliasNameIndex += 1;
|
|
111
65
|
}
|
|
112
66
|
}
|
|
113
|
-
if (!isGroupFirstImportKindValidForSyntax(importGroup, syntax)) context.report({
|
|
67
|
+
if (!(0, _eslint_zod_utils.isGroupFirstImportKindValidForSyntax)(importGroup, syntax)) context.report({
|
|
114
68
|
node: firstImportNode,
|
|
115
69
|
messageId: "changeImportSyntax",
|
|
116
70
|
data: { syntax },
|
|
@@ -127,7 +81,7 @@ const consistentImport = require_create_plugin_rule.createZodMiniPluginRule({
|
|
|
127
81
|
const allReferences = nodesWithVariablesToUpdate.flatMap((it) => sourceCode.getDeclaredVariables(it)).flatMap((it) => it.references);
|
|
128
82
|
for (const ref of allReferences) {
|
|
129
83
|
const { identifier } = ref;
|
|
130
|
-
if (shouldIdentifierBeRenamed(identifier)) context.report({
|
|
84
|
+
if ((0, _eslint_zod_utils.shouldIdentifierBeRenamed)(identifier)) context.report({
|
|
131
85
|
node: identifier,
|
|
132
86
|
messageId: "convertUsage",
|
|
133
87
|
data: { syntax },
|
|
@@ -1,57 +1,11 @@
|
|
|
1
1
|
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
import { IMPORT_SYNTAXES, getNamespaceAliasNameFrom, isGroupFirstImportKindValidForSyntax, shouldIdentifierBeRenamed, zodMiniImportScope } from "@eslint-zod/utils";
|
|
4
3
|
//#region src/rules/consistent-import.ts
|
|
5
|
-
const IMPORT_SYNTAXES = ["namespace", "named"];
|
|
6
|
-
/**
|
|
7
|
-
* Determines whether the first import in a group is valid for a given import
|
|
8
|
-
* syntax (`named` or `namespace`), taking into account whether the group
|
|
9
|
-
* contains only type imports.
|
|
10
|
-
*
|
|
11
|
-
* Rules enforced:
|
|
12
|
-
* - For `named` syntax:
|
|
13
|
-
* - The first import must have exactly one specifier
|
|
14
|
-
* - That specifier must be a named import of identifier `z`
|
|
15
|
-
* - For `namespace` syntax:
|
|
16
|
-
* - The first import must have exactly one namespace specifier
|
|
17
|
-
* - If the group contains only type imports, the first import must explicitly
|
|
18
|
-
* be declared as `import type`
|
|
19
|
-
*
|
|
20
|
-
* @param group - Metadata describing the import group
|
|
21
|
-
* @param syntax - Expected import syntax for the group
|
|
22
|
-
* @returns `true` if the first import matches the expected syntax and type rules
|
|
23
|
-
*/
|
|
24
|
-
function isGroupFirstImportKindValidForSyntax(group, syntax) {
|
|
25
|
-
const { hasOnlyTypeImports, nodes } = group;
|
|
26
|
-
const [firstImportNode] = nodes;
|
|
27
|
-
const { specifiers, importKind } = firstImportNode;
|
|
28
|
-
if (specifiers.length !== 1) return false;
|
|
29
|
-
const [specifier] = specifiers;
|
|
30
|
-
if (!(syntax === "named" ? specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "z" : specifier.type === AST_NODE_TYPES.ImportNamespaceSpecifier)) return false;
|
|
31
|
-
if (hasOnlyTypeImports) return importKind === "type";
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
function shouldIdentifierBeRenamed(node) {
|
|
35
|
-
if (node.parent.type === AST_NODE_TYPES.ImportSpecifier) return false;
|
|
36
|
-
if (node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.object.type === AST_NODE_TYPES.Identifier && node.parent.object.name !== node.name) return false;
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* From a given specifiers retrieve the most significant to use when creating an alias import
|
|
41
|
-
*/
|
|
42
|
-
function getNamespaceAliasNameFrom(node) {
|
|
43
|
-
if (node.type === AST_NODE_TYPES.ImportDefaultSpecifier || node.type === AST_NODE_TYPES.ImportNamespaceSpecifier) return node.local.name;
|
|
44
|
-
if (node.imported.type === AST_NODE_TYPES.Identifier && node.imported.name === "z") return node.local.name;
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
4
|
const consistentImport = createZodMiniPluginRule({
|
|
48
5
|
name: "consistent-import",
|
|
49
6
|
meta: {
|
|
50
7
|
type: "problem",
|
|
51
|
-
docs: {
|
|
52
|
-
zodImportAllowedSource: "zod-mini",
|
|
53
|
-
description: "Enforce a consistent import style for Zod Mini"
|
|
54
|
-
},
|
|
8
|
+
docs: { description: "Enforce a consistent import style for Zod Mini" },
|
|
55
9
|
fixable: "code",
|
|
56
10
|
messages: {
|
|
57
11
|
changeImportSyntax: "Use a {{syntax}} import for Zod Mini.",
|
|
@@ -76,8 +30,8 @@ const consistentImport = createZodMiniPluginRule({
|
|
|
76
30
|
return {
|
|
77
31
|
ImportDeclaration(node) {
|
|
78
32
|
const { source, importKind } = node;
|
|
79
|
-
if (!
|
|
80
|
-
|
|
33
|
+
if (!zodMiniImportScope.isAllowed(source.value)) return;
|
|
34
|
+
importGroups[source.value] ??= {
|
|
81
35
|
hasOnlyTypeImports: true,
|
|
82
36
|
nodes: []
|
|
83
37
|
};
|
|
@@ -9,16 +9,13 @@ const ZOD_OBJECT_METHODS = [
|
|
|
9
9
|
"strictObject"
|
|
10
10
|
];
|
|
11
11
|
const defaultOptions = { allow: ["object"] };
|
|
12
|
-
const {
|
|
12
|
+
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodMiniImportScope);
|
|
13
13
|
const consistentObjectSchemaType = require_create_plugin_rule.createZodMiniPluginRule({
|
|
14
14
|
name: "consistent-object-schema-type",
|
|
15
15
|
meta: {
|
|
16
16
|
hasSuggestions: true,
|
|
17
17
|
type: "suggestion",
|
|
18
|
-
docs: {
|
|
19
|
-
zodImportAllowedSource,
|
|
20
|
-
description: "Enforce consistent usage of Zod Mini schema methods"
|
|
21
|
-
},
|
|
18
|
+
docs: { description: "Enforce consistent usage of Zod Mini schema methods" },
|
|
22
19
|
messages: {
|
|
23
20
|
consistentMethod: "Inconsistent Zod Mini object schema method '{{actual}}'. Allowed: {{allowedList}}.",
|
|
24
21
|
useMethod: "Replace with '{{expected}}'."
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import { createZodSchemaImportTrack } from "@eslint-zod/utils";
|
|
2
|
+
import { createZodSchemaImportTrack, zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
4
|
//#region src/rules/consistent-object-schema-type.ts
|
|
5
5
|
const ZOD_OBJECT_METHODS = [
|
|
@@ -8,16 +8,13 @@ const ZOD_OBJECT_METHODS = [
|
|
|
8
8
|
"strictObject"
|
|
9
9
|
];
|
|
10
10
|
const defaultOptions = { allow: ["object"] };
|
|
11
|
-
const {
|
|
11
|
+
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodMiniImportScope);
|
|
12
12
|
const consistentObjectSchemaType = createZodMiniPluginRule({
|
|
13
13
|
name: "consistent-object-schema-type",
|
|
14
14
|
meta: {
|
|
15
15
|
hasSuggestions: true,
|
|
16
16
|
type: "suggestion",
|
|
17
|
-
docs: {
|
|
18
|
-
zodImportAllowedSource,
|
|
19
|
-
description: "Enforce consistent usage of Zod Mini schema methods"
|
|
20
|
-
},
|
|
17
|
+
docs: { description: "Enforce consistent usage of Zod Mini schema methods" },
|
|
21
18
|
messages: {
|
|
22
19
|
consistentMethod: "Inconsistent Zod Mini object schema method '{{actual}}'. Allowed: {{allowedList}}.",
|
|
23
20
|
useMethod: "Replace with '{{expected}}'."
|
|
@@ -4,16 +4,13 @@ let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
|
4
4
|
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
5
|
//#region src/rules/consistent-schema-output-type-style.ts
|
|
6
6
|
const ZOD_SCHEMA_TYPE_STYLES = ["infer", "output"];
|
|
7
|
-
const {
|
|
7
|
+
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodMiniImportScope);
|
|
8
8
|
const consistentSchemaOutputTypeStyle = require_create_plugin_rule.createZodMiniPluginRule({
|
|
9
9
|
name: "consistent-schema-output-type-style",
|
|
10
10
|
meta: {
|
|
11
11
|
type: "suggestion",
|
|
12
12
|
fixable: "code",
|
|
13
|
-
docs: {
|
|
14
|
-
zodImportAllowedSource,
|
|
15
|
-
description: "Enforce consistent use of z.infer or z.output for schema type inference"
|
|
16
|
-
},
|
|
13
|
+
docs: { description: "Enforce consistent use of z.infer or z.output for schema type inference" },
|
|
17
14
|
messages: {
|
|
18
15
|
useInfer: "Use infer instead of output.",
|
|
19
16
|
useOutput: "Use output instead of infer."
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import { createZodSchemaImportTrack } from "@eslint-zod/utils";
|
|
2
|
+
import { createZodSchemaImportTrack, zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
4
|
//#region src/rules/consistent-schema-output-type-style.ts
|
|
5
5
|
const ZOD_SCHEMA_TYPE_STYLES = ["infer", "output"];
|
|
6
|
-
const {
|
|
6
|
+
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodMiniImportScope);
|
|
7
7
|
const consistentSchemaOutputTypeStyle = createZodMiniPluginRule({
|
|
8
8
|
name: "consistent-schema-output-type-style",
|
|
9
9
|
meta: {
|
|
10
10
|
type: "suggestion",
|
|
11
11
|
fixable: "code",
|
|
12
|
-
docs: {
|
|
13
|
-
zodImportAllowedSource,
|
|
14
|
-
description: "Enforce consistent use of z.infer or z.output for schema type inference"
|
|
15
|
-
},
|
|
12
|
+
docs: { description: "Enforce consistent use of z.infer or z.output for schema type inference" },
|
|
16
13
|
messages: {
|
|
17
14
|
useInfer: "Use infer instead of output.",
|
|
18
15
|
useOutput: "Use output instead of infer."
|
|
@@ -3,15 +3,12 @@ const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
|
3
3
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
4
|
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
5
|
//#region src/rules/consistent-schema-var-name.ts
|
|
6
|
-
const {
|
|
6
|
+
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodMiniImportScope);
|
|
7
7
|
const consistentSchemaVarName = require_create_plugin_rule.createZodMiniPluginRule({
|
|
8
8
|
name: "consistent-schema-var-name",
|
|
9
9
|
meta: {
|
|
10
10
|
type: "suggestion",
|
|
11
|
-
docs: {
|
|
12
|
-
zodImportAllowedSource,
|
|
13
|
-
description: "Enforce a consistent naming convention for Zod Mini schema variables"
|
|
14
|
-
},
|
|
11
|
+
docs: { description: "Enforce a consistent naming convention for Zod Mini schema variables" },
|
|
15
12
|
messages: { invalidName: "Rename this Zod Mini schema to \"{{expected}}\"" },
|
|
16
13
|
schema: [{
|
|
17
14
|
type: "object",
|
|
@@ -37,26 +34,7 @@ const consistentSchemaVarName = require_create_plugin_rule.createZodMiniPluginRu
|
|
|
37
34
|
const initNode = node.init;
|
|
38
35
|
if (initNode?.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression || !detectZodSchemaRootNode(initNode)) return;
|
|
39
36
|
const chainMethods = collectZodChainMethods(initNode).map((it) => it.name);
|
|
40
|
-
if (
|
|
41
|
-
"parse",
|
|
42
|
-
"parseAsync",
|
|
43
|
-
"safeParse",
|
|
44
|
-
"safeParseAsync",
|
|
45
|
-
"spa",
|
|
46
|
-
"encode",
|
|
47
|
-
"encodeAsync",
|
|
48
|
-
"decode",
|
|
49
|
-
"decodeAsync",
|
|
50
|
-
"safeEncode",
|
|
51
|
-
"safeEncodeAsync",
|
|
52
|
-
"safeDecode",
|
|
53
|
-
"safeDecodeAsync",
|
|
54
|
-
"codec",
|
|
55
|
-
"treeifyError",
|
|
56
|
-
"prettifyError",
|
|
57
|
-
"formatError",
|
|
58
|
-
"flattenError"
|
|
59
|
-
].some((it) => chainMethods.includes(it))) return;
|
|
37
|
+
if (_eslint_zod_utils.ZOD_NON_SCHEMA_PRODUCING_METHODS.some((it) => chainMethods.includes(it))) return;
|
|
60
38
|
if (node.id.type !== _typescript_eslint_utils.AST_NODE_TYPES.Identifier) return;
|
|
61
39
|
const { name } = node.id;
|
|
62
40
|
const validPrefix = !before || name.startsWith(before);
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
-
import { createZodSchemaImportTrack } from "@eslint-zod/utils";
|
|
2
|
+
import { ZOD_NON_SCHEMA_PRODUCING_METHODS, createZodSchemaImportTrack, zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
4
|
//#region src/rules/consistent-schema-var-name.ts
|
|
5
|
-
const {
|
|
5
|
+
const { trackZodSchemaImports } = createZodSchemaImportTrack(zodMiniImportScope);
|
|
6
6
|
const consistentSchemaVarName = createZodMiniPluginRule({
|
|
7
7
|
name: "consistent-schema-var-name",
|
|
8
8
|
meta: {
|
|
9
9
|
type: "suggestion",
|
|
10
|
-
docs: {
|
|
11
|
-
zodImportAllowedSource,
|
|
12
|
-
description: "Enforce a consistent naming convention for Zod Mini schema variables"
|
|
13
|
-
},
|
|
10
|
+
docs: { description: "Enforce a consistent naming convention for Zod Mini schema variables" },
|
|
14
11
|
messages: { invalidName: "Rename this Zod Mini schema to \"{{expected}}\"" },
|
|
15
12
|
schema: [{
|
|
16
13
|
type: "object",
|
|
@@ -36,26 +33,7 @@ const consistentSchemaVarName = createZodMiniPluginRule({
|
|
|
36
33
|
const initNode = node.init;
|
|
37
34
|
if (initNode?.type !== AST_NODE_TYPES.CallExpression || !detectZodSchemaRootNode(initNode)) return;
|
|
38
35
|
const chainMethods = collectZodChainMethods(initNode).map((it) => it.name);
|
|
39
|
-
if (
|
|
40
|
-
"parse",
|
|
41
|
-
"parseAsync",
|
|
42
|
-
"safeParse",
|
|
43
|
-
"safeParseAsync",
|
|
44
|
-
"spa",
|
|
45
|
-
"encode",
|
|
46
|
-
"encodeAsync",
|
|
47
|
-
"decode",
|
|
48
|
-
"decodeAsync",
|
|
49
|
-
"safeEncode",
|
|
50
|
-
"safeEncodeAsync",
|
|
51
|
-
"safeDecode",
|
|
52
|
-
"safeDecodeAsync",
|
|
53
|
-
"codec",
|
|
54
|
-
"treeifyError",
|
|
55
|
-
"prettifyError",
|
|
56
|
-
"formatError",
|
|
57
|
-
"flattenError"
|
|
58
|
-
].some((it) => chainMethods.includes(it))) return;
|
|
36
|
+
if (ZOD_NON_SCHEMA_PRODUCING_METHODS.some((it) => chainMethods.includes(it))) return;
|
|
59
37
|
if (node.id.type !== AST_NODE_TYPES.Identifier) return;
|
|
60
38
|
const { name } = node.id;
|
|
61
39
|
const validPrefix = !before || name.startsWith(before);
|
|
@@ -3,16 +3,13 @@ const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
|
3
3
|
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
4
4
|
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
5
5
|
//#region src/rules/no-any-schema.ts
|
|
6
|
-
const {
|
|
6
|
+
const { trackZodSchemaImports } = (0, _eslint_zod_utils.createZodSchemaImportTrack)(_eslint_zod_utils.zodMiniImportScope);
|
|
7
7
|
const noAnySchema = require_create_plugin_rule.createZodMiniPluginRule({
|
|
8
8
|
name: "no-any-schema",
|
|
9
9
|
meta: {
|
|
10
10
|
hasSuggestions: true,
|
|
11
11
|
type: "suggestion",
|
|
12
|
-
docs: {
|
|
13
|
-
zodImportAllowedSource,
|
|
14
|
-
description: "Disallow usage of `z.any()` in Zod Mini schemas"
|
|
15
|
-
},
|
|
12
|
+
docs: { description: "Disallow usage of `z.any()` in Zod Mini schemas" },
|
|
16
13
|
messages: {
|
|
17
14
|
noZAny: "Using `z.any()` is not allowed. Please use a more specific schema.",
|
|
18
15
|
useUnknown: "Replace `z.any()` with `z.unknown()`"
|