Replace unless with if ! (project-wide)

This commit is contained in:
Ryan Lue 2018-05-04 22:05:10 +08:00
parent b79a76d6f8
commit 04055f7095
31 changed files with 42 additions and 58 deletions

View file

@ -36,7 +36,7 @@ module CreatesTicketArticles
clean_params.delete(:sender)
clean_params.delete(:origin_by_id)
type = Ticket::Article::Type.lookup(id: clean_params[:type_id])
unless type.name.match?(/^(note|web)$/)
if !type.name.match?(/^(note|web)$/)
clean_params[:type_id] = Ticket::Article::Type.lookup(name: 'note').id
end
clean_params.delete(:type)
@ -89,7 +89,7 @@ module CreatesTicketArticles
preferences[store_key] = attachment[key]
end
unless attachment[:data].match?(%r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$})
if !attachment[:data].match?(%r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$})
raise Exceptions::UnprocessableEntity, "Invalid base64 for attachment with index '#{index}'"
end

View file

@ -67,9 +67,7 @@ class FormController < ApplicationController
Rails.logger.info "Can't verify email #{params[:email]}: #{message}"
# ignore 450, graylistings
unless message.match?(/450/)
errors['email'] = message
end
errors['email'] = message if !message.match?(/450/)
end
end

View file

@ -39,7 +39,7 @@ class ImportZendeskController < ApplicationController
end
# since 2016-10-15 a redirect to a marketing page has been implemented
unless response.body.match?(/#{params[:url]}/)
if !response.body.match?(/#{params[:url]}/)
render json: {
result: 'invalid',
message_human: 'Hostname not found!',

View file

@ -13,7 +13,7 @@ class Integration::SipgateController < ApplicationController
# check if call need to be blocked
block_caller_ids.each do |item|
next unless item[:caller_id] == params['from']
next if item[:caller_id] != params['from']
xml = Builder::XmlMarkup.new(indent: 2)
xml.instruct!
content = xml.Response(onHangup: url, onAnswer: url) do

View file

@ -45,7 +45,7 @@ class SettingsController < ApplicationController
end
# validate image
unless clean_params[:logo].match?(/^data:image/i)
if !clean_params[:logo].match?(/^data:image/i)
render json: {
result: 'invalid',
message: 'Invalid payload, need data:image in logo param',

View file

@ -376,7 +376,7 @@ returns
next if !assoc_name.to_s.end_with?('s')
ref_names = "#{assoc_name.to_s.chomp('s')}_ids"
generic_object_tmp = new
next unless generic_object_tmp.respond_to?(ref_names) # if we do have an _ids attribute
next if !generic_object_tmp.respond_to?(ref_names) # if we do have an _ids attribute
next if data[ref_names.to_sym] # next if we have already the _ids filled
# get association class and do lookup

View file

@ -91,7 +91,7 @@ returns
next if !mail
# check how many content messages we have, for notice used
unless mail.match?(/x-zammad-ignore/i)
if !mail.match?(/x-zammad-ignore/i)
content_messages += 1
break if content_max_check < content_messages
end

View file

@ -863,7 +863,7 @@ module Mail
module Encodings
def self.value_decode(str)
# Optimization: If there's no encoded-words in the string, just return it
return str unless str.index('=?')
return str if !str.index('=?')
str = str.gsub(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's

View file

@ -144,13 +144,9 @@ module Channel::Filter::IdentifySender
end
def self.user_create(data, role_ids = nil)
unless data[:email].match?(/@/)
data[:email] += '@local'
end
user = User.find_by(email: data[:email].downcase)
if !user
user = User.find_by(login: data[:email].downcase)
end
data[:email] += '@local' if !data[:email].match?(/@/)
user = User.find_by(email: data[:email].downcase) ||
User.find_by(login: data[:email].downcase)
# check if firstname or lastname need to be updated
if user

View file

@ -296,7 +296,7 @@ returns
row.push record[key]
end
rows.push row
next unless rows_to_add.count.positive?
next if rows_to_add.count.zero?
rows_to_add.each do |item|
rows.push item
end

View file

@ -7,7 +7,6 @@ class History < ApplicationModel
belongs_to :history_type, class_name: 'History::Type'
belongs_to :history_object, class_name: 'History::Object'
belongs_to :history_attribute, class_name: 'History::Attribute'
# rubocop:enable Rails/InverseOf
# the noop is needed since Layout/EmptyLines detects
# the block commend below wrongly as the measurement of

View file

@ -3,7 +3,6 @@
class Link < ApplicationModel
belongs_to :link_type, class_name: 'Link::Type'
belongs_to :link_object, class_name: 'Link::Object'
# rubocop:enable Rails/InverseOf
after_destroy :touch_link_references

View file

@ -756,7 +756,7 @@ to send no browser reload event, pass false
if !data_type
raise 'Need data_type param'
end
unless data_type.match?(/^(input|user_autocompletion|checkbox|select|tree_select|datetime|date|tag|richtext|textarea|integer|autocompletion_ajax|boolean|user_permission|active)$/)
if !data_type.match?(/^(input|user_autocompletion|checkbox|select|tree_select|datetime|date|tag|richtext|textarea|integer|autocompletion_ajax|boolean|user_permission|active)$/)
raise "Invalid data_type param '#{data_type}'"
end

View file

@ -13,7 +13,6 @@ class Organization < ApplicationModel
include Organization::Search
include Organization::SearchIndex
has_many :members, class_name: 'User'
# rubocop:enable Rails/InverseOf
before_create :domain_cleanup
before_update :domain_cleanup

View file

@ -153,7 +153,7 @@ returns
permission = Permission.lookup(id: permission_id)
raise "Unable to find permission for id #{permission_id}" if !permission
raise "Permission #{permission.name} is disabled" if permission.preferences[:disabled] == true
next unless permission.preferences[:not]
next if !permission.preferences[:not]
permission.preferences[:not].each do |local_permission_name|
local_permission = Permission.lookup(name: local_permission_name)
next if !local_permission

View file

@ -6,7 +6,6 @@ require_dependency 'store/file'
class Store < ApplicationModel
belongs_to :store_object, class_name: 'Store::Object'
belongs_to :store_file, class_name: 'Store::File'
# rubocop:enable Rails/InverseOf
validates :filename, presence: true

View file

@ -3,7 +3,6 @@
class Tag < ApplicationModel
belongs_to :tag_object, class_name: 'Tag::Object'
belongs_to :tag_item, class_name: 'Tag::Item'
# rubocop:enable Rails/InverseOf
# the noop is needed since Layout/EmptyLines detects
# the block commend below wrongly as the measurement of

View file

@ -65,7 +65,6 @@ class Ticket < ApplicationModel
belongs_to :updated_by, class_name: 'User'
belongs_to :create_article_type, class_name: 'Ticket::Article::Type'
belongs_to :create_article_sender, class_name: 'Ticket::Article::Sender'
# rubocop:enable Rails/InverseOf
self.inheritance_column = nil

View file

@ -16,7 +16,6 @@ class Ticket::Article < ApplicationModel
belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, class_name: 'User'
belongs_to :origin_by, class_name: 'User'
# rubocop:enable Rails/InverseOf
before_create :check_subject, :check_body, :check_message_id_md5
before_update :check_subject, :check_body, :check_message_id_md5

View file

@ -4,7 +4,6 @@ class Ticket::State < ApplicationModel
belongs_to :state_type, class_name: 'Ticket::StateType', inverse_of: :states
belongs_to :next_state, class_name: 'Ticket::State'
# rubocop:enable Rails/InverseOf
after_create :ensure_defaults
after_update :ensure_defaults

View file

@ -362,7 +362,7 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation
translation_raw.each_key do |key|
# if translation target has changes
next unless translation_raw[key] != translation.target
next if translation_raw[key] == translation.target
# do not update translations which are already changed by user
if translation.target == translation.target_initial

View file

@ -3,8 +3,8 @@ class Issue1219ZhtwLocaleTypo < ActiveRecord::Migration[5.1]
APPLICABLE_VERSION = Gem::Version.new('2.5.0')
def up
return unless Setting.find_by(name: 'system_init_done')
return unless CURRENT_VERSION >= APPLICABLE_VERSION
return if !Setting.find_by(name: 'system_init_done')
return if CURRENT_VERSION < APPLICABLE_VERSION
if Locale.exists?(locale: 'zh-tw')
Locale.find_by(locale: 'zj-tw')&.destroy
@ -20,8 +20,8 @@ class Issue1219ZhtwLocaleTypo < ActiveRecord::Migration[5.1]
end
def down
return unless Setting.find_by(name: 'system_init_done')
return unless CURRENT_VERSION < APPLICABLE_VERSION
return if !Setting.find_by(name: 'system_init_done')
return if CURRENT_VERSION >= APPLICABLE_VERSION
if Locale.exists?(locale: 'zj-tw')
Locale.find_by(locale: 'zh-tw')&.destroy

View file

@ -15,7 +15,7 @@ module Net
check_response critical { recv_response() }
do_helo helo_domain
if starttls_always? or (capable_starttls? and starttls_auto?)
unless capable_starttls?
if !capable_starttls?
raise SMTPUnsupportedCommand,
"STARTTLS is not supported on this server"
end
@ -45,7 +45,7 @@ module Net
authenticate user, secret, (authtype || DEFAULT_AUTH_TYPE) if user
@started = true
ensure
unless @started
if !@started
# authentication failed, cancel connection.
s.close if s and not s.closed?
@socket = nil
@ -53,4 +53,4 @@ module Net
end
end
end
# rubocop:enable all
# rubocop:enable all

View file

@ -134,9 +134,7 @@ satinize html string based on whiltelist
value = node[key]
node.delete(key)
next if value.blank?
unless value.match?(/%|px|em/i)
value += 'px'
end
value += 'px' if !value.match?(/%|px|em/i)
node['style'] += "#{key}:#{value}"
end

View file

@ -394,7 +394,7 @@ returns
last_width = file['width'].to_i
last_height = file['height'].to_i
end
next unless file['width'].to_i < max_width && last_width < file['width'].to_i
next if file['width'].to_i >= max_width || file['width'].to_i <= last_width
photo = file
last_width = file['width'].to_i
last_height = file['height'].to_i

View file

@ -457,7 +457,7 @@ returns
else
ftp.login
end
ftp.chdir(remote_dir) unless remote_dir == '.'
ftp.chdir(remote_dir) if remote_dir != '.'
begin
ftp.getbinaryfile(filename, temp_file)

View file

@ -25,7 +25,7 @@ def before_fork
# remember open file handles
@files_to_reopen = []
ObjectSpace.each_object(File) do |file|
@files_to_reopen << file unless file.closed?
@files_to_reopen << file if !file.closed?
end
end

View file

@ -25,7 +25,7 @@ def before_fork
# remember open file handles
@files_to_reopen = []
ObjectSpace.each_object(File) do |file|
@files_to_reopen << file unless file.closed?
@files_to_reopen << file if !file.closed?
end
end

View file

@ -37,7 +37,7 @@ class AgentTicketTagTest < TestCase
css: '.active .newTicket button.js-submit',
)
sleep 5
unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
if !@browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
raise 'Unable to create ticket!'
end
@ -69,7 +69,7 @@ class AgentTicketTagTest < TestCase
click(css: '#global-search')
click(css: '.active .newTicket button.js-submit')
sleep 5
unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
if !@browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
raise 'Unable to create ticket!'
end
@ -428,7 +428,7 @@ class AgentTicketTagTest < TestCase
css: '.active .newTicket button.js-submit',
)
sleep 5
unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
if !@browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
raise 'Unable to create ticket!'
end

View file

@ -104,7 +104,7 @@ class TestCase < Test::Unit::TestCase
browser_width = ENV['BROWSER_WIDTH'] || 1024
browser_height = ENV['BROWSER_HEIGHT'] || 800
local_browser.manage.window.resize_to(browser_width, browser_height)
unless ENV['REMOTE_URL']&.match?(/saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)/i)
if !ENV['REMOTE_URL']&.match?(/saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)/i)
if @browsers.count == 1
local_browser.manage.window.move_to(0, 0)
else
@ -362,7 +362,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
sleep 0.7
current_url = instance.current_url
unless current_url.match?(/#{Regexp.quote(params[:url])}/)
if !current_url.match?(/#{Regexp.quote(params[:url])}/)
screenshot(browser: instance, comment: 'location_check_failed')
raise "url #{current_url} is not matching #{params[:url]}"
end
@ -1352,7 +1352,7 @@ wait untill text in selector disabppears
if params[:value]
begin
text = instance.find_elements(css: params[:css])[0].text
unless text.match?(/#{params[:value]}/i)
if !text.match?(/#{params[:value]}/i)
assert(true, "not matching '#{params[:value]}' in text '#{text}'")
sleep 1
return true
@ -2427,7 +2427,7 @@ wait untill text in selector disabppears
element.click
sleep 1
number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text
unless number.match?(/#{params[:number]}/)
if !number.match?(/#{params[:number]}/)
screenshot(browser: instance, comment: 'ticket_open_by_overview_open_failed_failed')
raise "unable to open ticket #{params[:number]}!"
end
@ -2473,7 +2473,7 @@ wait untill text in selector disabppears
instance.execute_script("$(\".js-global-search-result a:contains('#{params[:number]}') .nav-tab-icon\").first().click()")
sleep 1
number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text
unless number.match?(/#{params[:number]}/)
if !number.match?(/#{params[:number]}/)
screenshot(browser: instance, comment: 'ticket_open_by_search_failed')
raise "unable to search/find ticket #{params[:number]}!"
end
@ -2509,7 +2509,7 @@ wait untill text in selector disabppears
instance.execute_script("$(\".js-global-search-result a:contains('#{params[:title]}') .nav-tab-icon\").click()")
sleep 1
title = instance.find_elements(css: '.content.active .ticketZoom-header .js-objectTitle')[0].text
unless title.match?(/#{params[:title]}/)
if !title.match?(/#{params[:title]}/)
screenshot(browser: instance, comment: 'ticket_open_by_title_failed')
raise "unable to search/find ticket #{params[:title]}!"
end
@ -2597,7 +2597,7 @@ wait untill text in selector disabppears
instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()")
sleep 1
name = instance.find_elements(css: '.content.active h1')[0].text
unless name.match?(/#{params[:value]}/)
if !name.match?(/#{params[:value]}/)
screenshot(browser: instance, comment: 'organization_open_by_search_failed')
raise "unable to search/find org #{params[:value]}!"
end
@ -2632,7 +2632,7 @@ wait untill text in selector disabppears
instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()")
sleep 1
name = instance.find_elements(css: '.content.active h1')[0].text
unless name.match?(/#{params[:value]}/)
if !name.match?(/#{params[:value]}/)
screenshot(browser: instance, comment: 'user_open_by_search_failed')
raise "unable to search/find user #{params[:value]}!"
end

View file

@ -55,7 +55,7 @@ class AutoWizardTest < ActiveSupport::TestCase
assert_equal(local_user[:lastname], user.lastname)
assert_equal(local_user[:email], user.email)
assert_equal(local_user[:roles].count, user.role_ids.count)
next unless local_user[:roles]
next if !local_user[:roles]
local_user[:roles].each do |local_role_name|
local_role = Role.find_by(name: local_role_name)
assert(user.role_ids.include?(local_role.id))
@ -64,7 +64,7 @@ class AutoWizardTest < ActiveSupport::TestCase
auto_wizard_data[:Groups].each do |local_group|
group = Group.find_by(name: local_group[:name])
assert_equal(local_group[:name], group.name)
next unless local_group[:users]
next if !local_group[:users]
local_group[:users].each do |local_user_login|
local_user = User.find_by(login: local_user_login)
assert(group.user_ids.include?(local_user.id))
@ -193,7 +193,7 @@ class AutoWizardTest < ActiveSupport::TestCase
assert_equal(local_user[:firstname], user.firstname)
assert_equal(local_user[:lastname], user.lastname)
assert_equal(local_user[:email], user.email)
next unless local_user[:roles]
next if !local_user[:roles]
assert_equal(local_user[:roles].count, user.role_ids.count)
local_user[:roles].each do |local_role_name|
local_role = Role.find_by(name: local_role_name)