Skip to content

Commit

Permalink
Merge pull request #925 from lostisland/fix/rubocop-style-m
Browse files Browse the repository at this point in the history
chore: RuboCop lint Style/M*
  • Loading branch information
olleolleolle committed Mar 4, 2019
2 parents 5b49e6c + 2a04aea commit 8ba22d5
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 39 deletions.
23 changes: 0 additions & 23 deletions .rubocop_todo.yml
Expand Up @@ -117,34 +117,11 @@ Style/MissingRespondToMissing:
Exclude:
- 'lib/faraday.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, Autocorrect.
# SupportedStyles: module_function, extend_self
Style/ModuleFunction:
Exclude:
- 'lib/faraday/utils.rb'

# Offense count: 1
Style/MultipleComparison:
Exclude:
- 'lib/faraday/encoders/flat_params_encoder.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'lib/faraday.rb'
- 'lib/faraday/adapter/net_http.rb'
- 'lib/faraday/adapter/rack.rb'
- 'lib/faraday/options/env.rb'
- 'lib/faraday/request/retry.rb'
- 'lib/faraday/response/logger.rb'
- 'lib/faraday/response/raise_error.rb'
- 'lib/faraday/utils.rb'

# Offense count: 276
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
4 changes: 2 additions & 2 deletions lib/faraday.rb
Expand Up @@ -20,8 +20,8 @@
#
module Faraday
VERSION = '0.15.3'
METHODS_WITH_QUERY = %w[get head delete connect trace]
METHODS_WITH_BODY = %w[post put patch]
METHODS_WITH_QUERY = %w[get head delete connect trace].freeze
METHODS_WITH_BODY = %w[post put patch].freeze

class << self
# The root path that Faraday is being loaded from.
Expand Down
8 changes: 5 additions & 3 deletions lib/faraday/adapter/net_http.rb
Expand Up @@ -12,7 +12,7 @@ module Faraday
class Adapter
# Net::HTTP adapter.
class NetHttp < Faraday::Adapter
NET_HTTP_EXCEPTIONS = [
exceptions = [
IOError,
Errno::ECONNABORTED,
Errno::ECONNREFUSED,
Expand All @@ -28,8 +28,10 @@ class NetHttp < Faraday::Adapter
Zlib::GzipFile::Error
]

NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL)
NET_HTTP_EXCEPTIONS << Net::OpenTimeout if defined?(Net::OpenTimeout)
exceptions << OpenSSL::SSL::SSLError if defined?(OpenSSL)
exceptions << Net::OpenTimeout if defined?(Net::OpenTimeout)

NET_HTTP_EXCEPTIONS = exceptions.freeze

def initialize(app = nil, opts = {}, &block)
@ssl_cert_store = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/adapter/rack.rb
Expand Up @@ -19,7 +19,7 @@ class Rack < Faraday::Adapter
dependency 'rack/test'

# not prefixed with "HTTP_"
SPECIAL_HEADERS = %w[CONTENT_LENGTH CONTENT_TYPE]
SPECIAL_HEADERS = %w[CONTENT_LENGTH CONTENT_TYPE].freeze

def initialize(faraday_app, rack_app)
super(faraday_app)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/options/env.rb
Expand Up @@ -52,7 +52,7 @@ class Env < Options.new(:method, :request_body, :url, :request, :request_headers
# rubocop:disable Naming/ConstantName
ContentLength = 'Content-Length'
StatusesWithoutBody = Set.new [204, 304]
SuccessfulStatuses = 200..299
SuccessfulStatuses = (200..299).freeze
# rubocop:enable Naming/ConstantName

# A Set of HTTP verbs that typically send a body. If no body is set for
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/retry.rb
Expand Up @@ -24,7 +24,7 @@ class Request
# interval that is random between 0.1 and 0.15.
class Retry < Faraday::Middleware
DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error', Faraday::TimeoutError, Faraday::RetriableResponse].freeze
IDEMPOTENT_METHODS = %i[delete get head options put]
IDEMPOTENT_METHODS = %i[delete get head options put].freeze

class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
:backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/response/logger.rb
Expand Up @@ -7,7 +7,7 @@ class Response
class Logger < Middleware
extend Forwardable

DEFAULT_OPTIONS = { headers: true, bodies: false }
DEFAULT_OPTIONS = { headers: true, bodies: false }.freeze

def initialize(app, logger = nil, options = {})
super(app)
Expand Down
4 changes: 2 additions & 2 deletions lib/faraday/response/raise_error.rb
Expand Up @@ -3,8 +3,8 @@
module Faraday
class Response
class RaiseError < Middleware
ClientErrorStatuses = 400...500 # rubocop:disable Naming/ConstantName
ServerErrorStatuses = 500...600 # rubocop:disable Naming/ConstantName
ClientErrorStatuses = (400...500).freeze
ServerErrorStatuses = (500...600).freeze

def on_complete(env)
case env[:status]
Expand Down
8 changes: 3 additions & 5 deletions lib/faraday/utils.rb
Expand Up @@ -5,7 +5,7 @@

module Faraday
module Utils
extend self
module_function

def build_query(params)
FlatParamsEncoder.encode(params)
Expand All @@ -15,7 +15,7 @@ def build_nested_query(params)
NestedParamsEncoder.encode(params)
end

ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/.freeze

def escape(str)
str.to_s.gsub(ESCAPE_RE) do |match|
Expand All @@ -27,7 +27,7 @@ def unescape(str)
CGI.unescape str.to_s
end

DEFAULT_SEP = /[&;] */n
DEFAULT_SEP = /[&;] */n.freeze

# Adapted from Rack
def parse_query(query)
Expand Down Expand Up @@ -100,8 +100,6 @@ def deep_merge(source, hash)
deep_merge!(source.dup, hash)
end

protected

def sort_query_params(query)
query.split('&').sort.join('&')
end
Expand Down

0 comments on commit 8ba22d5

Please sign in to comment.