eslint-plugin-zod
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -15,3 +15,8 @@ declare const _default: { | ||
additionalProperties: boolean; | ||
properties: {}; | ||
properties: { | ||
allowPassthrough: { | ||
default: boolean; | ||
type: string; | ||
}; | ||
}; | ||
type: string; | ||
@@ -18,0 +23,0 @@ }[]; |
@@ -13,3 +13,8 @@ declare const _default: { | ||
additionalProperties: boolean; | ||
properties: {}; | ||
properties: { | ||
allowPassthrough: { | ||
default: boolean; | ||
type: string; | ||
}; | ||
}; | ||
type: string; | ||
@@ -16,0 +21,0 @@ }[]; |
"use strict"; | ||
const defaultOptions = { | ||
allowPassthrough: true, | ||
}; | ||
const create = (context) => { | ||
return { | ||
CallExpression(node) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
if (((_a = node.callee.object) === null || _a === void 0 ? void 0 : _a.name) !== 'z') { | ||
@@ -12,2 +15,3 @@ return; | ||
} | ||
const { allowPassthrough, } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : defaultOptions; | ||
if (!node.parent.property) { | ||
@@ -22,10 +26,14 @@ context.report({ | ||
} | ||
else if (((_c = (_b = node.parent) === null || _b === void 0 ? void 0 : _b.property) === null || _c === void 0 ? void 0 : _c.name) === 'and') { | ||
// Ignore .and() calls | ||
} | ||
else if ( | ||
// z.object().strict() | ||
((_e = (_d = node.parent) === null || _d === void 0 ? void 0 : _d.property) === null || _e === void 0 ? void 0 : _e.name) !== 'strict' && | ||
((_d = (_c = node.parent) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.name) !== 'strict' && | ||
// z.object().merge().strict() | ||
((_j = (_h = (_g = (_f = node.parent) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.parent) === null || _h === void 0 ? void 0 : _h.property) === null || _j === void 0 ? void 0 : _j.name) !== 'strict') { | ||
((_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') { | ||
if (((_k = (_j = node.parent) === null || _j === void 0 ? void 0 : _j.property) === null || _k === void 0 ? void 0 : _k.name) === 'passthrough' && allowPassthrough) { | ||
return; | ||
} | ||
if (((_m = (_l = node.parent) === null || _l === void 0 ? void 0 : _l.property) === null || _m === void 0 ? void 0 : _m.name) === 'and') { | ||
// Ignore .and() calls | ||
return; | ||
} | ||
// As far as I can think, in cases where the property name is not-strict, | ||
@@ -52,3 +60,8 @@ // e.g. passthrough, we should not add a strict() call. | ||
additionalProperties: false, | ||
properties: {}, | ||
properties: { | ||
allowPassthrough: { | ||
default: true, | ||
type: 'boolean', | ||
}, | ||
}, | ||
type: 'object', | ||
@@ -55,0 +68,0 @@ }, |
@@ -49,3 +49,3 @@ { | ||
}, | ||
"version": "1.2.1" | ||
"version": "1.3.0" | ||
} |
@@ -69,3 +69,11 @@ <a name="user-content-eslint-plugin-zod"></a> | ||
<a name="user-content-eslint-plugin-zod-rules-require-strict-options"></a> | ||
<a name="eslint-plugin-zod-rules-require-strict-options"></a> | ||
#### Options | ||
|configuration|format|default|description| | ||
|---|---|---|---| | ||
|`allowPassthrough`|boolean|`true`|Ignores objects explicitly set to `allowPassthrough()`.| | ||
10374
165
79