Skip to content

fix(diagnostics): re-lint open files on each scan; read nested DOL007 loop heads - #118

Merged
FROWNINGdev merged 1 commit into
mainfrom
fix/schema-rules-cold-start-and-nested-loop-heads
Sep 27, 2026
Merged

FROWNINGdev merged 1 commit into
mainfrom
fix/schema-rules-cold-start-and-nested-loop-heads

Conversation

@FROWNINGdev

Copy link
Copy Markdown
Owner

Two gaps found while capturing a demo of 0.19.0 on a five-model shop project: stauts="paid" (DOL008) and order.customer.email inside a date-bounded loop (DOL007) were not flagged in the editor, while the CLI reported the N+1.

1. Schema-aware rules silent in files open at startup. Documents open at activation are linted before the first scan finishes, and nothing re-lints them once the index arrives. registerCodeFixes now takes an onIndexChanged event (fired from doScan) and re-lints every open document. This also carries a models.py edit into diagnostics of views already open.

2. DOL007 skipped common loop heads. RE_FOR_LOOP_HEAD accepted only flat argument lists and no call after the first, so filter(created__lte=timezone.now()) and filter(...).order_by("-id") never reached the rule. Replaced with a small balanced-paren parser over the call chain that skips string literals.

Tests: three new DOL007 cases (nested call, chained call, select_related later in the chain with a ) inside a string). Full suite: 257/257.

… loop heads

Files open when VS Code starts were linted before the first workspace scan
finished and never again, so DOL008 and the schema gates of DOL007 stayed
silent until the user typed in them; a models.py edit likewise never
reached views already open. registerCodeFixes now takes an index-changed
event and re-lints every open document when it fires.

DOL007's loop-head regex allowed only flat argument lists and no call after
the first, so for o in Order.objects.filter(created__lte=timezone.now()):
and for o in Order.objects.filter(...).order_by("-id"): were never
inspected. The head is now parsed with balanced parentheses across the
whole chain, skipping string literals.
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4772c20b-f861-40cd-a104-8bdd34be0452

📥 Commits

Reviewing files that changed from the base of the PR and between 7d5396d and cafa689.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • src/codeActionProvider.ts
  • src/extension.ts
  • src/rules/queryset.ts
  • test/rules/n-plus-one.test.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@FROWNINGdev
FROWNINGdev merged commit cf2ff9a into main Sep 27, 2026
18 of 19 checks passed
@FROWNINGdev
FROWNINGdev deleted the fix/schema-rules-cold-start-and-nested-loop-heads branch September 27, 2026 20:23
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.

1 participant