Skip to content

Rubocop: Fix Lint/SafeNavigationWithEmpty offenses#230

Merged
DemetrisChr merged 1 commit into
couchbase:mainfrom
DemetrisChr:rubocop-safe-navigation-with-empty
Jun 22, 2026
Merged

Rubocop: Fix Lint/SafeNavigationWithEmpty offenses#230
DemetrisChr merged 1 commit into
couchbase:mainfrom
DemetrisChr:rubocop-safe-navigation-with-empty

Conversation

@DemetrisChr

Copy link
Copy Markdown
Contributor
lib/couchbase/json_transcoder.rb:38:31: W: [Correctable] Lint/SafeNavigationWithEmpty: Avoid calling empty? with the safe navigation operator in conditionals.
      JSON.parse(blob) unless blob&.empty?
                              ^^^^^^^^^^^^
lib/couchbase/options.rb:119:16: W: [Correctable] Lint/SafeNavigationWithEmpty: Avoid calling empty? with the safe navigation operator in conditionals.
        unless @projections&.empty?
               ^^^^^^^^^^^^^^^^^^^^

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses RuboCop Lint/SafeNavigationWithEmpty offenses by removing &.empty? checks in conditionals, while preserving the intended behavior of options serialization and JSON transcoding. It also adds explicit test coverage for encoding/decoding JSON null.

Changes:

  • Replace &.empty? conditional checks in Options::Get with explicit nil/empty? guards.
  • Replace blob&.empty? check in JsonTranscoder#decode with a non-safe-navigation equivalent.
  • Add tests asserting nil encodes to "null" and "null" decodes to nil.

Reviewed changes

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

File Description
test/json_transcoder_test.rb Adds coverage for encoding nil and decoding JSON null.
lib/couchbase/options.rb Fixes projections-related conditional logic without safe-navigation empty? usage.
lib/couchbase/json_transcoder.rb Updates decode guard to avoid safe-navigation empty? in conditionals.

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

@DemetrisChr DemetrisChr force-pushed the rubocop-safe-navigation-with-empty branch from aea25f3 to 8b48a67 Compare June 22, 2026 10:53
@DemetrisChr DemetrisChr merged commit 399285e into couchbase:main Jun 22, 2026
120 of 124 checks passed
@DemetrisChr DemetrisChr deleted the rubocop-safe-navigation-with-empty branch June 22, 2026 15:47
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