Skip to content

Commit f3aeba9

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
fix(core): require explicit Zod version imports
Mono-RevId: 6d4cc748ca1f7190f58e2983529b65d7326568af
1 parent 21146b1 commit f3aeba9

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎.oxlintrc.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"jsPlugins": [
88
"./oxlint-plugins/no-thrown-unawaited-redirect.mjs",
99
"./oxlint-plugins/runops-residency.mjs",
10-
"./oxlint-plugins/prisma-in-filter.mjs"
10+
"./oxlint-plugins/prisma-in-filter.mjs",
11+
"./oxlint-plugins/zod-imports.mjs"
1112
],
1213
"ignorePatterns": [
1314
"**/dist/**",
@@ -158,6 +159,12 @@
158159
"trigger-runops/no-control-plane-in-runops-slot": "error"
159160
}
160161
},
162+
{
163+
"files": ["packages/core/src/**/*.ts", "packages/core/src/**/*.tsx"],
164+
"rules": {
165+
"trigger-zod/require-versioned-import": "error"
166+
}
167+
},
161168
{
162169
"files": ["packages/react-hooks/src/**/*.ts", "packages/react-hooks/src/**/*.tsx"],
163170
"rules": {

‎oxlint-plugins/zod-imports.mjs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** @type {import("eslint").Rule.RuleModule} */
2+
const requireVersionedImport = {
3+
meta: {
4+
type: "problem",
5+
docs: {
6+
description:
7+
"Require an explicit Zod version import in packages that support multiple Zod major versions.",
8+
},
9+
fixable: "code",
10+
messages: {
11+
unversioned:
12+
'Import Zod 4 from "zod/v4" rather than "zod". The package supports Zod 3 and 4, so the bare import can resolve to the wrong major version.',
13+
},
14+
schema: [],
15+
},
16+
create(context) {
17+
function checkSource(node) {
18+
if (node.source?.value !== "zod") return;
19+
20+
context.report({
21+
node: node.source,
22+
messageId: "unversioned",
23+
fix: (fixer) => fixer.replaceText(node.source, '"zod/v4"'),
24+
});
25+
}
26+
27+
return {
28+
ImportDeclaration: checkSource,
29+
ExportAllDeclaration: checkSource,
30+
ExportNamedDeclaration: checkSource,
31+
};
32+
},
33+
};
34+
35+
/** @type {import("eslint").ESLint.Plugin} */
36+
const plugin = {
37+
meta: { name: "trigger-zod" },
38+
rules: {
39+
"require-versioned-import": requireVersionedImport,
40+
},
41+
};
42+
43+
export default plugin;

0 commit comments

Comments
 (0)