Skip to content

Commit

Permalink
Merge pull request #182 from sul-dlss/rubocop
Browse files Browse the repository at this point in the history
Add fixes for rubocop
  • Loading branch information
jcoyne authored Jun 13, 2024
2 parents 970287c + 178ac7a commit fc0d8e9
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 48 deletions.
18 changes: 11 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
inherit_from: .rubocop_todo.yml

require: rubocop-rspec
require:
- rubocop-rspec
- rubocop-rspec_rails
- rubocop-capybara

AllCops:
Exclude:
- '*.gemspec'
- 'bin/**/*'
- 'db/**/*'
- 'spec/fixtures/**/*'
- 'vendor/**/*'
- "*.gemspec"
- "bin/**/*"
- "db/**/*"
- "spec/fixtures/**/*"
- "vendor/**/*"
TargetRubyVersion: 2.7
NewCops: enable
SuggestExtensions: false

# Use single-quoted strings where possible
Style/StringLiterals:
Expand All @@ -35,4 +39,4 @@ Naming/MethodName:
Enabled: false

Naming/VariableName:
Enabled: false
Enabled: false
52 changes: 26 additions & 26 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
# Offense count: 2
Capybara/SpecificMatcher:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- "spec/helpers/record_helper_spec.rb"

# Offense count: 2
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'lib/mods_display/fields/title.rb'
- "lib/mods_display/fields/title.rb"

# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- "spec/helpers/record_helper_spec.rb"

# Offense count: 15
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Expand All @@ -36,7 +36,7 @@ Metrics/ClassLength:
# Configuration parameters: LengthThreshold.
Metrics/CollectionLiteralLength:
Exclude:
- 'lib/mods_display/relator_codes.rb'
- "lib/mods_display/relator_codes.rb"

# Offense count: 9
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand All @@ -62,31 +62,31 @@ RSpec/BeforeAfterAll:
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/fields/contents_spec.rb'
- 'spec/fields/form_spec.rb'
- "spec/fields/contents_spec.rb"
- "spec/fields/form_spec.rb"

# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/integration/html_spec.rb'
- "**/spec/features/**/*"
- "**/spec/requests/**/*"
- "**/spec/routing/**/*"
- "**/spec/system/**/*"
- "**/spec/views/**/*"
- "spec/integration/html_spec.rb"

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
RSpec/ExpectActual:
Exclude:
- '**/spec/routing/**/*'
- 'spec/fields/name_spec.rb'
- "**/spec/routing/**/*"
- "spec/fields/name_spec.rb"

# Offense count: 39
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
RSpec/SpecFilePathSuffix:
Enabled: false

# Offense count: 96
Expand All @@ -97,8 +97,8 @@ RSpec/InstanceVariable:
# Offense count: 2
RSpec/IteratedExpectation:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- 'spec/integration/html_spec.rb'
- "spec/helpers/record_helper_spec.rb"
- "spec/integration/html_spec.rb"

# Offense count: 4
# Configuration parameters: .
Expand All @@ -119,9 +119,9 @@ RSpec/NestedGroups:
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Inferences.
RSpec/Rails/InferredSpecType:
RSpecRails/InferredSpecType:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- "spec/helpers/record_helper_spec.rb"

# Offense count: 39
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
Expand All @@ -133,7 +133,7 @@ RSpec/SpecFilePathFormat:
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- "spec/helpers/record_helper_spec.rb"

# Offense count: 50
# Configuration parameters: AllowedConstants.
Expand All @@ -143,20 +143,20 @@ Style/Documentation:
# Offense count: 4
Style/MixinUsage:
Exclude:
- 'spec/fields/cartographics_spec.rb'
- 'spec/fields/imprint_spec.rb'
- 'spec/fields/name_spec.rb'
- 'spec/fields/subject_spec.rb'
- "spec/fields/cartographics_spec.rb"
- "spec/fields/imprint_spec.rb"
- "spec/fields/name_spec.rb"
- "spec/fields/subject_spec.rb"

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/mods_display/fields/imprint.rb'
- "lib/mods_display/fields/imprint.rb"

# Offense count: 13
Style/OpenStructUse:
Exclude:
- 'spec/helpers/record_helper_spec.rb'
- "spec/helpers/record_helper_spec.rb"

# Offense count: 46
# This cop supports safe autocorrection (--autocorrect).
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
source 'https://rubygems.org'

gem 'debug'
gem 'rubocop-capybara', require: false
gem 'rubocop-rspec', require: false
gem 'rubocop-rspec_rails', require: false

# Specify your gem's dependencies in mods_display.gemspec
gemspec
2 changes: 1 addition & 1 deletion lib/mods_display/fields/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Abstract < Field
private

def displayLabel(element)
super(element) || I18n.t('mods_display.abstract')
super || I18n.t('mods_display.abstract')
end
end
end
2 changes: 1 addition & 1 deletion lib/mods_display/fields/audience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Audience < Field
private

def displayLabel(element)
super(element) || I18n.t('mods_display.target_audience')
super || I18n.t('mods_display.target_audience')
end
end
end
2 changes: 1 addition & 1 deletion lib/mods_display/fields/contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def to_html(view_context = ApplicationController.renderer)
private

def displayLabel(element)
super(element) || I18n.t('mods_display.table_of_contents')
super || I18n.t('mods_display.table_of_contents')
end
end
end
2 changes: 1 addition & 1 deletion lib/mods_display/fields/genre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def delimiter
end

def displayLabel(element)
super(element) || I18n.t('mods_display.genre')
super || I18n.t('mods_display.genre')
end
end
end
2 changes: 1 addition & 1 deletion lib/mods_display/fields/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fields
end

def to_html(view_context = ApplicationController.renderer)
component = ModsDisplay::FieldComponent.with_collection(fields, value_transformer: ->(value) { value.to_s })
component = ModsDisplay::FieldComponent.with_collection(fields, value_transformer: lambda(&:to_s))

view_context.render component, layout: false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mods_display/fields/reference_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def root
end

def displayLabel(element)
super(element) || I18n.t('mods_display.title')
super || I18n.t('mods_display.title')
end

def title_value
Expand Down
2 changes: 1 addition & 1 deletion lib/mods_display/fields/resource_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def fields
private

def displayLabel(type_of_resource_element)
super(type_of_resource_element) || I18n.t('mods_display.type_of_resource')
super || I18n.t('mods_display.type_of_resource')
end
end
end
14 changes: 6 additions & 8 deletions lib/mods_display/fields/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ def delimiter
end

def values_from_subjects(element)
return_values = []
selected_subjects(element).each do |child|
return_values << if element_text(child).include?('--')
element_text(child).split('--').map(&:strip)
else
element_text(child)
end
selected_subjects(element).map do |child|
if element_text(child).include?('--')
element_text(child).split('--').map(&:strip)
else
element_text(child)
end
end
return_values
end

def selected_subjects(element = @value)
Expand Down
2 changes: 2 additions & 0 deletions spec/helpers/record_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'ostruct'

RSpec.describe ModsDisplay::RecordHelper, type: :helper do
let(:empty_field) { OpenStruct.new(label: 'test', values: ['']) }

Expand Down

0 comments on commit fc0d8e9

Please sign in to comment.