a84da2a61e
- Added astCondition to rule frontmatter parsing and rule metadata, with AST-grep normalization. - Updated TTSR bucketing so astCondition-only rules are treated as interruptible matches. - Added ts-redundant-clear-guard as a built-in JS/TS tool rule for guarded clear* calls. - Added AST snapshot matching in agent sessions with per-stream cache throttling and cleanup.
2.8 KiB
2.8 KiB
description, scope, interruptMode, astCondition
| description | scope | interruptMode | astCondition | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Do not guard clearTimeout/clearInterval/clearImmediate with a truthiness or null/undefined check — they accept null and undefined | tool:edit(*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}), tool:write(*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}) | never |
|
Do not guard clearTimeout / clearInterval / clearImmediate with a truthiness or null/undefined check. Per the WHATWG/Node timers spec these functions are no-ops when handed null, undefined, or any value that doesn't correspond to a live timer. The guard adds a redundant branch that the reader must still reason about.
Why it's wrong
- The branch can never change behavior — clearing a missing/
null/undefinedhandle does nothing. - Extra branches inflate the code and hide the one line that matters.
- It signals a misunderstanding of the timer API to future readers.
Avoid
if (this.timer) clearTimeout(this.timer);
if (handle !== null) clearInterval(handle);
if (id != undefined) {
clearImmediate(id);
}
Use
clearTimeout(this.timer);
clearInterval(handle);
clearImmediate(id);
When a guard is warranted
Keep the check only when the body does more than clear — e.g. it also reassigns the handle or runs other cleanup:
if (this.timer) {
clearTimeout(this.timer);
this.timer = undefined; // extra work → guard is not purely redundant
}
This rule only fires when the clear call is the sole statement in the guarded branch, so those legitimate cases are left alone.