From a976b9fb43c1099430fbe740543c3842ef568290 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 18 Feb 2020 20:51:31 +0100 Subject: [PATCH] Maintenance: Updated rubocop(-* gems) to latest version (0.80.0). --- .rubocop.yml | 19 ++-- .rubocop_todo.rspec.yml | 1 + Gemfile.lock | 22 +++-- app/controllers/channels_sms_controller.rb | 2 +- app/controllers/monitoring_controller.rb | 2 +- .../application_model/has_attachments.rb | 2 +- app/models/calendar.rb | 4 +- app/models/channel.rb | 6 +- app/models/channel/email_build.rb | 2 +- app/models/channel/email_parser.rb | 4 +- app/models/object_manager/attribute.rb | 2 +- app/models/store/provider/file.rb | 2 +- app/models/ticket/number/date.rb | 2 +- app/models/translation.rb | 18 ++-- config/environments/development.rb | 2 +- config/initializers/core_ext.rb | 2 +- config/initializers/omniauth.rb | 2 +- lib/core_ext/string.rb | 8 +- lib/html_sanitizer.rb | 2 +- lib/models.rb | 2 +- lib/notification_factory.rb | 4 +- lib/sessions.rb | 4 +- lib/sessions/event.rb | 2 +- lib/tasks/search_index_es.rake | 2 +- lib/tasks/zammad/ci/app/start.rake | 2 +- lib/tasks/zammad/ci/service/puma/start.rake | 2 +- lib/tasks/zammad/ci/service/puma/stop.rake | 4 +- .../zammad/ci/service/scheduler/start.rake | 2 +- .../zammad/ci/service/scheduler/stop.rake | 2 +- .../zammad/ci/service/websocket/start.rake | 2 +- .../zammad/ci/service/websocket/stop.rake | 2 +- lib/tasks/zammad/ci/test/fail.rake | 2 +- lib/tasks/zammad/ci/test/prepare.rake | 2 +- lib/tasks/zammad/ci/test/start.rake | 2 +- lib/tasks/zammad/ci/test/stop.rake | 2 +- lib/tasks/zammad/flush/cache.rake | 4 +- lib/tasks/zammad/flush/log/rails.rake | 2 +- lib/tasks/zammad/flush/log/scheduler.rake | 2 +- lib/tasks/zammad/flush/log/websocket.rake | 2 +- lib/tasks/zammad/setup/db_config.rake | 2 +- lib/twitter/streaming/connection_custom.rb | 2 +- lib/user_agent.rb | 8 +- .../initializer/db_preflight_check/mysql2.rb | 2 +- spec/lib/auth/base_spec.rb | 2 +- spec/lib/auth/developer_spec.rb | 2 +- spec/lib/auth/internal_spec.rb | 2 +- spec/lib/auth/ldap_spec.rb | 2 +- spec/lib/auth_spec.rb | 6 +- spec/lib/external_sync_spec.rb | 4 +- spec/lib/import/base_factory_examples.rb | 3 + spec/lib/import/import_stats_examples.rb | 1 + spec/lib/import/otrs/article_customer_spec.rb | 4 +- spec/lib/import/otrs/customer_user_spec.rb | 2 +- spec/lib/import/otrs/requester_spec.rb | 6 +- spec/lib/ldap/group_spec.rb | 8 +- spec/lib/ldap/guid_spec.rb | 10 +- spec/lib/ldap/user_spec.rb | 10 +- spec/lib/ldap_spec.rb | 6 +- spec/lib/notification_factory/mailer_spec.rb | 4 +- spec/lib/notification_factory_spec.rb | 4 +- spec/lib/signature_detection_spec.rb | 22 ++--- spec/lib/user_info_spec.rb | 2 +- spec/models/calendar_spec.rb | 10 +- spec/models/channel/email_parser_spec.rb | 91 +++---------------- .../channel/filter/match/email_regex_spec.rb | 4 +- spec/models/concerns/has_groups_examples.rb | 32 +++---- .../has_groups_permissions_examples.rb | 18 ++-- spec/models/concerns/has_roles_examples.rb | 10 +- .../has_search_index_backend_examples.rb | 2 +- spec/models/ticket/subject_spec.rb | 9 ++ spec/models/ticket_spec.rb | 4 +- spec/models/translation_spec.rb | 2 +- spec/models/trigger_spec.rb | 8 +- spec/rails_helper.rb | 2 +- spec/requests/integration/monitoring_spec.rb | 4 +- spec/requests/integration/telegram_spec.rb | 1 + .../integration/twitter_webhook_spec.rb | 4 +- spec/requests/search_spec.rb | 2 +- .../ticket/article_attachments_spec.rb | 6 +- spec/support/capybara/browser_test_helper.rb | 2 +- spec/support/db_migration.rb | 2 +- spec/system/setup/auto_wizard_spec.rb | 2 +- test/browser/agent_ticket_attachment_test.rb | 10 +- test/browser/agent_ticket_zoom_hide_test.rb | 2 +- test/browser_test_helper.rb | 14 +-- test/integration/elasticsearch_test.rb | 10 +- .../integration/email_postmaster_to_sender.rb | 8 +- test/integration_test_helper.rb | 4 +- test/test_helper.rb | 4 +- test/test_support_helper.rb | 2 +- test/unit/store_test.rb | 38 ++++---- .../ticket_trigger_recursive_disabled_test.rb | 20 ++-- test/unit/ticket_trigger_test.rb | 24 ++--- 93 files changed, 287 insertions(+), 330 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7e3b4291b..449462386 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -32,7 +32,7 @@ Rails: Style/FrozenStringLiteralComment: Enabled: false -Metrics/LineLength: +Layout/LineLength: Description: 'Limit lines to 80 characters.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits' Enabled: false @@ -106,7 +106,7 @@ Style/MethodDefParentheses: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' Enabled: false -Layout/AlignHash: +Layout/HashAlignment: Description: >- Align the elements of a hash literal if they span more than one line. @@ -155,6 +155,15 @@ Style/PerlBackrefs: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers' Enabled: false +Style/HashEachMethods: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true + Style/SelfAssignment: Description: >- Checks for places where self-assignment shorthand should have @@ -162,10 +171,6 @@ Style/SelfAssignment: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' Enabled: false -Style/BracesAroundHashParameters: - Description: 'Enforce braces style around hash parameters.' - Enabled: false - Rails/ApplicationRecord: Exclude: - 'app/models/application_model.rb' @@ -210,7 +215,7 @@ Naming/VariableNumber: Description: 'Use the configured style when numbering variables.' Enabled: false -Naming/UncommunicativeMethodParamName: +Naming/MethodParameterName: Description: >- Checks for method parameter names that contain capital letters, end in numbers, or do not meet a minimal length. diff --git a/.rubocop_todo.rspec.yml b/.rubocop_todo.rspec.yml index fe218b788..5ebe0d2d0 100644 --- a/.rubocop_todo.rspec.yml +++ b/.rubocop_todo.rspec.yml @@ -170,6 +170,7 @@ RSpec/ScatteredSetup: # Offense count: 8 RSpec/SubjectStub: Exclude: + - 'spec/lib/import/exchange/folder_spec.rb' - 'spec/models/concerns/has_groups_examples.rb' - 'spec/models/concerns/has_roles_examples.rb' - 'spec/models/job_spec.rb' diff --git a/Gemfile.lock b/Gemfile.lock index b98f13cf9..661086748 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -255,7 +255,7 @@ GEM ice_cube (0.16.3) inflection (1.0.0) interception (0.5) - jaro_winkler (1.5.3) + jaro_winkler (1.5.4) json (2.2.0) jwt (2.2.1) kgio (2.11.2) @@ -354,8 +354,8 @@ GEM omniauth-weibo-oauth2 (0.5.2) omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0) - parallel (1.17.0) - parser (2.6.4.0) + parallel (1.19.1) + parser (2.7.0.2) ast (~> 2.4.0) pg (0.21.0) pluginator (1.5.0) @@ -426,6 +426,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (2.1.0) + rexml (3.2.4) rspec-core (3.8.0) rspec-support (~> 3.8.0) rspec-expectations (3.8.2) @@ -444,20 +445,21 @@ GEM rspec-support (~> 3.8.0) rspec-support (3.8.0) rszr (0.5.2) - rubocop (0.74.0) + rubocop (0.80.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) + rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.4.1) + rubocop-performance (1.5.2) rubocop (>= 0.71.0) - rubocop-rails (2.3.2) + rubocop-rails (2.4.2) rack (>= 1.1) rubocop (>= 0.72.0) - rubocop-rspec (1.35.0) - rubocop (>= 0.60.0) + rubocop-rspec (1.38.1) + rubocop (>= 0.68.1) ruby-progressbar (1.10.1) ruby-saml (1.10.2) nokogiri (>= 1.5.10) @@ -526,7 +528,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.6.0) + unicode-display_width (1.6.1) unicorn (5.5.0) kgio (~> 2.6) raindrops (~> 0.7) diff --git a/app/controllers/channels_sms_controller.rb b/app/controllers/channels_sms_controller.rb index e6d99d05a..e9cd354e3 100644 --- a/app/controllers/channels_sms_controller.rb +++ b/app/controllers/channels_sms_controller.rb @@ -66,7 +66,7 @@ class ChannelsSmsController < ApplicationChannelController def channels_config list = [] - Dir.glob(Rails.root.join('app', 'models', 'channel', 'driver', 'sms', '*.rb')).each do |path| + Dir.glob(Rails.root.join('app/models/channel/driver/sms/*.rb')).each do |path| filename = File.basename(path) require_dependency "channel/driver/sms/#{filename.sub('.rb', '')}" list.push Channel.driver_class("sms/#{filename}").definition diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index 8b1981f20..3a855beea 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -64,7 +64,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX end # unprocessable mail check - directory = Rails.root.join('tmp', 'unprocessable_mail').to_s + directory = Rails.root.join('tmp/unprocessable_mail').to_s if File.exist?(directory) count = 0 Dir.glob("#{directory}/*.eml") do |_entry| diff --git a/app/models/application_model/has_attachments.rb b/app/models/application_model/has_attachments.rb index defd84783..d9770bb0f 100644 --- a/app/models/application_model/has_attachments.rb +++ b/app/models/application_model/has_attachments.rb @@ -54,7 +54,7 @@ store attachments for this object self.attachments_buffer = attachments # update if object already exists - return if !(id&.nonzero?) + return if !id&.nonzero? attachments_buffer_check end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index a347977ef..da82df7b7 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -86,7 +86,7 @@ returns =end def self.ical_feeds - data = YAML.load_file(Rails.root.join('config', 'holiday_calendars.yml')) + data = YAML.load_file(Rails.root.join('config/holiday_calendars.yml')) url = data['url'] data['countries'].map do |country, domain| @@ -256,7 +256,7 @@ returns # get day and comment by event def self.day_and_comment_by_event(event, start_time) - day = "#{start_time.year}-#{format('%02d', start_time.month)}-#{format('%02d', start_time.day)}" + day = "#{start_time.year}-#{format('%02d', month: start_time.month)}-#{format('%02d', day: start_time.day)}" comment = event.summary || event.description comment = comment.to_utf8(fallback: :read_as_sanitized_binary) diff --git a/app/models/channel.rb b/app/models/channel.rb index e184405b4..59965caa0 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -58,7 +58,7 @@ fetch one account self.last_log_in = result[:notice] preferences[:last_fetch] = Time.zone.now save! - return true + true rescue => e error = "Can't use Channel::Driver::#{adapter.to_classname}: #{e.inspect}" logger.error error @@ -67,7 +67,7 @@ fetch one account self.last_log_in = error preferences[:last_fetch] = Time.zone.now save! - return false + false end end @@ -98,7 +98,7 @@ stream instance of account # set scheduler job to active - return driver_instance + driver_instance rescue => e error = "Can't use Channel::Driver::#{adapter.to_classname}: #{e.inspect}" logger.error error diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index ee2083b0f..b1dc1cf13 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -153,7 +153,7 @@ Check if string is a complete html document. If not, add head and css styles. return html if html.match?(//i) - html_email_body = File.read(Rails.root.join('app', 'views', 'mailer', 'application_wrapper.html.erb').to_s) + html_email_body = File.read(Rails.root.join('app/views/mailer/application_wrapper.html.erb').to_s) html_email_body.gsub!('###html_email_css_font###', Setting.get('html_email_css_font')) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 205ceb28d..6d7cfa86a 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -473,7 +473,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again =end def self.process_unprocessable_mails(params = {}) - path = Rails.root.join('tmp', 'unprocessable_mail') + path = Rails.root.join('tmp/unprocessable_mail') files = [] Dir.glob("#{path}/*.eml") do |entry| ticket, _article, _user, _mail = Channel::EmailParser.new.process(params, IO.binread(entry)) @@ -847,7 +847,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again mail = OpenStruct.new mail.from_display_name = parsed_incoming_mail[:from_display_name] mail.subject = parsed_incoming_mail[:subject] - mail.msg_size = format('%.2f', raw_incoming_mail.size.to_f / 1024 / 1024) + mail.msg_size = format('%.2f', MB: raw_incoming_mail.size.to_f / 1024 / 1024) reply = NotificationFactory::Mailer.template( template: 'email_oversized', diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 40fa9c00a..1fe6ce62d 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -25,7 +25,7 @@ class ObjectManager::Attribute < ApplicationModel belongs_to :object_lookup, optional: true validates :name, presence: true - validates :data_type, inclusion: { in: DATA_TYPES, msg: '%{value} is not a valid data type' } + validates :data_type, inclusion: { in: DATA_TYPES, msg: '%{value} is not a valid data type' } # rubocop:disable Style/FormatStringToken validate :data_option_must_have_appropriate_values validate :data_type_must_not_change, on: :update diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 9077e3ddb..296be841d 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -79,7 +79,7 @@ class Store::Provider::File def self.get_location(sha) # generate directory - base = Rails.root.join('storage', 'fs').to_s + base = Rails.root.join('storage/fs').to_s parts = [] length1 = 4 length2 = 5 diff --git a/app/models/ticket/number/date.rb b/app/models/ticket/number/date.rb index 871b5d264..5f1f3338b 100644 --- a/app/models/ticket/number/date.rb +++ b/app/models/ticket/number/date.rb @@ -18,7 +18,7 @@ module Ticket::Number::Date counter.update(content: "#{counter_increment};#{date}") end - number = date.delete('-') + Setting.get('system_id').to_s + format('%04d', counter.content.split(';').first) + number = date.delete('-') + Setting.get('system_id').to_s + format('%04d', counter: counter.content.split(';').first) number += checksum(number) if config[:checksum] number diff --git a/app/models/translation.rb b/app/models/translation.rb index 4dd8d2432..26560b79e 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -246,15 +246,15 @@ or record = Translation.where(locale: locale, source: 'timestamp', format: 'time').pluck(:target).first return timestamp.to_s if !record - record.sub!('dd', format('%02d', timestamp.day)) + record.sub!('dd', format('%02d', day: timestamp.day)) record.sub!('d', timestamp.day.to_s) - record.sub!('mm', format('%02d', timestamp.month)) + record.sub!('mm', format('%02d', month: timestamp.month)) record.sub!('m', timestamp.month.to_s) record.sub!('yyyy', timestamp.year.to_s) record.sub!('yy', timestamp.year.to_s.last(2)) - record.sub!('SS', format('%02d', timestamp.sec.to_s)) - record.sub!('MM', format('%02d', timestamp.min.to_s)) - record.sub!('HH', format('%02d', timestamp.hour.to_s)) + record.sub!('SS', format('%02d', second: timestamp.sec.to_s)) + record.sub!('MM', format('%02d', minute: timestamp.min.to_s)) + record.sub!('HH', format('%02d', hour: timestamp.hour.to_s)) "#{record} (#{timezone})" end @@ -288,9 +288,9 @@ or record = Translation.where(locale: locale, source: 'date', format: 'time').pluck(:target).first return date.to_s if !record - record.sub!('dd', format('%02d', date.day)) + record.sub!('dd', format('%02d', day: date.day)) record.sub!('d', date.day.to_s) - record.sub!('mm', format('%02d', date.month)) + record.sub!('mm', format('%02d', month: date.month)) record.sub!('m', date.month.to_s) record.sub!('yyyy', date.year.to_s) record.sub!('yy', date.year.to_s.last(2)) @@ -313,7 +313,7 @@ all: def self.load_from_file(dedicated_locale = nil) version = Version.get - directory = Rails.root.join('config', 'translations') + directory = Rails.root.join('config/translations') locals_to_sync(dedicated_locale).each do |locale| file = Rails.root.join(directory, "#{locale}-#{version}.yml") return false if !File.exist?(file) @@ -358,7 +358,7 @@ all: ) raise "Can't load translations from #{url}: #{result.error}" if !result.success? - directory = Rails.root.join('config', 'translations') + directory = Rails.root.join('config/translations') if !File.directory?(directory) Dir.mkdir(directory, 0o755) end diff --git a/config/environments/development.rb b/config/environments/development.rb index 0167a307e..d8f76fe42 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,7 +14,7 @@ Rails.application.configure do # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.public_file_server.headers = { diff --git a/config/initializers/core_ext.rb b/config/initializers/core_ext.rb index d2e976842..a26ccbb12 100644 --- a/config/initializers/core_ext.rb +++ b/config/initializers/core_ext.rb @@ -1,5 +1,5 @@ # load all core_ext extensions -Dir.glob( Rails.root.join('lib', 'core_ext', '**', '*') ).each do |file| +Dir.glob( Rails.root.join('lib/core_ext/**/*') ).sort.each do |file| if File.file?(file) require file end diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 5b016ba69..ed8e270f5 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,4 +1,4 @@ -Dir[ Rails.root.join('lib', 'omniauth', '*') ].each do |file| +Dir[ Rails.root.join('lib/omniauth/*') ].sort.each do |file| if File.file?(file) require file end diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index b58f5735d..70d3c18a6 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -60,7 +60,7 @@ class String =end def to_filename - camel_cased_word = "#{self}" # rubocop:disable Style/UnneededInterpolation + camel_cased_word = dup camel_cased_word.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') @@ -77,7 +77,7 @@ class String =end def to_classname - camel_cased_word = "#{self}" # rubocop:disable Style/UnneededInterpolation + camel_cased_word = dup camel_cased_word.gsub!(/\.rb$/, '') camel_cased_word.split('/').map(&:camelize).join('::') end @@ -109,7 +109,7 @@ class String =end def html2text(string_only = false, strict = false) - string = "#{self}" # rubocop:disable Style/UnneededInterpolation + string = dup # in case of invalid encoding, strip invalid chars # see also test/data/mail/mail021.box @@ -322,7 +322,7 @@ class String =end def html2html_strict - string = "#{self}" # rubocop:disable Style/UnneededInterpolation + string = dup string = HtmlSanitizer.cleanup_replace_tags(string) string = HtmlSanitizer.strict(string, true).strip string = HtmlSanitizer.cleanup(string).strip diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index 727540feb..f062e209b 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -176,7 +176,7 @@ satinize html string based on whiltelist # remove attributes if not whitelisted node.each do |attribute, _value| attribute_name = attribute.downcase - next if attributes_whitelist[:all].include?(attribute_name) || (attributes_whitelist[node.name]&.include?(attribute_name)) + next if attributes_whitelist[:all].include?(attribute_name) || attributes_whitelist[node.name]&.include?(attribute_name) node.delete(attribute) end diff --git a/lib/models.rb b/lib/models.rb index 9aa7ae3c1..8c05d1efc 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -27,7 +27,7 @@ returns def self.all @all ||= begin all = {} - dir = Rails.root.join('app', 'models').to_s + dir = Rails.root.join('app/models').to_s tables = ActiveRecord::Base.connection.tables Dir.glob("#{dir}/**/*.rb") do |entry| next if entry.match?(/application_model/i) diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index 5831d0f5e..a54a4c641 100644 --- a/lib/notification_factory.rb +++ b/lib/notification_factory.rb @@ -1,6 +1,6 @@ module NotificationFactory - TEMPLATE_PATH_STRING = Rails.root.join('app', 'views', '%s', '%