1 import { createRule } from "../../create-rule"
2 import {
3 createWorkflowSdkBindings,
4 isInTransformCallback,
5 trackWorkflowSdkImports,
6 } from "../../util/workflow-scope"
7
8 type MessageIds = "throwInTransform"
9
10 export const rule = createRule<[], MessageIds>({
11 name: "no-throw-in-transform",
12 meta: {
13 type: "problem",
14 docs: {
15 description:
16 "Disallow `throw` statements inside a `transform()` callback. Use a validation step or `when-then` instead.",
17 },
18 messages: {
19 throwInTransform:
20 "Do not throw inside a `transform()` callback — transform runs at workflow-definition time and its errors don't surface as workflow failures. Create a validation step or use `when-then` to gate the work.",
21 },
22 schema: [],
23 },
24 defaultOptions: [],
25 create(context) {
26 const bindings = createWorkflowSdkBindings()
27
28 return {
29 ImportDeclaration(node) {
30 trackWorkflowSdkImports(node, bindings)
31 },
32
33 ThrowStatement(node) {
34 if (bindings.transform.size === 0) {
35 return
36 }
37 if (!isInTransformCallback(node, bindings)) {
38 return
39 }
40 context.report({
41 node,
42 messageId: "throwInTransform",
43 })
44 },
45 }
46 },
47 })
48
49 export default rule