Skip to content
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

[7.x] Update rubocop and autocorrect #3122

Closed
wants to merge 1 commit into from
Closed
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
349 changes: 215 additions & 134 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/components/blacklight/document/thumbnail_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ThumbnailComponent < Blacklight::Component
# @param [Blacklight::DocumentPresenter] presenter
# @param [Integer] counter
# @param [Hash] image_options options for the thumbnail presenter's image tag
def initialize(presenter: nil, document: nil, counter:, image_options: {})
def initialize(counter:, presenter: nil, document: nil, image_options: {})
@presenter = presenter
@document = presenter&.document || document
@counter = counter
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/response/sort_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Response
class SortComponent < ViewComponent::Base
def initialize(param: 'sort', choices: {}, search_state:, id: 'sort-dropdown', classes: [], selected: nil)
def initialize(search_state:, param: 'sort', choices: {}, id: 'sort-dropdown', classes: [], selected: nil)
@param = param
@choices = choices
@search_state = search_state
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/response/view_type_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ViewTypeComponent < ViewComponent::Base
renders_many :views, 'Blacklight::Response::ViewTypeButtonComponent'

# @param [Blacklight::Response] response
def initialize(response:, views: {}, search_state:, selected: nil)
def initialize(response:, search_state:, views: {}, selected: nil)
@response = response
@views = views
@search_state = search_state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FlashMessageComponent < ViewComponent::Base

with_collection_parameter :message

def initialize(message: nil, type:)
def initialize(type:, message: nil)
@message = message
@classes = alert_class(type)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create
end

if request.xhr?
success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count } }) : render(json: current_or_guest_user.errors.full_messages, status: "500")
success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count } }) : render(json: current_or_guest_user.errors.full_messages, status: :internal_server_error)
else
if @bookmarks.any? && success
flash[:notice] = I18n.t('blacklight.bookmarks.add.success', count: @bookmarks.length)
Expand Down Expand Up @@ -119,7 +119,7 @@ def destroy
redirect_back fallback_location: bookmarks_path, notice: I18n.t('blacklight.bookmarks.remove.success')
end
elsif request.xhr?
head 500 # ajaxy request needs no redirect and should not have flash set
head :internal_server_error # ajaxy request needs no redirect and should not have flash set
else
redirect_back fallback_location: bookmarks_path, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') }
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def search_action_url options = {}
end

def search_action_path *args
if args.first.is_a? Hash
args.first[:only_path] = true if args.first[:only_path].nil?
if args.first.is_a?(Hash) && args.first[:only_path].nil?
args.first[:only_path] = true
end

search_action_url(*args)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def to_email_text(config = nil)
body << I18n.t('blacklight.email.text.language', value: semantics[:language].join(" ")) if semantics[:language].present?
end

return body.join("\n") unless body.empty?
body.join("\n") unless body.empty?
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/document/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def to_sms_text(config = nil)
body << I18n.t('blacklight.sms.text.author', value: semantics[:author].first) if semantics[:author].present?
end

return body.join unless body.empty?
body.join unless body.empty?
end
end
18 changes: 9 additions & 9 deletions app/models/record_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
class RecordMailer < ActionMailer::Base
def email_record(documents, details, url_gen_params)
title = begin
title_field = details[:config].email.title_field
if title_field
[documents.first[title_field]].flatten.first
else
documents.first.to_semantic_values[:title]
end
rescue
I18n.t('blacklight.email.text.default_title')
end
title_field = details[:config].email.title_field
if title_field
[documents.first[title_field]].flatten.first
else
documents.first.to_semantic_values[:title]
end
rescue
I18n.t('blacklight.email.text.default_title')
end

subject = I18n.t('blacklight.email.text.subject',
count: documents.length,
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/_document.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ xml.entry do
end

#If they asked for a format, give it to them.
if (params["content_format"] &&
document.export_formats[params["content_format"].to_sym])
if params["content_format"] &&
document.export_formats[params["content_format"].to_sym]

type = document.export_formats[params["content_format"].to_sym][:content_type]

Expand Down
4 changes: 1 addition & 3 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def self.blacklight_yml?
end

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

def self.logger= logger
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def templates

component_class.sidecar_files(extensions).each_with_object([]) do |path, memo|
pieces = File.basename(path).split(".")
app_path = "#{Rails.root}/#{path.slice(path.index(component_class.view_component_path)..-1)}"
app_path = "#{Rails.root.join("#{path.slice(path.index(component_class.view_component_path)..-1)}")}"

memo << {
path: File.exist?(app_path) ? app_path : path,
Expand Down
15 changes: 7 additions & 8 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,13 @@ def view_config(view_type = nil, action_name: :index)
view_type = nil
end

@view_config[[view_type, action_name]] ||= begin
if view_type.nil?
action_config(action_name)
else
base_config = action_config(action_name)
base_config.merge(view.fetch(view_type, {}))
end
end
@view_config[[view_type, action_name]] ||= if view_type.nil?
action_config(action_name)
else
base_config = action_config(action_name)
base_config.merge(view.fetch(view_type, {}))
end

end

# YARD will include inline disabling as docs, cannot do multiline inside @!macro. AND this must be separate from doc block.
Expand Down
3 changes: 1 addition & 2 deletions lib/blacklight/search_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class SearchState
extend Deprecation
include Blacklight::Deprecations::SearchStateNormalization

attr_reader :blacklight_config # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config.
attr_reader :params
attr_reader :blacklight_config, :params # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config.

# This method is never accessed in this class, but may be used by subclasses that need
# to access the url_helpers
Expand Down
6 changes: 3 additions & 3 deletions lib/blacklight/solr/response/pagination_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module Blacklight::Solr::Response::PaginationMethods
include Kaminari::PageScopeMethods
include Kaminari::ConfigurationMethods::ClassMethods

def limit_value #:nodoc:
def limit_value # :nodoc:
rows
end

def offset_value #:nodoc:
def offset_value # :nodoc:
start
end

def total_count #:nodoc:
def total_count # :nodoc:
total
end

Expand Down
8 changes: 4 additions & 4 deletions spec/features/search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def number_of_results_from_page(page)
tmp_value = Capybara.ignore_hidden_elements
Capybara.ignore_hidden_elements = false
val = begin
page.find("meta[name=totalResults]")['content'].to_i
rescue StandardError
0
end
page.find("meta[name=totalResults]")['content'].to_i
rescue StandardError
0
end
Capybara.ignore_hidden_elements = tmp_value
val
end
2 changes: 1 addition & 1 deletion spec/models/blacklight/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Child < Parent
instance.blacklight_config.bar << "123"
expect(instance.blacklight_config).not_to eq klass.blacklight_config
expect(klass.blacklight_config.foo).to eq "bar"
expect(instance.blacklight_config.foo).to eq "bar"
expect(instance.blacklight_config.foo).to eq "bar"
expect(klass.blacklight_config.bar).not_to include("123")
expect(instance.blacklight_config.bar).to include("asd", "123")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/solr/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@
describe 'the search field query_builder config' do
let(:blacklight_config) do
Blacklight::Configuration.new do |config|
config.add_search_field('built_query', query_builder: ->(builder, *_args) { [builder.blacklight_params[:q].reverse, qq1: 'xyz'] })
config.add_search_field('built_query', query_builder: ->(builder, *_args) { [builder.blacklight_params[:q].reverse, { qq1: 'xyz' }] })
end
end

Expand Down
6 changes: 2 additions & 4 deletions tasks/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def system_with_error_handling(*args)
end
end

def with_solr
def with_solr(&block)
# We're being invoked by the app entrypoint script and solr is already up via docker-compose
if ENV['SOLR_ENV'] == 'docker-compose'
yield
Expand All @@ -36,9 +36,7 @@ def with_solr
end
else
SolrWrapper.wrap do |solr|
solr.with_collection do
yield
end
solr.with_collection(&block)
end
end
end
Expand Down
Loading