Repository navigation
feat(rules): add C# review rules - #1840
Conversation
Fixes alibaba#1612 Signed-off-by: Abhishek Sharma <[email protected]>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
Thanks for adding dedicated C# review rules. The mapping and regression tests look sound, and the focused scope makes sense.
After reviewing the rule text against Microsoft's official C#/.NET documentation, I found two areas where a small wording adjustment could help avoid false-positive findings:
-
Resource ownership and disposal (
csharp.md, L10–L12): The current wording doesn't explicitly account for DI-managed dependencies or transferred ownership. In ASP.NET Core, a service receiving a scopedDbContextshouldn't dispose it itself. Also, an owning type may legitimately implement onlyIAsyncDisposable, without implementingIDisposable.I suggest limiting missing-disposal findings to resources actually owned by the code under review, and recognizing
IDisposable,IAsyncDisposable, and explicit ownership transfer as valid lifetime-management mechanisms. -
Mutable structs (
csharp.md, L30): Copying and independently mutating a value-type instance is normal C# behavior and doesn't necessarily indicate a defect. This rule would be more precise if it required evidence that value copying or defensive copies cause unintended behavior or lost mutations, rather than treating mutability itself as sufficient.
These are rule-precision suggestions
Narrow two rules so they do not fire on correct code: - disposal now applies only to resources the reviewed code owns, so an injected scoped DbContext the container disposes is not a finding, and IAsyncDisposable alone is accepted as a lifetime mechanism - the mutable-struct rule now needs evidence that copying loses a write, rather than treating mutability as sufficient Signed-off-by: Abhishek Sharma <[email protected]>
Both applied and pushed. Disposal now only covers resources this code owns, so a scoped DbContext the container injects and disposes isn't a finding any more. And a type needs either IDisposable or IAsyncDisposable, not specifically IDisposable — the old wording implied IAsyncDisposable alone wasn't enough. The mutable-struct rule now needs evidence that copying actually loses a write, through a readonly field, an in parameter, or an indexer returning a copy. Copying and mutating a value type on its own no longer gets reported. Thanks for the references, both were fair. |
wu21-web
left a comment
There was a problem hiding this comment.
When can people remember to update the documentation.
The rule table in review-rules.md documents path_rule_map in matching order, and the new **/*.cs entry was missing from it. Added in all five locales, immediately after the F# row, which is where it sits in system_rules.json. The F# addition in alibaba#1448 is the shape this follows: the rule doc, the map entry, the tests, and the same row in en, ja, ko, ru and zh. Signed-off-by: Abhishek Sharma <[email protected]>
|
Added the While checking things out, I cross-checked Opened #1857 with those eight rows plus a test that compares the map against every locale's table in both directions. If you revert the doc files, the test fails and calls out the exact missing patterns per locale. That seemed way better than just adding the rows and promising to remember next time — people forget, so the test handles it instead. One quick note on that PR: the non-English rows are mine and they're super basic and factual. If the Chinese wording sounds a bit weird, feel free to just overwrite it or let me know and I'll fix it. |
Description
.csand.vbare already in the extension allowlist, so C# files are reviewedtoday — but
path_rule_maphas no entry for them, so every C# file falls throughto
default.mdand gets the generic prompt. F# already hasfsharp.md, so .NETis half covered.
This adds
csharp.mdand maps**/*.csto it, in the same shape as the existinglanguage docs: a precision preamble that defers formatting to
dotnet formatandanalyzers, then six sections of defect classes that are specific to C# and likely
to change behaviour — nullability and the null-forgiving operator, disposal,
async/cancellation, LINQ deferred execution and multiple enumeration, equality
and value semantics, and interop/serialization/trust boundaries.
Scope note: I mapped only
**/*.cs..vbis in the allowlist too, but VB.NET isa different language and most of the examples here would not read correctly for
it, so I would rather leave it than map it to a doc written for C#. Happy to add
vbnet.mdseparately if you want it.Type of Change
How Has This Been Tested?
make testpasses locallygo test ./internal/config/...passes;go fmtandgo vetare clean.I checked the mapping is load-bearing rather than assuming it: removing the
**/*.csline makes the two new rows insystem_rules_test.gofail withResolve(...)returningdefault.md's "#### Correctness" text, which is exactlythe behaviour reported in #1612. It also trips the repo's own
TestSystemRulesIntegrity/no_orphan_files, which confirms doc and mapping stayconsistent.
Checklist
go fmt,go vet)AI/LLM disclosure: AI-assisted (Claude). I reviewed the rule content and ran the
tests myself.
Related Issues
Closes #1612
Note: PR #1616 attempted this and was closed on 2026-10-20 only because the CLA
was never signed, not on merit. I have signed it.