Commit efa419a
authored
feat(eslint-plugin): add no-closure-in-durable-operations rule (#252)
- Add new rule to detect and prevent closure variable mutations in
durable operations (step, runInChildContext, waitForCondition,
waitForCallback)
- Rule allows reading closure variables but prevents assignments and
updates (=, +=, ++, --)
- Recursively tracks variable declarations across nested scopes
- Reorganize rules into subdirectories with rule implementation and
tests co-located
- Add unit tests covering mutations, reads, and scope handling
- Update README with new rule documentation and examples
**Limitations**:
1. Object/Array Mutations: The rule only catches direct assignments and
update expressions but misses property mutations:
```
let obj = { count: 0 };
await context.step(async () => {
obj.count++; // ❌ Not detected but equally problematic
obj.items.push(1); // ❌ Not detected
});
```
2. Destructuring Assignments:
```
let a = 1, b = 2;
await context.step(async () => {
[a, b] = [b, a]; // ❌ Not detected
});
```
3. Performance Consideration: The walkNode function recursively
traverses the entire callback AST. For large callbacks, this could be
slow. I'll investigate ESLint's built-in visitor pattern instead of
manual traversal later.
5. Duplicate Error in Nested Cases: Nested operations report the error
twice (once for each level). This might be confusing to users - I'll
enhance it later to report at the innermost level.1 parent 14dca12 commit efa419a
File tree
11 files changed
+1893
-15
lines changed- packages/aws-durable-execution-sdk-js-eslint-plugin
- src
- rules
- no-closure-in-durable-operations
- no-nested-durable-operations
- no-non-deterministic-outside-step
11 files changed
+1893
-15
lines changedLines changed: 77 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
68 | 132 | | |
69 | 133 | | |
70 | 134 | | |
71 | 135 | | |
72 | 136 | | |
73 | | - | |
74 | | - | |
| 137 | + | |
75 | 138 | | |
| 139 | + | |
| 140 | + | |
76 | 141 | | |
77 | 142 | | |
78 | | - | |
79 | 143 | | |
80 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
81 | 147 | | |
82 | 148 | | |
83 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
84 | 156 | | |
85 | 157 | | |
86 | 158 | | |
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 5 | + | |
| 6 | + | |
11 | 7 | | |
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
0 commit comments