Updated rubocop(-* gems) to latest version (1.2.0).

This commit is contained in:
Thorsten Eckel 2020-11-05 17:31:00 +01:00
parent 0655b370ed
commit 43b6374d16
29 changed files with 112 additions and 120 deletions

View file

@ -185,7 +185,7 @@ group :development, :test do
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'
gem 'rubocop-rspec', '2.0.0.pre' # see: https://github.com/rubocop-hq/rubocop-rspec/issues/1051
# changelog generation
gem 'github_changelog_generator'

View file

@ -452,16 +452,16 @@ GEM
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rszr (0.5.2)
rubocop (0.93.1)
rubocop (1.2.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
rubocop-ast (>= 1.0.1)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.0.0)
rubocop-ast (1.1.1)
parser (>= 2.7.1.5)
rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
@ -470,9 +470,8 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.87.0)
rubocop-rspec (1.44.1)
rubocop (~> 0.87)
rubocop-ast (>= 0.7.1)
rubocop-rspec (2.0.0.pre)
rubocop (~> 1.0)
ruby-progressbar (1.10.1)
ruby-saml (1.10.2)
nokogiri (>= 1.5.10)
@ -656,7 +655,7 @@ DEPENDENCIES
rubocop
rubocop-performance
rubocop-rails
rubocop-rspec
rubocop-rspec (= 2.0.0.pre)
rubyntlm!
sassc-rails
selenium-webdriver

View file

@ -16,10 +16,10 @@ class SearchController < ApplicationController
# convert objects string into array of class names
# e.g. user-ticket-another_object = %w( User Ticket AnotherObject )
objects = if !params[:objects]
Setting.get('models_searchable')
else
objects = if params[:objects]
params[:objects].split('-').map(&:camelize)
else
Setting.get('models_searchable')
end
# get priorities of result

View file

@ -329,10 +329,10 @@ example
begin
timeout(FETCH_MSG_TIMEOUT) do
if !keep_on_server
@imap.store(message_id, '+FLAGS', [:Deleted])
else
if keep_on_server
@imap.store(message_id, '+FLAGS', [:Seen])
else
@imap.store(message_id, '+FLAGS', [:Deleted])
end
end
rescue Timeout::Error => e

View file

@ -943,12 +943,11 @@ module Mail
# https://github.com/zammad/zammad/issues/348
class Body
def decoded
if !Encodings.defined?(encoding)
#raise UnknownEncodingType, "Don't know how to decode #{encoding}, please call #encoded and decode it yourself."
if Encodings.defined?(encoding)
Encodings.get_encoding(encoding).decode(raw_source)
else
Rails.logger.info "UnknownEncodingType: Don't know how to decode #{encoding}!"
raw_source
else
Encodings.get_encoding(encoding).decode(raw_source)
end
end
end

View file

@ -226,7 +226,7 @@ returns
# see specs for example
return [] if !text.is_a?(String)
text.scan(/([\d|\s|\-|(|)]{6,26})/).map do |match|
text.scan(/([\d\s\-(|)]{6,26})/).map do |match|
normalize_number(match[0])
end
end

View file

@ -155,16 +155,16 @@ class Observer::Transaction < ActiveRecord::Observer
# merge changes
if event[:changes]
if !store[:changes]
store[:changes] = event[:changes]
else
if store[:changes]
event[:changes].each do |key, value|
if !store[:changes][key]
store[:changes][key] = value
else
if store[:changes][key]
store[:changes][key][1] = value[1]
else
store[:changes][key] = value
end
end
else
store[:changes] = event[:changes]
end
end

View file

@ -73,23 +73,23 @@ class SMIMECertificate < ApplicationModel
@email_addresses ||= begin
subject_alt_name = parsed.extensions.detect { |extension| extension.oid == 'subjectAltName' }
if subject_alt_name.blank?
warning = <<~TEXT.squish
Rails.logger.warn <<~TEXT.squish
SMIMECertificate with ID #{id} has no subjectAltName
extension and therefore no email addresses assigned.
This makes it useless in terms of S/MIME. Please check.
TEXT
Rails.logger.warn warning
return []
end
# ["IP Address:192.168.7.23", "IP Address:192.168.7.42", "email:jd@example.com", "email:John.Doe@example.com", "dirName:dir_sect"]
entries = subject_alt_name.value.split(/,\s?/)
# ["email:jd@example.com", "email:John.Doe@example.com"]
email_address_entries = entries.select { |entry| entry.start_with?('email') }
# ["jd@example.com", "John.Doe@example.com"]
email_address_entries.map! { |entry| entry.split(':')[1] }
# ["jd@example.com", "john.doe@example.com"]
email_address_entries.map!(&:downcase)
[]
else
# ["IP Address:192.168.7.23", "IP Address:192.168.7.42", "email:jd@example.com", "email:John.Doe@example.com", "dirName:dir_sect"]
entries = subject_alt_name.value.split(/,\s?/)
# ["email:jd@example.com", "email:John.Doe@example.com"]
email_address_entries = entries.select { |entry| entry.start_with?('email') }
# ["jd@example.com", "John.Doe@example.com"]
email_address_entries.map! { |entry| entry.split(':')[1] }
# ["jd@example.com", "john.doe@example.com"]
email_address_entries.map!(&:downcase)
end
end
end

View file

@ -470,13 +470,13 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation
private_class_method def self.locals_to_sync(dedicated_locale = nil)
locales_list = []
if !dedicated_locale
if dedicated_locale
locales_list = [dedicated_locale]
else
locales = Locale.to_sync
locales.each do |locale|
locales_list.push locale.locale
end
else
locales_list = [dedicated_locale]
end
locales_list
end

View file

@ -33,7 +33,10 @@ class SettingAddPlacetel1 < ActiveRecord::Migration[5.1]
frontend: true
)
placetel_config = Setting.find_by(name: 'placetel_config')
if !placetel_config
if placetel_config
placetel_config.preferences[:cache] = ['placetelGetVoipUsers']
placetel_config.save!
else
Setting.create!(
title: 'Placetel config',
name: 'placetel_config',
@ -48,9 +51,6 @@ class SettingAddPlacetel1 < ActiveRecord::Migration[5.1]
},
frontend: false,
)
else
placetel_config.preferences[:cache] = ['placetelGetVoipUsers']
placetel_config.save!
end
Setting.create_if_not_exists(
title: 'PLACETEL Token',

View file

@ -124,16 +124,7 @@ class String
# find <a href=....> and replace it with [x]
link_list = ''
counter = 0
if !string_only
if string.scan(/<a[[:space:]]/i).count < 5_000
string.gsub!(/<a[[:space:]].*?href=("|')(.+?)("|').*?>/ix) do
link = $2
counter = counter + 1
link_list += "[#{counter}] #{link}\n"
"[#{counter}] "
end
end
else
if string_only
string.gsub!(%r{<a[[:space:]]+(|\S+[[:space:]]+)href=("|')(.+?)("|')([[:space:]]*|[[:space:]]+[^>]*)>(.+?)<[[:space:]]*/a[[:space:]]*>}mxi) do |_placeholder|
link = $3
text = $6
@ -168,6 +159,13 @@ class String
"#{link} (######LINKRAW:#{text}######)"
end
end
elsif string.scan(/<a[[:space:]]/i).count < 5_000
string.gsub!(/<a[[:space:]].*?href=("|')(.+?)("|').*?>/ix) do
link = $2
counter = counter + 1
link_list += "[#{counter}] #{link}\n"
"[#{counter}] "
end
end
# remove style tags with content
@ -195,7 +193,7 @@ class String
# blockquote handling
string.gsub!(%r{<blockquote(| [^>]*)>(.+?)</blockquote>}m) do
"\n#{$2.html2text(true).gsub(/^(.*)$/, '&gt; \1')}\n" # rubocop:disable Lint/OutOfRangeRegexpRef
"\n#{$2.html2text(true).gsub(/^(.*)$/, '&gt; \1')}\n"
end
# pre/code handling 2/2

View file

@ -241,10 +241,10 @@ result
to = nil
if post['to'] && post['to']['data']
post['to']['data'].each do |to_entry|
if !to
to = ''
else
if to
to += ', '
else
to = ''
end
to += to_entry['name']
end

View file

@ -45,21 +45,24 @@ or if you only want to create 100 tickets
# organizations
organization_pool = []
if !organizations.zero?
if organizations.zero?
organization_pool = Organization.where(active: true)
puts " take #{organization_pool.length} organizations"
else
(1..organizations).each do
ActiveRecord::Base.transaction do
organization = Organization.create!(name: "FillOrganization::#{rand(999_999)}", active: true)
organization_pool.push organization
end
end
else
organization_pool = Organization.where(active: true)
puts " take #{organization_pool.length} organizations"
end
# create agents
agent_pool = []
if !agents.zero?
if agents.zero?
agent_pool = Role.where(name: 'Agent').first.users.where(active: true)
puts " take #{agent_pool.length} agents"
else
roles = Role.where(name: [ 'Agent'])
groups_all = Group.all
@ -80,14 +83,14 @@ or if you only want to create 100 tickets
agent_pool.push user
end
end
else
agent_pool = Role.where(name: 'Agent').first.users.where(active: true)
puts " take #{agent_pool.length} agents"
end
# create customer
customer_pool = []
if !customers.zero?
if customers.zero?
customer_pool = Role.where(name: 'Customer').first.users.where(active: true)
puts " take #{customer_pool.length} customers"
else
roles = Role.where(name: [ 'Customer'])
groups_all = Group.all
@ -112,15 +115,15 @@ or if you only want to create 100 tickets
customer_pool.push user
end
end
else
customer_pool = Role.where(name: 'Customer').first.users.where(active: true)
puts " take #{customer_pool.length} customers"
end
# create groups
group_pool = []
if !groups.zero?
if groups.zero?
group_pool = Group.where(active: true)
puts " take #{group_pool.length} groups"
else
(1..groups).each do
ActiveRecord::Base.transaction do
group = Group.create!(name: "FillGroup::#{rand(999_999)}", active: true)
@ -134,9 +137,6 @@ or if you only want to create 100 tickets
sleep nice
end
end
else
group_pool = Group.where(active: true)
puts " take #{group_pool.length} groups"
end
# create overviews

View file

@ -113,10 +113,10 @@ satinize html string based on whiltelist
end
class_new += local_class
end
if class_new != ''
node['class'] = class_new
else
if class_new == ''
node.delete('class')
else
node['class'] = class_new
end
end

View file

@ -139,11 +139,7 @@ examples how to use
break
end
end
placeholder = if !value
object_refs
else
value
end
placeholder = value || object_refs
escaping(convert_to_timezone(placeholder), escape)
end

View file

@ -20,7 +20,7 @@ examples how to use
@template.gsub(/\#{\s*(.*?)\s*}/m) do
# some browsers start adding HTML tags
# fixes https://github.com/zammad/zammad/issues/385
input_template = $1.gsub(/\A<.+?>\s*|\s*<.+?>\z/, '') # rubocop:disable Lint/OutOfRangeRegexpRef
input_template = $1.gsub(/\A<.+?>\s*|\s*<.+?>\z/, '')
case input_template
when /\At\('(.+?)'\)\z/m

View file

@ -160,13 +160,7 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
data[:assets] = assets.to_h
if !@client
result = {
event: 'ticket_overview_list',
data: data,
}
results.push result
else
if @client
@client.log "push overview_list #{overview.link} for user #{@user.id}"
# send update to browser
@ -174,6 +168,12 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
event: 'ticket_overview_list',
data: data,
)
else
result = {
event: 'ticket_overview_list',
data: data,
}
results.push result
end
assets.flush

View file

@ -26,10 +26,10 @@ class Sessions::Event::Base
end
def websocket_send(recipient_client_id, data)
msg = if data.class != Array
"[#{data.to_json}]"
else
msg = if data.instance_of?(Array)
data.to_json
else
"[#{data.to_json}]"
end
if @clients[recipient_client_id]
log 'debug', "ws send #{msg}", recipient_client_id

View file

@ -253,10 +253,10 @@ class TwitterSync
if item['entities']
item['entities']['user_mentions']&.each do |local_user|
if !to
to = ''
else
if to
to += ', '
else
to = ''
end
to += "@#{local_user['screen_name']}"
mention_ids.push local_user['id']
@ -380,10 +380,10 @@ class TwitterSync
from = "@#{tweet.user.screen_name}"
mention_ids = []
tweet.user_mentions&.each do |local_user|
if !to
to = ''
else
if to
to += ', '
else
to = ''
end
to += "@#{local_user.screen_name}"
mention_ids.push local_user.id

View file

@ -115,10 +115,10 @@ class WebsocketServer
end
def self.websocket_send(client_id, data)
msg = if data.class != Array
"[#{data.to_json}]"
else
msg = if data.instance_of?(Array)
data.to_json
else
"[#{data.to_json}]"
end
log 'debug', "send #{msg}", client_id
if !@clients[client_id]

View file

@ -7,8 +7,8 @@ FactoryBot.define do
area { 'Email::Dummy' }
group { ::Group.find(1) }
active { true }
options {}
preferences {}
options { nil }
preferences { nil }
updated_by_id { 1 }
created_by_id { 1 }

View file

@ -1,7 +1,7 @@
FactoryBot.define do
factory :import_job do
name { 'Import::Test' }
payload {}
payload { nil }
dry_run { false }
end
end

View file

@ -1,6 +1,6 @@
FactoryBot.define do
factory :notification_factory_renderer, class: NotificationFactory::Renderer do
objects {}
objects { nil }
locale { 'en-en' }
template { '' }
escape { true }

View file

@ -4,7 +4,7 @@ FactoryBot.define do
key { 'Ticket-1234' }
add_attribute(:callback) { 'TicketZoom' }
params { {} }
state {}
state { nil }
prio { 1 }
notify { false }
user_id { 1 }

View file

@ -31,7 +31,7 @@ RSpec.describe ApplicationHandleInfo do
end
it 'resets ApplicationHandleInfo to its original value' do
described_class.use('bar') {}
described_class.use('bar') { nil }
expect(described_class.current).to eq('foo')
end

View file

@ -72,7 +72,7 @@ RSpec.describe 'Gmail XOAUTH2' do # rubocop:disable RSpec/DescribeClass
end
it "doesn't remove email address assignments" do
expect { Channel.where(area: 'Google::Account').find_each {} }.not_to change { email_address.reload.channel_id }
expect { Channel.where(area: 'Google::Account').find_each { nil } }.not_to change { email_address.reload.channel_id }
end
end
end

View file

@ -71,7 +71,7 @@ RSpec.describe 'Microsoft365 XOAUTH2' do # rubocop:disable RSpec/DescribeClass
end
it "doesn't remove email address assignments" do
expect { Channel.where(area: 'Microsoft365::Account').find_each {} }.not_to change { email_address.reload.channel_id }
expect { Channel.where(area: 'Microsoft365::Account').find_each { nil } }.not_to change { email_address.reload.channel_id }
end
end
end

View file

@ -6,7 +6,7 @@ module KnowledgeBasePublicMatchers
match { breadcrumb_found? && of_specified_length? }
chain(:with, :length)
chain(:items) {}
chain(:items) { nil }
description do
if @length.present?

View file

@ -265,13 +265,13 @@ class TestCase < ActiveSupport::TestCase
sleep 4
login_failed = false
if !instance.find_elements(css: '.user-menu .user a')[0]
login_failed = true
else
if instance.find_elements(css: '.user-menu .user a')[0]
login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
if login != params[:username]
login_failed = true
end
else
login_failed = true
end
if login_failed
if params[:success] == false
@ -784,14 +784,14 @@ class TestCase < ActiveSupport::TestCase
end
begin
if !params[:slow]
element.send_keys(params[:value])
else
if params[:slow]
element.send_keys('')
keys = params[:value].to_s.split('')
keys.each do |key|
instance.action.send_keys(key).perform
end
else
element.send_keys(params[:value])
end
rescue
sleep 0.5
@ -801,14 +801,14 @@ class TestCase < ActiveSupport::TestCase
element = instance.find_elements(css: params[:css])[0]
raise "No such element '#{params[:css]}'" if !element
if !params[:slow]
element.send_keys(params[:value])
else
if params[:slow]
element.send_keys('')
keys = params[:value].to_s.split('')
keys.each do |key|
instance.action.send_keys(key).perform
end
else
element.send_keys(params[:value])
end
end