eslint-plugin-zod-mini 1.1.1 → 1.2.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/README.md +17 -15
- package/dist/index.cjs +5 -0
- package/dist/index.mjs +5 -0
- package/dist/rules/no-throw-in-refine.cjs +17 -0
- package/dist/rules/no-throw-in-refine.mjs +17 -0
- package/dist/rules/no-transform-in-record-key.cjs +29 -0
- package/dist/rules/no-transform-in-record-key.mjs +29 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,21 +31,23 @@ Find out more about [Oxlint's `jsPLugins`](https://oxc.rs/docs/guide/usage/linte
|
|
|
31
31
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
32
32
|
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
|
33
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-
|
|
44
|
-
| [
|
|
45
|
-
| [
|
|
46
|
-
| [
|
|
47
|
-
| [
|
|
48
|
-
| [
|
|
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-throw-in-refine](docs/rules/no-throw-in-refine.md) | Disallow throwing errors directly inside Zod Mini refine callbacks | ✅ | | |
|
|
44
|
+
| [no-transform-in-record-key](docs/rules/no-transform-in-record-key.md) | Disallow transforms in z.record() key schemas, which can cause silent key mutations and data loss through key collisions | | | |
|
|
45
|
+
| [no-unknown-schema](docs/rules/no-unknown-schema.md) | Disallow usage of `z.unknown()` in Zod Mini schemas | | | |
|
|
46
|
+
| [prefer-enum-over-literal-union](docs/rules/prefer-enum-over-literal-union.md) | Prefer `z.enum()` over `z.union()` when all members are string literals. | ✅ | 🔧 | |
|
|
47
|
+
| [prefer-meta](docs/rules/prefer-meta.md) | Enforce usage of `z.meta()` over `z.describe()` | ✅ | 🔧 | |
|
|
48
|
+
| [require-brand-type-parameter](docs/rules/require-brand-type-parameter.md) | Require type parameter on `.brand()` functions | ✅ | | 💡 |
|
|
49
|
+
| [require-error-message](docs/rules/require-error-message.md) | Enforce that custom refinements include an error message | ✅ | 🔧 | |
|
|
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) | | | |
|
|
49
51
|
|
|
50
52
|
<!-- end auto-generated rules list -->
|
|
51
53
|
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ const require_consistent_schema_output_type_style = require("./rules/consistent-
|
|
|
6
6
|
const require_consistent_schema_var_name = require("./rules/consistent-schema-var-name.cjs");
|
|
7
7
|
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
|
+
const require_no_throw_in_refine = require("./rules/no-throw-in-refine.cjs");
|
|
10
|
+
const require_no_transform_in_record_key = require("./rules/no-transform-in-record-key.cjs");
|
|
9
11
|
const require_no_unknown_schema = require("./rules/no-unknown-schema.cjs");
|
|
10
12
|
const require_prefer_enum_over_literal_union = require("./rules/prefer-enum-over-literal-union.cjs");
|
|
11
13
|
const require_prefer_meta = require("./rules/prefer-meta.cjs");
|
|
@@ -26,6 +28,8 @@ const eslintPluginZodMini = {
|
|
|
26
28
|
"consistent-schema-var-name": require_consistent_schema_var_name.consistentSchemaVarName,
|
|
27
29
|
"no-any-schema": require_no_any_schema.noAnySchema,
|
|
28
30
|
"no-empty-custom-schema": require_no_empty_custom_schema.noEmptyCustomSchema,
|
|
31
|
+
"no-throw-in-refine": require_no_throw_in_refine.noThrowInRefine,
|
|
32
|
+
"no-transform-in-record-key": require_no_transform_in_record_key.noTransformInRecordKey,
|
|
29
33
|
"no-unknown-schema": require_no_unknown_schema.noUnknownSchema,
|
|
30
34
|
"prefer-enum-over-literal-union": require_prefer_enum_over_literal_union.preferEnumOverLiteralUnion,
|
|
31
35
|
"prefer-meta": require_prefer_meta.preferMeta,
|
|
@@ -43,6 +47,7 @@ const recommendedConfig = {
|
|
|
43
47
|
"zod-mini/consistent-schema-var-name": "error",
|
|
44
48
|
"zod-mini/no-any-schema": "error",
|
|
45
49
|
"zod-mini/no-empty-custom-schema": "error",
|
|
50
|
+
"zod-mini/no-throw-in-refine": "error",
|
|
46
51
|
"zod-mini/prefer-enum-over-literal-union": "error",
|
|
47
52
|
"zod-mini/prefer-meta": "error",
|
|
48
53
|
"zod-mini/require-brand-type-parameter": "error",
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import { consistentSchemaOutputTypeStyle } from "./rules/consistent-schema-outpu
|
|
|
6
6
|
import { consistentSchemaVarName } from "./rules/consistent-schema-var-name.mjs";
|
|
7
7
|
import { noAnySchema } from "./rules/no-any-schema.mjs";
|
|
8
8
|
import { noEmptyCustomSchema } from "./rules/no-empty-custom-schema.mjs";
|
|
9
|
+
import { noThrowInRefine } from "./rules/no-throw-in-refine.mjs";
|
|
10
|
+
import { noTransformInRecordKey } from "./rules/no-transform-in-record-key.mjs";
|
|
9
11
|
import { noUnknownSchema } from "./rules/no-unknown-schema.mjs";
|
|
10
12
|
import { preferEnumOverLiteralUnion } from "./rules/prefer-enum-over-literal-union.mjs";
|
|
11
13
|
import { preferMeta } from "./rules/prefer-meta.mjs";
|
|
@@ -26,6 +28,8 @@ const eslintPluginZodMini = {
|
|
|
26
28
|
"consistent-schema-var-name": consistentSchemaVarName,
|
|
27
29
|
"no-any-schema": noAnySchema,
|
|
28
30
|
"no-empty-custom-schema": noEmptyCustomSchema,
|
|
31
|
+
"no-throw-in-refine": noThrowInRefine,
|
|
32
|
+
"no-transform-in-record-key": noTransformInRecordKey,
|
|
29
33
|
"no-unknown-schema": noUnknownSchema,
|
|
30
34
|
"prefer-enum-over-literal-union": preferEnumOverLiteralUnion,
|
|
31
35
|
"prefer-meta": preferMeta,
|
|
@@ -43,6 +47,7 @@ const recommendedConfig = {
|
|
|
43
47
|
"zod-mini/consistent-schema-var-name": "error",
|
|
44
48
|
"zod-mini/no-any-schema": "error",
|
|
45
49
|
"zod-mini/no-empty-custom-schema": "error",
|
|
50
|
+
"zod-mini/no-throw-in-refine": "error",
|
|
46
51
|
"zod-mini/prefer-enum-over-literal-union": "error",
|
|
47
52
|
"zod-mini/prefer-meta": "error",
|
|
48
53
|
"zod-mini/require-brand-type-parameter": "error",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
3
|
+
let _eslint_zod_utils_rule_builders_no_throw_in_refine = require("@eslint-zod/utils/rule-builders/no-throw-in-refine");
|
|
4
|
+
//#region src/rules/no-throw-in-refine.ts
|
|
5
|
+
const noThrowInRefine = require_create_plugin_rule.createZodMiniPluginRule({
|
|
6
|
+
name: "no-throw-in-refine",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: "Disallow throwing errors directly inside Zod Mini refine callbacks" },
|
|
10
|
+
messages: { noThrowInRefine: "Do not throw errors directly inside a z.refine callback." },
|
|
11
|
+
schema: []
|
|
12
|
+
},
|
|
13
|
+
defaultOptions: [],
|
|
14
|
+
create: (0, _eslint_zod_utils_rule_builders_no_throw_in_refine.buildNoThrowInRefineCreate)(_eslint_zod_utils.zodMiniImportScope)
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.noThrowInRefine = noThrowInRefine;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { buildNoThrowInRefineCreate } from "@eslint-zod/utils/rule-builders/no-throw-in-refine";
|
|
4
|
+
//#region src/rules/no-throw-in-refine.ts
|
|
5
|
+
const noThrowInRefine = createZodMiniPluginRule({
|
|
6
|
+
name: "no-throw-in-refine",
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: "Disallow throwing errors directly inside Zod Mini refine callbacks" },
|
|
10
|
+
messages: { noThrowInRefine: "Do not throw errors directly inside a z.refine callback." },
|
|
11
|
+
schema: []
|
|
12
|
+
},
|
|
13
|
+
defaultOptions: [],
|
|
14
|
+
create: buildNoThrowInRefineCreate(zodMiniImportScope)
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { noThrowInRefine };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_create_plugin_rule = require("../utils/create-plugin-rule.cjs");
|
|
2
|
+
let _eslint_zod_utils = require("@eslint-zod/utils");
|
|
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
|
+
//#region src/rules/no-transform-in-record-key.ts
|
|
6
|
+
const noTransformInRecordKey = require_create_plugin_rule.createZodMiniPluginRule({
|
|
7
|
+
name: "no-transform-in-record-key",
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: { description: "Disallow transforms in z.record() key schemas, which can cause silent key mutations and data loss through key collisions" },
|
|
11
|
+
messages: { noTransformInRecordKey: "Transforms in z.record() key schemas cause silent key mutation and potential data loss. Use validators like z.minLength() instead of mutating checks like z.trim() or z.toLowerCase()." },
|
|
12
|
+
schema: []
|
|
13
|
+
},
|
|
14
|
+
defaultOptions: [],
|
|
15
|
+
create: (0, _eslint_zod_utils_rule_builders_no_transform_in_record_key.buildNoTransformInRecordKeyCreate)(_eslint_zod_utils.zodMiniImportScope, { findTransformNode(keySchema, { detectZodSchemaRootNode, collectZodChainMethods }) {
|
|
16
|
+
if (keySchema.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) return null;
|
|
17
|
+
for (const method of collectZodChainMethods(keySchema)) {
|
|
18
|
+
if (method.name !== "check") continue;
|
|
19
|
+
for (const argument of method.node.arguments) {
|
|
20
|
+
if (argument.type !== _typescript_eslint_utils.AST_NODE_TYPES.CallExpression) continue;
|
|
21
|
+
const zodCheck = detectZodSchemaRootNode(argument);
|
|
22
|
+
if (zodCheck && _eslint_zod_utils.ZOD_MUTATING_CHECK_NAMES.includes(zodCheck.schemaType)) return argument;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
} })
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.noTransformInRecordKey = noTransformInRecordKey;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createZodMiniPluginRule } from "../utils/create-plugin-rule.mjs";
|
|
2
|
+
import { ZOD_MUTATING_CHECK_NAMES, zodMiniImportScope } from "@eslint-zod/utils";
|
|
3
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
4
|
+
import { buildNoTransformInRecordKeyCreate } from "@eslint-zod/utils/rule-builders/no-transform-in-record-key";
|
|
5
|
+
//#region src/rules/no-transform-in-record-key.ts
|
|
6
|
+
const noTransformInRecordKey = createZodMiniPluginRule({
|
|
7
|
+
name: "no-transform-in-record-key",
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: { description: "Disallow transforms in z.record() key schemas, which can cause silent key mutations and data loss through key collisions" },
|
|
11
|
+
messages: { noTransformInRecordKey: "Transforms in z.record() key schemas cause silent key mutation and potential data loss. Use validators like z.minLength() instead of mutating checks like z.trim() or z.toLowerCase()." },
|
|
12
|
+
schema: []
|
|
13
|
+
},
|
|
14
|
+
defaultOptions: [],
|
|
15
|
+
create: buildNoTransformInRecordKeyCreate(zodMiniImportScope, { findTransformNode(keySchema, { detectZodSchemaRootNode, collectZodChainMethods }) {
|
|
16
|
+
if (keySchema.type !== AST_NODE_TYPES.CallExpression) return null;
|
|
17
|
+
for (const method of collectZodChainMethods(keySchema)) {
|
|
18
|
+
if (method.name !== "check") continue;
|
|
19
|
+
for (const argument of method.node.arguments) {
|
|
20
|
+
if (argument.type !== AST_NODE_TYPES.CallExpression) continue;
|
|
21
|
+
const zodCheck = detectZodSchemaRootNode(argument);
|
|
22
|
+
if (zodCheck && ZOD_MUTATING_CHECK_NAMES.includes(zodCheck.schemaType)) return argument;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
} })
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
export { noTransformInRecordKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zod-mini",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "ESLint plugin that adds custom linting rules to enforce best practices when using Zod Mini",
|
|
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.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@marcalexiei/prettier-config": "2.0.0",
|