Skip to content

Commit b2e38c7

Browse files
committed
Apply rubocop and enable in CI
1 parent fe9d943 commit b2e38c7

30 files changed

Lines changed: 519 additions & 493 deletions

.github/workflows/tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,26 @@ jobs:
6060
with:
6161
coverageCommand: bundle exec appraisal rspec
6262

63+
lint:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Set up Ruby
70+
uses: ruby/setup-ruby@v1
71+
with:
72+
ruby-version: 4.0.1
73+
bundler-cache: true
74+
75+
- name: Lint code for consistent style
76+
run: bundle exec rubocop -f github
77+
6378
all-passed:
6479
runs-on: ubuntu-latest
6580
if: always()
6681
needs:
6782
- test
83+
- lint
6884
steps:
6985
- run: exit ${{ contains(needs.*.result, 'failure') && 1 || 0 }}

.rubocop.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
AllCops:
2+
NewCops: disable
3+
Exclude:
4+
- 'spec/app/**/*'
5+
- 'gemfiles/**/*'
6+
7+
Metrics:
8+
Enabled: false
9+
10+
Style/Documentation:
11+
Enabled: false
12+
113
Layout/LineLength:
214
Max: 120
315

Appraisals

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
max_ruby_version = ->(version) {
2-
RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) <= Gem::Version.new(version)
3-
}
4-
5-
min_ruby_version = ->(version) {
1+
min_ruby_version = lambda { |version|
62
RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version)
73
}
84

Rakefile

100644100755
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ begin
44
require 'bundler/setup'
55

66
Bundler::GemHelper.install_tasks
7-
87
rescue LoadError
98
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
109
end
1110

1211
##
1312
# Testing
1413
#
15-
require "rspec"
16-
require "rspec/core/rake_task"
14+
require 'rspec'
15+
require 'rspec/core/rake_task'
1716

1817
RSpec::Core::RakeTask.new(:spec)
1918

2019
# Test for multiple Rails scenarios
2120
if !ENV['APPRAISAL_INITIALIZED'] && !ENV['GITHUB_ACTIONS']
22-
require "appraisal"
21+
require 'appraisal'
2322

24-
task :default => :appraisal
23+
task default: :appraisal
2524
else
26-
task :default => :spec
25+
task default: :spec
2726
end
2827

2928
##

config.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'English'
12
require_relative 'lib/config/version'
23
require_relative 'lib/config/dry_validation_requirements'
34

@@ -8,20 +9,20 @@ Gem::Specification.new do |s|
89
s.authors = ['Piotr Kuczynski', 'Fred Wu', 'Jacques Crocker']
910
s.email = %w[piotr.kuczynski@gmail.com ifredwu@gmail.com railsjedi@gmail.com]
1011
s.summary = 'Effortless multi-environment settings in Rails, Sinatra, Padrino and others'
11-
s.description = 'Easiest way to manage multi-environment settings in any ruby project or framework: ' +
12+
s.description = 'Easiest way to manage multi-environment settings in any ruby project or framework: ' \
1213
'Rails, Sinatra, Padrino and others'
1314
s.homepage = 'https://github.com/rubyconfig/config'
1415
s.license = 'MIT'
1516
s.extra_rdoc_files = %w[README.md CHANGELOG.md CONTRIBUTING.md LICENSE.md]
1617
s.rdoc_options = ['--charset=UTF-8']
1718

1819
s.metadata = {
19-
'changelog_uri' => "https://github.com/rubyconfig/config/blob/master/CHANGELOG.md",
20+
'changelog_uri' => 'https://github.com/rubyconfig/config/blob/master/CHANGELOG.md',
2021
'funding_uri' => 'https://opencollective.com/rubyconfig/donate',
2122
'source_code_uri' => 'https://github.com/rubyconfig/config',
2223
'bug_tracker_uri' => 'https://github.com/rubyconfig/config/issues'
2324
}
24-
s.files = `git ls-files`.split($/)
25+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
2526
s.files.select! { |file| /(^lib\/|^\w+.md$|\.gemspec$)/ =~ file }
2627

2728
s.require_paths = ['lib']

lib/config/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Configuration < Module
44
# Accepts configuration options,
55
# initializing a module that can be used to extend
66
# the necessary class with the provided config methods
7-
def initialize(**attributes)
7+
def initialize(**attributes) # rubocop:disable Lint/MissingSuper
88
attributes.each do |name, default|
99
define_reader(name, default)
1010
define_writer(name)

lib/config/dry_validation_requirements.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
module Config
42
module DryValidationRequirements
53
VERSIONS = ['~> 1.0', '>= 1.0.0'].freeze
@@ -10,11 +8,10 @@ def self.load_dry_validation!
108
begin
119
require 'dry/validation/version'
1210
version = Gem::Version.new(Dry::Validation::VERSION)
13-
unless VERSIONS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
14-
raise LoadError
15-
end
11+
raise LoadError unless VERSIONS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
1612
rescue LoadError
17-
raise ::Config::Error, "Could not find a dry-validation version matching requirements (#{VERSIONS.map(&:inspect) * ','})"
13+
raise ::Config::Error,
14+
"Could not find a dry-validation version matching requirements (#{VERSIONS.map(&:inspect) * ','})"
1815
end
1916

2017
require 'dry/validation'

lib/config/integrations/heroku.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Config
44
module Integrations
5-
class Heroku < Struct.new(:app)
5+
Heroku = Struct.new(:app) do
66
def invoke
77
puts 'Setting vars...'
88
heroku_command = "config:set #{vars}"
@@ -14,14 +14,14 @@ def invoke
1414
def vars
1515
# Load only local options to Heroku
1616
Config.load_and_set_settings(
17-
Rails.root.join("config", "#{Config.file_name}.local.yml").to_s,
18-
Rails.root.join("config", Config.dir_name, "#{environment}.local.yml").to_s,
19-
Rails.root.join("config", "environments", "#{environment}.local.yml").to_s
17+
Rails.root.join('config', "#{Config.file_name}.local.yml").to_s,
18+
Rails.root.join('config', Config.dir_name, "#{environment}.local.yml").to_s,
19+
Rails.root.join('config', 'environments', "#{environment}.local.yml").to_s
2020
)
2121

2222
out = ''
2323
dotted_hash = to_dotted_hash Kernel.const_get(Config.const_name).to_hash, {}, Config.const_name
24-
dotted_hash.each {|key, value| out += " #{key}=#{value} "}
24+
dotted_hash.each { |key, value| out += " #{key}=#{value} " }
2525
out
2626
end
2727

@@ -30,7 +30,7 @@ def environment
3030
end
3131

3232
def heroku(command)
33-
with_app = app ? " --app #{app}" : ""
33+
with_app = app ? " --app #{app}" : ''
3434
`heroku #{command}#{with_app}`
3535
end
3636

@@ -41,16 +41,16 @@ def `(command)
4141
def to_dotted_hash(source, target = {}, namespace = nil)
4242
prefix = "#{namespace}." if namespace
4343
case source
44-
when Hash
45-
source.each do |key, value|
46-
to_dotted_hash(value, target, "#{prefix}#{key}")
47-
end
48-
when Array
49-
source.each_with_index do |value, index|
50-
to_dotted_hash(value, target, "#{prefix}#{index}")
51-
end
52-
else
53-
target[namespace] = source
44+
when Hash
45+
source.each do |key, value|
46+
to_dotted_hash(value, target, "#{prefix}#{key}")
47+
end
48+
when Array
49+
source.each_with_index do |value, index|
50+
to_dotted_hash(value, target, "#{prefix}#{index}")
51+
end
52+
else
53+
target[namespace] = source
5454
end
5555
target
5656
end

lib/config/integrations/rails/railtie.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def preload
99

1010
# Parse the settings before any of the initializers
1111
Config.load_and_set_settings(
12-
Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
12+
Config.setting_files(::Rails.root.join('config'),
13+
Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
1314
)
1415
end
1516

lib/config/integrations/sinatra.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "config/rack/reloader"
1+
require 'config/rack/reloader'
22

33
module Config
44
# provide helper to register within your Sinatra app
@@ -8,8 +8,7 @@ module Config
88
#
99
def self.registered(app)
1010
app.configure do |inner_app|
11-
12-
env = inner_app.environment || ENV["RACK_ENV"]
11+
env = inner_app.environment || ENV['RACK_ENV']
1312
root = inner_app.root
1413

1514
# use Padrino settings if applicable

0 commit comments

Comments
 (0)