Skip to content

Commit b6381cc

Browse files
authored
Merge pull request #154 from maxmind/horgh/plugins
Enable additional rubocop plugins
2 parents 295cfec + 1fc5b3c commit b6381cc

29 files changed

+225
-169
lines changed

.rubocop.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
plugins:
2+
- rubocop-performance
3+
- rubocop-rake
4+
- rubocop-rspec
5+
- rubocop-thread_safety
6+
17
AllCops:
28
TargetRubyVersion: '3.2'
39
NewCops: enable
@@ -88,3 +94,20 @@ Naming/VariableNumber:
8894

8995
Gemspec/DevelopmentDependencies:
9096
Enabled: false
97+
98+
# This might make sense, but I don't think it's worth moving things around for.
99+
RSpec/SpecFilePathFormat:
100+
Enabled: false
101+
# Sometimes it makes sense to have lots of assertions.
102+
RSpec/MultipleExpectations:
103+
Enabled: false
104+
# Sometimes it makes sense to have long tests.
105+
RSpec/ExampleLength:
106+
Enabled: false
107+
# This seems okay.
108+
RSpec/MultipleDescribes:
109+
Enabled: false
110+
# This seems to give a bunch of false positives. Specifically it's flagging
111+
# things where we are creating an object and checking no exception happens.
112+
RSpec/NoExpectationExample:
113+
Enabled: false

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ RSpec::Core::RakeTask.new(:spec)
88

99
RuboCop::RakeTask.new
1010

11-
task default: :spec
12-
task default: :rubocop
11+
desc 'Run tests and RuboCop'
12+
task default: %i[spec rubocop]

lib/minfraud.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# for the gem's classes.
3333
module Minfraud
3434
class << self
35+
# rubocop:disable ThreadSafety/ClassAndModuleAttributes
36+
# This is a false positive - these configuration attributes are set during initialization
37+
3538
# The MaxMind account ID that is used for authorization.
3639
#
3740
# @return [Integer, nil]
@@ -57,6 +60,8 @@ class << self
5760
# @return [String, nil]
5861
attr_accessor :license_key
5962

63+
# rubocop:enable ThreadSafety/ClassAndModuleAttributes
64+
6065
# @!visibility private
6166
attr_reader :connection_pool
6267

@@ -67,19 +72,25 @@ def configure
6772
yield self
6873

6974
pool_size = 5
75+
# rubocop:disable ThreadSafety/ClassInstanceVariable
76+
# This is a false positive - this configuration is set during initialization
7077
host = @host.nil? ? 'minfraud.maxmind.com' : @host
7178
@connection_pool = ConnectionPool.new(size: pool_size) do
79+
# rubocop:enable ThreadSafety/ClassInstanceVariable
7280
make_http_client.persistent("https://#{host}")
7381
end
7482
end
7583

7684
private
7785

7886
def make_http_client
87+
# rubocop:disable ThreadSafety/ClassInstanceVariable
88+
# This is a false positive - this configuration is set during initialization
7989
HTTP.basic_auth(
8090
user: @account_id,
8191
pass: @license_key,
8292
).headers(
93+
# rubocop:enable ThreadSafety/ClassInstanceVariable
8394
accept: 'application/json',
8495
user_agent: "minfraud-api-ruby/#{Minfraud::VERSION} ruby/#{RUBY_VERSION} http/#{HTTP::VERSION}",
8596
)

lib/minfraud/components/email.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def clean_email_address(address)
9999
end
100100

101101
if domain == 'gmail.com'
102-
local_part.gsub!('.', '')
102+
local_part.delete!('.')
103103
end
104104

105105
domain_parts = domain.split('.')

lib/minfraud/components/report/transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def validate
103103
end
104104

105105
def empty_uuid?(value)
106-
stripped_value = value.to_s.gsub('-', '')
106+
stripped_value = value.to_s.delete('-')
107107
stripped_value == '0' * 32
108108
end
109109
end

lib/minfraud/components/shopping_cart.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ShoppingCart < Base
1717
# to an item's field, or as a Minfraud:::Components::ShoppingCartItem
1818
# object.
1919
def initialize(params = [])
20-
@items = params.map(&method(:resolve))
20+
@items = params.map { |param| resolve(param) }
2121
end
2222

2323
# A JSON representation of Minfraud::Components::ShoppingCart items.

lib/minfraud/enum.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ module ClassMethods
1515
#
1616
# @return [Hash]
1717
def mapping
18+
# rubocop:disable ThreadSafety/ClassInstanceVariable
19+
# This is a false positive - this is set during class definition and then only read
1820
@mapping ||= {}
21+
# rubocop:enable ThreadSafety/ClassInstanceVariable
1922
end
2023

2124
# Create a set of methods for enum-like behavior of the attribute.

lib/minfraud/validates.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def validate_md5(field, value)
2727
def validate_uuid(field, value)
2828
return if !value
2929

30-
stripped_value = value.to_s.gsub('-', '')
30+
stripped_value = value.to_s.delete('-')
3131

3232
# Define a regex pattern for a valid UUID without dashes
3333
uuid_regex = /\A[0-9a-f]{32}\z/i
@@ -78,7 +78,7 @@ def validate_credit_card_token(field, value)
7878
raise InvalidInputError, "The #{field} value is not valid. It must contain only non-space printable ASCII characters."
7979
end
8080

81-
if /\A[0-9]{1,19}\z/.match(s)
81+
if /\A[0-9]{1,19}\z/.match?(s)
8282
raise InvalidInputError, "The #{field} value is not valid. If it is all digits, it must be longer than 19 characters."
8383
end
8484
end
@@ -147,7 +147,7 @@ def validate_nonnegative_integer(field, value)
147147
def validate_email(field, value)
148148
return if !value
149149

150-
if /.@./.match(value)
150+
if /.@./.match?(value)
151151
validate_string(field, 255, value)
152152
return
153153
end

minfraud.gemspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Gem::Specification.new do |spec|
3131
spec.add_development_dependency 'rake', '~> 13.0'
3232
spec.add_development_dependency 'rspec', '~> 3.0'
3333
spec.add_development_dependency 'rubocop', '~> 1.23'
34+
spec.add_development_dependency 'rubocop-performance'
35+
spec.add_development_dependency 'rubocop-rake'
36+
spec.add_development_dependency 'rubocop-rspec'
37+
spec.add_development_dependency 'rubocop-thread_safety'
3438
spec.add_development_dependency 'webmock', '~> 3.14'
3539
spec.metadata = {
3640
'rubygems_mfa_required' => 'true'

spec/assessments_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
require 'spec_helper'
44

55
describe Minfraud::Assessments do
6-
let(:resolver) { double(Minfraud::Resolver) }
7-
subject { described_class.new({}, resolver) }
6+
subject(:assessment) { described_class.new({}, resolver) }
7+
8+
let(:resolver) { class_double(Minfraud::Resolver) }
89

910
before { allow(resolver).to receive(:assign) }
1011

1112
%w[account billing credit_card custom_inputs device email event order payment shipping shopping_cart].each do |attribute|
1213
it "responds_to #{attribute}" do
13-
expect(subject).to respond_to(attribute)
14+
expect(assessment).to respond_to(attribute)
1415
end
1516
end
1617

1718
describe '#initialize' do
1819
it { is_expected.to be_an_instance_of described_class }
1920

2021
it 'calls resolver for components assignment' do
21-
expect(resolver).to have_received(:assign).with(subject, {})
22+
expect(resolver).to have_received(:assign).with(assessment, {})
2223
end
2324
end
2425

@@ -63,7 +64,7 @@
6364
]
6465

6566
tests.each do |i|
66-
assessment = Minfraud::Assessments.new(
67+
assessment = described_class.new(
6768
email: i[:email],
6869
)
6970
body = assessment.send :request_body

0 commit comments

Comments
 (0)