Skip to content

Commit

Permalink
Add new rubocops and autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 11, 2024
1 parent 97f2e9e commit 4c8c6d4
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 85 deletions.
80 changes: 59 additions & 21 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ AllCops:
TargetRubyVersion: 3.2
DisplayCopNames: true
Exclude:
- 'bin/**/*'
- 'db/**/*'
- 'config/**/*'
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- "bin/**/*"
- "db/**/*"
- "config/**/*"
- "vendor/**/*"
- "spec/fixtures/**/*"

Rails:
Enabled: true

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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
75 changes: 24 additions & 51 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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'

Expand All @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/exhibit_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 4c8c6d4

Please sign in to comment.