@sarj/eslint-plugin 4.1.0 → 4.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 CHANGED
@@ -105,6 +105,7 @@ Both distilled from two years of PR-review comments across ~1,065 PRs.
105
105
  |---|---|---|
106
106
  | `no-zod-native-enum` | `z.nativeEnum(...)` and `z.enum(SomeTsEnum)` — the schema-layer back door around `no-enum`. Autofixes an inline string-literal object to `z.enum([...])`. | warn / error |
107
107
  | `prefer-zod-enum` | `z.union([z.literal("a"), z.literal("b")])` — autofixes closed string choices to the shorter, equivalent `z.enum(["a", "b"])`. | warn / error |
108
+ | `prefer-zod-infer` | An `interface`/`type` that restates a Zod schema declared in the same module instead of deriving it with `z.infer`. Options: `ignoreTypeNames`, `requireIdenticalShape` (default `true`). | warn / error |
108
109
  | `prefer-module-level-constant` | A literal-only `const` collection (array, object, `Set`, `Map`, `Object.freeze`) or non-global regex declared inside a function body, never mutated and never escaping — hoist it to module scope. Options: `minElements` (default 3), `checkRegex`, `ignoreTestFiles`. | warn / error |
109
110
  | `prefer-non-nullable-collection` | An array type explicitly combined with `null`/`undefined`, creating two equivalent empty states. | warn / error |
110
111
 
@@ -146,6 +147,26 @@ already recognises. Set `"prefix"` or `"suffix"` to pin one:
146
147
  "@sarj/zod-naming-convention": ["error", { convention: "suffix" }]
147
148
  ```
148
149
 
150
+ ### `prefer-zod-infer`: `requireIdenticalShape` / `ignoreTypeNames`
151
+
152
+ By default the rule only reports a type whose members match its schema's keys
153
+ one for one — same names, same optionality, same nullability, no `.transform()`
154
+ anywhere in the pair. On a 30,759-file, 17-repo sweep that is 5 reports and 5
155
+ true positives. Drop the shape comparison to report on name correlation alone
156
+ (8 reports on the same corpus, 1 of them noise, and it catches twins that have
157
+ already drifted):
158
+
159
+ ```js
160
+ "@sarj/prefer-zod-infer": ["error", { requireIdenticalShape: false }]
161
+ ```
162
+
163
+ `ignoreTypeNames` takes regex sources matched against the declared type name,
164
+ for the pair that is genuinely meant to be maintained by hand:
165
+
166
+ ```js
167
+ "@sarj/prefer-zod-infer": ["error", { ignoreTypeNames: ["^LegacyUser$"] }]
168
+ ```
169
+
149
170
  ### `prefer-string-literal-union`: `ignoreFields`
150
171
 
151
172
  Field names whose value set is owned by a vendor and genuinely open (a Slack