feat(lint): db-call-in-loop rule + loop_depth on call records#63
Merged
smochan merged 1 commit intoJun 10, 2026
Merged
Conversation
Parser changes: - typescript.py _collect_calls: stack entries now carry loop_depth; for_statement/for_in_statement/while_statement/do_statement children get depth+1; .map/.forEach/.filter/.reduce/.flatMap function-typed argument children also get depth+1; CALLS edge metadata gains loop_depth and in_loop fields. - python.py _collect_calls: same depth-threading for for_statement and while_statement; stop-at-nested-defs behaviour preserved. Lint changes: - analysis/lint.py: new _check_db_call_in_loop checker fires when ctx.loop_depth >= 1 and the call chain matches the per-language DB pattern (TS: db/database.select|insert|..., Python: session/cursor/db.query|execute|...). New _iter_children_with_depth helper extends the lint DFS to bump depth inside .forEach/.map/etc callbacks. Registered in _CHECK_REGISTRY; added to DEFAULT_LINT_RULES with severity high. Fixtures & tests: - tests/fixtures/lint_sample/src/loops.ts: for...of + .forEach cases that fire, plus a non-loop counterexample that must not. - tests/fixtures/lint_sample/src/batch.py: Python for-loop case that fires and a non-loop counterexample. - tests/fixtures/df0_typescript/loop_calls.ts: small fixture for parser metadata assertions. - tests/test_lint.py: 8 new tests covering TS for-of, forEach callback, Python for-loop, non-loop negative, severity, and message content. - tests/test_lint_cli.py: updated --fail-on gate test to account for new high-severity findings in the shared fixture. - tests/test_df0_typescript.py: 3 new tests asserting loop_depth/in_loop metadata on CALLS edges. - tests/test_df0_python.py: 4 new tests for Python loop depth threading including nested loops.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #62. Phase 1 continues (gap-analysis findings #8/#10 — N+1 / DB-call-in-loop):
typescript.py,python.py):_collect_callsDFS now carriesloop_depth; CALLS edge metadata gainsloop_depth/in_loop. TS also treats function args to.map/.forEach/.filter/.reduce/.flatMapas implicit loop bodies.db.select|insert|update|delete|execute|query; Pysession|cursor|db . query|execute|add|commit) flagged whenloop_depth >= 1.getUsers().map(cb)— fixed + regression test.Implemented by a Sonnet subagent against a Fable-authored spec; reviewed, corrected, and verified by the orchestrating session.
Test plan
🤖 Generated with Claude Code