Skip to content

Commit

Permalink
Bring RuboCop up to date and eliminate warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
laserlemon committed Apr 26, 2024
1 parent 59958cd commit b830671
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 80 deletions.
80 changes: 29 additions & 51 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,56 @@
require: rubocop-rspec
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

# This should always correspond to the earliest non-EOL Ruby version.
AllCops:
TargetRubyVersion: 2.4
NewCops: enable
TargetRubyVersion: 3.1

# TODO: Re-enable this cop after TomDoc code deocumentation is added.
Style/Documentation:
Enabled: false

# Allow some style changes in the specs.
Metrics/BlockLength:
Exclude:
- figaro.gemspec
- spec/**/*
Metrics/ModuleLength:
Exclude:
- spec/**/*
Layout/LineLength:
Exclude:
- figaro.gemspec
- spec/**/*
RSpec/ContextWording:
Enabled: false
RSpec/DescribedClass:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Gemspec/DevelopmentDependencies:
Enabled: false

# These style conventions are personal preference.
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
Layout/ClosingHeredocIndentation:
Enabled: false
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
Layout/HashAlignment:
EnforcedLastArgumentHashStyle: ignore_implicit
Layout/LineEndStringConcatenationIndentation:
EnforcedStyle: indented
Layout/LineLength:
Enabled: false
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation
Metrics/ParameterLists:

Metrics:
Enabled: false

Naming/AccessorMethodName:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
Naming/RescuedExceptionsVariableName:
PreferredName: error
Style/DoubleNegation:

RSpec/BeEq:
Enabled: false
RSpec/ContextWording:
Enabled: false
RSpec/DescribedClass:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false

Style/Documentation:
Enabled: false
Style/FetchEnvVar:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/SymbolArray:
EnforcedStyle: brackets
Style/WordArray:
EnforcedStyle: brackets

# New cops:
Layout/SpaceAroundMethodCallOperator:
Enabled: true
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Style/ExponentialNotation:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ source "https://rubygems.org"
gemspec

group :test do
gem "rspec"
gem "rubocop", "~> 0.82.0", require: false
gem "rubocop-rspec", "~> 1.39", require: false
gem "rspec", "~> 3.13"
gem "rubocop", "~> 1.63", require: false
gem "rubocop-performance", "~> 1.21", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
gem "rubocop-rspec", "~> 2.29", require: false
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ require "rubocop/rake_task"
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop)

task default: [:spec, :rubocop]
task default: [:rubocop, :spec]
3 changes: 2 additions & 1 deletion figaro.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(/\Aexe/) { |f| File.basename(f) }

spec.required_ruby_version = ">= 2.4.0"
spec.required_ruby_version = ">= 3.1"

spec.add_dependency "thor", ">= 0.14.0", "< 2"

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.metadata["rubygems_mfa_required"] = "true"
end
10 changes: 5 additions & 5 deletions lib/figaro/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def to_s

include ::Thor::Actions

source_root ::File.expand_path("../install", __FILE__)
source_root ::File.expand_path("install", __dir__)

attr_reader :variables, :environment_options

Expand All @@ -36,7 +36,7 @@ def variable_names_must_be_simple
return if complex_names.none?

raise Figaro::CLI::ComplexVariableNamesError,
complex_names: complex_names
complex_names:
end

def variable_types_must_be_valid
Expand All @@ -47,7 +47,7 @@ def variable_types_must_be_valid
return if invalid_types.none?

raise Figaro::CLI::InvalidVariableTypesError,
valid_types: valid_types, invalid_types: invalid_types
valid_types:, invalid_types:
end

def variable_names_must_be_unique
Expand All @@ -59,13 +59,13 @@ def variable_names_must_be_unique
return if duplicate_names.none?

raise Figaro::CLI::DuplicateVariableNamesError,
duplicate_names: duplicate_names
duplicate_names:
end

def infer_environment_options
keys = using_rack? ? ["RACK_ENV"] : []
keys.unshift(using_rails? ? "RAILS_ENV" : "APP_ENV")
options = keys.count > 1 ? { keys: keys } : { key: keys.first }
options = keys.count > 1 ? { keys: } : { key: keys.first }
options[:default] = "development"
@environment_options = options
end
Expand Down
10 changes: 5 additions & 5 deletions lib/figaro/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def <<(variable)
add_accessors(variable)
end

def get(key, &default)
ENV.fetch(key, &default)
def get(key, &)
ENV.fetch(key, &)
end

def set(key, value)
Expand All @@ -94,9 +94,9 @@ def to_h

def add_accessors(variable)
@accessors.instance_eval do
define_method(variable.name, &variable.method(:value))
define_method(:"#{variable.name}=", &variable.method(:value=))
define_method(:"#{variable.name}?", &variable.method(:value?))
define_method(variable.name) { variable.value }
define_method(:"#{variable.name}=") { |value| variable.value = value }
define_method(:"#{variable.name}?") { variable.value? }
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/figaro/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def defaults(path)
def variable(name, type_class, **options)
variable =
Figaro::Variable.new(
config: config,
name: name,
type_class: type_class,
config:,
name:,
type_class:,
**options
)
config << variable
Expand Down
2 changes: 1 addition & 1 deletion lib/figaro/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def dump(_value)
private

def raise_type_load_error(value)
raise Figaro::TypeLoadError, type: self, value: value
raise Figaro::TypeLoadError, type: self, value:
end
end
end
2 changes: 1 addition & 1 deletion lib/figaro/type/decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Decimal < Figaro::Type
def load(value)
case value
when nil then nil
when /\A\-?\d+(\.\d+)\z/ then BigDecimal(value)
when /\A-?\d+(\.\d+)\z/ then BigDecimal(value)
else raise_type_load_error(value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/figaro/type/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Integer < Figaro::Type
def load(value)
case value
when nil then nil
when /\A\-?\d+\z/ then Integer(value)
when /\A-?\d+\z/ then Integer(value)
else raise_type_load_error(value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

Bundler.require(:test)

Dir[File.expand_path("support/*.rb", __dir__)].sort.each { |f| require f }
Dir[File.expand_path("support/*.rb", __dir__)].each { |f| require f }
12 changes: 5 additions & 7 deletions spec/support/reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

RSpec.configure do |config|
config.around do |example|
begin
original_env = ENV.to_hash
example.run
ensure
ENV.replace(original_env)
Thread.current[:figaro_config] = nil
end
original_env = ENV.to_hash
example.run
ensure
ENV.replace(original_env)
Thread.current[:figaro_config] = nil
end
end

0 comments on commit b830671

Please sign in to comment.