From 1d994810f90c634d25e931fa96defb0da85de757 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 8 Feb 2017 19:59:07 -0800 Subject: [PATCH] Enable the Style/OptionHash cop We should start favoring keyword arguments See: https://github.com/httprb/http/pull/368#issuecomment-278060919 --- .rubocop.yml | 5 ++++- lib/http/chainable.rb | 26 +++++++++++++------------- lib/http/client.rb | 2 +- lib/http/feature.rb | 2 +- lib/http/options.rb | 4 ++-- lib/http/redirector.rb | 2 +- lib/http/timeout/null.rb | 2 +- spec/support/dummy_server.rb | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cb90b824..b60b753e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - DisplayCopNames: true + DisplayCopNames: true Metrics/BlockNesting: Max: 2 @@ -64,6 +64,9 @@ Style/HashSyntax: Style/Lambda: Enabled: false +Style/OptionHash: + Enabled: true + Style/SpaceAroundOperators: AllowForAlignment: true diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index f3c9469e..a7858f1a 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -8,70 +8,70 @@ module Chainable # Request a get sans response body # @param uri # @option options [Hash] - def head(uri, options = {}) + def head(uri, options = {}) # rubocop:disable Style/OptionHash request :head, uri, options end # Get a resource # @param uri # @option options [Hash] - def get(uri, options = {}) + def get(uri, options = {}) # rubocop:disable Style/OptionHash request :get, uri, options end # Post to a resource # @param uri # @option options [Hash] - def post(uri, options = {}) + def post(uri, options = {}) # rubocop:disable Style/OptionHash request :post, uri, options end # Put to a resource # @param uri # @option options [Hash] - def put(uri, options = {}) + def put(uri, options = {}) # rubocop:disable Style/OptionHash request :put, uri, options end # Delete a resource # @param uri # @option options [Hash] - def delete(uri, options = {}) + def delete(uri, options = {}) # rubocop:disable Style/OptionHash request :delete, uri, options end # Echo the request back to the client # @param uri # @option options [Hash] - def trace(uri, options = {}) + def trace(uri, options = {}) # rubocop:disable Style/OptionHash request :trace, uri, options end # Return the methods supported on the given URI # @param uri # @option options [Hash] - def options(uri, options = {}) + def options(uri, options = {}) # rubocop:disable Style/OptionHash request :options, uri, options end # Convert to a transparent TCP/IP tunnel # @param uri # @option options [Hash] - def connect(uri, options = {}) + def connect(uri, options = {}) # rubocop:disable Style/OptionHash request :connect, uri, options end # Apply partial modifications to a resource # @param uri # @option options [Hash] - def patch(uri, options = {}) + def patch(uri, options = {}) # rubocop:disable Style/OptionHash request :patch, uri, options end # Make an HTTP request with the given verb # @param uri # @option options [Hash] - def request(verb, uri, options = {}) + def request(verb, uri, options = {}) # rubocop:disable Style/OptionHash branch(options).request verb, uri end @@ -85,7 +85,7 @@ def request(verb, uri, options = {}) # @option options [Float] :read Read timeout # @option options [Float] :write Write timeout # @option options [Float] :connect Connect timeout - def timeout(klass, options = {}) + def timeout(klass, options = {}) # rubocop:disable Style/OptionHash if klass.is_a? Hash options = klass klass = :per_operation @@ -168,8 +168,8 @@ def via(*proxy) # @param opts # @return [HTTP::Client] # @see Redirector#initialize - def follow(opts = {}) - branch default_options.with_follow opts + def follow(options = {}) # rubocop:disable Style/OptionHash + branch default_options.with_follow options end # Make a request with the given headers diff --git a/lib/http/client.rb b/lib/http/client.rb index 922a539f..016710e6 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -23,7 +23,7 @@ def initialize(default_options = {}) end # Make an HTTP request - def request(verb, uri, opts = {}) + def request(verb, uri, opts = {}) # rubocop:disable Style/OptionHash opts = @default_options.merge(opts) uri = make_request_uri(uri, opts) headers = make_request_headers(opts) diff --git a/lib/http/feature.rb b/lib/http/feature.rb index b5b21a3c..022400ec 100644 --- a/lib/http/feature.rb +++ b/lib/http/feature.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module HTTP class Feature - def initialize(opts = {}) + def initialize(opts = {}) # rubocop:disable Style/OptionHash @opts = opts end end diff --git a/lib/http/options.rb b/lib/http/options.rb index f2b72c27..9054e803 100644 --- a/lib/http/options.rb +++ b/lib/http/options.rb @@ -22,7 +22,7 @@ class << self attr_accessor :default_socket_class, :default_ssl_socket_class, :default_timeout_class attr_reader :available_features - def new(options = {}) + def new(options = {}) # rubocop:disable Style/OptionHash return options if options.is_a?(self) super end @@ -46,7 +46,7 @@ def def_option(name, &interpreter) end end - def initialize(options = {}) + def initialize(options = {}) # rubocop:disable Style/OptionHash defaults = { :response => :auto, :proxy => {}, diff --git a/lib/http/redirector.rb b/lib/http/redirector.rb index 86028ec8..3da451a1 100644 --- a/lib/http/redirector.rb +++ b/lib/http/redirector.rb @@ -38,7 +38,7 @@ class EndlessRedirectError < TooManyRedirectsError; end # @param [Hash] opts # @option opts [Boolean] :strict (true) redirector hops policy # @option opts [#to_i] :max_hops (5) maximum allowed amount of hops - def initialize(opts = {}) + def initialize(opts = {}) # rubocop:disable Style/OptionHash @strict = opts.fetch(:strict, true) @max_hops = opts.fetch(:max_hops, 5).to_i end diff --git a/lib/http/timeout/null.rb b/lib/http/timeout/null.rb index cf2d3f0d..510f5a3e 100644 --- a/lib/http/timeout/null.rb +++ b/lib/http/timeout/null.rb @@ -11,7 +11,7 @@ class Null attr_reader :options, :socket - def initialize(options = {}) + def initialize(options = {}) # rubocop:disable Style/OptionHash @options = options end diff --git a/spec/support/dummy_server.rb b/spec/support/dummy_server.rb index 671fbeb3..3c4bc5b3 100644 --- a/spec/support/dummy_server.rb +++ b/spec/support/dummy_server.rb @@ -23,7 +23,7 @@ class DummyServer < WEBrick::HTTPServer :SSLStartImmediately => true ).freeze - def initialize(options = {}) + def initialize(options = {}) # rubocop:disable Style/OptionHash super(options[:ssl] ? SSL_CONFIG : CONFIG) mount("/", Servlet) end