chore: RuboCop: Support Frozen String Literals (#868)

This commit is contained in:
Mattia 2019-02-24 19:35:12 +00:00 committed by Olle Jonsson
parent fcc4c4043e
commit b427091f0e
97 changed files with 210 additions and 25 deletions

View File

@ -603,13 +603,6 @@ Style/FormatStringToken:
- 'test/adapters/integration.rb'
- 'test/live_server.rb'
# Offense count: 96
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
Enabled: false
# Offense count: 2
# Configuration parameters: AllowedVariables.
Style/GlobalVars:

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
ruby RUBY_VERSION

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rake/testtask'
task :default => :test

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/setup'
require 'faraday'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
lib = "faraday"
lib_file = File.expand_path("../lib/#{lib}.rb", __FILE__)
File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'thread'
require 'cgi'
require 'set'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Base class for all Faraday adapters. Adapters are
# responsible for fulfilling a Faraday request.
@ -5,7 +7,7 @@ module Faraday
extend MiddlewareRegistry
extend DependencyLoader
CONTENT_LENGTH = 'Content-Length'.freeze
CONTENT_LENGTH = 'Content-Length'
register_middleware File.expand_path('../adapter', __FILE__),
:test => [:Test, 'test'],

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# EventMachine adapter. This adapter is useful for either asynchronous

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'openssl'
require 'em-http'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'uri'
module Faraday

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
class EMSynchrony < Faraday::Adapter

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Excon adapter.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# HTTPClient adapter.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
begin
require 'net/https'
rescue LoadError

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Net::HTTP::Persistent adapter.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Patron adapter.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Sends requests to a Rack app.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Examples

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Adapter
# Typhoeus adapter. This class is just a stub, the real adapter is in https://github.com/philsturgeon/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Adds the ability for other modules to manage autoloadable
# constants.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Connection objects manage the default properties and the middleware
# stack for fulfilling an HTTP request.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module DependencyLoader
attr_accessor :load_error

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module FlatParamsEncoder
class << self
@ -24,7 +26,7 @@ module Faraday
end
# The params have form [['key1', 'value1'], ['key2', 'value2']].
buffer = ''
buffer = +""
params.each do |key, value|
encoded_key = escape(key)
value = value.to_s if value == true || value == false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# This is the default encoder for Faraday requests.
# Using this encoder, parameters will be encoded respecting their structure,
@ -39,7 +41,7 @@ module Faraday
[key, val]
end
value.sort!
buffer = ""
buffer = +""
value.each do |key, val|
new_parent = "#{parent}%5B#{key}%5D"
buffer << "#{to_query.call(new_parent, val)}&"
@ -49,7 +51,7 @@ module Faraday
new_parent = "#{parent}%5B%5D"
return new_parent if value.empty?
buffer = ""
buffer = +""
value.each_with_index do |val, i|
buffer << "#{to_query.call(new_parent, val)}&"
end
@ -63,7 +65,7 @@ module Faraday
end
# The params have form [['key1', 'value1'], ['key2', 'value2']].
buffer = ''
buffer = +""
params.each do |parent, value|
encoded_parent = escape(parent)
buffer << "#{to_query.call(encoded_parent, value)}&"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Faraday error base class.
class Error < StandardError
@ -27,7 +29,7 @@ module Faraday
end
def inspect
inner = ''
inner = +""
if @wrapped_exception
inner << " wrapped=#{@wrapped_exception.inspect}"
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Middleware
extend MiddlewareRegistry

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Adds the ability for other modules to register and lookup
# middleware classes.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Subclasses Struct with some special helpers for converting from a Hash to
# a Struct.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class ConnectionOptions < Options.new(:request, :proxy, :ssl, :builder, :url,
:parallel_manager, :params, :headers, :builder_class)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# @!attribute method
# @return [Symbol] HTTP method (`:get`, `:post`)
@ -47,7 +49,7 @@ module Faraday
:ssl, :parallel_manager, :params, :response, :response_headers, :status,
:reason_phrase, :response_body)
ContentLength = 'Content-Length'.freeze
ContentLength = 'Content-Length'
StatusesWithoutBody = Set.new [204, 304]
SuccessfulStatuses = 200..299

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class ProxyOptions < Options.new(:uri, :user, :password)
extend Forwardable

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
:timeout, :open_timeout, :write_timeout, :boundary,

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# SSL-related options.
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'forwardable'
require 'faraday/encoders/nested_params_encoder'
require 'faraday/encoders/flat_params_encoder'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# A Builder that processes requests into responses by passing through an inner
# middleware stack (heavily inspired by Rack).

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Used to setup URLs, params, headers, and the request body in a sane manner.
#

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
module Faraday
# Request middleware for the Authorization HTTP header
class Request::Authorization < Faraday::Middleware
KEY = "Authorization".freeze unless defined? KEY
KEY = "Authorization" unless defined? KEY
# @param type [String, Symbol]
# @param token [String, Symbol, Hash]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'base64'
module Faraday

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Middleware for instrumenting Requests.
class Request::Instrumentation < Faraday::Middleware

View File

@ -1,11 +1,13 @@
# frozen_string_literal: true
require File.expand_path("../url_encoded", __FILE__)
require 'securerandom'
module Faraday
# Middleware for supporting multi-part requests.
class Request::Multipart < Request::UrlEncoded
self.mime_type = 'multipart/form-data'.freeze
DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost".freeze unless defined? DEFAULT_BOUNDARY_PREFIX
self.mime_type = 'multipart/form-data'
DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost" unless defined? DEFAULT_BOUNDARY_PREFIX
# Checks for files in the payload, otherwise leaves everything untouched.
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
# Catches exceptions and retries each request a limited number of times.
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Request::TokenAuthentication < Request.load_middleware(:authorization)
# Public

View File

@ -1,12 +1,14 @@
# frozen_string_literal: true
module Faraday
# Middleware for supporting urlencoded requests.
class Request::UrlEncoded < Faraday::Middleware
CONTENT_TYPE = 'Content-Type'.freeze unless defined? CONTENT_TYPE
CONTENT_TYPE = 'Content-Type' unless defined? CONTENT_TYPE
class << self
attr_accessor :mime_type
end
self.mime_type = 'application/x-www-form-urlencoded'.freeze
self.mime_type = 'application/x-www-form-urlencoded'
# Encodes as "application/x-www-form-urlencoded" if not already encoded or
# of another type.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'forwardable'
module Faraday

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'forwardable'
module Faraday

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
class Response::RaiseError < Response::Middleware
ClientErrorStatuses = 400...500

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
begin
require 'composite_io'
require 'parts'
@ -35,7 +37,7 @@ module Faraday
# @param outbuf [String, nil]
def read(length = nil, outbuf = nil)
got_result = false
outbuf = outbuf ? outbuf.replace("") : ""
outbuf = outbuf ? (+outbuf).replace("") : +""
while io = current_io
if result = io.read(length)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'thread'
require 'faraday/utils/headers'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module Utils
# A case-insensitive Hash that preserves the original case of a header

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module Utils
# A hash with stringified keys.

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# Usage: generate_certs
# Generate test certs for testing Faraday with SSL

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# Usage: script/proxy-server [-p PORT] [-u USER:PASSWORD]
require 'webrick'
require 'webrick/httpproxy'

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
old_verbose, $VERBOSE = $VERBOSE, nil
begin
require File.expand_path('../../test/live_server', __FILE__)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::Excon do
features :body_on_get, :reason_phrase_parse

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::HTTPClient do
features :body_on_get, :reason_phrase_parse, :compression

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::NetHttpPersistent do
features :body_on_get, :reason_phrase_parse, :compression

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::NetHttp do
features :body_on_get, :reason_phrase_parse, :compression, :streaming

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::Patron do
features :reason_phrase_parse

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Adapter::Typhoeus do
features :body_on_get, :parallel

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'stringio'
RSpec.describe Faraday::CompositeReadIO do
@ -67,11 +69,11 @@ RSpec.describe Faraday::CompositeReadIO do
context 'with utf8 multibyte part' do
subject { composite_io(part("\x86"), part("ファイル")) }
it { expect(subject.read).to eq("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB".force_encoding("BINARY"))}
it { expect(subject.read).to eq(String.new("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB", encoding: "BINARY"))}
it 'allows to read in chunks' do
expect(subject.read(3)).to eq("\x86\xE3\x83".force_encoding("BINARY"))
expect(subject.read(3)).to eq("\x95\xE3\x82".force_encoding("BINARY"))
expect(subject.read(8)).to eq("\xA1\xE3\x82\xA4\xE3\x83\xAB".force_encoding("BINARY"))
expect(subject.read(3)).to eq(String.new("\x86\xE3\x83", encoding: "BINARY"))
expect(subject.read(3)).to eq(String.new("\x95\xE3\x82", encoding: "BINARY"))
expect(subject.read(8)).to eq(String.new("\xA1\xE3\x82\xA4\xE3\x83\xAB", encoding: "BINARY"))
expect(subject.read(3)).to be_nil
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
shared_examples 'initializer with url' do
context 'with simple url' do
let(:address) { 'http://sushi.com' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::ClientError do
describe '.initialize' do
subject { described_class.new(exception, response) }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Env do
subject(:env) { described_class.new }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Options do
SubOptions = Class.new(Faraday::Options.new(:sub_a, :sub_b))
class ParentOptions < Faraday::Options.new(:a, :b, :c)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::ProxyOptions do
describe '#from' do
it 'works with string' do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::RequestOptions do
it 'allows to set the request proxy' do
options = Faraday::RequestOptions.new

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rack/utils'
RSpec.describe Faraday::FlatParamsEncoder do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rack/utils'
RSpec.describe Faraday::NestedParamsEncoder do

View File

@ -1,8 +1,11 @@
# frozen_string_literal: true
RSpec.describe Faraday::RackBuilder do
# mock handler classes
class Handler < Struct.new(:app)
def call(env)
(env[:request_headers]['X-Middleware'] ||= '') << ":#{self.class.name.split('::').last}"
env[:request_headers]['X-Middleware'] ||= ''
env[:request_headers]['X-Middleware'] += ":#{self.class.name.split('::').last}"
app.call(env)
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Request::Authorization do
let(:conn) do
Faraday.new do |b|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Request::Instrumentation do
class FakeInstrumenter
attr_reader :instrumentations

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Faraday::CompositeReadIO.class_eval { attr_reader :ios }
RSpec.describe Faraday::Request::Multipart do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Request::Retry do
let(:calls) { [] }
let(:times_called) { calls.size }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Request::UrlEncoded do
let(:conn) do
Faraday.new do |b|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Request do
let(:conn) do
Faraday.new(url: 'http://sushi.com/api',

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'stringio'
require 'logger'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Response::Middleware do
let(:conn) do
Faraday.new do |b|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Response::RaiseError do
let(:conn) do
Faraday.new do |b|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Response do
subject { Faraday::Response.new(env) }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Utils::Headers do
subject { Faraday::Utils::Headers.new }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday::Utils do
describe 'headers parsing' do
let(:multi_response_headers) {

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Faraday do
it 'has a version number' do
expect(Faraday::VERSION).not_to be nil

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# emulates ActiveSupport::SafeBuffer#gsub
FakeSafeBuffer = Struct.new(:string) do
def to_s; self end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module HelperMethods
def self.included(base)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
shared_examples 'an adapter' do |**options|
before { skip } if options[:skip]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
shared_examples 'a params encoder' do
it 'escapes safe buffer' do
monies = FakeSafeBuffer.new('$32,000.00')

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
shared_examples 'a request method' do |http_method|
let(:query_or_body) { method_with_body?(http_method) ? :body : :query }
let(:response) { conn.public_send(http_method, '/') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module StreamingResponseChecker
def check_streaming_response(streamed, options = {})

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path('../integration', __FILE__)
module Adapters

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path('../integration', __FILE__)
module Adapters

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'forwardable'
require File.expand_path("../../helper", __FILE__)
require File.expand_path("../../shared", __FILE__)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../integration", __FILE__)
require File.expand_path('../../live_server', __FILE__)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path('../../helper', __FILE__)
module Adapters

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'simplecov'
require 'coveralls'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'sinatra/base'
require_relative 'shared'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Faraday
module Shared
def self.big_string