diff options
author | Go MAEDA <maeda@farend.jp> | 2024-08-25 08:44:33 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-08-25 08:44:33 +0000 |
commit | fdd90bab2b02d6fdd08a860808560eb2cf382af6 (patch) | |
tree | bcf26941dbc0fc8a0a6542f35d9fd5a92e1b5aa1 | |
parent | fd83e97b135ee8affedf57f18952bce30271fc2e (diff) | |
download | redmine-fdd90bab2b02d6fdd08a860808560eb2cf382af6.tar.gz redmine-fdd90bab2b02d6fdd08a860808560eb2cf382af6.zip |
Fix RuboCop offenses Style/NegatedIf and Style/NegatedWhile (#39887, #7770).
git-svn-id: https://svn.redmine.org/redmine/trunk@22987 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | .rubocop_todo.yml | 22 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/messages_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
-rw-r--r-- | app/helpers/repositories_helper.rb | 2 | ||||
-rw-r--r-- | app/models/attachment.rb | 4 | ||||
-rw-r--r-- | app/models/auth_source_ldap.rb | 2 | ||||
-rw-r--r-- | app/models/custom_field.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/repository/cvs.rb | 6 | ||||
-rw-r--r-- | lib/redmine/codeset_util.rb | 2 | ||||
-rw-r--r-- | lib/redmine/string_array_diff/diff.rb | 2 | ||||
-rw-r--r-- | lib/redmine/thumbnail.rb | 2 |
13 files changed, 18 insertions, 38 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b0e2d58c7..5c196e8b7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1012,28 +1012,6 @@ Style/MutableConstant: Enabled: false # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: both, prefix, postfix -Style/NegatedIf: - Exclude: - - 'app/controllers/application_controller.rb' - - 'app/controllers/messages_controller.rb' - - 'app/helpers/repositories_helper.rb' - - 'app/models/attachment.rb' - - 'app/models/auth_source_ldap.rb' - - 'app/models/custom_field.rb' - - 'app/models/project.rb' - - 'app/models/repository/cvs.rb' - - 'lib/redmine/codeset_util.rb' - - 'lib/redmine/string_array_diff/diff.rb' - - 'lib/redmine/thumbnail.rb' - -# This cop supports safe autocorrection (--autocorrect). -Style/NegatedWhile: - Exclude: - - 'app/helpers/application_helper.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowedMethods. # AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with Style/NestedParenthesizedCalls: diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d7d588eb3..15d2ff72b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -261,7 +261,7 @@ class ApplicationController < ActionController::Base end def require_login - if !User.current.logged? + unless User.current.logged? # Extract only the basic url parameters on non-GET requests if request.get? url = request.original_url @@ -297,7 +297,7 @@ class ApplicationController < ActionController::Base def require_admin return unless require_login - if !User.current.admin? + unless User.current.admin? render_403 return false end @@ -519,7 +519,7 @@ class ApplicationController < ActionController::Base path = uri.to_s # Ensure that the remaining URL starts with a slash, followed by a # non-slash character or the end - if !%r{\A/([^/]|\z)}.match?(path) + unless %r{\A/([^/]|\z)}.match?(path) return false end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c197757f5..769cdff67 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -79,7 +79,7 @@ class MessagesController < ApplicationController @reply.safe_attributes = params[:reply] @reply.save_attachments(params[:attachments]) @topic.children << @reply - if !@reply.new_record? + unless @reply.new_record? call_hook(:controller_messages_reply_after_save, {:params => params, :message => @reply}) render_attachment_warning_if_needed(@reply) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 369291a3c..ca8e1c266 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -916,7 +916,7 @@ module ApplicationHelper s = StringScanner.new(text) tags = [] parsed = +'' - while !s.eos? + until s.eos? s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im) text, full_tag, closing, tag = s[1], s[2], s[3], s[4] if tags.empty? diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index abc994495..7a6978979 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -56,7 +56,7 @@ module RepositoriesHelper case change.action when 'A' # Detects moved/copied files - if !change.from_path.blank? + if change.from_path.present? change.action = @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index dea287c97..2c0b7635a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -412,12 +412,12 @@ class Attachment < ApplicationRecord return if src == dest - if !FileUtils.mkdir_p(File.dirname(dest)) + unless FileUtils.mkdir_p(File.dirname(dest)) logger.error "Could not create directory #{File.dirname(dest)}" if logger return end - if !FileUtils.mv(src, dest) + unless FileUtils.mv(src, dest) logger.error "Could not move attachment from #{src} to #{dest}" if logger return end diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index 2d86a8f5d..df46ed085 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -73,7 +73,7 @@ class AuthSourceLdap < AuthSource ldap_con.open {} if self.account.present? && !self.account.include?("$login") && self.account_password.present? ldap_auth = authenticate_dn(self.account, self.account_password) - raise AuthSourceException.new(l(:error_ldap_bind_credentials)) if !ldap_auth + raise AuthSourceException.new(l(:error_ldap_bind_credentials)) unless ldap_auth end end rescue *NETWORK_EXCEPTIONS => e diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 136a336ed..ec8c5de8d 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -301,7 +301,7 @@ class CustomField < ApplicationRecord unless errs.any? if value.is_a?(Array) - if !multiple? + unless multiple? errs << ::I18n.t('activerecord.errors.messages.invalid') end if is_required? && value.detect(&:present?).nil? diff --git a/app/models/project.rb b/app/models/project.rb index 42499ae58..c438be16d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -121,6 +121,7 @@ class Project < ApplicationRecord def initialize(attributes=nil, *args) super + # rubocop:disable Style/NegatedIf initialized = (attributes || {}).stringify_keys if !initialized.key?('identifier') && Setting.sequential_project_identifiers? self.identifier = Project.next_identifier @@ -139,6 +140,7 @@ class Project < ApplicationRecord self.trackers = Tracker.sorted.to_a end end + # rubocop:enable Style/NegatedIf end def identifier=(identifier) diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index 45ca9fbe8..a5fce91bb 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -52,7 +52,7 @@ class Repository::Cvs < Repository def scm_entries(path=nil, identifier=nil) rev = nil - if ! identifier.nil? + unless identifier.nil? rev = changesets.find_by_revision(identifier) return nil if rev.nil? end @@ -80,7 +80,7 @@ class Repository::Cvs < Repository def cat(path, identifier=nil) rev = nil - if ! identifier.nil? + unless identifier.nil? rev = changesets.find_by_revision(identifier) return nil if rev.nil? end @@ -89,7 +89,7 @@ class Repository::Cvs < Repository def annotate(path, identifier=nil) rev = nil - if ! identifier.nil? + unless identifier.nil? rev = changesets.find_by_revision(identifier) return nil if rev.nil? end diff --git a/lib/redmine/codeset_util.rb b/lib/redmine/codeset_util.rb index 04284e194..aa0a23334 100644 --- a/lib/redmine/codeset_util.rb +++ b/lib/redmine/codeset_util.rb @@ -24,7 +24,7 @@ module Redmine str = str.dup str.force_encoding('UTF-8') - if ! str.valid_encoding? + unless str.valid_encoding? str = str.encode("UTF-16LE", :invalid => :replace, :undef => :replace, :replace => '?').encode("UTF-8") end diff --git a/lib/redmine/string_array_diff/diff.rb b/lib/redmine/string_array_diff/diff.rb index 4b54fb740..4540f1e72 100644 --- a/lib/redmine/string_array_diff/diff.rb +++ b/lib/redmine/string_array_diff/diff.rb @@ -81,7 +81,7 @@ module Redmine } } - if !thresh.empty? + unless thresh.empty? link = links[thresh.length-1] while link mvector[link[1]] = link[2] diff --git a/lib/redmine/thumbnail.rb b/lib/redmine/thumbnail.rb index 6a0729411..91d6a6fed 100644 --- a/lib/redmine/thumbnail.rb +++ b/lib/redmine/thumbnail.rb @@ -40,7 +40,7 @@ module Redmine unless File.exist?(target) # Make sure we only invoke Imagemagick if the file type is allowed mime_type = File.open(source) {|f| Marcel::MimeType.for(f)} - return nil if !ALLOWED_TYPES.include? mime_type + return nil unless ALLOWED_TYPES.include? mime_type return nil if is_pdf && mime_type != "application/pdf" directory = File.dirname(target) |