eslint-plugin-zod 1.2.0 → 1.3.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 CHANGED
@@ -66,5 +66,13 @@ _The `--fix` option on the command line automatically fixes problems reported by
66
66
 
67
67
  Requires that objects are initialized with `.strict()`.
68
68
 
69
+ <a name="user-content-eslint-plugin-zod-rules-require-strict-options"></a>
70
+ <a name="eslint-plugin-zod-rules-require-strict-options"></a>
71
+ #### Options
72
+
73
+ |configuration|format|default|description|
74
+ |---|---|---|---|
75
+ |`allowPassthrough`|boolean|`true`|Ignores objects explicitly set to `allowPassthrough()`.|
76
+
69
77
 
70
78
 
@@ -12,7 +12,12 @@ declare const _default: {
12
12
  fixable: string;
13
13
  schema: {
14
14
  additionalProperties: boolean;
15
- properties: {};
15
+ properties: {
16
+ allowPassthrough: {
17
+ default: boolean;
18
+ type: string;
19
+ };
20
+ };
16
21
  type: string;
17
22
  }[];
18
23
  type: string;
@@ -10,7 +10,12 @@ declare const _default: {
10
10
  fixable: string;
11
11
  schema: {
12
12
  additionalProperties: boolean;
13
- properties: {};
13
+ properties: {
14
+ allowPassthrough: {
15
+ default: boolean;
16
+ type: string;
17
+ };
18
+ };
14
19
  type: string;
15
20
  }[];
16
21
  type: string;
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
+ const defaultOptions = {
3
+ allowPassthrough: true,
4
+ };
2
5
  const create = (context) => {
3
6
  return {
4
7
  CallExpression(node) {
5
- var _a, _b, _c, _d, _e, _f, _g;
8
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
9
  if (((_a = node.callee.object) === null || _a === void 0 ? void 0 : _a.name) !== 'z') {
7
10
  return;
8
11
  }
9
12
  if (node.callee.property.name !== 'object') {
10
13
  return;
11
14
  }
15
+ const { allowPassthrough, } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : defaultOptions;
12
16
  if (!node.parent.property) {
13
17
  context.report({
14
18
  fix: (fixer) => {
@@ -20,9 +24,16 @@ const create = (context) => {
20
24
  }
21
25
  else if (
22
26
  // z.object().strict()
23
- ((_c = (_b = node.parent) === null || _b === void 0 ? void 0 : _b.property) === null || _c === void 0 ? void 0 : _c.name) !== 'strict' &&
27
+ ((_d = (_c = node.parent) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.name) !== 'strict' &&
24
28
  // z.object().merge().strict()
25
- ((_g = (_f = (_e = (_d = node.parent) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.parent) === null || _f === void 0 ? void 0 : _f.property) === null || _g === void 0 ? void 0 : _g.name) !== '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
+ }
26
37
  // As far as I can think, in cases where the property name is not-strict,
27
38
  // e.g. passthrough, we should not add a strict() call.
28
39
  context.report({
@@ -44,7 +55,12 @@ module.exports = {
44
55
  schema: [
45
56
  {
46
57
  additionalProperties: false,
47
- properties: {},
58
+ properties: {
59
+ allowPassthrough: {
60
+ default: true,
61
+ type: 'boolean',
62
+ },
63
+ },
48
64
  type: 'object',
49
65
  },
50
66
  ],
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "lint": "eslint ./src ./test && tsc --noEmit",
47
47
  "test": "mocha --require tsx test/**/*"
48
48
  },
49
- "version": "1.2.0"
49
+ "version": "1.3.0"
50
50
  }