Skip to content

Conversation

@ParidelPooya
Copy link
Contributor

@ParidelPooya ParidelPooya commented Nov 12, 2025

  • 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
});
  1. Destructuring Assignments:
let a = 1, b = 2;
await context.step(async () => {
  [a, b] = [b, a]; // ❌ Not detected
});
  1. 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.

  2. 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.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ParidelPooya ParidelPooya force-pushed the feat/eslint-plugin-closure-rule branch from 13d2ad8 to b015e9a Compare November 12, 2025 05:53
…organize structure

- 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
- Supports function parameter overloads (function as 1st or 2nd parameter)
- Add comprehensive inline documentation with examples for better code readability
- Reorganize rules into subdirectories with rule implementation and tests co-located
- Add unit tests for all rules (34 tests total)
- Add integration tests using ESLint RuleTester with real TypeScript code (34 tests total)
- Fix duplicate error reporting by checking only assignment/update expressions
- Update README with new rule documentation and examples
- Total: 68 tests (34 unit + 34 integration)
@ParidelPooya ParidelPooya force-pushed the feat/eslint-plugin-closure-rule branch from b015e9a to 436fc3b Compare November 12, 2025 05:58
@ParidelPooya ParidelPooya merged commit efa419a into development Nov 12, 2025
11 of 13 checks passed
@ParidelPooya ParidelPooya deleted the feat/eslint-plugin-closure-rule branch November 12, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants