eslint-plugin-zod-v4 0.1.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 +21 -0
- package/README.md +250 -0
- package/dist/index.cjs +12515 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +175 -0
- package/dist/index.d.ts +175 -0
- package/dist/index.js +12493 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Matheus Pimenta - Koda AI Studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# eslint-plugin-zod-v4
|
|
2
|
+
|
|
3
|
+
ESLint plugin for Zod v4 best practices and migration from v3.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/eslint-plugin-zod-v4)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Detects deprecated Zod v3 patterns that break in v4
|
|
11
|
+
- Enforces Zod v4 best practices
|
|
12
|
+
- Auto-fix support for most rules
|
|
13
|
+
- Educational error messages explaining the correct approach
|
|
14
|
+
- Full ESLint 9+ flat config support
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install --save-dev eslint-plugin-zod-v4
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- ESLint >= 9.0.0
|
|
25
|
+
- Node.js >= 18.18.0
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### ESLint 9+ (Flat Config)
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
// eslint.config.js
|
|
33
|
+
import zodPlugin from "eslint-plugin-zod-v4"
|
|
34
|
+
|
|
35
|
+
export default [
|
|
36
|
+
// Use recommended config (breaking changes only)
|
|
37
|
+
zodPlugin.configs.recommended,
|
|
38
|
+
|
|
39
|
+
// Or use strict config (recommended + best practices)
|
|
40
|
+
// zodPlugin.configs.strict,
|
|
41
|
+
|
|
42
|
+
// Or configure rules manually
|
|
43
|
+
{
|
|
44
|
+
plugins: {
|
|
45
|
+
"zod-v4": zodPlugin,
|
|
46
|
+
},
|
|
47
|
+
rules: {
|
|
48
|
+
"zod-v4/no-deprecated-string-format": "error",
|
|
49
|
+
"zod-v4/prefer-safeParse": "warn",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Configs
|
|
56
|
+
|
|
57
|
+
| Config | Description |
|
|
58
|
+
|--------|-------------|
|
|
59
|
+
| `recommended` | Breaking changes only (errors). Use to catch code that will break in Zod v4. |
|
|
60
|
+
| `strict` | Recommended + best practices (warnings). Enforces optimal Zod v4 patterns. |
|
|
61
|
+
| `all` | All rules enabled as errors. Maximum strictness. |
|
|
62
|
+
|
|
63
|
+
## Rules
|
|
64
|
+
|
|
65
|
+
### Breaking Changes (severity: error)
|
|
66
|
+
|
|
67
|
+
These rules detect Zod v3 patterns that will break in v4.
|
|
68
|
+
|
|
69
|
+
| Rule | Description | Fixable |
|
|
70
|
+
|------|-------------|---------|
|
|
71
|
+
| [no-deprecated-string-format](docs/rules/no-deprecated-string-format.md) | Disallow `z.string().email()` etc. Use `z.email()` instead. | Yes |
|
|
72
|
+
| [no-record-single-arg](docs/rules/no-record-single-arg.md) | Require `z.record(keySchema, valueSchema)` with two arguments. | No |
|
|
73
|
+
| [no-deprecated-error-params](docs/rules/no-deprecated-error-params.md) | Disallow `invalid_type_error`/`required_error`. Use `error` param. | Yes |
|
|
74
|
+
| [no-deprecated-format-methods](docs/rules/no-deprecated-format-methods.md) | Disallow `.format()`/`.flatten()` on ZodError. Use `z.treeifyError()`. | No |
|
|
75
|
+
| [no-merge-method](docs/rules/no-merge-method.md) | Disallow `.merge()`. Use `.extend()` instead. | No |
|
|
76
|
+
| [no-superrefine](docs/rules/no-superrefine.md) | Disallow `.superRefine()`. Use `.check()` instead. | No |
|
|
77
|
+
| [no-errors-property](docs/rules/no-errors-property.md) | Disallow `error.errors`. Use `error.issues` instead. | Yes |
|
|
78
|
+
| [no-deprecated-object-methods](docs/rules/no-deprecated-object-methods.md) | Disallow `.strict()`/`.passthrough()`/`.strip()`. Use top-level functions. | No |
|
|
79
|
+
| [no-native-enum](docs/rules/no-native-enum.md) | Disallow `z.nativeEnum()`. Use `z.enum()` instead. | No |
|
|
80
|
+
| [no-deep-partial](docs/rules/no-deep-partial.md) | Disallow `.deepPartial()` (removed in v4). | No |
|
|
81
|
+
| [no-deprecated-ip-methods](docs/rules/no-deprecated-ip-methods.md) | Disallow `.ip()`/`.cidr()`. Use `.ipv4()`/`.ipv6()` variants. | No |
|
|
82
|
+
| [no-promise-schema](docs/rules/no-promise-schema.md) | Disallow `z.promise()`. Await before parsing. | No |
|
|
83
|
+
|
|
84
|
+
### Best Practices (severity: warn)
|
|
85
|
+
|
|
86
|
+
These rules enforce Zod v4 best practices for optimal code quality.
|
|
87
|
+
|
|
88
|
+
| Rule | Description | Fixable |
|
|
89
|
+
|------|-------------|---------|
|
|
90
|
+
| [prefer-safeParse](docs/rules/prefer-safeParse.md) | Prefer `.safeParse()` over `.parse()` for explicit error handling. | Yes |
|
|
91
|
+
| [no-schema-in-render](docs/rules/no-schema-in-render.md) | Disallow creating schemas inside functions/components. | No |
|
|
92
|
+
| [prefer-error-param](docs/rules/prefer-error-param.md) | Prefer `error` param over deprecated `message` param. | Yes |
|
|
93
|
+
|
|
94
|
+
## Migration Guide
|
|
95
|
+
|
|
96
|
+
### From Zod v3 to v4
|
|
97
|
+
|
|
98
|
+
#### 1. String Format Methods
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Before (deprecated)
|
|
102
|
+
z.string().email()
|
|
103
|
+
z.string().url()
|
|
104
|
+
z.string().uuid()
|
|
105
|
+
|
|
106
|
+
// After (v4)
|
|
107
|
+
z.email()
|
|
108
|
+
z.url()
|
|
109
|
+
z.uuid()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### 2. Record Schema
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
// Before (v3 - single argument)
|
|
116
|
+
z.record(z.string())
|
|
117
|
+
|
|
118
|
+
// After (v4 - two arguments)
|
|
119
|
+
z.record(z.string(), z.string())
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### 3. Error Parameters
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
// Before (deprecated)
|
|
126
|
+
z.string({ invalid_type_error: "Must be string", required_error: "Required" })
|
|
127
|
+
|
|
128
|
+
// After (v4)
|
|
129
|
+
z.string({ error: "Must be string" })
|
|
130
|
+
// Or with function
|
|
131
|
+
z.string({ error: (iss) => `Error: ${iss.code}` })
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### 4. ZodError Methods
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// Before (deprecated)
|
|
138
|
+
error.format()
|
|
139
|
+
error.flatten()
|
|
140
|
+
|
|
141
|
+
// After (v4)
|
|
142
|
+
z.treeifyError(error)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### 5. ZodError Property
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// Before (v3)
|
|
149
|
+
error.errors
|
|
150
|
+
|
|
151
|
+
// After (v4)
|
|
152
|
+
error.issues
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### 6. Schema Merging
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
// Before (deprecated)
|
|
159
|
+
schema1.merge(schema2)
|
|
160
|
+
|
|
161
|
+
// After (v4)
|
|
162
|
+
schema1.extend(schema2.shape)
|
|
163
|
+
// Or
|
|
164
|
+
z.object({ ...schema1.shape, ...schema2.shape })
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### 7. Super Refine
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
// Before (deprecated)
|
|
171
|
+
schema.superRefine((val, ctx) => {
|
|
172
|
+
if (!isValid(val)) {
|
|
173
|
+
ctx.addIssue({ code: "custom", message: "Invalid" })
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// After (v4)
|
|
178
|
+
schema.check((val) => isValid(val) || "Invalid")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### 8. Object Methods
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
// Before (deprecated)
|
|
185
|
+
z.object({ name: z.string() }).strict()
|
|
186
|
+
z.object({ name: z.string() }).passthrough()
|
|
187
|
+
|
|
188
|
+
// After (v4)
|
|
189
|
+
z.strictObject({ name: z.string() })
|
|
190
|
+
z.looseObject({ name: z.string() })
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### 9. Native Enums
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
// Before (deprecated)
|
|
197
|
+
z.nativeEnum(MyEnum)
|
|
198
|
+
|
|
199
|
+
// After (v4)
|
|
200
|
+
z.enum(MyEnum) // z.enum() now supports native enums
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### 10. IP and CIDR Validation
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
// Before (removed)
|
|
207
|
+
z.string().ip()
|
|
208
|
+
z.string().cidr()
|
|
209
|
+
|
|
210
|
+
// After (v4)
|
|
211
|
+
z.ipv4() // or z.ipv6()
|
|
212
|
+
z.cidrv4() // or z.cidrv6()
|
|
213
|
+
z.union([z.ipv4(), z.ipv6()]) // for both
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### 11. Promise Schema
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
// Before (deprecated)
|
|
220
|
+
z.promise(z.string())
|
|
221
|
+
|
|
222
|
+
// After (v4)
|
|
223
|
+
const data = await fetchData()
|
|
224
|
+
schema.parse(data) // await before parsing
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### 12. Deep Partial
|
|
228
|
+
|
|
229
|
+
```javascript
|
|
230
|
+
// Before (removed)
|
|
231
|
+
schema.deepPartial()
|
|
232
|
+
|
|
233
|
+
// After (v4)
|
|
234
|
+
schema.partial() // shallow only
|
|
235
|
+
// For deep partial, manually create nested partial schemas
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Contributing
|
|
239
|
+
|
|
240
|
+
Contributions are welcome! Please read our contributing guidelines before submitting a PR.
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
245
|
+
|
|
246
|
+
## Author
|
|
247
|
+
|
|
248
|
+
**Matheus Pimenta** - [Koda AI Studio](https://kodaai.app)
|
|
249
|
+
|
|
250
|
+
Built with Claude Code.
|