Skip to content

Commit

Permalink
Merge pull request #2298 from projectblacklight/upgrade-rubocop
Browse files Browse the repository at this point in the history
Upgrade rubocop to 0.85.1
  • Loading branch information
cdmo committed Aug 31, 2020
2 parents cb921ef + 149836a commit 91d5e6f
Show file tree
Hide file tree
Showing 56 changed files with 271 additions and 116 deletions.
48 changes: 46 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require: rubocop-rspec
require:
- rubocop-rspec
- rubocop-rails


inherit_from:
- .rubocop_todo.yml

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Exclude:
- "lib/generators/blacklight/templates/**/*"
- "blacklight.gemspec"
Expand Down Expand Up @@ -62,3 +65,44 @@ Style/StringLiterals:

Style/MethodDefParentheses:
Enabled: false

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Lint/DeprecatedOpenSSLConstant:
Enabled: true

Lint/MixedRegexpCaptureTypes:
Enabled: true

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Style/ExponentialNotation:
Enabled: true

Style/HashEachMethods:
Enabled: true
Exclude:
- 'spec/services/blacklight/search_service_spec.rb'

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true

Style/RedundantRegexpCharacterClass:
Enabled: true

Style/RedundantRegexpEscape:
Enabled: true

Style/SlicingWithRange:
Enabled: true
91 changes: 48 additions & 43 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-08-10 16:59:54 UTC using RuboCop version 0.89.1.
# on 2020-08-28 23:25:40 UTC using RuboCop version 0.89.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -20,14 +20,6 @@ Capybara/VisibilityMatcher:
- 'spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb'
- 'spec/helpers/blacklight_helper_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_argument, with_fixed_indentation
Layout/ArgumentAlignment:
Exclude:
- 'app/views/catalog/_document.atom.builder'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
Expand All @@ -51,11 +43,11 @@ Layout/EmptyLineAfterMagicComment:

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
Exclude:
- 'app/views/catalog/index.atom.builder'
- 'app/presenters/blacklight/field_presenter.rb'

# Offense count: 7
# Cop supports --auto-correct.
Expand Down Expand Up @@ -125,13 +117,12 @@ Layout/SpaceAfterComma:
- 'app/views/catalog/index.atom.builder'
- 'app/views/catalog/opensearch.xml.builder'

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Exclude:
- 'app/views/catalog/index.atom.builder'
- 'spec/models/blacklight/solr/response/facets_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
Expand Down Expand Up @@ -182,12 +173,6 @@ Lint/AmbiguousRegexpLiteral:
- 'spec/views/catalog/index.html.erb_spec.rb'
- 'spec/views/catalog/show.html.erb_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/NonDeterministicRequireOrder:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 29
# Cop supports --auto-correct.
Lint/ParenthesesAsGroupedExpression:
Expand All @@ -199,12 +184,6 @@ Lint/ParenthesesAsGroupedExpression:
- 'spec/lib/blacklight/search_state_spec.rb'
- 'spec/models/blacklight/solr/repository_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/SendWithMixinArgument:
Exclude:
- 'lib/blacklight/engine.rb'

# Offense count: 2
Lint/ShadowingOuterLocalVariable:
Exclude:
Expand Down Expand Up @@ -303,7 +282,7 @@ RSpec/BeforeAfterAll:
- 'spec/models/blacklight/document/sms_spec.rb'
- 'spec/models/blacklight/solr/document_spec.rb'

# Offense count: 80
# Offense count: 81
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand All @@ -313,18 +292,13 @@ RSpec/ContextWording:
RSpec/DescribeClass:
Enabled: false

# Offense count: 1
# Offense count: 2
# Configuration parameters: CustomIncludeMethods.
RSpec/EmptyExampleGroup:
Exclude:
- 'spec/helpers/blacklight_helper_spec.rb'
- 'spec/models/blacklight/solr/search_builder_spec.rb'

# Offense count: 108
# Cop supports --auto-correct.
# Configuration parameters: AllowConsecutiveOneLiners.
RSpec/EmptyLineAfterExample:
Enabled: false

# Offense count: 134
# Configuration parameters: Max.
RSpec/ExampleLength:
Expand Down Expand Up @@ -403,6 +377,11 @@ RSpec/MessageSpies:
RSpec/MultipleExpectations:
Max: 16

# Offense count: 160
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 14

# Offense count: 337
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Expand Down Expand Up @@ -458,6 +437,40 @@ RSpec/VoidExpect:
Exclude:
- 'spec/lib/blacklight/configuration/facet_field_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
Rails/ContentTag:
Exclude:
- 'app/components/blacklight/document_component.rb'
- 'app/components/blacklight/facet_item_pivot_component.rb'

# Offense count: 4
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'spec/models/search_spec.rb'

# Offense count: 37
# Configuration parameters: Include.
# Include: app/helpers/**/*.rb
Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/blacklight/blacklight_helper_behavior.rb'
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
- 'app/helpers/blacklight/component_helper_behavior.rb'
- 'app/helpers/blacklight/facets_helper_behavior.rb'
- 'app/helpers/blacklight/render_partials_helper_behavior.rb'

# Offense count: 11
Rails/OutputSafety:
Exclude:
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
- 'app/helpers/blacklight/configuration_helper_behavior.rb'
- 'app/helpers/blacklight/icon_helper_behavior.rb'
- 'app/helpers/blacklight/url_helper_behavior.rb'
- 'app/presenters/blacklight/rendering/join.rb'

# Offense count: 13
Security/Eval:
Exclude:
Expand Down Expand Up @@ -550,14 +563,6 @@ Style/GuardClause:
Style/IfUnlessModifier:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
Style/MethodDefParentheses:
Exclude:
- 'app/controllers/concerns/blacklight/bookmarks.rb'

# Offense count: 5
# Cop supports --auto-correct.
Style/MultilineIfModifier:
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ matrix:
env: "RAILS_VERSION=5.2.4.2"
- rvm: 2.5.7
env: "RAILS_VERSION=5.2.4.2 BLACKLIGHT_API_TEST=true ENGINE_CART_RAILS_OPTIONS=\"--api --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-test\""
- rvm: 2.4.9
env: "RAILS_VERSION=5.2.4.2"
- rvm: jruby-9.2.8.0
env: "RAILS_VERSION=5.2.4.2 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
allow_failures:
Expand Down
12 changes: 6 additions & 6 deletions app/components/blacklight/facet_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def content_from_legacy_view_helper
# @return [String]
# @private
def render_facet_value
content_tag(:span, class: "facet-label") do
tag.span(class: "facet-label") do
link_to_unless(@suppress_link, @label, @href, class: "facet-select")
end + render_facet_count
end
Expand All @@ -85,12 +85,12 @@ def render_facet_value
# @param [String] item
# @private
def render_selected_facet_value
content_tag(:span, class: "facet-label") do
content_tag(:span, @label, class: "selected") +
tag.span(class: "facet-label") do
tag.span(@label, class: "selected") +
# remove link
link_to(@href, class: "remove") do
content_tag(:span, '✖', class: "remove-icon") +
content_tag(:span, '[remove]', class: 'sr-only')
tag.span('✖', class: "remove-icon") +
tag.span('[remove]', class: 'sr-only')
end
end + render_facet_count(classes: ["selected"])
end
Expand All @@ -108,7 +108,7 @@ def render_facet_count(options = {})
return @view_context.render_facet_count(@hits, options) unless @view_context.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?

classes = (options[:classes] || []) << "facet-count"
content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(@hits)), class: classes)
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(@hits)), class: classes)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def track
if params[:redirect] && (params[:redirect].starts_with?('/') || params[:redirect] =~ URI::DEFAULT_PARSER.make_regexp)
uri = URI.parse(params[:redirect])
path = uri.query ? "#{uri.path}?#{uri.query}" : uri.path
redirect_to path, status: 303
redirect_to path, status: :see_other
else
redirect_to({ action: :show, id: params[:id] }, status: 303)
redirect_to({ action: :show, id: params[:id] }, status: :see_other)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/component_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def render_nav_actions(options = {}, &block)
def render_index_doc_actions(document, options = {})
wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).document_actions, { document: document }.merge(options))
content_tag("div", rendered, class: wrapping_class) if rendered.present?
tag.div(rendered, class: wrapping_class) if rendered.present?
end

##
Expand All @@ -51,7 +51,7 @@ def render_index_doc_actions(document, options = {})
def render_results_collection_tools(options = {})
wrapping_class = options.delete(:wrapping_class) || "search-widgets"
rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).collection_actions, options)
content_tag("div", rendered, class: wrapping_class) if rendered.present?
tag.div(rendered, class: wrapping_class) if rendered.present?
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/blacklight/facets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def render_selected_facet_value(facet_field, item)
def render_facet_count(num, options = {})
deprecated_method(:render_facet_count)
classes = (options[:classes] || []) << "facet-count"
content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes)
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes)
end

##
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/blacklight/icon_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Blacklight::IconHelperBehavior
def blacklight_icon(icon_name, options = {})
Rails.cache.fetch([:blacklight_icons, icon_name, options]) do
icon = Blacklight::Icon.new(icon_name, **options)
content_tag(:span, icon.svg.html_safe, icon.options)
tag.span(icon.svg.html_safe, icon.options)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,33 @@ def render_search_to_s_filters(params)
safe_join(value_list.collect do |value|
render_filter_value(value, facet_field)
end,
content_tag(:span, " #{t('blacklight.and')} ", class: 'filter-separator')))
tag.span(" #{t('blacklight.and')} ", class: 'filter-separator')))
end, " \n ")
end

# value can be Array, in which case elements are joined with
# 'and'. Pass in option :escape_value => false to pass in pre-rendered
# html for value. key with escape_key if needed.
def render_search_to_s_element(key, value, _options = {})
content_tag(:span,
render_filter_name(key) + content_tag(:span, value, class: 'filter-values'),
class: 'constraint')
tag.span(render_filter_name(key) + tag.span(value, class: 'filter-values'),
class: 'constraint')
end

##
# Render the name of the facet
def render_filter_name name
return "".html_safe if name.blank?

content_tag(:span,
t('blacklight.search.filters.label', label: name),
class: 'filter-name')
tag.span(t('blacklight.search.filters.label', label: name),
class: 'filter-name')
end

##
# Render the value of the facet
def render_filter_value value, key = nil
display_value = value
display_value = facet_display_value(key, value) if key
content_tag(:span,
h(display_value),
class: 'filter-value')
tag.span(h(display_value),
class: 'filter-value')
end
end
4 changes: 2 additions & 2 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def document_link_params(doc, opts)
def link_to_previous_document(previous_document)
link_opts = session_tracking_params(previous_document, search_session['counter'].to_i - 1).merge(class: "previous", rel: 'prev')
link_to_unless previous_document.nil?, raw(t('views.pagination.previous')), url_for_document(previous_document), link_opts do
content_tag :span, raw(t('views.pagination.previous')), class: 'previous'
tag.span raw(t('views.pagination.previous')), class: 'previous'
end
end

Expand All @@ -56,7 +56,7 @@ def link_to_previous_document(previous_document)
def link_to_next_document(next_document)
link_opts = session_tracking_params(next_document, search_session['counter'].to_i + 1).merge(class: "next", rel: 'next')
link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do
content_tag :span, raw(t('views.pagination.next')), class: 'next'
tag.span raw(t('views.pagination.next')), class: 'next'
end
end

Expand Down
Loading

0 comments on commit 91d5e6f

Please sign in to comment.