feat(allowlist): add matlab support - #574
Conversation
|
✅ OpenCodeReview: No comments generated. Looks good to me. |
lizhengfeng101
left a comment
There was a problem hiding this comment.
Thanks for the contribution — the MATLAB rule doc itself is excellent and very thorough!
One concern before merging: the .m extension is shared between MATLAB and Objective-C. This PR maps all **/*.m files to matlab.md, which means Objective-C files (e.g. ios/ViewController.m, AppDelegate.m) will receive MATLAB-specific review feedback — clearly incorrect for those files.
The test change confirms this: ios/ViewController.m was removed from the "fallback to default" test because it now matches the MATLAB rule.
Possible approaches
-
Path-based heuristics — put ObjC-specific glob patterns (e.g.
**/{ios,macos,tvos,watchos,Pods,Classes}/**/*.m) before**/*.minsystem_rules.json, leveraging "first match wins" order. Downside: incomplete coverage, maintenance burden. -
Content-based detection — sniff the first line of the file (
function→ MATLAB,#import/#include→ ObjC). Downside: requires changes to theResolveinterface which currently only takes a path. -
Accept the limitation — document that
.mdefaults to MATLAB and ObjC projects should use a project-level.opencodereview/rule.jsonto override. Simplest, but shifts burden to ObjC users.
Minor formatting issues in system_rules.json
- Trailing space on the
"**/*.bicep": "bicep.md",line - The new
"**/*.m"entry uses a tab for indentation, while the rest of the file uses 4 spaces
Would love to hear your thoughts on how you'd like to handle the extension ambiguity. Happy to discuss further!
|
Dear @lizhengfeng101, I opted for Option Number 2, as this will ensure that it just works instead of anyone stumbling onto this in a few months. I added a mock objc.md for someone to fill at a later date (I don't know anything about objective c). The beahviour is documented in review_rules.md |
|
Dear @lizhengfeng101 |
|
@GenosseFlosse Thanks for adding MATLAB support — the rule doc is thorough and the test coverage looks solid! One architectural suggestion before we move forward: the current approach threads a A lighter-weight alternative would be a decorator/sniffer wrapper around the existing resolver:
This keeps the sniffing logic in one new file (~50 lines), avoids new interfaces ( Would you be open to restructuring along these lines? Happy to pair on it if that would help. Also, please rebase onto the latest |
|
@lizhengfeng101 Yes, good point, I am on it. And sure, I can rebase. |
.m is shared by MATLAB and Objective-C, so mapping **/*.m to matlab.md on path alone gives Objective-C files MATLAB-specific review guidance. Add matlab.md plus an objc.md placeholder, and decorate the system rule layer with a sniffer that peeks a .m file's first non-blank line, selecting objc.md when it looks like Objective-C (#import, @interface, ...). The sniffer wraps the *system layer* rather than the composed resolver: user layers (custom / project / global) must keep outranking it, including when a user rule sets merge_system_rule. Wrapping the outermost resolver would let the sniff discard a user's own .m rule. Content is read at the ref under review via `git show <ref>:<path>`, so the sniff is correct when that ref is not checked out; workspace reviews, scan, and `ocr rules check` pass no ref and read the working tree. Any read failure falls back to matlab.md, matching pre-sniff behavior. The Resolver interface is unchanged. The sniffer forwards ResolveDetail (so `ocr rules check` keeps working, annotating the pattern as "(sniffed: objc)") and CanonicalConfig with the objc rule folded in, so editing objc.md still invalidates the run manifest's rule_config_sha256. objc.md ships as a copy of default.md: it is selected by the sniff rather than from path_rule_map, so it is a neutral checklist to be filled in with Objective-C specifics later. Callers no longer lowercase paths before resolving: the resolver already lowercases internally for glob matching, and passing a pre-lowered path broke content reads for mixed-case paths.
|
Resolver is unchanged again; ContentAwareResolver, ContentAwareDetailResolver and the content parameter are all gone. Logic now is in one new file, internal/config/rules/sniffer.go. internal/delegate/rulegroup.go (and its test) and internal/agent/coverage_test.go are back to untouched. Production code outside internal/config/rules is now 46 changed lines across 7 files, six of them one-liners. Three notes on the implementation:
Also fixed a bug the new tests surfaced: callers passed strings.ToLower(path), which was harmless for glob matching but broke content reads for mixed-case paths. The resolver already lowercases internally, so I removed it at the call sites. Coverage went up — rules 85.8% → 88.2%, delegate 96.4% → 100%. make check and the full suite pass. One open question: I used a ResolverOptions struct rather than two more positional params on NewResolver. Happy to switch if you prefer. |
Description
Type of Change
How Has This Been Tested?
make testpasses locallyChecklist
go fmt,go vet)Related Issues