1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-04 08:03:23 +00:00

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
This commit is contained in:
Go MAEDA 2024-08-25 08:44:33 +00:00
parent fd83e97b13
commit fdd90bab2b
13 changed files with 18 additions and 38 deletions

View File

@ -1011,28 +1011,6 @@ Style/MultipleComparison:
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

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -81,7 +81,7 @@ module Redmine
}
}
if !thresh.empty?
unless thresh.empty?
link = links[thresh.length-1]
while link
mvector[link[1]] = link[2]

View File

@ -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)