From 32d2b1c42f76c07e13bcf748b2071a29cf350606 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 25 Mar 2023 01:32:23 +0000 Subject: [PATCH] Fix RuboCop offense Style/InverseMethods: Use `present?` instead of inverting `blank?` (#37248). git-svn-id: https://svn.redmine.org/redmine/trunk@22152 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/application_controller.rb | 2 +- app/controllers/roles_controller.rb | 2 +- app/controllers/trackers_controller.rb | 2 +- app/helpers/custom_fields_helper.rb | 2 +- app/models/auth_source_ldap.rb | 2 +- app/models/import.rb | 2 +- app/models/mail_handler.rb | 2 +- app/models/query.rb | 4 ++-- app/models/setting.rb | 2 +- app/models/wiki_page.rb | 2 +- app/views/common/feed.atom.builder | 2 +- app/views/journals/index.builder | 2 +- lib/redmine/plugin.rb | 2 +- test/unit/project_copy_test.rb | 2 +- test/unit/project_test.rb | 4 ++-- test/unit/user_test.rb | 6 +++--- 16 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c39fe8ad1..e83e08989 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -251,7 +251,7 @@ class ApplicationController < ActionController::Base end if lang.nil? && !Setting.force_default_language_for_anonymous? && request.env['HTTP_ACCEPT_LANGUAGE'] accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first - if !accept_lang.blank? + if accept_lang.present? accept_lang = accept_lang.downcase lang = find_language(accept_lang) || find_language(accept_lang.split('-').first) end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 70aa19ae6..35b753f31 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -63,7 +63,7 @@ class RolesController < ApplicationController @role.safe_attributes = params[:role] if request.post? && @role.save # workflow copy - if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) + if params[:copy_workflow_from].present? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) @role.copy_workflow_rules(copy_from) end flash[:notice] = l(:notice_successful_create) diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 88381a1b8..64367f373 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -48,7 +48,7 @@ class TrackersController < ApplicationController @tracker.safe_attributes = params[:tracker] if @tracker.save # workflow copy - if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from])) + if params[:copy_workflow_from].present? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from])) @tracker.copy_workflow_rules(copy_from) end flash[:notice] = l(:notice_successful_create) diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 13974daff..435634df8 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -155,7 +155,7 @@ module CustomFieldsHelper def custom_field_value_tag(value) attr_value = show_value(value) - if !attr_value.blank? && value.custom_field.full_text_formatting? + if attr_value.present? && value.custom_field.full_text_formatting? content_tag('div', attr_value, :class => 'wiki') else attr_value diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index b9cf21ccc..a2d43b7f7 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -245,7 +245,7 @@ class AuthSourceLdap < AuthSource # Singleton class method is public class << self def get_attr(entry, attr_name) - if !attr_name.blank? + if attr_name.present? value = entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name] (+value.to_s).force_encoding('UTF-8') end diff --git a/app/models/import.rb b/app/models/import.rb index 5dcb05882..fe3f24fab 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -94,7 +94,7 @@ class Import < ActiveRecord::Base 'notifications' => '0' ) - if options.key?(:project_id) && !options[:project_id].blank? + if options.key?(:project_id) && options[:project_id].present? # Do not fail if project doesn't exist begin project = Project.find(options[:project_id]) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 2fa4de00d..5925608bd 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -365,7 +365,7 @@ class MailHandler < ActionMailer::Base end if override && (v = extract_keyword!(cleaned_up_text_body, attr, options[:format])) v - elsif !handler_options[:issue][attr].blank? + elsif handler_options[:issue][attr].present? handler_options[:issue][attr] end end diff --git a/app/models/query.rb b/app/models/query.rb index 4a0aeb4fd..473ea4d86 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -505,7 +505,7 @@ class Query < ActiveRecord::Base add_filter_error(field, :blank) unless # filter requires one or more values - (values_for(field) and !values_for(field).first.blank?) or + (values_for(field) and values_for(field).first.present?) or # filter doesn't require any value ["o", "c", "!*", "*", "nd", "t", "ld", "nw", "w", "lw", "l2w", "nm", "m", "lm", "y", "*o", "!o"].include? operator_for(field) end if filters @@ -830,7 +830,7 @@ class Query < ActiveRecord::Base def column_names=(names) if names - names = names.select {|n| n.is_a?(Symbol) || !n.blank?} + names = names.select {|n| n.is_a?(Symbol) || n.present?} names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym} if names.delete(:all_inline) names = available_inline_columns.map(&:name) | names diff --git a/app/models/setting.rb b/app/models/setting.rb index 155ed23b1..81f121db4 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -111,7 +111,7 @@ class Setting < ActiveRecord::Base v = YAML.safe_load(v, permitted_classes: Rails.configuration.active_record.yaml_column_permitted_classes) v = force_utf8_strings(v) end - v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank? + v = v.to_sym if available_settings[name]['format'] == 'symbol' && v.present? v end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 594c44bd6..0ee06673e 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -273,7 +273,7 @@ class WikiPage < ActiveRecord::Base protected def validate_parent_title - errors.add(:parent_title, :invalid) if !@parent_title.blank? && parent.nil? + errors.add(:parent_title, :invalid) if @parent_title.present? && parent.nil? errors.add(:parent_title, :circular_dependency) if parent && (parent == self || parent.ancestors.include?(self)) if parent_id_changed? && parent && (parent.wiki_id != wiki_id) errors.add(:parent_title, :not_same_project) diff --git a/app/views/common/feed.atom.builder b/app/views/common/feed.atom.builder index 13fda6b1b..e62b535d1 100644 --- a/app/views/common/feed.atom.builder +++ b/app/views/common/feed.atom.builder @@ -24,7 +24,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do author = item.event_author if item.respond_to?(:event_author) xml.author do xml.name(author) - xml.email(author.mail) if author.is_a?(User) && !author.mail.blank? && !author.pref.hide_mail + xml.email(author.mail) if author.is_a?(User) && author.mail.present? && !author.pref.hide_mail end if author xml.content "type" => "html" do xml.text! textilizable(item, :event_description, :only_path => false) diff --git a/app/views/journals/index.builder b/app/views/journals/index.builder index 26a067f6c..7682a3fa5 100644 --- a/app/views/journals/index.builder +++ b/app/views/journals/index.builder @@ -18,7 +18,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.updated change.created_on.xmlschema xml.author do xml.name change.user.name - xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail + xml.email(change.user.mail) if change.user.is_a?(User) && change.user.mail.present? && !change.user.pref.hide_mail end xml.content "type" => "html" do xml.text! '