diff --git a/.rubocop.yml b/.rubocop.yml index cffa6afb30..5183fdac23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,16 +13,34 @@ AllCops: - 'vendor/**/*' - 'lib/hyrax/specs/**/*' +Bundler/DuplicatedGem: # This doesn't work with engine_cart + Enabled: false + Lint/ImplicitStringConcatenation: Exclude: - 'lib/generators/hyrax/**/*' +Lint/AmbiguousBlockAssociation: + Enabled: false + Metrics/LineLength: Max: 200 Metrics/AbcSize: Max: 28 +Metrics/BlockLength: + ExcludedMethods: ['included'] + Exclude: + - 'hyrax.gemspec' + - 'app/services/hyrax/workflow/workflow_schema.rb' + - 'config/initializers/simple_form.rb' + - 'config/routes.rb' + - 'lib/generators/hyrax/templates/catalog_controller.rb' + - 'lib/generators/hyrax/templates/config/initializers/simple_form_bootstrap.rb' + - 'lib/hyrax/rails/routes.rb' + - 'spec/**/*.rb' + Metrics/MethodLength: Max: 14 @@ -37,6 +55,10 @@ Style/CollectionMethods: detect: 'find' find_all: 'select' +Style/FileName: # https://github.com/bbatsov/rubocop/issues/2973 + Exclude: + - 'Gemfile' + Style/MethodMissing: Exclude: - 'app/models/concerns/hyrax/file_set/characterization.rb' @@ -45,6 +67,9 @@ Style/NumericPredicate: Exclude: - 'app/controllers/concerns/hyrax/file_sets_controller_behavior.rb' +Style/SymbolArray: + Enabled: false + Style/WordArray: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 083cae999f..2832865e03 100755 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -4,19 +4,6 @@ Security/MarshalLoad: Exclude: - 'app/models/concerns/hyrax/user.rb' -Metrics/BlockLength: - Exclude: - - 'app/controllers/concerns/hyrax/collections_controller_behavior.rb' - - 'app/models/concerns/hyrax/basic_metadata.rb' - - 'app/models/concerns/hyrax/admin_set_behavior.rb' - - 'app/services/hyrax/workflow/workflow_schema.rb' - - 'config/initializers/simple_form.rb' - - 'config/routes.rb' - - 'lib/generators/hyrax/templates/catalog_controller.rb' - - 'lib/generators/hyrax/templates/config/initializers/simple_form_bootstrap.rb' - - 'lib/hyrax/rails/routes.rb' - - 'spec/**/*' - Metrics/ClassLength: Exclude: - 'app/forms/hyrax/forms/permission_template_form.rb' diff --git a/Gemfile b/Gemfile index de454d63a3..1a6710d3e7 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,10 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem "simplecov", require: false gem 'coveralls', require: false gem 'pry' unless ENV['CI'] gem 'pry-byebug' unless ENV['CI'] + gem "simplecov", require: false end # BEGIN ENGINE_CART BLOCK @@ -36,9 +36,9 @@ else case ENV['RAILS_VERSION'] when /^4.2/ + gem 'coffee-rails', '~> 4.2.0' gem 'responders', '~> 2.0' gem 'sass-rails', '>= 5.0' - gem 'coffee-rails', '~> 4.2.0' when /^4.[01]/ gem 'sass-rails', '< 5.0' end diff --git a/app/actors/hyrax/actors/apply_permission_template_actor.rb b/app/actors/hyrax/actors/apply_permission_template_actor.rb index 3056cfe7db..3742343de3 100644 --- a/app/actors/hyrax/actors/apply_permission_template_actor.rb +++ b/app/actors/hyrax/actors/apply_permission_template_actor.rb @@ -11,7 +11,7 @@ def create(attributes) protected def add_edit_users(attributes) - return unless attributes[:admin_set_id].present? + return if attributes[:admin_set_id].blank? template = Hyrax::PermissionTemplate.find_by!(admin_set_id: attributes[:admin_set_id]) curation_concern.edit_users += template.agent_ids_for(agent_type: 'user', access: 'manage') curation_concern.edit_groups += template.agent_ids_for(agent_type: 'group', access: 'manage') diff --git a/app/actors/hyrax/actors/file_set_actor.rb b/app/actors/hyrax/actors/file_set_actor.rb index 7601008f11..d9501994bf 100644 --- a/app/actors/hyrax/actors/file_set_actor.rb +++ b/app/actors/hyrax/actors/file_set_actor.rb @@ -126,7 +126,7 @@ def save end def assign_visibility?(file_set_params = {}) - !((file_set_params || {}).keys.map(&:to_s) & %w(visibility embargo_release_date lease_expiration_date)).empty? + !((file_set_params || {}).keys.map(&:to_s) & %w[visibility embargo_release_date lease_expiration_date]).empty? end # copy visibility from source_concern to destination_concern @@ -135,12 +135,12 @@ def copy_visibility(source_concern, destination_concern) end def set_representative(work, file_set) - return unless work.representative_id.blank? + return if work.representative_id.present? work.representative = file_set end def set_thumbnail(work, file_set) - return unless work.thumbnail_id.blank? + return if work.thumbnail_id.present? work.thumbnail = file_set end diff --git a/app/actors/hyrax/actors/interpret_visibility_actor.rb b/app/actors/hyrax/actors/interpret_visibility_actor.rb index f412381042..6d6dd2b897 100644 --- a/app/actors/hyrax/actors/interpret_visibility_actor.rb +++ b/app/actors/hyrax/actors/interpret_visibility_actor.rb @@ -137,7 +137,7 @@ def validate_release_type(template) # Validate visibility complies with AdminSet template requirements def validate_visibility(attributes, template) # NOTE: For embargo/lease, attributes[:visibility] will be nil (see sanitize_params), so visibility will be validated as part of embargo/lease - return true unless attributes[:visibility].present? + return true if attributes[:visibility].blank? # Validate against template's visibility requirements return true if validate_template_visibility(attributes[:visibility], template) @@ -157,7 +157,7 @@ def validate_embargo(attributes, template) valid_template_embargo_date?(embargo_release_date, template) && valid_template_visibility_after_embargo?(attributes, template) - curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.') unless embargo_release_date.present? + curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.') if embargo_release_date.blank? false end @@ -171,7 +171,7 @@ def valid_future_date?(date, attribute_name: :embargo_release_date) # Validate an embargo date against permission template restrictions def valid_template_embargo_date?(date, template) - return true unless template.present? + return true if template.blank? # Validate against template's release_date requirements return true if template.valid_release_date?(date) @@ -191,7 +191,7 @@ def valid_template_visibility_after_embargo?(attributes, template) # Validate that a given visibility value satisfies template requirements def validate_template_visibility(visibility, template) - return true unless template.present? + return true if template.blank? template.valid_visibility?(visibility) end diff --git a/app/controllers/concerns/hyrax/parent_container.rb b/app/controllers/concerns/hyrax/parent_container.rb index b8d4fa5bbf..f3f64e1550 100644 --- a/app/controllers/concerns/hyrax/parent_container.rb +++ b/app/controllers/concerns/hyrax/parent_container.rb @@ -29,7 +29,7 @@ def parent_id protected def new_or_create? - %w(create new).include? action_name + %w[create new].include? action_name end end end diff --git a/app/controllers/concerns/hyrax/users_controller_behavior.rb b/app/controllers/concerns/hyrax/users_controller_behavior.rb index e128277dce..8a86b468eb 100644 --- a/app/controllers/concerns/hyrax/users_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/users_controller_behavior.rb @@ -34,7 +34,7 @@ def notifications_number def search(query) clause = query.blank? ? nil : "%" + query.downcase + "%" base = User.where(*base_query) - unless clause.blank? + if clause.present? base = base.where("#{Devise.authentication_keys.first} like lower(?) OR display_name like lower(?)", clause, clause) end base.registered diff --git a/app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb b/app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb index 58165cf0b7..e60013a7e4 100644 --- a/app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb +++ b/app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb @@ -19,7 +19,7 @@ def format(work) def authors_text_for(work) # setup formatted author list - authors_list = author_list(work).select { |author| !author.blank? } + authors_list = author_list(work).reject(&:blank?) author_text = format_authors(authors_list) if author_text.blank? author_text diff --git a/app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb b/app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb index cc9281d15e..2398b83b94 100644 --- a/app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb +++ b/app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb @@ -11,7 +11,7 @@ def format(work) # setup formatted author list authors_list = all_authors(work) text << format_authors(authors_list) - unless text.blank? + if text.present? text = "#{text}" end # Get Pub Date @@ -21,7 +21,7 @@ def format(work) text << format_title(work.to_s) pub_info = setup_pub_info(work, false) - text << " #{pub_info}." unless pub_info.blank? + text << " #{pub_info}." if pub_info.present? text.html_safe end diff --git a/app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb b/app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb index 4a80bffedb..2777a62ab8 100644 --- a/app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb +++ b/app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb @@ -9,7 +9,7 @@ def format(work) text = '' # setup formatted author list - authors = author_list(work).select { |author| !author.blank? } + authors = author_list(work).reject(&:blank?) text << "#{format_authors(authors)}" # setup title title_info = setup_title_info(work) @@ -18,7 +18,7 @@ def format(work) # Publication pub_info = clean_end_punctuation(setup_pub_info(work, true)) - text << pub_info unless pub_info.blank? + text << pub_info if pub_info.present? text << "." unless text.blank? || text =~ /\.$/ text.html_safe end @@ -27,7 +27,7 @@ def format_authors(authors_list = []) return "" if authors_list.blank? authors_list = Array.wrap(authors_list) text = concatenate_authors_from(authors_list) - unless text.blank? + if text.present? text << "." unless text =~ /\.$/ text << " " end diff --git a/app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb b/app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb index 87d81b5348..6a301128d7 100644 --- a/app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb +++ b/app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb @@ -13,7 +13,7 @@ def format(work) export_text << "rft.#{kev}=#{CGI.escape(value.to_s)}" end end - export_text.join('&') unless export_text.blank? + export_text.join('&') if export_text.present? end FIELD_MAP = { diff --git a/app/helpers/hyrax/citations_behaviors/publication_behavior.rb b/app/helpers/hyrax/citations_behaviors/publication_behavior.rb index b9eba33a16..9d50dc87c3 100644 --- a/app/helpers/hyrax/citations_behaviors/publication_behavior.rb +++ b/app/helpers/hyrax/citations_behaviors/publication_behavior.rb @@ -4,7 +4,7 @@ module PublicationBehavior include Hyrax::CitationsBehaviors::CommonBehavior def setup_pub_date(work) first_date = work.date_created.first if work.date_created - unless first_date.blank? + if first_date.present? first_date = CGI.escapeHTML(first_date) date_value = first_date.gsub(/[^0-9|n\.d\.]/, "")[0, 4] return nil if date_value.nil? diff --git a/app/helpers/hyrax/citations_behaviors/title_behavior.rb b/app/helpers/hyrax/citations_behaviors/title_behavior.rb index 57488359a5..ba1736e7ca 100644 --- a/app/helpers/hyrax/citations_behaviors/title_behavior.rb +++ b/app/helpers/hyrax/citations_behaviors/title_behavior.rb @@ -38,7 +38,7 @@ def process_title_parts(title_text, &block) def setup_title_info(work) text = '' title = work.to_s - unless title.blank? + if title.present? title = CGI.escapeHTML(title) title_info = clean_end_punctuation(title.strip) text << title_info diff --git a/app/helpers/hyrax/collections_helper.rb b/app/helpers/hyrax/collections_helper.rb index 0714ca08f6..4f5c7dc4a3 100644 --- a/app/helpers/hyrax/collections_helper.rb +++ b/app/helpers/hyrax/collections_helper.rb @@ -11,7 +11,7 @@ def render_collection_links(solr_doc) # @return [Boolean] def has_collection_search_parameters? - !params[:cq].blank? + params[:cq].present? end def button_for_remove_from_collection(collection, document, label = 'Remove From Collection') diff --git a/app/helpers/hyrax/hyrax_helper_behavior.rb b/app/helpers/hyrax/hyrax_helper_behavior.rb index e411fffb8c..1e0549d28e 100644 --- a/app/helpers/hyrax/hyrax_helper_behavior.rb +++ b/app/helpers/hyrax/hyrax_helper_behavior.rb @@ -1,4 +1,5 @@ # coding: utf-8 + module Hyrax module HyraxHelperBehavior include Hyrax::CitationsBehavior diff --git a/app/indexers/hyrax/basic_metadata_indexer.rb b/app/indexers/hyrax/basic_metadata_indexer.rb index db86e74fb5..648a1a247b 100644 --- a/app/indexers/hyrax/basic_metadata_indexer.rb +++ b/app/indexers/hyrax/basic_metadata_indexer.rb @@ -1,9 +1,9 @@ module Hyrax class BasicMetadataIndexer < ActiveFedora::RDF::IndexingService class_attribute :stored_and_facetable_fields, :stored_fields, :symbol_fields - self.stored_and_facetable_fields = %i(resource_type creator contributor keyword publisher subject language based_near) - self.stored_fields = %i(description license rights_statement date_created identifier related_url bibliographic_citation source) - self.symbol_fields = %i(import_url) + self.stored_and_facetable_fields = %i[resource_type creator contributor keyword publisher subject language based_near] + self.stored_fields = %i[description license rights_statement date_created identifier related_url bibliographic_citation source] + self.symbol_fields = %i[import_url] protected diff --git a/app/models/concerns/hyrax/collection_behavior.rb b/app/models/concerns/hyrax/collection_behavior.rb index b07e0b31c2..94d3b34309 100644 --- a/app/models/concerns/hyrax/collection_behavior.rb +++ b/app/models/concerns/hyrax/collection_behavior.rb @@ -18,7 +18,7 @@ module CollectionBehavior # Add members using the members association. def add_members(new_member_ids) - return if new_member_ids.nil? || new_member_ids.empty? + return if new_member_ids.blank? members << ActiveFedora::Base.find(new_member_ids) end diff --git a/app/models/concerns/hyrax/file_set/belongs_to_works.rb b/app/models/concerns/hyrax/file_set/belongs_to_works.rb index a55b06aa6d..310cdb3ffa 100644 --- a/app/models/concerns/hyrax/file_set/belongs_to_works.rb +++ b/app/models/concerns/hyrax/file_set/belongs_to_works.rb @@ -28,8 +28,8 @@ def related_files parent_objects = parents return [] if parent_objects.empty? parent_objects.flat_map do |work| - work.file_sets.select do |file_set| - file_set.id != id + work.file_sets.reject do |file_set| + file_set.id == id end end end diff --git a/app/models/concerns/hyrax/proxy_deposit.rb b/app/models/concerns/hyrax/proxy_deposit.rb index 4717b72d2b..aefda2fee5 100644 --- a/app/models/concerns/hyrax/proxy_deposit.rb +++ b/app/models/concerns/hyrax/proxy_deposit.rb @@ -16,7 +16,7 @@ module ProxyDeposit end def create_transfer_request - return unless on_behalf_of.present? + return if on_behalf_of.blank? ContentDepositorChangeEventJob.perform_later(self, ::User.find_by_user_key(on_behalf_of)) end diff --git a/app/models/concerns/hyrax/solr_document/metadata.rb b/app/models/concerns/hyrax/solr_document/metadata.rb index 4acbc2e270..a06ee1bfdb 100644 --- a/app/models/concerns/hyrax/solr_document/metadata.rb +++ b/app/models/concerns/hyrax/solr_document/metadata.rb @@ -43,7 +43,6 @@ def self.coerce(input) end end - # rubocop:disable Metrics/BlockLength included do attribute :identifier, Solr::Array, solr_name('identifier') attribute :based_near, Solr::Array, solr_name('based_near') @@ -81,7 +80,6 @@ def self.coerce(input) attribute :embargo_release_date, Solr::Date, Hydra.config.permissions.embargo.release_date attribute :lease_expiration_date, Solr::Date, Hydra.config.permissions.lease.expiration_date end - # rubocop:enable Metrics/BlockLength end end end diff --git a/app/models/concerns/hyrax/solr_document_behavior.rb b/app/models/concerns/hyrax/solr_document_behavior.rb index 238fb5037c..500f61288f 100644 --- a/app/models/concerns/hyrax/solr_document_behavior.rb +++ b/app/models/concerns/hyrax/solr_document_behavior.rb @@ -1,4 +1,5 @@ # -*- encoding : utf-8 -*- + module Hyrax module SolrDocumentBehavior extend ActiveSupport::Concern diff --git a/app/models/hyrax/permission_template.rb b/app/models/hyrax/permission_template.rb index d894bbe72a..94756c6413 100644 --- a/app/models/hyrax/permission_template.rb +++ b/app/models/hyrax/permission_template.rb @@ -106,7 +106,7 @@ def valid_release_date?(date) # @param [String] value - visibility value to validate def valid_visibility?(value) # If template doesn't specify a visiblity (i.e. is "varies"), then any visibility is valid - return true unless visibility.present? + return true if visibility.blank? # Validate that passed in value matches visibility requirement exactly visibility == value diff --git a/app/models/hyrax/permission_template_access.rb b/app/models/hyrax/permission_template_access.rb index ffc79e9ad9..cf973220fc 100644 --- a/app/models/hyrax/permission_template_access.rb +++ b/app/models/hyrax/permission_template_access.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Hyrax class PermissionTemplateAccess < ActiveRecord::Base self.table_name = 'permission_template_accesses' diff --git a/app/models/proxy_deposit_request.rb b/app/models/proxy_deposit_request.rb index 8f5fb9a4e2..346e97e0b5 100644 --- a/app/models/proxy_deposit_request.rb +++ b/app/models/proxy_deposit_request.rb @@ -91,7 +91,7 @@ def send_request_transfer_message_as_part_of_create def send_request_transfer_message_as_part_of_update message = "Your transfer request was #{status}." - message += " Comments: #{receiver_comment}" unless receiver_comment.blank? + message += " Comments: #{receiver_comment}" if receiver_comment.present? User.batch_user.send_message(sending_user, message, "Ownership Change #{status}") end diff --git a/app/presenters/hyrax/admin_set_options_presenter.rb b/app/presenters/hyrax/admin_set_options_presenter.rb index 5e5f8b8445..2b57fb6530 100644 --- a/app/presenters/hyrax/admin_set_options_presenter.rb +++ b/app/presenters/hyrax/admin_set_options_presenter.rb @@ -30,9 +30,9 @@ def data_attributes(admin_set) def attributes_for(permission_template:) {}.tap do |attrs| attrs['data-sharing'] = sharing?(permission_template: permission_template) - attrs['data-release-date'] = permission_template.release_date unless permission_template.release_date.blank? + attrs['data-release-date'] = permission_template.release_date if permission_template.release_date.present? attrs['data-release-before-date'] = true if permission_template.release_before_date? - attrs['data-visibility'] = permission_template.visibility unless permission_template.visibility.blank? + attrs['data-visibility'] = permission_template.visibility if permission_template.visibility.present? end end diff --git a/app/presenters/hyrax/admin_stats_presenter.rb b/app/presenters/hyrax/admin_stats_presenter.rb index 2ba803c45c..030ce2f3d7 100644 --- a/app/presenters/hyrax/admin_stats_presenter.rb +++ b/app/presenters/hyrax/admin_stats_presenter.rb @@ -18,7 +18,7 @@ def end_date private def extract_date_from_stats_filters(key:, as_of:) - return unless stats_filters[key].present? + return if stats_filters[key].blank? Time.zone.parse(stats_filters[key]).public_send(as_of) end diff --git a/app/presenters/hyrax/characterization_behavior.rb b/app/presenters/hyrax/characterization_behavior.rb index 7918fc01bf..aa3a442674 100644 --- a/app/presenters/hyrax/characterization_behavior.rb +++ b/app/presenters/hyrax/characterization_behavior.rb @@ -76,7 +76,7 @@ def truncate_all(values) def build_characterization_metadata self.class.characterization_terms.each do |term| value = send(term) - additional_characterization_metadata[term.to_sym] = value unless value.blank? + additional_characterization_metadata[term.to_sym] = value if value.present? end additional_characterization_metadata end diff --git a/app/renderers/hyrax/renderers/attribute_renderer.rb b/app/renderers/hyrax/renderers/attribute_renderer.rb index ff4fbe711e..c51c39529f 100644 --- a/app/renderers/hyrax/renderers/attribute_renderer.rb +++ b/app/renderers/hyrax/renderers/attribute_renderer.rb @@ -23,7 +23,7 @@ def initialize(field, values, options = {}) def render markup = '' - return markup if !values.present? && !options[:include_empty] + return markup if values.blank? && !options[:include_empty] markup << %(#{label}\n