diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5633375 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +AllCops: + Include: + - 'Gemfile' + Exclude: + - 'vendor/**/*' + - 'benchmarks/**/*' diff --git a/Gemfile b/Gemfile index e7841aa..6639e3b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,4 @@ source 'https://rubygems.org' gemspec -gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git' -eval File.read('Gemfile.devtools') +gem 'devtools', git: 'https://github.com/mbj/devtools.git', branch: 'master' diff --git a/Gemfile.devtools b/Gemfile.devtools deleted file mode 100644 index 318d37b..0000000 --- a/Gemfile.devtools +++ /dev/null @@ -1,71 +0,0 @@ -# encoding: utf-8 - -group :development do - gem 'rake', '~> 10.3.2' - gem 'rspec', '~> 3.0.0' - gem 'rspec-its', '~> 1.0.1' - gem 'yard', '~> 0.8.7.4' - - platform :rbx do - gem 'rubysl-singleton', '~> 2.0.0' - end -end - -group :yard do - gem 'kramdown', '~> 1.3.3' -end - -group :guard do - gem 'guard', '~> 2.6.1' - gem 'guard-bundler', '~> 2.0.0' - gem 'guard-rspec', '~> 4.2.9' - gem 'guard-rubocop', '~> 1.1.0' - - # file system change event handling - gem 'listen', '~> 2.7.7' - gem 'rb-fchange', '~> 0.0.6', require: false - gem 'rb-fsevent', '~> 0.9.4', require: false - gem 'rb-inotify', '~> 0.9.5', require: false - - # notification handling - gem 'libnotify', '~> 0.8.3', require: false - gem 'rb-notifu', '~> 0.0.4', require: false - gem 'terminal-notifier-guard', '~> 1.5.3', require: false -end - -group :metrics do - gem 'coveralls', '~> 0.7.0' - gem 'flay', '~> 2.5.0' - gem 'flog', '~> 4.2.1' - gem 'reek', '~> 1.3.7' - gem 'rubocop', '~> 0.23.0' - gem 'simplecov', '~> 0.7.1' - gem 'yardstick', '~> 0.9.9' - - platforms :mri do - gem 'mutant', '~> 0.6.0' - gem 'mutant-rspec', '~> 0.6.0' - end - - platforms :ruby_19, :ruby_20 do - gem 'yard-spellcheck', '~> 0.1.5' - end - - platform :rbx do - gem 'json', '~> 1.8.1' - gem 'racc', '~> 1.4.11' - gem 'rubysl-logger', '~> 2.0.0' - gem 'rubysl-open-uri', '~> 2.0.0' - gem 'rubysl-prettyprint', '~> 2.0.3' - end -end - -group :benchmarks do - gem 'rbench', '~> 0.2.3' -end - -platform :jruby do - group :jruby do - gem 'jruby-openssl', '~> 0.9.4' - end -end diff --git a/config/flay.yml b/config/flay.yml index 1ae5a76..d5454bb 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 12 -total_score: 74 +total_score: 72 diff --git a/config/rubocop.yml b/config/rubocop.yml new file mode 100644 index 0000000..0c154c9 --- /dev/null +++ b/config/rubocop.yml @@ -0,0 +1,113 @@ +inherit_from: ../.rubocop.yml + +# Avoid parameter lists longer than five parameters. +ParameterLists: + Max: 3 + CountKeywordArgs: true + +# Avoid more than `Max` levels of nesting. +BlockNesting: + Max: 3 + +# Align with the style guide. +CollectionMethods: + PreferredMethods: + collect: 'map' + inject: 'reduce' + find: 'detect' + find_all: 'select' + +# Do not force public/protected/private keyword to be indented at the same +# level as the def keyword. My personal preference is to outdent these keywords +# because I think when scanning code it makes it easier to identify the +# sections of code and visually separate them. When the keyword is at the same +# level I think it sort of blends in with the def keywords and makes it harder +# to scan the code and see where the sections are. +AccessModifierIndentation: + Enabled: false + +# Limit line length +LineLength: + Max: 106 + +# Disable documentation checking until a class needs to be documented once +Documentation: + Enabled: false + +# Do not always use &&/|| instead of and/or. +AndOr: + Enabled: false + +# Do not favor modifier if/unless usage when you have a single-line body +IfUnlessModifier: + Enabled: false + +# Allow case equality operator (in limited use within the specs) +CaseEquality: + Enabled: false + +# Constants do not always have to use SCREAMING_SNAKE_CASE +ConstantName: + Enabled: false + +# Not all trivial readers/writers can be defined with attr_* methods +TrivialAccessors: + Enabled: false + +# Allow empty lines around class body +EmptyLinesAroundClassBody: + Enabled: false + +# Allow empty lines around module body +EmptyLinesAroundModuleBody: + Enabled: false + +# Allow empty lines around block body +EmptyLinesAroundBlockBody: + Enabled: false + +# Allow multiple line operations to not require indentation +MultilineOperationIndentation: + Enabled: false + +# Prefer String#% over Kernel#sprintf +FormatString: + Enabled: false + +# Use square brackets for literal Array objects +PercentLiteralDelimiters: + PreferredDelimiters: + '%': '{}' + '%i': '[]' + '%q': () + '%Q': () + '%r': '{}' + '%s': () + '%w': '[]' + '%W': '[]' + '%x': () + +# Align if/else blocks with the variable assignment +EndAlignment: + AlignWith: variable + +# Do not always align parameters when it is easier to read +AlignParameters: + Exclude: + - spec/**/*_spec.rb + +# Prefer #kind_of? over #is_a? +ClassCheck: + EnforcedStyle: kind_of? + +# Do not prefer double quotes to be used when %q or %Q is more appropriate +UnneededPercentQ: + Enabled: false + +# Allow a maximum ABC score +Metrics/AbcSize: + Max: 21.02 + +# Do not prefer lambda.call(...) over lambda.(...) +LambdaCall: + Enabled: false diff --git a/lib/request.rb b/lib/request.rb index 1c2a88b..407028b 100644 --- a/lib/request.rb +++ b/lib/request.rb @@ -9,13 +9,22 @@ # Library namespace and abstract base class class Request - KEYS = %W( - path_info protocol port request_method - host if_modified_since query_params query_params_hash - query_string content_length content_type body - ).map(&:to_sym).freeze - - METHODS = (KEYS + %W(rack_env get? post?)).map(&:to_sym).freeze + KEYS = %w[ + path_info + protocol + port + request_method + host + if_modified_since + query_params + query_params_hash + query_string + content_length + content_type + body + ].map(&:to_sym).freeze + + METHODS = (KEYS + %w[rack_env get? post?]).map(&:to_sym).freeze include Adamantium::Flat, AbstractType, Equalizer.new(*KEYS) @@ -98,7 +107,7 @@ def uid # def query_params_hash query_params.each_with_object({}) do |(key, value), hash| - hash[key]=value + hash[key] = value end end memoize :query_params_hash @@ -153,7 +162,7 @@ def root_uri # @api private # def host_with_port - uhost, uport = self.host, self.port + uhost, uport = host, port if port != protocol.default_port "#{uhost}:#{uport}" else diff --git a/lib/request/method.rb b/lib/request/method.rb index 880a64d..8dcca2a 100644 --- a/lib/request/method.rb +++ b/lib/request/method.rb @@ -22,7 +22,7 @@ class Method attr_reader :verb INDEX = ALL.each_with_object({}) do |method, index| - index[method.verb]=method + index[method.verb] = method end.freeze # Return request method diff --git a/lib/request/rack.rb b/lib/request/rack.rb index 8cf42cd..c7c9348 100644 --- a/lib/request/rack.rb +++ b/lib/request/rack.rb @@ -94,7 +94,7 @@ def content_length end unless value =~ CONTENT_LENGTH_REGEXP - raise InvalidKeyError, 'invalid content length' + fail InvalidKeyError, 'invalid content length' end value.to_i @@ -125,18 +125,18 @@ def query_params def if_modified_since value = @rack_env.fetch(IF_MODIFIED_SINCE) { return } begin - Time.httpdate(value) - rescue ArgumentError + Time.httpdate(value) + rescue ArgumentError nil end end memoize :if_modified_since - accessor(:path_info, Key.new('PATH_INFO') ) - accessor(:host, Key.new('SERVER_NAME') ) - accessor(:query_string, Key.new('QUERY_STRING') ) + accessor(:path_info, Key.new('PATH_INFO')) + accessor(:host, Key.new('SERVER_NAME')) + accessor(:query_string, Key.new('QUERY_STRING')) accessor(:content_type, Key.new('CONTENT_TYPE'), nil) - accessor(:body, Key.new('rack.input') ) + accessor(:body, Key.new('rack.input')) private diff --git a/spec/shared/rack_env_accessor_behavior.rb b/spec/shared/rack_env_accessor_behavior.rb index 8aa8df6..8ff62eb 100644 --- a/spec/shared/rack_env_accessor_behavior.rb +++ b/spec/shared/rack_env_accessor_behavior.rb @@ -23,7 +23,7 @@ it 'should not freeze the input env' do subject - env.frozen?.should be(false) + expect(env.frozen?).to be(false) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5855b55..8479c74 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,6 @@ # encoding: utf-8 -require 'request' require 'devtools' -Devtools.init_spec_helper +require 'request' -RSpec.configure do |config| -end +Devtools.init_spec_helper diff --git a/spec/unit/request/key/hash_spec.rb b/spec/unit/request/key/hash_spec.rb index 4c84887..0c09f5a 100644 --- a/spec/unit/request/key/hash_spec.rb +++ b/spec/unit/request/key/hash_spec.rb @@ -3,7 +3,7 @@ describe Request::Key, '#hash' do subject { described_class.new(string).hash } - let(:string) { "teststring" } + let(:string) { 'teststring' } it { should == string.hash } -end \ No newline at end of file +end diff --git a/spec/unit/request/rack/content_length_spec.rb b/spec/unit/request/rack/content_length_spec.rb index d2d1133..81e5abb 100644 --- a/spec/unit/request/rack/content_length_spec.rb +++ b/spec/unit/request/rack/content_length_spec.rb @@ -3,7 +3,7 @@ describe Request::Rack, '#content_length' do subject { object.content_length } - let(:rack_key) { 'CONTENT_LENGTH'} + let(:rack_key) { 'CONTENT_LENGTH' } context 'with decimal positive integer' do it_should_behave_like 'a rack env accessor' do @@ -40,7 +40,7 @@ it_should_behave_like 'a rack env accessor' do - let(:expected_value) { 0 } + let(:expected_value) { 0 } end end