Skip to content

RUBY-3914 Fix multiple excluded cops#3081

Open
jamis wants to merge 14 commits into
mongodb:masterfrom
jamis:3914-multiple-cops
Open

RUBY-3914 Fix multiple excluded cops#3081
jamis wants to merge 14 commits into
mongodb:masterfrom
jamis:3914-multiple-cops

Conversation

@jamis

@jamis jamis commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Each of the following cops were being excluded by our rubocop todo file. Each had only a single recorded violation, so this PR tackles them all in one batch.

  • Lint/MixedRegexpCaptureTypes
  • Lint/NonLocalExitFromIterator
  • Lint/RedundantSafeNavigation
  • Style/CommentedKeyword
  • Style/GuardClause
  • Style/InfiniteLoop
  • Style/ItAssignment
  • Style/MapJoin
  • Style/MixinUsage
  • Style/OpenStructUse
  • Style/ReduceToHash
  • Style/RedundantCondition
  • Style/SelectByRegexp

jamis added 14 commits July 10, 2026 10:43
Make the unused version-suffix group non-capturing so the regex no
longer mixes named and numbered captures.
Use next instead of return when skipping an unsupported URI option, so
the iterator continues processing the remaining options instead of
returning early from smc_to_ruby.
Use a plain call for is_a?, which already handles nil receivers, so the
safe navigation operator is redundant.
The excluded file was deleted as dead code in RUBY-3814, so the todo
entry no longer refers to anything.
Replace the unless-wrapped raise in validate_same_origin! with a guard
clause, extracting the domain match condition into a local variable for
readability.
Use Kernel#loop instead of while true in run_state_machine.
Rename the block parameter from it to doc to avoid shadowing the default
block parameter name.
Drop the redundant map(&:to_s) before join, which already stringifies
each element.
Include Mongo explicitly into Object instead of using a bare top-level
include, keeping the namespace constants available unqualified in the
console.
Replace OpenStruct with a keyword-initialized Struct for background
thread records.
Build the filter hash with to_h instead of each_with_object.
Use || to select the with_transaction deadline instead of an if/else
that returns the condition value in one branch.
Use grep_v to exclude the mongos-unpin fixture instead of reject with a
regexp match.
Copilot AI review requested due to automatic review settings July 10, 2026 17:04
@jamis jamis requested a review from a team as a code owner July 10, 2026 17:04
@jamis jamis requested a review from comandeo-mongo July 10, 2026 17:04

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

This PR removes a set of one-off RuboCop cop exclusions by fixing the underlying single offenses across the driver codebase and test suite, allowing .rubocop_todo.yml to be simplified.

Changes:

  • Replace/adjust a handful of Ruby constructs to satisfy RuboCop style/lint cops (e.g., OpenStructStruct, while trueloop do, guard clauses, safer iterator control flow).
  • Modernize some collection operations in specs (e.g., grep_v, to_h) and minor variable naming cleanups.
  • Remove the corresponding cop exclusion entries from .rubocop_todo.yml.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/support/background_thread_registry.rb Removes OpenStruct usage by introducing a small Struct record.
spec/spec_tests/transactions_unified_spec.rb Uses grep_v to exclude a specific YAML test file more idiomatically.
spec/runners/crud/requirement.rb Simplifies topology formatting by relying on Array#join coercion.
spec/mongo/monitoring/command_log_subscriber_spec.rb Refactors hash construction to to_h with a block.
spec/integration/cursor_pinning_spec.rb Avoids it block variable assignment to satisfy style cop.
lib/mongo/uri/options_mapper.rb Replaces return inside an iterator with next; removes redundant safe navigation.
lib/mongo/srv/result.rb Refactors conditional into a guard-clause-style return/raise flow.
lib/mongo/session.rb Simplifies deadline selection logic for with_transaction.
lib/mongo/crypt/context.rb Replaces while true with loop do.
lib/mongo/crypt/binding.rb Fixes regex capture grouping to avoid mixed capture types.
bin/mongo_console Changes how Mongo is mixed in so constants are available without qualification.
.rubocop_todo.yml Removes exclusions for the addressed cops.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants