From 85573432c047f27082e205d142ef64a562d051aa Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 24 Nov 2020 17:20:57 +0100 Subject: [PATCH] Maintenance: Updated rubocop(-* gems) to latest version (1.4.1). --- .rubocop/default.yml | 8 ++++---- Gemfile | 2 +- Gemfile.lock | 13 +++++++------ app/jobs/issue_2715_fix_broken_twitter_urls_job.rb | 2 +- app/models/token.rb | 2 +- .../20170905140038_cti_log_preferences_migration.rb | 1 + lib/core_ext/string.rb | 2 +- lib/exceptions.rb | 1 + lib/html_sanitizer.rb | 2 +- lib/import/exchange/folder.rb | 2 +- lib/import/helper/attributes_examples.rb | 2 +- lib/knowledge_base/menu_item_update_action.rb | 4 +--- lib/ldap/guid.rb | 2 +- lib/notification_factory.rb | 2 +- lib/pseudonymisation.rb | 2 +- .../unit/import/common/model/associations/assign.rb | 6 +++--- .../unit/import/ldap/user/lookup/attributes.rb | 2 +- spec/factories/knowledge_base/category.rb | 4 ++-- spec/factories/notification_factory/renderer.rb | 2 +- spec/factories/object_manager_attribute.rb | 2 +- spec/factories/vendor/net/ldap/entry.rb | 2 +- spec/lib/search_index_backend_spec.rb | 4 ++-- spec/support/db_migration.rb | 2 +- spec/support/vcr.rb | 8 ++++++-- 24 files changed, 42 insertions(+), 37 deletions(-) diff --git a/.rubocop/default.yml b/.rubocop/default.yml index 318e5dc8f..ac9e8e0c4 100644 --- a/.rubocop/default.yml +++ b/.rubocop/default.yml @@ -23,10 +23,10 @@ AllCops: - 'node_modules/**/*' - 'public/assets/**/*' - 'public/packs/**/*' - RSpec: - Patterns: - - '_spec.rb$' - - '_examples.rb$' +RSpec: + Include: + - "**/*_spec.rb" + - "**/*_examples.rb" Rails: Enabled: true diff --git a/Gemfile b/Gemfile index 11e88dd40..b97775d7c 100644 --- a/Gemfile +++ b/Gemfile @@ -185,7 +185,7 @@ group :development, :test do gem 'rubocop' gem 'rubocop-performance' gem 'rubocop-rails' - gem 'rubocop-rspec', '2.0.0.pre' # see: https://github.com/rubocop-hq/rubocop-rspec/issues/1051 + gem 'rubocop-rspec' # changelog generation gem 'github_changelog_generator' diff --git a/Gemfile.lock b/Gemfile.lock index 9bf7b7ffc..3b4a99887 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -357,7 +357,7 @@ GEM omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0) openssl (2.1.2) - parallel (1.20.0) + parallel (1.20.1) parser (2.7.2.0) ast (~> 2.4.1) pg (0.21.0) @@ -452,7 +452,7 @@ GEM rspec-support (~> 3.9.0) rspec-support (3.9.3) rszr (0.5.2) - rubocop (1.3.0) + rubocop (1.4.1) parallel (~> 1.10) parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) @@ -463,15 +463,16 @@ GEM unicode-display_width (>= 1.4.0, < 2.0) rubocop-ast (1.1.1) parser (>= 2.7.1.5) - rubocop-performance (1.8.1) - rubocop (>= 0.87.0) + rubocop-performance (1.9.0) + rubocop (>= 0.90.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rails (2.8.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 0.87.0) - rubocop-rspec (2.0.0.pre) + rubocop-rspec (2.0.0) rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) ruby-progressbar (1.10.1) ruby-saml (1.10.2) nokogiri (>= 1.5.10) @@ -655,7 +656,7 @@ DEPENDENCIES rubocop rubocop-performance rubocop-rails - rubocop-rspec (= 2.0.0.pre) + rubocop-rspec rubyntlm! sassc-rails selenium-webdriver diff --git a/app/jobs/issue_2715_fix_broken_twitter_urls_job.rb b/app/jobs/issue_2715_fix_broken_twitter_urls_job.rb index 792d0a965..ec5c9c846 100644 --- a/app/jobs/issue_2715_fix_broken_twitter_urls_job.rb +++ b/app/jobs/issue_2715_fix_broken_twitter_urls_job.rb @@ -7,7 +7,7 @@ class Issue2715FixBrokenTwitterUrlsJob < ApplicationJob .where(ticket_article_types: { name: ['twitter status', 'twitter direct-message'] }) .order(created_at: :desc) .limit(10_000) - .find_each(&method(:fix_broken_links)) + .find_each { |article| fix_broken_links(article) } end private diff --git a/app/models/token.rb b/app/models/token.rb index 5a1de2b4d..0d8518577 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -116,7 +116,7 @@ cleanup old token def with_context(user:, &block) @effective_user = user - instance_eval(&block) if block_given? + instance_eval(&block) if block ensure @effective_user = nil end diff --git a/db/migrate/20170905140038_cti_log_preferences_migration.rb b/db/migrate/20170905140038_cti_log_preferences_migration.rb index 69ac51a9a..61d8277bb 100644 --- a/db/migrate/20170905140038_cti_log_preferences_migration.rb +++ b/db/migrate/20170905140038_cti_log_preferences_migration.rb @@ -19,6 +19,7 @@ module ActiveRecord end end end + module ActiveRecord module ConnectionAdapters module PostgreSQL diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index f8f9d6a6e..2f5d3ca6e 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -95,7 +95,7 @@ class String end c end - .join('') + .join end =begin diff --git a/lib/exceptions.rb b/lib/exceptions.rb index 3951068e4..f9114b6e4 100644 --- a/lib/exceptions.rb +++ b/lib/exceptions.rb @@ -1,6 +1,7 @@ module Exceptions class NotAuthorized < StandardError; end + class UnprocessableEntity < StandardError; end end diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index 3d41b7535..cccab18ce 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -103,7 +103,7 @@ satinize html string based on whiltelist # clean class / only use allowed classes if node['class'] - classes = node['class'].gsub(/\t|\n|\r/, '').split(' ') + classes = node['class'].gsub(/\t|\n|\r/, '').split class_new = '' classes.each do |local_class| next if classes_whitelist.exclude?(local_class.to_s.strip) diff --git a/lib/import/exchange/folder.rb b/lib/import/exchange/folder.rb index 505a52d1b..d3bb540db 100644 --- a/lib/import/exchange/folder.rb +++ b/lib/import/exchange/folder.rb @@ -33,7 +33,7 @@ module Import def children(*parents) return [] if parents.empty? - direct_descendants = parents.map(&method(:request_children)) + direct_descendants = parents.map { |parent| request_children(parent) } .flatten.uniq.compact direct_descendants | children(*direct_descendants) diff --git a/lib/import/helper/attributes_examples.rb b/lib/import/helper/attributes_examples.rb index fcdf4c94e..587ea1bff 100644 --- a/lib/import/helper/attributes_examples.rb +++ b/lib/import/helper/attributes_examples.rb @@ -20,7 +20,7 @@ module Import # Import::Helper::AttributesExamples.new do |extractor| # extractor.extract(attributes) # end - return if !block_given? + return if !block if block.arity.zero? instance_eval(&block) diff --git a/lib/knowledge_base/menu_item_update_action.rb b/lib/knowledge_base/menu_item_update_action.rb index f746a575c..4a3e967c1 100644 --- a/lib/knowledge_base/menu_item_update_action.rb +++ b/lib/knowledge_base/menu_item_update_action.rb @@ -31,9 +31,7 @@ class KnowledgeBase return if params.blank? params - .map { |location_params| update_location_using_params! knowledge_base, location_params } - .map(&:reload) - .sum + .map { |location_params| update_location_using_params! knowledge_base, location_params }.sum(&:reload) end # Mass-update KB menu items in a given location diff --git a/lib/ldap/guid.rb b/lib/ldap/guid.rb index 301b16acd..f9371ab22 100644 --- a/lib/ldap/guid.rb +++ b/lib/ldap/guid.rb @@ -92,7 +92,7 @@ class Ldap # re-order according to oracle format index and join oracle_format_indices = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15] - result = oracle_format_indices.map { |index| parts[index] }.join('') + result = oracle_format_indices.map { |index| parts[index] }.join # add dashes if requested return result if !dashify diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index a54a4c641..de933e0cc 100644 --- a/lib/notification_factory.rb +++ b/lib/notification_factory.rb @@ -44,7 +44,7 @@ returns .map { |filename| data.merge(filename: filename) } .map { |data_hash| TEMPLATE_PATH_STRING % data_hash } - found = candidates.find(&File.method(:exist?)) + found = candidates.find { |candidate| File.exist?(candidate) } raise FileNotFoundError, "Missing template files #{candidates}!" if !found diff --git a/lib/pseudonymisation.rb b/lib/pseudonymisation.rb index 7d582e5df..846e131b8 100644 --- a/lib/pseudonymisation.rb +++ b/lib/pseudonymisation.rb @@ -36,7 +36,7 @@ class Pseudonymisation return '*' if source.length == 1 return "#{source.first}*#{source.last}" if source.exclude?(' ') - source.split(' ').map do |sub_string| + source.split.map do |sub_string| of_string(sub_string) end.join(' ') end diff --git a/lib/sequencer/unit/import/common/model/associations/assign.rb b/lib/sequencer/unit/import/common/model/associations/assign.rb index 633900cba..4fdd0b6ae 100644 --- a/lib/sequencer/unit/import/common/model/associations/assign.rb +++ b/lib/sequencer/unit/import/common/model/associations/assign.rb @@ -44,17 +44,17 @@ class Sequencer # Because it doesn't include associations # stored on OTHER TABLES (has-one, has-many, HABTM) def changes - @changes ||= unfiltered_changes.reject(&method(:no_diff?)) + @changes ||= unfiltered_changes.reject { |_attribute, values| no_diff?(values) } end def unfiltered_changes attrs = associations.keys - before = attrs.map(&instance.method(:send)) + before = attrs.map { |attribute| instance.send(attribute) } after = associations.values attrs.zip(before.zip(after)).to_h.with_indifferent_access end - def no_diff?(_, values) + def no_diff?(values) values.map!(&:sort) if values.all? { |val| val.respond_to?(:sort) } values.map!(&:presence) # [nil, []] -> [nil, nil] values.uniq.length == 1 diff --git a/lib/sequencer/unit/import/ldap/user/lookup/attributes.rb b/lib/sequencer/unit/import/ldap/user/lookup/attributes.rb index 0edef07ac..66785d581 100644 --- a/lib/sequencer/unit/import/ldap/user/lookup/attributes.rb +++ b/lib/sequencer/unit/import/ldap/user/lookup/attributes.rb @@ -18,7 +18,7 @@ class Sequencer end def not_synced(entries) - entries.find(&method(:not_synced?)) + entries.find { |entry| not_synced?(entry) } end def not_synced?(entry) diff --git a/spec/factories/knowledge_base/category.rb b/spec/factories/knowledge_base/category.rb index f802b3baa..22c8fda79 100644 --- a/spec/factories/knowledge_base/category.rb +++ b/spec/factories/knowledge_base/category.rb @@ -31,10 +31,10 @@ FactoryBot.define do create(:knowledge_base_category, parent: obj) level2 = create(:knowledge_base_category, parent: obj) - 2.times { create(:knowledge_base_category, parent: level2) } + create_list(:knowledge_base_category, 2, parent: level2) level3 = level2.children.reload.first - 2.times { create(:knowledge_base_category, parent: level3) } + create_list(:knowledge_base_category, 2, parent: level3) obj.reload end diff --git a/spec/factories/notification_factory/renderer.rb b/spec/factories/notification_factory/renderer.rb index 87813b3e6..e19e72bc1 100644 --- a/spec/factories/notification_factory/renderer.rb +++ b/spec/factories/notification_factory/renderer.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :notification_factory_renderer, class: NotificationFactory::Renderer do + factory :notification_factory_renderer, class: 'NotificationFactory::Renderer' do objects { nil } locale { 'en-en' } template { '' } diff --git a/spec/factories/object_manager_attribute.rb b/spec/factories/object_manager_attribute.rb index eccfb980a..11a8250f8 100644 --- a/spec/factories/object_manager_attribute.rb +++ b/spec/factories/object_manager_attribute.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :object_manager_attribute, class: ObjectManager::Attribute do + factory :object_manager_attribute, class: 'ObjectManager::Attribute' do transient do object_name { 'Ticket' } additional_data_options { nil } diff --git a/spec/factories/vendor/net/ldap/entry.rb b/spec/factories/vendor/net/ldap/entry.rb index e2972014d..215be1c8f 100644 --- a/spec/factories/vendor/net/ldap/entry.rb +++ b/spec/factories/vendor/net/ldap/entry.rb @@ -3,7 +3,7 @@ FactoryBot.define do # add custom attributes via: # mocked_entry = build(:ldap_entry) # mocked_entry['attr'] = [value, another_value] - factory :ldap_entry, class: Net::LDAP::Entry do + factory :ldap_entry, class: 'Net::LDAP::Entry' do initialize_with { new('dc=com') } end end diff --git a/spec/lib/search_index_backend_spec.rb b/spec/lib/search_index_backend_spec.rb index 4f45ce78c..e26c7be00 100644 --- a/spec/lib/search_index_backend_spec.rb +++ b/spec/lib/search_index_backend_spec.rb @@ -75,7 +75,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do QUERIES it 'appends a * to the original query' do - expect(queries.map(&described_class.method(:append_wildcard_to_simple_query))) + expect(queries.map { |query| described_class.append_wildcard_to_simple_query(query) }) .to eq(queries.map { |q| "#{q}*" }) end end @@ -117,7 +117,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do QUERIES it 'returns the original query verbatim' do - expect(queries.map(&described_class.method(:append_wildcard_to_simple_query))) + expect(queries.map { |query| described_class.append_wildcard_to_simple_query(query) }) .to eq(queries) end end diff --git a/spec/support/db_migration.rb b/spec/support/db_migration.rb index aceadd163..9640e6a2c 100644 --- a/spec/support/db_migration.rb +++ b/spec/support/db_migration.rb @@ -115,7 +115,7 @@ module DbMigrationHelper # remove_foreign_key(:online_notifications, :users) # # @return [nil] - def respond_to_missing?(*) # rubocop:disable Lint/MissingSuper + def respond_to_missing?(*) true end diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index 2267e036d..db218e1a2 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -92,6 +92,10 @@ RSpec.configure do |config| end end - config.around(:each, use_vcr: true, &RSpec::Support::VCRHelper.method(:inject_advisory)) - config.around(:each, use_vcr: true, &RSpec::Expectations::VCRHelper.method(:inject_advisory)) + config.around(:each, use_vcr: true) do |example| + RSpec::Support::VCRHelper.inject_advisory(example) + end + config.around(:each, use_vcr: true) do |example| + RSpec::Expectations::VCRHelper.inject_advisory(example) + end end