8000 Use the safe navigation operator by jcoyne · Pull Request #3545 · projectblacklight/blacklight · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use the safe navigation operator #3545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -532,20 +532,6 @@ Style/RescueStandardError:
- 'lib/blacklight/configuration/fields.rb'
- 'lib/railties/blacklight.rake'

# Offense count: 11
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'app/controllers/concerns/blacklight/bookmarks.rb'
- 'app/controllers/concerns/blacklight/controller.rb'
- 'app/services/blacklight/field_retriever.rb'
- 'lib/blacklight.rb'
- 'lib/blacklight/configuration/facet_field.rb'
- 'lib/blacklight/configuration/search_field.rb'
- 'lib/blacklight/solr/search_builder_behavior.rb'

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowAsExpressionSeparator.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def destroy

success = @bookmarks.all? do |bookmark|
bookmark = current_or_guest_user.bookmarks.find_by(bookmark)
bookmark && bookmark.delete && bookmark.destroyed?
bookmark&.delete && bookmark.destroyed?
end

if success
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def access_denied
# send the user home if the access was previously denied by the same
# request to avoid sending the user back to the login page
# (e.g. protected page -> logout -> returned to protected page -> home)
redirect_to(root_url) && flash.discard && return if request.referer && request.referer.ends_with?(request.fullpath)
redirect_to(root_url) && flash.discard && return if request.referer&.ends_with?(request.fullpath)

redirect_to(root_url) && return unless has_user_authentication_provider?

Expand Down
2 changes: 1 addition & 1 deletion app/services/blacklight/field_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def fetch

def retrieve_simple
# regular document field
if field_config.default && field_config.default.is_a?(Proc)
if field_config.default.is_a?(Proc)
document.fetch(field_config.field, &field_config.default)
else
document.fetch(field_config.field, field_config.default)
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def self.blacklight_yml?
end

def self.logger
@logger ||= (::Rails.logger if defined? Rails && Rails.respond_to?(:logger))
@logger ||= ::Rails.logger
end

def self.logger= logger
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/facet_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Configuration::FacetField < Blacklight::Configuration::Field

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def normalize! blacklight_config = nil
query.stringify_keys! if query
query&.stringify_keys!

normalize_pivot_config! if pivot
self.collapse = true if collapse.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/search_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def normalize! blacklight_config = nil
self.if = include_in_simple_select if self.if.nil?

super
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config&.default_solr_params

self
end
Expand Down
20 changes: 9 additions & 11 deletions lib/blacklight/solr/search_builder_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ def add_facetting_to_solr(solr_parameters)
solr_parameters[:"f.#{facet.field}.facet.sort"] = facet.sort
end

if facet.solr_params
facet.solr_params.each do |k, v|
solr_parameters[:"f.#{facet.field}.#{k}"] = v
end
facet.solr_params&.each do |k, v|
solr_parameters[:"f.#{facet.field}.#{k}"] = v
end

limit = facet_limit_with_pagination(field_name)
Expand All @@ -203,9 +201,9 @@ def add_facetting_to_solr(solr_parameters)

def add_solr_fields_to_query solr_parameters
blacklight_config.show_fields.select(&method(:should_add_field_to_request?)).each_value do |field|
field.solr_params.each do |k, v|
field.solr_params&.each do |k, v|
solr_parameters[:"f.#{field.field}.#{k}"] = v
end if field.solr_params
end
end

blacklight_config.index_fields.select(&method(:should_add_field_to_request?)).each_value do |field|
Expand All @@ -214,9 +212,9 @@ def add_solr_fields_to_query solr_parameters
solr_parameters.append_highlight_field field.field
end

field.solr_params.each do |k, v|
field.solr_params&.each do |k, v|
solr_parameters[:"f.#{field.field}.#{k}"] = v
end if field.solr_params
end
end
end

Expand Down Expand Up @@ -350,9 +348,9 @@ def facet_value_to_fq_string(facet_field, value, use_local_params: true)
solr_field ||= facet_field

local_params = []
local_params << "tag=#{facet_config.tag}" if use_local_params && facet_config && facet_config.tag
local_params << "tag=#{facet_config.tag}" if use_local_params && facet_config&.tag

if facet_config && facet_config.query
if facet_config&.query
if facet_config.query[value]
facet_config.query[value][:fq]
else
Expand Down Expand Up @@ -380,7 +378,7 @@ def facet_inclusive_value_to_fq_string(facet_field, values)
facet_config = blacklight_config.facet_fields[facet_field]

local_params = []
local_params << "tag=#{facet_config.tag}" if facet_config && facet_config.tag
local_params << "tag=#{facet_config.tag}" if facet_config&.tag

solr_filters = values.each_with_object({}).with_index do |(v, h), index|
h["f_inclusive.#{facet_field}.#{index}"] = facet_value_to_fq_string(facet_field, v, use_local_params: false)
Expand Down
0