Skip to content

feat(rules): add Ruby review rules - #1940

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
mvanhorn:feat/ruby-review-rules
Nov 19, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
mvanhorn:feat/ruby-review-rules

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Description

.rb (and .rake / .gemspec) are already on the extension allowlist, so Ruby files are reviewed, but system_rules.json had no Ruby mapping. Those paths fell through to default.md.

This adds internal/config/rules/rule_docs/ruby.md and maps:

  • **/*.{rb,rake} → ruby.md
  • **/*.gemspec → ruby.md
  • **/{Gemfile,Rakefile} → ruby.md

**/*.erb is unchanged and still resolves to erb.md.

The Ruby rule is a precision-first language doc in the same shape as the other built-in language rules. It defers formatting and naming to RuboCop / standardrb, then covers defect classes that actually change behaviour: nil/false/Hash#[] vs fetch, frozen-string and argument mutation, broad rescue / ensure+return / unbounded retry, ActiveRecord N+1 / raw SQL / mass assignment / callbacks / update_column, send/eval/Marshal.load/YAML.load/html_safe/system, and class-level mutable state plus return in a Proc versus a lambda. It does not change shared review prompts.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing (describe below)

make test: 26 packages ok, 2735 --- PASS: lines, 0 --- FAIL: lines (LC_ALL=C go test -v -race -count=1).

go test ./internal/config/...: 5 packages ok (allowlist, rules, template, testconnection, toolsconfig).

make check: license-check, english-check, gofmt -s -w ., go vet — passed. gofmt -l . produced no paths. go vet ./internal/config/... clean.

make build produced ./dist/opencodereview.

Resolve rows added for app/models/user.rb, lib/tasks/cleanup.rake, mygem.gemspec, Gemfile, Rakefile, lib/Rakefile, and app/views/users/show.html.erb. Load-bearing check: the three Ruby path_rule_map entries were removed and TestResolve_DefaultRules failed on all six Ruby paths (they resolved to default.md Correctness); app/views/users/show.html.erb still passed on erb.md. Restoring the map made TestResolve_DefaultRules, TestSystemRulesIntegrity, and TestReviewRulesGuide* pass again.

Manual: binaries from upstream main (d77d70b) and this branch in a scratch repo.

/tmp/ocr-main rules check app/models/user.rb
# Source: System built-in
# Pattern: default

/tmp/ocr-ruby rules check app/models/user.rb
# Source: System built-in
# Pattern: **/*.{rb,rake}
# first heading: Nil, False, and Absent Values

/tmp/ocr-ruby rules check lib/tasks/cleanup.rake
# Pattern: **/*.{rb,rake}

/tmp/ocr-ruby rules check Gemfile
# Pattern: **/{Gemfile,Rakefile}

/tmp/ocr-ruby rules check app/views/users/show.html.erb
# Pattern: **/*.erb

/tmp/ocr-ruby review --preview
# Will review (4): Gemfile, app/models/user.rb, app/views/users/show.html.erb, lib/tasks/cleanup.rake

--preview lists files; it does not print the per-file rule body. Rule bodies were inspected with ocr rules check.

Not run: a live review that calls a model, make coverage, or a full Rails application beyond the four scratch paths.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI disclosure: written with AI assistance (Cursor, grok-4.6); the need, scope and review are mine.

Related Issues

No existing issue tracks Ruby-specific review rules.

Demo

demo

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@Walternater

Copy link
Copy Markdown
Contributor

Verified locally on 718c363 (macOS arm64, Go 1.26.10):

  • TMPDIR=/private/tmp go test ./internal/config/rules passes, including rule_docs_table_test — so the new mappings also match the generated tables in all five locale docs.
  • Built the CLI and ran ocr rules check against scratch files: app.rb, t.rake → **/*.{rb,rake} / ruby.md; foo.gemspec → **/*.gemspec / ruby.md; Gemfile, Rakefile → **/{Gemfile,Rakefile} / ruby.md; .erb still resolves to erb.md as described.
  • The rule body is picked up as system built-in text and the mapping order in system_rules.json is consistent with the docs table.

No issues from my side.

AI disclosure: verification drafted with DeepSeek Harness (deepseek-v4.1-flash); commands were run locally.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for going through the Gemfile, Rakefile and gemspec cases too, @Walternater.

@wu21-web wu21-web left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, but I think we can exclude some specs? I have some experience working with Homebrew, not much, but that are tests path that might follow a common pattern?

Merge when addressed.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @wu21-web. RSpec files are already skipped before rule lookup: default_exclude_patterns.json on main has **/*_spec.rb and **/spec/**/*_spec.rb, so Homebrew's Library/Homebrew/test/**/*_spec.rb never reaches ruby.md. This PR only changes which rule a reviewed file gets, not which files are reviewed.

What isn't excluded today is Minitest (test/**/*_test.rb) and spec helpers like spec/spec_helper.rb and spec/support/**. I can add **/*_test.rb to the exclude list here if you want it, or do it as a separate PR since it changes what gets reviewed.

@wu21-web

Copy link
Copy Markdown
Contributor

OK sure. I didn't see it in the diff, sorry!

🟡 Queued to merge.

There are 4 pull requests ahead of this submission.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 817ed02 into alibaba:main Nov 19, 2026
15 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101 thanks for taking the Ruby review rules. Ruby files, gemspecs, Gemfile and Rakefile now get their own precision-first rule doc.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

thanks for taking the Ruby review rules. Ruby files, gemspecs, Gemfile and Rakefile now get their own precision-first rule doc.

@mvanhorn Thanks for your contribution! This will be included in the next release, expected in the next few days.

We'll also be releasing a more powerful open-code-review skill that has been in beta testing for a month. Going forward, maintainers will be able to get a report that explains cross-file behavioral changes with traceable evidence, while still keeping the line-by-line review comments.

It is not just another summary of the comments, but an optional, independent investigation. It can surface changes that were missed by the standard review. By default, calling it won't trigger this investigation (it's opt-in).

@wu21-web

Copy link
Copy Markdown
Contributor

thanks for taking the Ruby review rules. Ruby files, gemspecs, Gemfile and Rakefile now get their own precision-first rule doc.

@mvanhorn Thanks for your contribution! This will be included in the next release, expected in the next few days.

We'll also be releasing a more powerful open-code-review skill that has been in beta testing for a month. Going forward, maintainers will be able to get a report that explains cross-file behavioral changes with traceable evidence, while still keeping the line-by-line review comments.

It is not just another summary of the comments, but an optional, independent investigation. It can surface changes that were missed by the standard review. By default, calling it won't trigger this investigation (it's opt-in).

Good to hear, let us put this in the Announcements.

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.

4 participants