Skip to content

Lint/LiternalAsCondition false positive in case statement #14329

@jcoyne

Description

@jcoyne

Expected behavior

It should not detect any problem, because this is not a condition in the sense of an if/unless.

Actual behavior

Describe here what actually happened.

Offenses:

lib/blacklight.rb:32:48: W: Lint/LiteralAsCondition: Literal 'solr' appeared as a condition.
    case connection_config&.fetch(:adapter) || 'solr'

Steps to reproduce the problem

Error occurs on first line.

    case connection_config&.fetch(:adapter) || 'solr'
    when 'solr'
      Blacklight::Solr::Repository
    when /::/
      connection_config[:adapter].constantize
    else
      raise "The value for :adapter was not found in the blacklight.yml config" unless connection_config.key? :adapter

      Blacklight.const_get("#{connection_config.fetch(:adapter)}/Repository".classify)
    end

RuboCop version

bundle exec rubocop -V
1.76.2 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.2, running on ruby 3.4.1) [arm64-darwin24]
  - rubocop-capybara 2.22.1
  - rubocop-rspec 3.6.0
  - rubocop-rspec_rails 2.31.0
  - rubocop-rails 2.32.0
  - rubocop-factory_bot 2.27.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions