Skip to content

Enable RuboCop ambiguity rules - #3725

Merged
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-rubocop-ambiguity
Aug 16, 2026
Merged

Enable RuboCop ambiguity rules#3725
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-rubocop-ambiguity

Conversation

@kpumuk

@kpumuk kpumuk commented Aug 16, 2026

Copy link
Copy Markdown
Member

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.

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Client: rb

Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Copilot AI lite review requested due to automatic review settings August 16, 2026 20:19
@mergeable mergeable Bot added the ruby Pull requests that update Ruby code label Aug 16, 2026

Copilot AI 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.

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. Use and_wrap_original to 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.

Comment thread lib/rb/spec/socket_spec_shared.rb
@kpumuk
kpumuk merged commit 796b756 into apache:master Aug 16, 2026
94 of 95 checks passed
@kpumuk
kpumuk deleted the rb-rubocop-ambiguity branch August 16, 2026 23:28
@kpumuk kpumuk mentioned this pull request Aug 16, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants