diff --git a/.rubocop.yml b/.rubocop.yml index 456f6d1..4631b4a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,8 @@ AllCops: TargetRubyVersion: 2.2 DisabledByDefault: true + Exclude: + - "examples/instrumentation.rb" Bundler: Enabled: true @@ -16,3 +18,11 @@ Performance: Security: Enabled: true + +Lint: + Enabled: true + +# TODO +# Remove cop disabling and fix offenses +Lint/HandleExceptions: + Enabled: false diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index ad5e1eb..c7596ef 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -101,7 +101,7 @@ class Rack::Attack end def throttled?(req) - throttles.any? do |name, throttle| + throttles.any? do |_name, throttle| throttle[req] end end @@ -149,7 +149,7 @@ class Rack::Attack # Set defaults @notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications) - @blocklisted_response = lambda { |env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] } + @blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] } @throttled_response = lambda { |env| retry_after = (env['rack.attack.match_data'] || {})[:period] [429, { 'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s }, ["Retry later\n"]] diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index d8edddb..d83cab9 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -12,8 +12,6 @@ module Rack klass ? klass.new(client) : client end - private - def self.unwrap_active_support_stores(store) # ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry, # so use the raw Redis::Store instead. diff --git a/lib/rack/attack/store_proxy/mem_cache_proxy.rb b/lib/rack/attack/store_proxy/mem_cache_proxy.rb index bc23942..4675789 100644 --- a/lib/rack/attack/store_proxy/mem_cache_proxy.rb +++ b/lib/rack/attack/store_proxy/mem_cache_proxy.rb @@ -23,12 +23,12 @@ module Rack rescue MemCache::MemCacheError end - def increment(key, amount, options = {}) + def increment(key, amount, _options = {}) incr(key, amount) rescue MemCache::MemCacheError end - def delete(key, options = {}) + def delete(key, _options = {}) with do |client| client.delete(key) end diff --git a/lib/rack/attack/store_proxy/redis_store_proxy.rb b/lib/rack/attack/store_proxy/redis_store_proxy.rb index 9833c26..1741b99 100644 --- a/lib/rack/attack/store_proxy/redis_store_proxy.rb +++ b/lib/rack/attack/store_proxy/redis_store_proxy.rb @@ -45,7 +45,7 @@ module Rack rescue Redis::BaseError end - def delete(key, options = {}) + def delete(key, _options = {}) del(key) rescue Redis::BaseError end diff --git a/spec/acceptance/cache_store_config_for_allow2ban_spec.rb b/spec/acceptance/cache_store_config_for_allow2ban_spec.rb index aa7208e..4b6cb11 100644 --- a/spec/acceptance/cache_store_config_for_allow2ban_spec.rb +++ b/spec/acceptance/cache_store_config_for_allow2ban_spec.rb @@ -81,11 +81,11 @@ describe "Cache store config when using allow2ban" do @backend[key] end - def write(key, value, options = {}) + def write(key, value, _options = {}) @backend[key] = value end - def increment(key, count, options = {}) + def increment(key, _count, _options = {}) @backend[key] ||= 0 @backend[key] += 1 end diff --git a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb index 53b43e5..4f978a1 100644 --- a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb +++ b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb @@ -81,11 +81,11 @@ describe "Cache store config when using fail2ban" do @backend[key] end - def write(key, value, options = {}) + def write(key, value, _options = {}) @backend[key] = value end - def increment(key, count, options = {}) + def increment(key, _count, _options = {}) @backend[key] ||= 0 @backend[key] += 1 end diff --git a/spec/acceptance/cache_store_config_for_throttle_spec.rb b/spec/acceptance/cache_store_config_for_throttle_spec.rb index 9df9a6c..524048b 100644 --- a/spec/acceptance/cache_store_config_for_throttle_spec.rb +++ b/spec/acceptance/cache_store_config_for_throttle_spec.rb @@ -29,7 +29,7 @@ describe "Cache store config when throttling without Rails" do @counts = {} end - def increment(key, count, options) + def increment(key, _count, _options) @counts[key] ||= 0 @counts[key] += 1 end diff --git a/spec/acceptance/customizing_blocked_response_spec.rb b/spec/acceptance/customizing_blocked_response_spec.rb index 190f5c0..cf297b0 100644 --- a/spec/acceptance/customizing_blocked_response_spec.rb +++ b/spec/acceptance/customizing_blocked_response_spec.rb @@ -12,7 +12,7 @@ describe "Customizing block responses" do assert_equal 403, last_response.status - Rack::Attack.blocklisted_response = lambda do |env| + Rack::Attack.blocklisted_response = lambda do |_env| [503, {}, ["Blocked"]] end diff --git a/spec/acceptance/customizing_throttled_response_spec.rb b/spec/acceptance/customizing_throttled_response_spec.rb index 5f657aa..61acc01 100644 --- a/spec/acceptance/customizing_throttled_response_spec.rb +++ b/spec/acceptance/customizing_throttled_response_spec.rb @@ -18,7 +18,7 @@ describe "Customizing throttled response" do assert_equal 429, last_response.status - Rack::Attack.throttled_response = lambda do |env| + Rack::Attack.throttled_response = lambda do |_env| [503, {}, ["Throttled"]] end diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index 8a0df19..0361c7c 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -51,7 +51,7 @@ describe 'Rack::Attack.throttle with limit as proc' do before do @period = 60 # Use a long period; failures due to cache key rotation less likely Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new - Rack::Attack.throttle('ip/sec', :limit => lambda { |req| 1 }, :period => @period) { |req| req.ip } + Rack::Attack.throttle('ip/sec', :limit => lambda { |_req| 1 }, :period => @period) { |req| req.ip } end it_allows_ok_requests @@ -75,7 +75,7 @@ describe 'Rack::Attack.throttle with period as proc' do before do @period = 60 # Use a long period; failures due to cache key rotation less likely Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new - Rack::Attack.throttle('ip/sec', :limit => lambda { |req| 1 }, :period => lambda { |req| @period }) { |req| req.ip } + Rack::Attack.throttle('ip/sec', :limit => lambda { |_req| 1 }, :period => lambda { |_req| @period }) { |req| req.ip } end it_allows_ok_requests diff --git a/spec/rack_attack_track_spec.rb b/spec/rack_attack_track_spec.rb index 8e0f9c6..24a408f 100644 --- a/spec/rack_attack_track_spec.rb +++ b/spec/rack_attack_track_spec.rb @@ -16,7 +16,7 @@ describe 'Rack::Attack.track' do end before do - Rack::Attack.track("everything") { |req| true } + Rack::Attack.track("everything") { |_req| true } end it_allows_ok_requests @@ -33,7 +33,7 @@ describe 'Rack::Attack.track' do # A second track Rack::Attack.track("homepage") { |req| req.path == "/" } - ActiveSupport::Notifications.subscribe("rack.attack") do |*args| + ActiveSupport::Notifications.subscribe("rack.attack") do |*_args| Counter.incr end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7d62673..8f8a71d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,7 +42,7 @@ class MiniTest::Spec use Rack::Attack use Rack::Lint - run lambda { |env| [200, {}, ['Hello World']] } + run lambda { |_env| [200, {}, ['Hello World']] } }.to_app end