Skip to content

Commit

Permalink
Bump Rubocop to latest version (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Aug 10, 2019
1 parent a64f7c1 commit 3eaf587
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ AllCops:
Layout/CaseIndentation:
EnforcedStyle: end

Layout/IndentArray:
Layout/IndentFirstArrayElement:
EnforcedStyle: consistent

Layout/IndentFirstHashElement:
EnforcedStyle: consistent

# This can be re-enabled once we're 2.3+ only and can use the squiggly heredoc
Expand All @@ -16,9 +19,6 @@ Layout/IndentArray:
Layout/IndentHeredoc:
Enabled: false

Layout/IndentHash:
EnforcedStyle: consistent

Metrics/LineLength:
Exclude:
- "test/**/*.rb"
Expand Down
24 changes: 11 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-05-24 10:18:48 -0700 using RuboCop version 0.57.2.
# on 2019-07-30 09:56:31 +0800 using RuboCop version 0.73.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 20
# Offense count: 23
Metrics/AbcSize:
Max: 53
Max: 48

# Offense count: 33
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 39
Max: 509

# Test `context` is a block and generates all kinds of false positives
# without exclusion.
Exclude:
- 'test/**/*'

# Offense count: 11
# Offense count: 12
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 700
Max: 694

# Offense count: 12
Metrics/CyclomaticComplexity:
Expand All @@ -32,10 +30,10 @@ Metrics/CyclomaticComplexity:
Metrics/ParameterLists:
Max: 7

# Offense count: 7
# Offense count: 8
Metrics/PerceivedComplexity:
Max: 17

# Offense count: 84
# Offense count: 86
Style/Documentation:
Enabled: false
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ group :development do
# `Gemfile.lock` checked in, so to prevent good builds from suddenly going
# bad, pin to a specific version number here. Try to keep this relatively
# up-to-date, but it's not the end of the world if it's not.
# Note that 0.57.2 is the most recent version we can use until we drop
# support for Ruby 2.1.
gem "rubocop", "0.57.2"
gem "rubocop", "0.73"

# Rack 2.0+ requires Ruby >= 2.2.2 which is problematic for the test suite on
# older Ruby versions. Check Ruby the version here and put a maximum
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/list_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def retrieve(id, opts = {})
# was given, the default limit will be fetched again.
def next_page(params = {}, opts = {})
return self.class.empty_list(opts) unless has_more

last_id = data.last.id

params = filters.merge(starting_after: last_id).merge(params)
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/multipart_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def initialize
# Gets the encoded body. `#close` must be called first.
def body
raise "object must be closed before getting body" unless @closed

@body
end

Expand Down
1 change: 1 addition & 0 deletions lib/stripe/resources/usage_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.create(params = {}, opts = {})
unless params.key?(:subscription_item)
raise ArgumentError, "Params must have a subscription_item key"
end

req_params = params.clone.delete_if do |key, _value|
key == :subscription_item
end
Expand Down
8 changes: 4 additions & 4 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def execute_request(method, path,
# The original error message is also appended onto the final exception for
# full transparency.
NETWORK_ERROR_MESSAGES_MAP = {
Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
SocketError => ERROR_MESSAGE_CONNECTION,
Errno::ECONNREFUSED => ERROR_MESSAGE_CONNECTION,
SocketError => ERROR_MESSAGE_CONNECTION,

Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT,
Net::ReadTimeout => ERROR_MESSAGE_TIMEOUT_READ,
Net::OpenTimeout => ERROR_MESSAGE_TIMEOUT_CONNECT,
Net::ReadTimeout => ERROR_MESSAGE_TIMEOUT_READ,

OpenSSL::SSL::SSLError => ERROR_MESSAGE_SSL,
}.freeze
Expand Down
2 changes: 2 additions & 0 deletions lib/stripe/stripe_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def as_json(*opts)
def to_hash
maybe_to_hash = lambda do |value|
return nil if value.nil?

value.respond_to?(:to_hash) ? value.to_hash : value
end

Expand Down Expand Up @@ -257,6 +258,7 @@ def serialize_params(options = {})
#
unsaved = @unsaved_values.include?(k)
next unless options[:force] || unsaved || v.is_a?(StripeObject)

update_hash[k.to_sym] = serialize_params_value(
@values[k], @original_values[k], unsaved, options[:force], key: k
)
Expand Down
16 changes: 9 additions & 7 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ def self.normalize_opts(opts)

def self.check_string_argument!(key)
raise TypeError, "argument must be a string" unless key.is_a?(String)

key
end

def self.check_api_key!(key)
raise TypeError, "api_key must be a string" unless key.is_a?(String)

key
end

Expand Down Expand Up @@ -245,14 +247,14 @@ def self.secure_compare(str_a, str_b)
#

COLOR_CODES = {
black: 0, light_black: 60,
red: 1, light_red: 61,
green: 2, light_green: 62,
yellow: 3, light_yellow: 63,
blue: 4, light_blue: 64,
black: 0, light_black: 60,
red: 1, light_red: 61,
green: 2, light_green: 62,
yellow: 3, light_yellow: 63,
blue: 4, light_blue: 64,
magenta: 5, light_magenta: 65,
cyan: 6, light_cyan: 66,
white: 7, light_white: 67,
cyan: 6, light_cyan: 66,
white: 7, light_white: 67,
default: 9,
}.freeze
private_constant :COLOR_CODES
Expand Down
10 changes: 5 additions & 5 deletions stripe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Gem::Specification.new do |s|
s.license = "MIT"

s.metadata = {
"bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues",
"changelog_uri" =>
"bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues",
"changelog_uri" =>
"https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md",
"documentation_uri" => "https://stripe.com/docs/api/ruby",
"github_repo" => "ssh://github.com/stripe/stripe-ruby",
"homepage_uri" => "https://stripe.com/docs/api/ruby",
"source_code_uri" => "https://github.com/stripe/stripe-ruby",
"github_repo" => "ssh://github.com/stripe/stripe-ruby",
"homepage_uri" => "https://stripe.com/docs/api/ruby",
"source_code_uri" => "https://github.com/stripe/stripe-ruby",
}

s.files = `git ls-files`.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/login_link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LoginLinkTest < Test::Unit::TestCase
"data" => [],
"has_more" => false,
"object" => "list",
"url" => "/v1/accounts/acct_123/login_links",
"url" => "/v1/accounts/acct_123/login_links",
},
}
@account = Stripe::Account.construct_from(account_fixture)
Expand Down
8 changes: 4 additions & 4 deletions test/stripe/stripe_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ def to_hash
end

should "#serialize_params on an array that shortens" do
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
obj.foo = ["new-value"]
assert_equal({ foo: ["new-value"] },
obj.serialize_params)
end

should "#serialize_params on an array that lengthens" do
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
obj.foo = ["new-value"] * 4
assert_equal({ foo: ["new-value"] * 4 },
obj.serialize_params)
Expand All @@ -331,8 +331,8 @@ def to_hash
end

should "#serialize_params on an array that is unchanged" do
obj = Stripe::StripeObject.construct_from(foo: ["0-index", "1-index", "2-index"])
obj.foo = ["0-index", "1-index", "2-index"]
obj = Stripe::StripeObject.construct_from(foo: %w[0-index 1-index 2-index])
obj.foo = %w[0-index 1-index 2-index]
assert_equal({}, obj.serialize_params)
end

Expand Down
3 changes: 2 additions & 1 deletion test/stripe_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.start
@stderr, @child_stderr = ::IO.pipe

@pid = ::Process.spawn(
["stripe-mock", "stripe-mock"],
%w[stripe-mock stripe-mock],
"-http-port",
"0", # have stripe-mock select a port
"-spec",
Expand Down Expand Up @@ -66,6 +66,7 @@ def self.start
# Stops stripe-mock, if necessary.
def self.stop
return if @pid.nil?

puts("Stopping stripe-mock...")
::Process.kill(:SIGTERM, @pid)
::Process.waitpid2(@pid)
Expand Down

0 comments on commit 3eaf587

Please sign in to comment.