From 40dcb0e1324c9f500836eb44b52cb5ec3373d4a4 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 2 Sep 2019 13:52:11 +0200 Subject: [PATCH] Updated rubocop to latest version (0.74). --- .rubocop.yml | 2 ++ .rubocop_todo.yml | 25 ++++++++++++------- Gemfile | 1 + Gemfile.lock | 20 ++++++++------- .../concerns/creates_ticket_articles.rb | 4 +-- .../ticket_article_communicate_email_job.rb | 1 + app/models/channel/email_parser.rb | 2 +- app/models/channel/filter/identify_sender.rb | 2 +- app/models/locale.rb | 2 +- app/models/package.rb | 4 +-- app/models/store/provider/file.rb | 1 + lib/html_sanitizer.rb | 2 +- .../exchange/folder_contacts/sub_sequence.rb | 2 +- lib/sessions.rb | 1 + lib/stats.rb | 2 +- test/browser/abb_one_group_test.rb | 2 +- test/browser/agent_ticket_attachment_test.rb | 1 + test/integration/elasticsearch_active_test.rb | 2 +- test/unit/calendar_subscription_test.rb | 2 +- 19 files changed, 47 insertions(+), 31 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a49e015c3..055107138 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ require: - rubocop-performance + - rubocop-rails - rubocop-rspec inherit_from: @@ -17,6 +18,7 @@ AllCops: - 'bin/spring' - 'db/schema.rb' - 'vendor/**/*' + - 'public/assets/**/*' RSpec: Patterns: - '_spec.rb$' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9355ee33b..5902525df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,12 +1,12 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-04-12 18:08:21 +0800 using RuboCop version 0.67.2. +# on 2019-09-02 13:20:31 +0200 using RuboCop version 0.74.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 97 +# Offense count: 163 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. Layout/ExtraSpacing: @@ -25,25 +25,25 @@ Lint/MissingCopEnableDirective: - 'lib/import/otrs/user_factory.rb' - 'lib/import/transaction_factory.rb' -# Offense count: 469 +# Offense count: 833 Metrics/AbcSize: Max: 637 -# Offense count: 28 +# Offense count: 29 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 5 -# Offense count: 336 +# Offense count: 340 Metrics/CyclomaticComplexity: Max: 97 -# Offense count: 23 +# Offense count: 27 # Configuration parameters: CountComments. Metrics/ModuleLength: Max: 559 -# Offense count: 272 +# Offense count: 274 Metrics/PerceivedComplexity: Max: 115 @@ -94,11 +94,18 @@ Rails/HasManyOrHasOneDependent: - 'app/models/ticket/state_type.rb' - 'app/models/user.rb' -# Offense count: 759 +# Offense count: 15 +# Configuration parameters: Include. +# Include: app/helpers/**/*.rb +Rails/HelperInstanceVariable: + Exclude: + - 'app/helpers/knowledge_base_helper.rb' + +# Offense count: 808 Style/Documentation: Enabled: false -# Offense count: 170 +# Offense count: 172 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit diff --git a/Gemfile b/Gemfile index f510e7326..4c1abd880 100644 --- a/Gemfile +++ b/Gemfile @@ -176,6 +176,7 @@ group :development, :test do gem 'pre-commit' gem 'rubocop' gem 'rubocop-performance' + gem 'rubocop-rails' gem 'rubocop-rspec' # changelog generation diff --git a/Gemfile.lock b/Gemfile.lock index 07705d2fc..cb17749c2 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.2) + jaro_winkler (1.5.3) json (2.2.0) jwt (2.1.0) kgio (2.11.2) @@ -352,7 +352,7 @@ GEM omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0) parallel (1.17.0) - parser (2.6.3.0) + parser (2.6.4.0) ast (~> 2.4.0) pg (0.21.0) pluginator (1.5.0) @@ -373,7 +373,6 @@ GEM pry-stack_explorer (0.4.9.3) binding_of_caller (>= 0.7) pry (>= 0.9.11) - psych (3.1.0) public_suffix (3.0.3) puma (3.12.1) rack (2.0.7) @@ -442,19 +441,21 @@ GEM rspec-support (~> 3.8.0) rspec-support (3.8.0) rszr (0.5.2) - rubocop (0.67.2) + rubocop (0.74.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - psych (>= 3.1.0) + parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.6) + unicode-display_width (>= 1.4.0, < 1.7) rubocop-performance (1.1.0) rubocop (>= 0.67.0) + rubocop-rails (2.3.2) + rack (>= 1.1) + rubocop (>= 0.72.0) rubocop-rspec (1.33.0) rubocop (>= 0.60.0) - ruby-progressbar (1.10.0) + ruby-progressbar (1.10.1) ruby_dep (1.5.0) rubyzip (1.2.2) safe_yaml (1.0.5) @@ -521,7 +522,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.5) - unicode-display_width (1.5.0) + unicode-display_width (1.6.0) unicorn (5.5.0) kgio (~> 2.6) raindrops (~> 0.7) @@ -629,6 +630,7 @@ DEPENDENCIES rszr (= 0.5.2) rubocop rubocop-performance + rubocop-rails rubocop-rspec rubyntlm! sassc-rails diff --git a/app/controllers/concerns/creates_ticket_articles.rb b/app/controllers/concerns/creates_ticket_articles.rb index 487b4cc2a..3d367af57 100644 --- a/app/controllers/concerns/creates_ticket_articles.rb +++ b/app/controllers/concerns/creates_ticket_articles.rb @@ -79,14 +79,14 @@ module CreatesTicketArticles params[:attachments].each_with_index do |attachment, index| # validation - ['mime-type', 'filename', 'data'].each do |key| + %w[mime-type filename data].each do |key| next if attachment[key] raise Exceptions::UnprocessableEntity, "Attachment needs '#{key}' param for attachment with index '#{index}'" end preferences = {} - ['charset', 'mime-type'].each do |key| + %w[charset mime-type].each do |key| next if !attachment[key] store_key = key.tr('-', '_').camelize.gsub(/(.+)([A-Z])/, '\1_\2').tr('_', '-') diff --git a/app/jobs/ticket_article_communicate_email_job.rb b/app/jobs/ticket_article_communicate_email_job.rb index f77fc761d..6d22bd310 100644 --- a/app/jobs/ticket_article_communicate_email_job.rb +++ b/app/jobs/ticket_article_communicate_email_job.rb @@ -154,6 +154,7 @@ class TicketArticleCommunicateEmailJob < ApplicationJob notification: true, }, ) + ticket = Ticket.find(local_record.ticket_id) ticket.state = Ticket::State.find_by(default_follow_up: true) ticket.save! diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 7c9713e3c..cc789e860 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -724,7 +724,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again # e. g. Content-Type: video/quicktime if filename.blank? map = { - 'message/delivery-status': ['txt', 'delivery-status'], + 'message/delivery-status': %w[txt delivery-status], 'text/plain': %w[txt document], 'text/html': %w[html document], 'video/quicktime': %w[mov video], diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index 21ed211a3..a890878f4 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -94,7 +94,7 @@ module Channel::Filter::IdentifySender def self.create_recipients(mail) max_count = 40 current_count = 0 - ['raw-to', 'raw-cc'].each do |item| + %w[raw-to raw-cc].each do |item| next if mail[item.to_sym].blank? begin diff --git a/app/models/locale.rb b/app/models/locale.rb index 459bc503d..26dbcd1e7 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -22,7 +22,7 @@ returns def self.to_sync locales = Locale.where(active: true) if Rails.env.test? - locales = Locale.where(active: true, locale: ['en-us', 'de-de']) + locales = Locale.where(active: true, locale: %w[en-us de-de]) end # read used locales based on env, e. g. export Z_LOCALES='en-us:de-de' diff --git a/app/models/package.rb b/app/models/package.rb index eae2a8671..6a02394e7 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -133,7 +133,7 @@ execute migration down + unlink files Dir.glob(package_base_dir + '/**/*') do |entry| entry = entry.sub('//', '/') file = entry - file = file.sub(/#{package_base_dir.to_s}/, '') + file = file.sub(/#{package_base_dir}/, '') dest = @@root + '/' + file if File.symlink?(dest.to_s) @@ -166,7 +166,7 @@ link files + execute migration up Dir.glob(package_base_dir + '/**/*') do |entry| entry = entry.sub('//', '/') file = entry - file = file.sub(/#{package_base_dir.to_s}/, '') + file = file.sub(/#{package_base_dir}/, '') file = file.sub(%r{^/}, '') # ignore files diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index f4fc0de03..cd2b639e5 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -100,6 +100,7 @@ class Store::Provider::File parts.push sha[last_position, length3] last_position = end_position end + path = parts[ 0..6 ].join('/') + '/' file = sha[last_position, sha.length] location = "#{base}/#{path}" diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index 11f477f0d..2e99f790c 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -25,7 +25,7 @@ satinize html string based on whiltelist # We whitelist yahoo_quoted because Yahoo Mail marks quoted email content using #
and we rely on this class to identify quoted messages - classes_whitelist = ['js-signatureMarker', 'yahoo_quoted'] + classes_whitelist = %w[js-signatureMarker yahoo_quoted] attributes_2_css = %w[width height] # remove html comments diff --git a/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb b/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb index fb0eff3f6..0ce073575 100644 --- a/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb +++ b/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb @@ -24,7 +24,7 @@ class Sequencer total = folder.total_count per_page = 1000 - pages = (total.to_f / per_page.to_f).ceil + pages = (total.to_f / per_page).ceil display_path = ews_folder.display_path(folder) (1..pages).each do |page| diff --git a/lib/sessions.rb b/lib/sessions.rb index 9c8835dac..fcce72a9a 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -519,6 +519,7 @@ get spool messages def self.spool_list(timestamp, current_user_id) path = "#{@path}/spool/" FileUtils.mkpath path + data = [] to_delete = [] files = [] diff --git a/lib/stats.rb b/lib/stats.rb index 5050f676b..c691cbfca 100644 --- a/lib/stats.rb +++ b/lib/stats.rb @@ -63,7 +63,7 @@ returns # generate average param and icon state backend_average_sum.each do |backend_model_average, result| - average = ( result.to_f / agent_count.to_f ).round(1) + average = ( result.to_f / agent_count ).round(1) user_result.each do |user_id, data| next if !data[backend_model_average] next if !data[backend_model_average].key?(:used_for_average) diff --git a/test/browser/abb_one_group_test.rb b/test/browser/abb_one_group_test.rb index 5547e5912..993d99b51 100644 --- a/test/browser/abb_one_group_test.rb +++ b/test/browser/abb_one_group_test.rb @@ -3,7 +3,7 @@ require 'browser_test_helper' class AgentTicketActionLevel0Test < TestCase def test_aaa_agent_ticket_create_with_one_group - agent = "bob.smith_one_group#{rand(99_999_999)}" + agent = "bob.smith_one_group#{rand(99_999_999)}" @browser = browser_instance login( diff --git a/test/browser/agent_ticket_attachment_test.rb b/test/browser/agent_ticket_attachment_test.rb index 19065a1ae..d1f40ed57 100644 --- a/test/browser/agent_ticket_attachment_test.rb +++ b/test/browser/agent_ticket_attachment_test.rb @@ -218,6 +218,7 @@ class AgentTicketAttachmentTest < TestCase tasks_close_all( browser: browser2, ) + random = 'ticket-actions-6-test-' + rand(999_999).to_s user_email = random + '@example.com' user_create( diff --git a/test/integration/elasticsearch_active_test.rb b/test/integration/elasticsearch_active_test.rb index 555c734f6..f3e9ca143 100644 --- a/test/integration/elasticsearch_active_test.rb +++ b/test/integration/elasticsearch_active_test.rb @@ -9,7 +9,7 @@ class ElasticsearchActiveTest < ActiveSupport::TestCase rebuild_searchindex - roles = Role.where(name: 'Agent') + roles = Role.where(name: 'Agent') @agent = User.create!( login: 'es-agent@example.com', diff --git a/test/unit/calendar_subscription_test.rb b/test/unit/calendar_subscription_test.rb index b5c50fbe9..4abdf7642 100644 --- a/test/unit/calendar_subscription_test.rb +++ b/test/unit/calendar_subscription_test.rb @@ -10,7 +10,7 @@ class CalendarSubscriptionTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where(name: 'Agent') + roles = Role.where(name: 'Agent') agent1 = User.create!( login: 'ticket-calendar-subscription-agent1@example.com', firstname: 'Notification',