From 047256c7b70d4fe444545ee039707cbea8ee3959 Mon Sep 17 00:00:00 2001 From: Daniela Lemow Date: Wed, 3 Apr 2024 11:43:57 +1300 Subject: [PATCH] feat: Upgrade rubocop for compatability with ruby 3.2.2 --- Gemfile.lock | 30 +++++++++++-------- app/api/api/record.rb | 2 +- app/api/api/request.rb | 4 +-- app/models/abstract_job.rb | 4 +-- app/models/collection_statistics.rb | 2 +- app/models/enrichment_job.rb | 2 +- app/models/harvest_job.rb | 2 +- app/models/harvest_schedule.rb | 6 ++-- app/models/link_check_job.rb | 4 +-- app/models/parser_version.rb | 2 +- app/models/snippet.rb | 4 +-- app/workers/concerns/validates_resource.rb | 2 +- app/workers/enrichment_worker.rb | 4 +-- app/workers/link_check_worker.rb | 2 +- .../link_check_rules_controller_spec.rb | 2 +- spec/factories/record.rb | 16 +++++----- spec/models/abstract_job_spec.rb | 2 +- spec/models/harvest_job_spec.rb | 2 +- spec/models/parser_version_spec.rb | 2 +- spec/workers/enrichment_worker_spec.rb | 8 ++--- spec/workers/harvest_worker_spec.rb | 4 +-- 21 files changed, 55 insertions(+), 51 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a5c9986a..4793d1f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -239,6 +239,7 @@ GEM kaminari-mongoid (1.0.2) kaminari-core (~> 1.0) mongoid + language_server-protocol (3.17.0.3) llhttp-ffi (0.4.0) ffi-compiler (~> 1.0) rake (~> 13.0) @@ -301,10 +302,11 @@ GEM optparse (0.4.0) ougai (1.9.1) oj (~> 3.10) - parallel (1.21.0) + parallel (1.24.0) parse-cron (0.1.4) - parser (3.1.1.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc prometheus-client (4.0.0) pry (0.14.2) coderay (~> 1.1) @@ -361,7 +363,7 @@ GEM rainbow (3.1.1) rake (13.2.0) redis (4.8.1) - regexp_parser (2.2.1) + regexp_parser (2.9.0) request_store (1.5.1) rack (>= 1.4) responders (3.0.1) @@ -373,7 +375,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.2.5) + rexml (3.2.6) rspec-activemodel-mocks (1.1.0) activemodel (>= 3.0) activesupport (>= 3.0) @@ -398,17 +400,19 @@ GEM rspec-core (~> 3.0, >= 3.0.0) sidekiq (>= 2.4.0) rspec-support (3.11.0) - rubocop (1.25.1) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) rubocop-minitest (0.17.2) rubocop (>= 0.90, < 2.0) rubocop-packaging (0.5.1) @@ -430,7 +434,7 @@ GEM rubocop-rails (~> 2.0) rubocop-rspec (2.9.0) rubocop (~> 1.19) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sanitize (6.1.0) crass (~> 1.0.2) @@ -453,7 +457,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8.2) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) diff --git a/app/api/api/record.rb b/app/api/api/record.rb index ff214cae..df599a6f 100644 --- a/app/api/api/record.rb +++ b/app/api/api/record.rb @@ -19,7 +19,7 @@ def self.put(record_id, params) def self.delete(id) Api::Request.new( '/harvester/records/delete', - { id: id } + { id: } ).put end end diff --git a/app/api/api/request.rb b/app/api/api/request.rb index 094b7427..f38e203b 100644 --- a/app/api/api/request.rb +++ b/app/api/api/request.rb @@ -41,9 +41,9 @@ def execute(method) end RestClient::Request.execute( - method: method, + method:, url: @url, - payload: payload, + payload:, headers: { 'Authentication-Token': @token }.merge(url_params) diff --git a/app/models/abstract_job.rb b/app/models/abstract_job.rb index c209829d..d43f1084 100644 --- a/app/models/abstract_job.rb +++ b/app/models/abstract_job.rb @@ -72,9 +72,9 @@ def enqueue def parser return @parser if @parser.present? if version_id.present? - @parser = ParserVersion.find(version_id, params: { parser_id: parser_id }) + @parser = ParserVersion.find(version_id, params: { parser_id: }) elsif environment.present? && !preview? - version = ParserVersion.find(:one, from: :current, params: { parser_id: parser_id, environment: environment }) + version = ParserVersion.find(:one, from: :current, params: { parser_id:, environment: }) version.parser_id = parser_id self.version_id = version.id if version.present? @parser = version diff --git a/app/models/collection_statistics.rb b/app/models/collection_statistics.rb index 18b0ebf0..c1d6e34f 100644 --- a/app/models/collection_statistics.rb +++ b/app/models/collection_statistics.rb @@ -40,7 +40,7 @@ def add_record_item(record_id, status, landing_url) send("#{status}_records=", []) if send("#{status}_records").nil? records = send("#{status}_records") - record = { record_id: record_id, landing_url: landing_url } + record = { record_id:, landing_url: } return if records.include?(record) records << record diff --git a/app/models/enrichment_job.rb b/app/models/enrichment_job.rb index 2873cd4e..ff4ed345 100644 --- a/app/models/enrichment_job.rb +++ b/app/models/enrichment_job.rb @@ -22,7 +22,7 @@ def self.create_from_harvest_job(job, enrichment) user_id: job.user_id, environment: job.environment, harvest_job_id: job.id, - enrichment: enrichment, + enrichment:, parser_code: job.parser_code) end diff --git a/app/models/harvest_job.rb b/app/models/harvest_job.rb index 32bac9d6..5d407587 100644 --- a/app/models/harvest_job.rb +++ b/app/models/harvest_job.rb @@ -35,7 +35,7 @@ def enqueue_enrichment_jobs end def flush_old_records - Api::Record.flush({ source_id: source_id, job_id: id }) + Api::Record.flush({ source_id:, job_id: id }) rescue RestClient::Exception => e create_harvest_failure(exception_class: e.class, message: "Flush old records failed with the following error mesage: #{e.message}", diff --git a/app/models/harvest_schedule.rb b/app/models/harvest_schedule.rb index 6125c33e..88ad6c02 100644 --- a/app/models/harvest_schedule.rb +++ b/app/models/harvest_schedule.rb @@ -83,9 +83,9 @@ def generate_next_run_at def create_job if active? - harvest_jobs.create(parser_id: parser_id, - environment: environment, - mode: mode, enrichments: enrichments) + harvest_jobs.create(parser_id:, + environment:, + mode:, enrichments:) self.last_run_at = Time.zone.now self.status = 'inactive' unless recurrent diff --git a/app/models/link_check_job.rb b/app/models/link_check_job.rb index 8bdde414..40a38fc6 100644 --- a/app/models/link_check_job.rb +++ b/app/models/link_check_job.rb @@ -23,14 +23,14 @@ def source private def already_checked? - previous_job = LinkCheckJob.where(record_id: record_id).last + previous_job = LinkCheckJob.where(record_id:).last return unless previous_job check_interval = ENV.fetch('LINK_CHECKING_INTERVAL', 6).to_i errors.add(:record_id, - I18n.t('link_check_job.error', record_id: record_id, check_interval: check_interval) + I18n.t('link_check_job.error', record_id:, check_interval:) ) if (DateTime.now.in_time_zone - previous_job.created_at) / 1.hour < check_interval end diff --git a/app/models/parser_version.rb b/app/models/parser_version.rb index 90726455..725cbc47 100644 --- a/app/models/parser_version.rb +++ b/app/models/parser_version.rb @@ -11,7 +11,7 @@ class ParserVersion < ActiveResource::Base def last_harvested_at HarvestJob.where( - parser_id: parser_id, + parser_id:, status: 'finished', environment: { '$ne': 'preview' } ).max(:start_time) diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 5fae076c..c4de22a9 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -10,8 +10,8 @@ class Snippet < ActiveResource::Base headers['Authorization'] = "Token token=#{ENV['WORKER_KEY']}" def self.find_by_name(name, environment) - find(:one, from: :current_version, params: { name: name, - environment: environment }) + find(:one, from: :current_version, params: { name:, + environment: }) rescue StandardError => e Rails.logger.error "Snippet with name: #{name} was not found" ElasticAPM.report(e) diff --git a/app/workers/concerns/validates_resource.rb b/app/workers/concerns/validates_resource.rb index 889b2b08..5fae0228 100644 --- a/app/workers/concerns/validates_resource.rb +++ b/app/workers/concerns/validates_resource.rb @@ -6,7 +6,7 @@ module ValidatesResource def link_check_rule(source_id) @link_check_rule ||= begin - LinkCheckRule.find_by(source_id: source_id) + LinkCheckRule.find_by(source_id:) rescue StandardError nil end diff --git a/app/workers/enrichment_worker.rb b/app/workers/enrichment_worker.rb index 65194880..ee204e81 100644 --- a/app/workers/enrichment_worker.rb +++ b/app/workers/enrichment_worker.rb @@ -85,10 +85,10 @@ def fetch_records(page = 0) { 'fragments.source_id' => job.parser.source.source_id } end - SupplejackApi::Record.find(query.merge(ENRICH_STATUS), page: page) + SupplejackApi::Record.find(query.merge(ENRICH_STATUS), page:) else klass = job.preview? ? SupplejackApi::PreviewRecord : SupplejackApi::Record - klass.find({ record_id: job.record_id }.merge(ENRICH_STATUS), page: page) + klass.find({ record_id: job.record_id }.merge(ENRICH_STATUS), page:) end end diff --git a/app/workers/link_check_worker.rb b/app/workers/link_check_worker.rb index 4ec6d42e..7f6c7ab9 100644 --- a/app/workers/link_check_worker.rb +++ b/app/workers/link_check_worker.rb @@ -116,7 +116,7 @@ def suppress_record(job_id, record_id, strike) end def set_record_status(record_id, status) - Api::Record.put(record_id, { record: { status: status } }) + Api::Record.put(record_id, { record: { status: } }) add_record_stats(record_id, status) rescue StandardError Sidekiq.logger.warn("LinkCheckWorker[#{record_id}]: Record not found when updating status = #{status} in LinkChecking. Ignoring.") diff --git a/spec/controllers/link_check_rules_controller_spec.rb b/spec/controllers/link_check_rules_controller_spec.rb index 75a6c867..6fe68847 100644 --- a/spec/controllers/link_check_rules_controller_spec.rb +++ b/spec/controllers/link_check_rules_controller_spec.rb @@ -20,7 +20,7 @@ it 'performs a where if link_check_rule is defined' do params = { link_check_rule: { collection_title: 'link_check_rule' } } expect(LinkCheckRule).to receive(:where).with(params[:link_check_rule].stringify_keys) - get :index, params: params, format: 'json' + get :index, params:, format: 'json' end end diff --git a/spec/factories/record.rb b/spec/factories/record.rb index e94aca38..e43cc676 100644 --- a/spec/factories/record.rb +++ b/spec/factories/record.rb @@ -19,10 +19,10 @@ module SupplejackApi factory :record_with_fragment do fragments do [FactoryBot.build(:record_fragment, - display_collection: display_collection, - copyright: copyright, - category: category, - tag: tag)] + display_collection:, + copyright:, + category:, + tag:)] end after(:build) do |record_with_fragment| @@ -35,10 +35,10 @@ module SupplejackApi [ FactoryBot.build( :record_fragment, - display_collection: display_collection, - copyright: copyright, - category: category, - tag: tag, + display_collection:, + copyright:, + category:, + tag:, large_thumbnail_url: nil ) ] diff --git a/spec/models/abstract_job_spec.rb b/spec/models/abstract_job_spec.rb index b58a3285..5ebd0bca 100644 --- a/spec/models/abstract_job_spec.rb +++ b/spec/models/abstract_job_spec.rb @@ -450,7 +450,7 @@ describe '#job_states' do let(:stateful_job) { create(:harvest_job, :stateful) } let(:states) { build_list(:state, 5) } - let(:full_job) { create(:harvest_job, states: states) } + let(:full_job) { create(:harvest_job, states:) } it 'can have an embedded history of the job state' do expect(stateful_job.states.count).not_to eq(0) diff --git a/spec/models/harvest_job_spec.rb b/spec/models/harvest_job_spec.rb index a08b7c40..33526921 100644 --- a/spec/models/harvest_job_spec.rb +++ b/spec/models/harvest_job_spec.rb @@ -29,7 +29,7 @@ %w[normal full_and_flush incremental].each do |mode| it "is valid with mode of '#{mode}'" do - job1 = build(:harvest_job, parser_id: '333', mode: mode) + job1 = build(:harvest_job, parser_id: '333', mode:) expect(job1).to be_valid end end diff --git a/spec/models/parser_version_spec.rb b/spec/models/parser_version_spec.rb index f89e28f0..661981b1 100644 --- a/spec/models/parser_version_spec.rb +++ b/spec/models/parser_version_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe ParserVersion do - let(:parser) { Parser.new(name: 'Europeana', id: '123', data_type: 'Record', source: source) } + let(:parser) { Parser.new(name: 'Europeana', id: '123', data_type: 'Record', source:) } let(:parser_version) { ParserVersion.new(parser_id: '123') } let(:parser_version_no_job) { ParserVersion.new(parser_id: '1') } let(:job) { mock_model(HarvestJob).as_null_object } diff --git a/spec/workers/enrichment_worker_spec.rb b/spec/workers/enrichment_worker_spec.rb index 80bca9e0..209e279c 100644 --- a/spec/workers/enrichment_worker_spec.rb +++ b/spec/workers/enrichment_worker_spec.rb @@ -300,13 +300,13 @@ def self.get_source_id let(:block) { proc { 'Hi' } } before(:each) do - allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: block } } } + allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: } } } end it 'should fetch the enrichment definition options' do job.enrichment = 'ndha_rights' worker.send(:setup_parser) - expect(worker.send(:enrichment_options)).to eq(block: block) + expect(worker.send(:enrichment_options)).to eq(block:) end end @@ -314,7 +314,7 @@ def self.get_source_id let(:block) { proc { 'Hi' } } before(:each) do - allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: block } } } + allow(parser).to receive(:enrichment_definitions) { { ndha_rights: { block: } } } job.enrichment = 'ndha_rights' worker.send(:setup_parser) end @@ -326,7 +326,7 @@ def self.get_source_id describe '#post_to_api' do let(:record) { double(:record, id: 123) } - let(:enrichment) { double(:enrichment, record: record, record_attributes: { '1' => { title: 'foo' }, '2' => { category: 'books' } }) } + let(:enrichment) { double(:enrichment, record:, record_attributes: { '1' => { title: 'foo' }, '2' => { category: 'books' } }) } it 'enqueues an ApiUpdate job with record_id, attributes (including job_id) and enrichment_job_id for each enriched record' do worker.send(:post_to_api, enrichment) diff --git a/spec/workers/harvest_worker_spec.rb b/spec/workers/harvest_worker_spec.rb index a46c280d..c642eb09 100644 --- a/spec/workers/harvest_worker_spec.rb +++ b/spec/workers/harvest_worker_spec.rb @@ -60,7 +60,7 @@ describe '#process_record' do let(:errors) { double(:errors, full_messages: []) } let(:record) { - double(:record, attributes: { title: 'Hi', internal_identifier: ['record123'] }, valid?: true, raw_data: '', errors: errors, + double(:record, attributes: { title: 'Hi', internal_identifier: ['record123'] }, valid?: true, raw_data: '', errors:, full_raw_data: '') } context 'record' do @@ -148,7 +148,7 @@ context 'concept' do let(:record) { double(:record, attributes: { label: ['Colin John McCahon'], internal_identifier: ['record123'], match_concepts: :create_or_match }, valid?: true, -errors: errors).as_null_object } +errors:).as_null_object } let(:parser) { double(:parser, data_type: 'concept', concept?: true, record?: false).as_null_object } before do