Skip to content

MONGOID-5931 Remove dead and unreachable code - #6164

Merged
jamis merged 1 commit into
mongodb:masterfrom
jamis:5931-dead-code
Jul 9, 2026
Merged

MONGOID-5931 Remove dead and unreachable code#6164
jamis merged 1 commit into
mongodb:masterfrom
jamis:5931-dead-code

Conversation

@jamis

@jamis jamis commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

MONGOID-5931: audit the codebase for dead and unreachable code and remove/refactor/document each site.

I ran three detection passes:

  • RuboCop lint cops (Lint/UnreachableCode, UselessAssignment, UnusedMethodArgument, UselessMethodDefinition, etc.) — zero offenses across all files.
  • debride — 312 flagged methods, which a grep/AST caller cross-reference (against both lib/ and spec/) narrowed to 5 non-public zero-caller candidates. All 5 were false positives: the _dependent_*! methods in association/depending.rb are dispatched via send("_dependent_#{dependent}!", ...).
  • Version/capability guard sweep — checked RUBY_VERSION, BSON::VERSION, and driver-version guards against the gemspec minimums.

The main outcome is that the codebase is largely free of dead code. The one genuine site was an obsolete driver-version guard.

Changes

  • clients/factory.rb: removed the if (driver_version <=> [2, 13]) >= 0 guard. The gemspec requires mongo >= 2.18.0, so this is always true; the body now runs unconditionally. The driver_version helper (its only caller) is removed.
  • config.rb: documented that DeprecatedOptions::OPTIONS is intentionally empty when no options are deprecated, so the inert-looking module reads as deliberate scaffolding.

Reviewed and intentionally left in place

  • config.rb RUBY_VERSION < '3.2' and < '3.0' guards — reachable under supported Ruby (gemspec requires >= 2.7).
  • config.rb BSON::VERSION >= '5.0.0' guard — both bson 4 and 5 are supported at runtime.

Testing

spec/mongoid/clients/factory_spec.rb and spec/mongoid/config_spec.rb pass against a local replica set (313 examples, 0 failures; 4 pending are libmongocrypt-gated and unrelated). RuboCop is clean.

…atedOptions

Audited the codebase for dead and unreachable code using RuboCop lint
cops, debride, and a grep/AST caller cross-reference. The codebase is
largely free of dead code; the one genuine site was an obsolete guard.

- clients/factory.rb: drop the `driver_version <=> [2, 13]` guard, which
  is always true now that the gemspec requires mongo >= 2.18.0, and
  remove the now-unused driver_version helper.
- config.rb: document that DeprecatedOptions::OPTIONS is intentionally
  empty when no options are deprecated.
@jamis
jamis requested a review from a team as a code owner July 8, 2026 16:39
@jamis
jamis requested review from comandeo-mongo and Copilot July 8, 2026 16:39

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

Removes an obsolete, always-true MongoDB driver version guard in the client factory and documents intentional “empty scaffolding” in configuration, as part of auditing Mongoid for dead/unreachable code.

Changes:

  • Removed the driver_version helper and the mongo driver >= 2.13 conditional in Mongoid::Clients::Factory#options, making wrapping-library tagging run unconditionally.
  • Added clarifying documentation to Mongoid::Config::DeprecatedOptions explaining why OPTIONS may be empty.

Reviewed changes

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

File Description
lib/mongoid/clients/factory.rb Removes an obsolete driver-version gate and simplifies wrapping-library option construction.
lib/mongoid/config.rb Documents that DeprecatedOptions::OPTIONS can be intentionally empty when no options are deprecated.

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

@jamis
jamis merged commit 416ae7e into mongodb:master Jul 9, 2026
76 checks passed
@jamis
jamis deleted the 5931-dead-code branch July 9, 2026 15:27
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.

3 participants