diff --git a/.rubocop.yml b/.rubocop.yml index 4631b4a..cc0e049 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,18 @@ +inherit_mode: + merge: + - Exclude + AllCops: TargetRubyVersion: 2.2 DisabledByDefault: true Exclude: - "examples/instrumentation.rb" + # Remove the following line once we are able to make bundler install gems to /vendor/bundle instead + # of /gemfiles/vendor/bundle during TravisCI builds. The reason that happens for now is because + # bundler 1.x only installs relative to the Gemfile (which during CI builds is always one inside gemfiles/ folder) + # instead of the CWD. Bundler 2.x will add support to install relative to CWD + # (see https://github.com/bundler/bundler/pull/5803). + - "gemfiles/vendor/**/*" Bundler: Enabled: true @@ -13,6 +23,14 @@ Gemspec: Layout: Enabled: true +Lint: + Enabled: true + +Naming: + Enabled: true + Exclude: + - "lib/rack/attack/path_normalizer.rb" + Performance: Enabled: true @@ -22,6 +40,15 @@ Security: Lint: Enabled: true +Style/BracesAroundHashParameters: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: true + +Style/RedundantFreeze: + Enabled: true + # TODO # Remove cop disabling and fix offenses Lint/HandleExceptions: diff --git a/Rakefile b/Rakefile index 52b39f2..961943b 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,9 @@ require "rubygems" require "bundler/setup" require 'bundler/gem_tasks' require 'rake/testtask' +require "rubocop/rake_task" + +RuboCop::RakeTask.new namespace :test do Rake::TestTask.new(:units) do |t| @@ -20,4 +23,4 @@ end desc 'Run tests' task :test => %w[test:units test:integration test:acceptance] -task :default => :test +task :default => [:rubocop, :test] diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 1140f91..4a96778 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -38,15 +38,15 @@ class Rack::Attack self.blocklists[name] = Blocklist.new(name, block) end - def blocklist_ip(ip) + def blocklist_ip(ip_address) @ip_blocklists ||= [] - ip_blocklist_proc = lambda { |request| IPAddr.new(ip).include?(IPAddr.new(request.ip)) } + ip_blocklist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } @ip_blocklists << Blocklist.new(nil, ip_blocklist_proc) end - def safelist_ip(ip) + def safelist_ip(ip_address) @ip_safelists ||= [] - ip_safelist_proc = lambda { |request| IPAddr.new(ip).include?(IPAddr.new(request.ip)) } + ip_safelist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } @ip_safelists << Safelist.new(nil, ip_safelist_proc) end diff --git a/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb b/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb index 319445e..8bb3f46 100644 --- a/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb +++ b/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb @@ -18,11 +18,11 @@ module Rack end def read(name, options = {}) - super(name, options.merge!({ raw: true })) + super(name, options.merge!(raw: true)) end def write(name, value, options = {}) - super(name, value, options.merge!({ raw: true })) + super(name, value, options.merge!(raw: true)) end end end diff --git a/rack-attack.gemspec b/rack-attack.gemspec index f63c35c..233e9ea 100644 --- a/rack-attack.gemspec +++ b/rack-attack.gemspec @@ -38,7 +38,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rack-test' s.add_development_dependency 'rake' s.add_development_dependency 'redis-activesupport' - s.add_development_dependency "rubocop", "0.55.0" + s.add_development_dependency "rubocop", "0.57.2" s.add_development_dependency "timecop" # Need to explicitly depend on guard because guard-minitest doesn't declare diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index 0361c7c..b32891a 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -37,7 +37,7 @@ describe 'Rack::Attack.throttle' do it 'should tag the env' do last_request.env['rack.attack.matched'].must_equal 'ip/sec' last_request.env['rack.attack.match_type'].must_equal :throttle - last_request.env['rack.attack.match_data'].must_equal({ :count => 2, :limit => 1, :period => @period }) + last_request.env['rack.attack.match_data'].must_equal(:count => 2, :limit => 1, :period => @period) last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4') end