Skip to content

Commit

Permalink
RuboCop updates (puma#3123)
Browse files Browse the repository at this point in the history
* Rubocop updates

* 3 Rubocop fixes

* 5 Rubocop fixes

* test_bundle_pruner.rb - replace regex tests with end_with?

* test_config.rb - fix 'warning: assigned but unused variable - conf'
  • Loading branch information
MSP-Greg authored May 2, 2023
1 parent 34d3d94 commit c4c547c
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.1
bundler-cache: true # `bundle install` and cache
- name: rubocop
run: bundle exec rake rubocop
Expand Down
46 changes: 10 additions & 36 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require: rubocop-performance
require:
- rubocop-performance

AllCops:
DisabledByDefault: true
Expand All @@ -12,12 +13,15 @@ AllCops:
- 'pkg/**/*'
- 'Rakefile'
SuggestExtensions: false
NewCops: disable
NewCops: enable

# enable all Performance cops
Performance:
Enabled: true

# ————————————————————————————————————————— disabled cops

# ————————————————————————————————————————— enabled cops

Layout/AccessModifierIndentation:
EnforcedStyle: indent

Expand Down Expand Up @@ -52,6 +56,9 @@ Lint/Debugger:
Metrics/ParameterLists:
Max: 7

Naming/ConstantName:
Enabled: true

Naming/MethodName:
Enabled: true
EnforcedStyle: snake_case
Expand All @@ -61,39 +68,6 @@ Naming/MethodName:
Naming/VariableName:
Enabled: true

Performance:
Enabled: true

Performance/ChainArrayAllocation:
Enabled: true

Performance/CollectionLiteralInLoop:
Enabled: true

Performance/DeletePrefix:
Enabled: true

Performance/DeleteSuffix:
Enabled: true

Performance/MethodObjectAsBlock:
Enabled: true

Performance/RedundantMatch:
Enabled: true

Performance/RedundantBlockCall:
Enabled: true

Performance/StringIdentifierArgument:
Enabled: true

Performance/StringInclude:
Enabled: true

Performance/StringReplacement:
Enabled: true

Style/MethodDefParentheses:
Enabled: true

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gem "rackup" unless ENV['PUMA_CI_RACK_2']
gem "jruby-openssl", :platform => "jruby"

unless ENV['PUMA_NO_RUBOCOP'] || RUBY_PLATFORM.include?('mswin')
gem "rubocop", "1.12.1"
gem "rubocop"
gem 'rubocop-performance', require: false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puma/app/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def call(env)

def authenticate(env)
return true unless @auth_token
env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
env['QUERY_STRING'].to_s.split('&;').include? "token=#{@auth_token}"
end

def rack_response(status, body, content_type='application/json')
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initialize(io, env=nil)
@to_io = io.to_io
@io_buffer = IOBuffer.new
@proto_env = env
@env = env ? env.dup : nil
@env = env&.dup

@parser = HttpParser.new
@parsed_bytes = 0
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/log_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def parse_error(error, req)
def ssl_error(error, ssl_socket)
peeraddr = ssl_socket.peeraddr.last rescue "<unknown>"
peercert = ssl_socket.peercert
subject = peercert ? peercert.subject : nil
subject = peercert&.subject
@error_logger.info(error: error, text: "SSL error, peer: #{peeraddr}, peer cert: #{subject}")
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puma/rack/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def self.new_from_string(builder_script, file="(rackup)")
TOPLEVEL_BINDING, file, 0
end

def initialize(default_app = nil,&block)
def initialize(default_app = nil, &block)
@use, @map, @run, @warmup = [], nil, default_app, nil

# Conditionally load rack now, so that any rack middlewares,
Expand All @@ -183,7 +183,7 @@ def initialize(default_app = nil,&block)
rescue LoadError
end

instance_eval(&block) if block_given?
instance_eval(&block) if block
end

def self.app(default_app = nil, &block)
Expand Down
6 changes: 3 additions & 3 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Server
def_delegators :@binder, :add_tcp_listener, :add_ssl_listener,
:add_unix_listener, :connected_ports

ThreadLocalKey = :puma_server
THREAD_LOCAL_KEY = :puma_server

# Create a server for the rack app +app+.
#
Expand Down Expand Up @@ -118,7 +118,7 @@ def inherit_binder(bind)
class << self
# @!attribute [r] current
def current
Thread.current[ThreadLocalKey]
Thread.current[THREAD_LOCAL_KEY]
end

# :nodoc:
Expand Down Expand Up @@ -404,7 +404,7 @@ def handle_check
# Return true if one or more requests were processed.
def process_client(client)
# Advertise this server into the thread
Thread.current[ThreadLocalKey] = self
Thread.current[THREAD_LOCAL_KEY] = self

clean_thread_locals = @options[:clean_thread_locals]
close_socket = true
Expand Down
6 changes: 4 additions & 2 deletions test/test_bundle_pruner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

class TestBundlePruner < Minitest::Test

PUMA_VERS = "puma-#{Puma::Const::PUMA_VERSION}"

def test_paths_to_require_after_prune_is_correctly_built_for_no_extra_deps
skip_if :no_bundler

dirs = bundle_pruner.send(:paths_to_require_after_prune)

assert_equal(2, dirs.length)
assert_equal(File.join(PROJECT_ROOT, "lib"), dirs[0]) # lib dir
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
assert_operator dirs[1], :end_with?, PUMA_VERS # native extension dir
refute_match(%r{gems/minitest-[\d.]+/lib$}, dirs[2])
end

Expand All @@ -22,7 +24,7 @@ def test_paths_to_require_after_prune_is_correctly_built_with_extra_deps

assert_equal(3, dirs.length)
assert_equal(File.join(PROJECT_ROOT, "lib"), dirs[0]) # lib dir
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
assert_operator dirs[1], :end_with?, PUMA_VERS # native extension dir
assert_match(%r{gems/minitest-[\d.]+/lib$}, dirs[2]) # minitest dir
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def assert_run_hooks(hook_name, options = {})

def assert_warning_for_hooks_defined_in_single_mode(hook_name)
out, _ = capture_io do
conf = Puma::Configuration.new do |c|
Puma::Configuration.new do |c|
c.send(hook_name)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def <<(work, &block)
work = [work] unless work.is_a?(Array)
with_mutex do
work.each {|arg| super arg}
yield if block_given?
yield if block
@not_full.wait(@mutex)
end
end
Expand Down

0 comments on commit c4c547c

Please sign in to comment.