Add option to merge system and user review rules#161
Conversation
|
✅ OpenCodeReview: No comments generated. Looks good to me. |
# Conflicts: # cmd/opencodereview/flags.go # cmd/opencodereview/flags_test.go
|
Thanks for the contribution! The merge behavior itself is a valid use case, but I think the approach could be improved. Adding Since this behavior is inherently tied to user rules, I'd suggest making it a rule-level configuration instead — a {
"rules": [
{
"path": "force-api/**/*.java",
"rule": "所有新方法必须对必填参数进行空值校验",
"merge_system_rule": true
}
]
}This way:
|
Great suggestion — I agree that moving this behavior into the rule configuration makes a lot more sense than exposing it as a CLI flag. Thanks for the detailed feedback. I’ll work on this and get it sorted out as soon as fast. Thanks! |
|
Hi, I’d like to confirm the intended matching semantics for user rule entries, especially for backward compatibility. In the previous implementation, when a rule entry matched the file path, the resolver returned that entry’s func matchProjectRule(pr *ProjectRule, path string) string {
if pr == nil {
return ""
}
lowerPath := strings.ToLower(path)
for _, entry := range pr.Rules {
expanded := expandBraces(entry.Path)
for _, p := range expanded {
// not check whether the entry's rule is empty, just return if matched
if matched, _ := doublestar.Match(strings.ToLower(p), lowerPath); matched {
return entry.Rule
}
}
}
return ""
}For example: {
"rules": [
{
"path": "internal/**/*.go",
"rule": ""
},
{
"path": "internal/config/**/*.go",
"rule": "Config code must validate default values."
}
]
}For the file
Could you confirm what the intended behavior should be? Should the resolver preserve the previous “first matched entry wins” behavior within the same rule file, even when the matched rule is empty? More generally, when a file matches multiple rules in the same JSON rule file, should the first matching rule always take precedence, or should the resolver continue looking for a later matching rule under some conditions, such as when the earlier rule has an empty I want to keep this change compatible with the existing rule priority semantics as much as possible. Looking forward to your reply. |
Summary
Adds a new
ocr review --merge-sys-ruleflag that keeps the matched built-in system rule when a custom, project, or global user rule also matches the reviewed file.By default, user rules continue to replace the matched system rule. When
--merge-sys-ruleis enabled, OCR merges both rule sources into the review checklist.Changes
--merge-sys-ruletoocr reviewResolverOptionsandNewResolverWithOptionsto configure resolver behavior without changing theResolverinterfaceBelow is what the rules look like after merging:
unit tests all pass:
