Enable RuboCop ambiguity rules - #3725
Merged
Merged
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Enables RuboCop’s ambiguity-related cops for the Ruby codebase (lib/rb) and applies the corresponding autocorrections to make operator precedence and block association explicit (primarily via added parentheses / grouping).
Changes:
- Enabled RuboCop ambiguity cops (assignment, block association, operators/precedence, ranges, regexp literals, endless method definitions).
- Applied autocorrections across Ruby library code, benchmarks, and specs to add explicit grouping for potentially ambiguous expressions.
- Updated a few RSpec expectations to explicitly group matcher arguments to satisfy the new ambiguity cops.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/rb/.rubocop.yml | Enables RuboCop ambiguity cops and endless method ambiguity cop. |
| lib/rb/spec/socket_spec_shared.rb | Adjusts RSpec expect(...).to ... syntax for block association/ambiguity enforcement. |
| lib/rb/spec/serializer_spec.rb | Wraps raise_error matcher usage to make block association explicit. |
| lib/rb/spec/header_transport_spec.rb | Adds grouping around array arithmetic before pack to clarify precedence. |
| lib/rb/spec/binary_protocol_spec_shared.rb | Adds grouping around exponentiation/arithmetic to clarify precedence in boundary values. |
| lib/rb/lib/thrift/union.rb | Adds explicit grouping in == to make ` |
| lib/rb/lib/thrift/struct.rb | Adds grouping around arithmetic before bitmask to clarify evaluation order. |
| lib/rb/lib/thrift/struct_union.rb | Adds explicit grouping around concatenation before appending to map_buf. |
| lib/rb/lib/thrift/server/nonblocking_server.rb | Makes proc-to-block passing explicit with Thread.new(&shutdown_proc). |
| lib/rb/lib/thrift/protocol/compact_protocol.rb | Adds grouping around shift/or expressions for clarity and ambiguity-cop compliance. |
| lib/rb/lib/thrift/protocol/binary_protocol.rb | Adds grouping around exponentiation for max constant definitions. |
| lib/rb/benchmark/thin_server.rb | Adds grouping around addition before appending to seq. |
| lib/rb/benchmark/server.rb | Adds grouping around addition before appending to seq. |
Suppressed comments (1)
lib/rb/spec/socket_spec_shared.rb:132
- Same issue as above: using
.to(receive(...).once { ... })makes block ownership unclear and is inconsistent with other spec stubbing patterns. Useand_wrap_originalto attach the implementation block explicitly.
expect(IO).to(receive(:select).once { sleep(0.6); nil })
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable RuboCop's ambiguity cops for assignments, block association, operators, precedence, ranges, regular expressions, and endless method definitions.
The autocorrections add explicit grouping where Ruby's parse could otherwise be unclear, including mixed arithmetic and bitwise expressions, proc arguments, and RSpec matchers with blocks. These changes preserve behavior while making operator precedence and block ownership visible in the source.
This follows the merged spacing PR #3723; its diff contains only the ambiguity layer.
[skip ci]anywhere in the commit message to free up build resources.