diff --git a/.rubocop.yml b/.rubocop.yml index fb22d1e95..a849dd007 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,11 +12,11 @@ AllCops: TargetRubyVersion: 3.2 DisplayCopNames: true Exclude: - - 'bin/**/*' - - 'db/**/*' - - 'config/**/*' - - 'vendor/**/*' - - 'spec/fixtures/**/*' + - "bin/**/*" + - "db/**/*" + - "config/**/*" + - "vendor/**/*" + - "spec/fixtures/**/*" Rails: Enabled: true @@ -24,17 +24,17 @@ Rails: Layout/LineLength: Max: 120 Exclude: - - 'app/controllers/concerns/search_across_blacklight_overrides.rb' - - 'app/models/spotlight/dor/indexer.rb' - - 'lib/traject/dor_config.rb' - - 'spec/features/indexing_integration_spec.rb' - - 'spec/models/spotlight/dor/indexer_spec.rb' - - 'spec/features/bibliography_formatting_spec.rb' + - "app/controllers/concerns/search_across_blacklight_overrides.rb" + - "app/models/spotlight/dor/indexer.rb" + - "lib/traject/dor_config.rb" + - "spec/features/indexing_integration_spec.rb" + - "spec/models/spotlight/dor/indexer_spec.rb" + - "spec/features/bibliography_formatting_spec.rb" Style/PercentLiteralDelimiters: PreferredDelimiters: - '%i': '()' - '%w': '()' + "%i": "()" + "%w": "()" Style/StringLiterals: Enabled: true @@ -54,8 +54,8 @@ Style/HashTransformValues: Metrics/ClassLength: Exclude: - - 'app/controllers/catalog_controller.rb' - - 'app/controllers/search_across_controller.rb' + - "app/controllers/catalog_controller.rb" + - "app/controllers/search_across_controller.rb" Capybara: Enabled: false @@ -72,21 +72,21 @@ Bundler/OrderedGems: RSpec/ExampleLength: Max: 10 Exclude: - - 'spec/features/indexing_integration_spec.rb' + - "spec/features/indexing_integration_spec.rb" RSpec/MultipleMemoizedHelpers: Enabled: false Metrics/BlockLength: Exclude: - - 'app/controllers/catalog_controller.rb' - - 'app/controllers/search_across_controller.rb' - - 'app/models/spotlight/dor/indexer.rb' - - 'spec/**/*' + - "app/controllers/catalog_controller.rb" + - "app/controllers/search_across_controller.rb" + - "app/models/spotlight/dor/indexer.rb" + - "spec/**/*" Performance/RedundantBlockCall: Exclude: - - 'lib/traject/macros/**/*' + - "lib/traject/macros/**/*" Gemspec/DeprecatedAttributeAssignment: # new in 1.30 Enabled: true @@ -472,3 +472,41 @@ FactoryBot/RedundantFactoryOption: # new in 2.23 Enabled: true FactoryBot/SyntaxMethods: # new in 2.7 Enabled: true +Gemspec/AddRuntimeDependency: # new in 1.65 + Enabled: true +Lint/DuplicateSetElement: # new in 1.67 + Enabled: true +Lint/HashNewWithKeywordArgumentsAsDefault: # new in 1.69 + Enabled: true +Lint/NumericOperationWithConstantResult: # new in 1.69 + Enabled: true +Lint/UnescapedBracketInRegexp: # new in 1.68 + Enabled: true +Lint/UselessDefined: # new in 1.69 + Enabled: true +Lint/UselessNumericOperation: # new in 1.66 + Enabled: true +Style/AmbiguousEndlessMethodDefinition: # new in 1.68 + Enabled: true +Style/BitwisePredicate: # new in 1.68 + Enabled: true +Style/CombinableDefined: # new in 1.68 + Enabled: true +Style/DigChain: # new in 1.69 + Enabled: true +Style/FileNull: # new in 1.69 + Enabled: true +Style/FileTouch: # new in 1.69 + Enabled: true +Style/KeywordArgumentsMerging: # new in 1.68 + Enabled: true +Style/RedundantInterpolationUnfreeze: # new in 1.66 + Enabled: true +Style/SafeNavigationChainLength: # new in 1.68 + Enabled: true +RSpec/StringAsInstanceDoubleConstant: # new in 3.1 + Enabled: true +Performance/StringBytesize: # new in 1.23 + Enabled: true +Rails/EnumSyntax: # new in 2.26 + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1ffdd6e66..5bd96c2b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,19 +1,18 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-06-17 15:14:45 UTC using RuboCop version 1.64.1. +# on 2024-12-11 20:34:40 UTC using RuboCop version 1.69.1. # 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: 23 +# Offense count: 22 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Include. # Include: **/*_spec.rb, **/spec/**/*, **/test/**/*, **/features/support/factories/**/*.rb FactoryBot/SyntaxMethods: Exclude: - 'spec/controllers/application_controller_spec.rb' - - 'spec/controllers/spotlight/catalog_controller_spec.rb' - 'spec/features/indexing_integration_spec.rb' - 'spec/features/search_across_spec.rb' - 'spec/features/search_by_exhibit_title_spec.rb' @@ -80,17 +79,17 @@ Lint/ToEnumArguments: Exclude: - 'spec/support/etl_helper.rb' -# Offense count: 9 +# Offense count: 10 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 42 + Max: 39 -# Offense count: 3 +# Offense count: 4 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 9 -# Offense count: 12 +# Offense count: 14 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 30 @@ -128,7 +127,7 @@ Performance/StringInclude: Exclude: - 'app/models/full_text_parser.rb' -# Offense count: 3 +# Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). RSpec/BeEq: Exclude: @@ -159,11 +158,10 @@ RSpec/ExcessiveDocstringSpacing: Exclude: - 'spec/features/bibliography_resource_integration_spec.rb' -# Offense count: 4 +# Offense count: 3 RSpec/ExpectInHook: Exclude: - 'spec/helpers/catalog_helper_spec.rb' - - 'spec/views/catalog/_exhibits_document_header_default.html.erb_spec.rb' - 'spec/views/viewers/edit.html.erb_spec.rb' # Offense count: 2 @@ -172,7 +170,7 @@ RSpec/IndexedLet: Exclude: - 'spec/features/search_by_exhibit_title_spec.rb' -# Offense count: 20 +# Offense count: 18 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: hash, symbol @@ -187,10 +185,9 @@ RSpec/MetadataStyle: - 'spec/features/range_limit_spec.rb' - 'spec/features/search_across_spec.rb' - 'spec/features/search_by_exhibit_title_spec.rb' - - 'spec/features/theme_switching_spec.rb' - 'spec/features/viewers_spec.rb' -# Offense count: 125 +# Offense count: 132 RSpec/MultipleExpectations: Max: 6 @@ -221,22 +218,20 @@ RSpec/ReceiveMessages: Exclude: - 'spec/helpers/blacklight/maps_helper_override_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -RSpec/SortMetadata: +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/StringAsInstanceDoubleConstant: Exclude: - - 'spec/features/embed_block_spec.rb' - - 'spec/features/range_limit_spec.rb' - - 'spec/features/search_by_exhibit_title_spec.rb' + - 'spec/helpers/application_helper_spec.rb' + - 'spec/models/exhibit_finder_spec.rb' -# Offense count: 14 +# Offense count: 13 RSpec/StubbedMock: Exclude: - 'spec/helpers/application_helper_spec.rb' - 'spec/helpers/catalog_helper_spec.rb' - 'spec/helpers/search_across_helper_spec.rb' - 'spec/models/spotlight/resources/iiif_manifest_spec.rb' - - 'spec/views/catalog/_exhibits_document_header_default.html.erb_spec.rb' - 'spec/views/catalog/_metadata_button_default.html.erb_spec.rb' - 'spec/views/viewers/edit.html.erb_spec.rb' @@ -245,30 +240,24 @@ RSpec/SubjectStub: Exclude: - 'spec/models/dor_harvester_spec.rb' -# Offense count: 26 +# Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: constant, string RSpec/VerifiedDoubleReference: Exclude: - - 'spec/controllers/catalog_controller_spec.rb' - - 'spec/controllers/search_across_controller_spec.rb' - 'spec/helpers/application_helper_spec.rb' - - 'spec/helpers/search_across_helper_spec.rb' - 'spec/jobs/index_exhibit_metadata_job_spec.rb' - 'spec/models/exhibit_bot_spec.rb' - 'spec/models/exhibit_finder_spec.rb' - 'spec/models/exhibit_indexer_spec.rb' + +# Offense count: 4 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Exclude: - 'spec/models/full_text_parser_spec.rb' - 'spec/models/search_builder_spec.rb' - - 'spec/models/spotlight/resources/upload_spec.rb' - - 'spec/requests/exhibit_finder_requests_spec.rb' - -# Offense count: 36 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Inferences. -RSpecRails/InferredSpecType: - Enabled: false # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). @@ -280,14 +269,13 @@ Rails/ActionOrder: - 'app/controllers/exhibit_finder_controller.rb' - 'app/controllers/index_statuses_controller.rb' -# Offense count: 5 +# Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Rails/CompactBlank: Exclude: - 'app/models/dor_harvester.rb' - 'app/models/exhibit_indexer.rb' - 'app/models/search_builder.rb' - - 'lib/traject/dor_config.rb' - 'lib/traject/macros/general.rb' # Offense count: 2 @@ -336,14 +324,6 @@ Style/FileRead: Exclude: - 'spec/features/bibliography_resource_integration_spec.rb' -# Offense count: 103 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -# SupportedShorthandSyntax: always, never, either, consistent, either_consistent -Style/HashSyntax: - Enabled: false - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: @@ -368,13 +348,12 @@ Style/MinMaxComparison: Exclude: - 'app/controllers/concerns/search_across_blacklight_overrides.rb' -# Offense count: 7 +# Offense count: 6 Style/MixinUsage: Exclude: - 'lib/traject/bibtex_config.rb' - 'lib/traject/canvas_config.rb' - 'lib/traject/dor_config.rb' - - 'spec/features/viewers_spec.rb' # Offense count: 1 Style/MultilineBlockChain: @@ -392,12 +371,6 @@ Style/RedundantAssignment: Exclude: - 'app/controllers/concerns/search_across_blacklight_overrides.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantBegin: - Exclude: - - 'app/models/purl.rb' - # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). Style/RedundantConstantBase: diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index d20a53cb4..698c91a02 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -489,7 +489,7 @@ def search_tips def documents_list search_service = Blacklight::SearchService.new(config: blacklight_config) ids = params[:ids].present? ? params[:ids].split : [] - @documents = ids.empty? ? [] : search_service.fetch(ids, { :rows => 1000 }) + @documents = ids.empty? ? [] : search_service.fetch(ids, { rows: 1000 }) render json: @documents end diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index 9ff00ae96..e603c00d0 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -9,7 +9,7 @@ expect( described_class.document_has_full_text_and_search_is_query?( subject, - instance_double('Config'), + nil, instance_double(SolrDocument, full_text?: true) ) ).to be true @@ -20,7 +20,7 @@ expect( described_class.document_has_full_text_and_search_is_query?( subject, - instance_double('Config'), + nil, instance_double(SolrDocument, full_text?: true) ) ).to be false @@ -32,7 +32,7 @@ expect( described_class.document_has_full_text_and_search_is_query?( subject, - instance_double('Config'), + nil, instance_double(SolrDocument, full_text?: false) ) ).to be false diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index a18faefb1..26df0e794 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -78,7 +78,7 @@ let(:canvas_index) { 4 } let(:st_block) do instance_double( - 'SirTrevorRails::Blocks::SolrDocumentsEmbedBlock', + SirTrevorRails::Blocks::SolrDocumentsEmbedBlock, items: [{ 'iiif_canvas_id' => "http://example.com/ab123cd4567_#{canvas_index}" }] ) end @@ -90,7 +90,7 @@ context 'with SirTrevorBlock that is missing things' do let(:st_block) do - instance_double('SirTrevorRails::Blocks::SolrDocumentsEmbedBlock') + instance_double(SirTrevorRails::Blocks::SolrDocumentsEmbedBlock) end it 'defaults to nil' do diff --git a/spec/models/exhibit_finder_spec.rb b/spec/models/exhibit_finder_spec.rb index 4b40084b3..aef7ab960 100644 --- a/spec/models/exhibit_finder_spec.rb +++ b/spec/models/exhibit_finder_spec.rb @@ -23,7 +23,7 @@ describe '.search' do let(:exhibit) { create(:exhibit) } - let(:solr_connection) { instance_double('Blacklighgt::Solr::Connection') } + let(:solr_connection) { instance_double('RSolr::Client') } before do allow(Blacklight.default_index).to receive_messages(connection: solr_connection) diff --git a/spec/models/full_text_parser_spec.rb b/spec/models/full_text_parser_spec.rb index 08c08cd58..b850eecb7 100644 --- a/spec/models/full_text_parser_spec.rb +++ b/spec/models/full_text_parser_spec.rb @@ -5,7 +5,7 @@ describe FullTextParser do subject(:parser) { described_class.new(purl_object) } - let(:purl_object) { instance_double('PurlObject', bare_druid: 'cc842mn9348', public_xml: public_xml) } + let(:purl_object) { double('PurlObject', bare_druid: 'cc842mn9348', public_xml: public_xml) } let(:public_xml) { Nokogiri::XML.parse(File.read(File.join(FIXTURES_PATH, 'cc842mn9348.xml'))) } describe '#ocr_files' do @@ -35,7 +35,7 @@ end context 'with an hOCR transcription' do - let(:purl_object) { instance_double('PurlObject', bare_druid: 'hocrexample', public_xml: public_xml) } + let(:purl_object) { double('PurlObject', bare_druid: 'hocrexample', public_xml: public_xml) } let(:public_xml) { Nokogiri::XML.parse(File.read(File.join(FIXTURES_PATH, 'hocrexample.xml'))) } let(:text) do <<-FIXTURE @@ -64,7 +64,7 @@ end context 'with a plain-text transcription' do - let(:purl_object) { instance_double('PurlObject', bare_druid: 'xt162pg0437', public_xml: public_xml) } + let(:purl_object) { double('PurlObject', bare_druid: 'xt162pg0437', public_xml: public_xml) } let(:public_xml) { Nokogiri::XML.parse(File.read(File.join(FIXTURES_PATH, 'xt162pg0437.xml'))) } before do diff --git a/spec/models/search_builder_spec.rb b/spec/models/search_builder_spec.rb index 1d5d99704..668e358c8 100644 --- a/spec/models/search_builder_spec.rb +++ b/spec/models/search_builder_spec.rb @@ -7,8 +7,8 @@ let(:exhibit) { create(:exhibit) } let(:scope) do - instance_double('scope', blacklight_config: blacklight_config, current_exhibit: exhibit, search_state_class: nil, - action_name: nil) + double('scope', blacklight_config: blacklight_config, current_exhibit: exhibit, search_state_class: nil, + action_name: nil) end let(:rows) { 999 } let(:blacklight_params) do diff --git a/spec/requests/exhibit_finder_requests_spec.rb b/spec/requests/exhibit_finder_requests_spec.rb index 2b5392ad2..74608b27b 100644 --- a/spec/requests/exhibit_finder_requests_spec.rb +++ b/spec/requests/exhibit_finder_requests_spec.rb @@ -36,7 +36,7 @@ end describe '#index' do - let(:solr_connection) { instance_double('Blacklighgt::Solr::Connection') } + let(:solr_connection) { instance_double(RSolr::Client) } before do allow(Blacklight.default_index).to receive_messages(connection: solr_connection)