Add frozen_string_literal to every file and enforce Rubocop rule

Adds the magic `frozen_string_literal: true` comment to every file and
enables a Rubocop rule to make sure that it's always going to be there
going forward as well.

See here for more background [1], but the basic idea is that unlike many
other languages, static strings in code are mutable by default. This has
since been acknowledged as not a particularly good idea, and the
intention is to rectify the mistake when Ruby 3 comes out, where all
string literals will be frozen. The `frozen_string_literal` magic
comment was introduced in Ruby 2.3 as a way of easing the transition,
and allows libraries and projects to freeze their literals in advance.

I don't think this is breaking in any way: it's possible that users
might've been pulling out one of are literals somehow and mutating it,
but that would probably not have been useful for anything and would
certainly not be recommended, so I'm quite comfortable pushing this
change through as a minor version.

As discussed in #641.

[1] https://stackoverflow.com/a/37799399
This commit is contained in:
Brandur 2018-05-10 14:56:14 -07:00
parent 40e4883ddc
commit 863da48398
124 changed files with 248 additions and 0 deletions

View File

@ -13,6 +13,9 @@ Layout/IndentArray:
Layout/IndentHash:
EnforcedStyle: consistent
Style/FrozenStringLiteralComment:
EnforcedStyle: always
Style/StringLiterals:
EnforcedStyle: double_quotes

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"
gemspec

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "rake/testtask"
require "rubocop/rake_task"

View File

@ -1,5 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "irb"
require "irb/completion"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Stripe Ruby bindings
# API spec at https://stripe.com/docs/api
require "cgi"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Account < APIResource
extend Gem::Deprecate

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class AlipayAccount < APIResource
include Stripe::APIOperations::Save

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
module Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
module Delete

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
module List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
# Adds methods to help manipulate a subresource from its parent resource so

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
module Request

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module APIOperations
module Save

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class APIResource < StripeObject
include Stripe::APIOperations::Request

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
# Domains registered for Apple Pay on the Web
class ApplePayDomain < APIResource

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class ApplicationFee < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class ApplicationFeeRefund < APIResource
include Stripe::APIOperations::Save

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Balance < SingletonAPIResource
OBJECT_NAME = "balance".freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class BalanceTransaction < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class BankAccount < APIResource
include Stripe::APIOperations::Save

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class BitcoinReceiver < APIResource
# Directly creating or retrieving BitcoinReceivers is deprecated. Please use

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class BitcoinTransaction < APIResource
# Directly retrieving BitcoinTransactions is deprecated. Please use the

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Card < APIResource
include Stripe::APIOperations::Save

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Charge < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class CountrySpec < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Coupon < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Customer < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Dispute < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class EphemeralKey < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
# StripeError is the base error from which all other more specific Stripe
# errors derive.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Event < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class ExchangeRate < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class FileUpload < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Invoice < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class InvoiceItem < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class InvoiceLineItem < StripeObject
OBJECT_NAME = "line_item".freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class IssuerFraudRecord < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class ListObject < StripeObject
include Enumerable

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class LoginLink < APIResource
OBJECT_NAME = "login_link".freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module OAuth
module OAuthOperations

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Order < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class OrderReturn < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Payout < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Plan < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Product < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
# Recipients objects are deprecated. Please use Stripe Connect instead.
class Recipient < APIResource

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class RecipientTransfer < StripeObject
OBJECT_NAME = "recipient_transfer".freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Refund < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Reversal < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class SingletonAPIResource < APIResource
def self.resource_url

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class SKU < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Source < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class SourceTransaction < StripeObject
OBJECT_NAME = "source_transaction".freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
# StripeClient executes requests against the Stripe API and allows a user to
# recover both a resource a call returns as well as a response object that

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class StripeObject
include Enumerable

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
# StripeResponse encapsulates some vitals of a response that came back from
# the Stripe API.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Subscription < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class SubscriptionItem < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class ThreeDSecure < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Token < APIResource
extend Stripe::APIOperations::Create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Topup < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class Transfer < APIResource
extend Stripe::APIOperations::List

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
class UsageRecord < APIResource
def self.create(params = {}, opts = {})

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "cgi"
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
VERSION = "3.14.0".freeze
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Stripe
module Webhook
DEFAULT_TOLERANCE = 300

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
require "stripe/version"

View File

@ -0,0 +1 @@
# frozen_string_literal: true

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test_helper", __FILE__)
module Stripe

Some files were not shown because too many files have changed in this diff Show More