@sarj/eslint-plugin 4.1.0 → 5.0.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 +27 -3
- package/dist/index.cjs +1503 -644
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -26
- package/dist/index.d.ts +60 -26
- package/dist/index.js +1709 -847
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -168,7 +189,7 @@ and every repo gets to name its own.
|
|
|
168
189
|
|
|
169
190
|
| Rule | Option | Default | Effect |
|
|
170
191
|
|---|---|---|---|
|
|
171
|
-
| `no-raw-fetch-outside-clients` | `allow` | client/
|
|
192
|
+
| `no-raw-fetch-outside-clients` | `allow` | client / vendor-wrapper path patterns | Extra files exempt from the "no bare `fetch`" rule (test files are exempt unconditionally) |
|
|
172
193
|
| `no-dynamic-sql` | `methods` | `["prepare", "exec", "query"]` | Statement-taking methods to inspect |
|
|
173
194
|
| `no-storage-in-stateless-modules` | `modules` | `[]` (rule off) | Directories declared stateless |
|
|
174
195
|
| `no-storage-in-stateless-modules` | `methods` | `["prepare", "put", "getWithMetadata"]` | Storage methods to flag |
|
|
@@ -177,7 +198,10 @@ and every repo gets to name its own.
|
|
|
177
198
|
|
|
178
199
|
The path options on the first three rules are **regular-expression sources
|
|
179
200
|
matched against the absolute filename**, not globs — so they can express both
|
|
180
|
-
path separators.
|
|
201
|
+
path separators. Test files no longer need to appear there: the rule delegates
|
|
202
|
+
to the shared `isTestFile` predicate, so supplying `allow` replaces only the
|
|
203
|
+
production exemptions and cannot accidentally un-exempt a test tree.
|
|
204
|
+
`allowIn` is the exception, on `no-hand-rolled-sleep` as on
|
|
181
205
|
`require-fetch-timeout`: it takes minimatch-ish **globs**, also matched against
|
|
182
206
|
the absolute path, so anchor them with a `**/` prefix. Supplying an option
|
|
183
207
|
**replaces** the default rather than extending it.
|
|
@@ -198,7 +222,7 @@ export default [
|
|
|
198
222
|
// This repo keeps its HTTP layer in `lib/api/`, not `clients/`.
|
|
199
223
|
"@sarj/no-raw-fetch-outside-clients": [
|
|
200
224
|
"error",
|
|
201
|
-
{ allow: ["[\\\\/]lib[\\\\/]api[\\\\/]"
|
|
225
|
+
{ allow: ["[\\\\/]lib[\\\\/]api[\\\\/]"] },
|
|
202
226
|
],
|
|
203
227
|
// Declare which modules must stay stateless.
|
|
204
228
|
"@sarj/no-storage-in-stateless-modules": [
|