Skip to content

Commit d113aab

Browse files
committed
Enable pending cops
Note that `Gemspec/RequireMFA` is enabled. Please refer to the article below for RubyGems MFA status. https://blog.rubygems.org/2022/08/15/requiring-mfa-on-popular-gems.html
1 parent cca1e25 commit d113aab

30 files changed

+80
-68
lines changed

.rubocop.yml

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
AllCops:
22
TargetRubyVersion: 2.7
3+
NewCops: enable
4+
5+
# Suppress noise for obvious operator precedence.
6+
Lint/AmbiguousOperatorPrecedence:
7+
Description: Checks for expressions containing multiple binary operations with ambiguous precedence.
8+
Enabled: false
39

410
Layout/LineLength:
511
Description: This cop checks the length of lines in the source code. The maximum length is configurable.
@@ -53,6 +59,10 @@ Style/Documentation:
5359
Description: This cop checks for missing top-level documentation of classes and modules.
5460
Enabled: false
5561

62+
Style/DocumentDynamicEvalDefinition:
63+
Description: When using `class_eval` (or other `eval`) with string interpolation, add a comment block showing its appearance if interpolated.
64+
Enabled: false
65+
5666
Style/EvalWithLocation:
5767
Description: This cop checks eval method usage. eval can receive source location metadata, that are filename and line number.
5868
Exclude:

faker.gemspec

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$LOAD_PATH.push File.expand_path('lib', __dir__)
44
require 'faker/version'
55

6+
# rubocop:todo Gemspec/RequireMFA
67
Gem::Specification.new do |spec|
78
spec.name = 'faker'
89
spec.version = Faker::VERSION
@@ -42,3 +43,4 @@ Gem::Specification.new do |spec|
4243
spec.add_development_dependency('timecop', '0.9.5')
4344
spec.add_development_dependency('yard', '0.9.27')
4445
end
46+
# rubocop:enable Gemspec/RequireMFA

lib/faker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def regexify(reg)
9292
.gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
9393
.gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[()]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
9494
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
95-
.gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).split('')) } # All [ABC] become B (or A or C)
95+
.gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).chars) } # All [ABC] become B (or A or C)
9696
.gsub('\d') { |_match| sample(Numbers) }
9797
.gsub('\w') { |_match| sample(Letters) }
9898
end

lib/faker/blockchain/aeternity.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def oracle
6161
def rand_strings(length = 50)
6262
hex_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
6363
var = +''
64-
length.times { var << sample(shuffle(hex_alphabet.split(''))) }
64+
length.times { var << sample(shuffle(hex_alphabet.chars)) }
6565
var
6666
end
6767
end

lib/faker/blockchain/ethereum.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class << self
1717
def address
1818
hex_alphabet = '0123456789abcdef'
1919
var = +'0x'
20-
40.times { var << sample(shuffle(hex_alphabet.split(''))) }
20+
40.times { var << sample(shuffle(hex_alphabet.chars)) }
2121
var
2222
end
2323
end

lib/faker/blockchain/tezos.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def secret_key
125125
# @return [String]
126126
def encode_tz(prefix, payload_size)
127127
prefix = PREFIXES.fetch(prefix)
128-
packed = prefix.map(&:chr).join('') + Faker::Config.random.bytes(payload_size)
128+
packed = prefix.map(&:chr).join + Faker::Config.random.bytes(payload_size)
129129
checksum = OpenSSL::Digest::SHA256.digest(OpenSSL::Digest::SHA256.digest(packed))[0..3]
130130
Faker::Base58.encode(packed + checksum)
131131
end

lib/faker/default/bank.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def bsb_number
145145
private
146146

147147
def checksum(num_string)
148-
num_array = num_string.split('').map(&:to_i)
148+
num_array = num_string.chars.map(&:to_i)
149149
(
150150
7 * (num_array[0] + num_array[3] + num_array[6]) +
151151
3 * (num_array[1] + num_array[4] + num_array[7]) +
@@ -194,8 +194,8 @@ def valid_checksum?(routing_number, checksum)
194194

195195
def compile_fraction(routing_num)
196196
prefix = (1..50).to_a.map(&:to_s).sample
197-
numerator = routing_num.split('')[5..8].join.to_i.to_s
198-
denominator = routing_num.split('')[0..4].join.to_i.to_s
197+
numerator = routing_num.chars[5..8].join.to_i.to_s
198+
denominator = routing_num.chars[0..4].join.to_i.to_s
199199
"#{prefix}-#{numerator}/#{denominator}"
200200
end
201201

lib/faker/default/chile_rut.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 1, fixed:
3737
#
3838
# @faker.version 1.9.2
3939
def dv
40-
split_reversed_rut = @last_rut.to_s.reverse.split('')
40+
split_reversed_rut = @last_rut.to_s.reverse.chars
4141
seq = [2, 3, 4, 5, 6, 7]
4242
i = 0
4343
digit_sum = split_reversed_rut.reduce(0) do |sum, n|

lib/faker/default/code.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def generate_imei
206206
str[len - 1] = (10 - (sum % 10)) % 10
207207

208208
# Output the IMEI value.
209-
str.join('')
209+
str.join
210210
end
211211

212212
def generate_base10_isbn
@@ -222,34 +222,34 @@ def generate_base13_isbn
222222
end
223223

224224
def sum(values)
225-
values.split(//).each_with_index.inject(0) do |sum, (value, index)|
225+
values.chars.each_with_index.inject(0) do |sum, (value, index)|
226226
sum + yield(value, index)
227227
end
228228
end
229229

230230
def generate_base8_ean
231231
values = regexify(/\d{7}/)
232-
check_digit = 10 - values.split(//).each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
232+
check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
233233
values << (check_digit == 10 ? 0 : check_digit).to_s
234234
end
235235

236236
def generate_base13_ean
237237
values = regexify(/\d{12}/)
238-
check_digit = 10 - values.split(//).each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
238+
check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
239239
values << (check_digit == 10 ? 0 : check_digit).to_s
240240
end
241241

242242
EAN_CHECK_DIGIT8 = [3, 1, 3, 1, 3, 1, 3].freeze
243243
EAN_CHECK_DIGIT13 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3].freeze
244244

245245
def rut_verificator_digit(rut)
246-
total = rut.to_s.rjust(8, '0').split(//).zip(%w[3 2 7 6 5 4 3 2]).collect { |a, b| a.to_i * b.to_i }.inject(:+)
246+
total = rut.to_s.rjust(8, '0').chars.zip(%w[3 2 7 6 5 4 3 2]).collect { |a, b| a.to_i * b.to_i }.inject(:+)
247247
(11 - total % 11).to_s.gsub(/10/, 'k').gsub(/11/, '0')
248248
end
249249

250250
def generate_nric_check_alphabet(values, prefix)
251251
weight = %w[2 7 6 5 4 3 2]
252-
total = values.split(//).zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
252+
total = values.chars.zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
253253
total += 4 if prefix == 'T'
254254
%w[A B C D E F G H I Z J][10 - total % 11]
255255
end

lib/faker/default/company.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def polish_taxpayer_identification_number
296296
result = Array.new(3) { rand(1..9) } + Array.new(7) { rand(10) }
297297
break if (weight_sum(result, weights) % 11) == result[9]
298298
end
299-
result.join('')
299+
result.join
300300
end
301301

302302
##
@@ -321,7 +321,7 @@ def polish_register_of_national_economy(legacy_length = NOT_GIVEN, length: 9)
321321
random_digits = Array.new(length) { rand(10) }
322322
break if collect_regon_sum(random_digits) == random_digits.last
323323
end
324-
random_digits.join('')
324+
random_digits.join
325325
end
326326

327327
##
@@ -459,7 +459,7 @@ def mod11(number)
459459
def luhn_algorithm(number)
460460
multiplications = []
461461

462-
number.to_s.reverse.split(//).each_with_index do |digit, i|
462+
number.to_s.reverse.chars.each_with_index do |digit, i|
463463
multiplications << if i.even?
464464
digit.to_i * 2
465465
else
@@ -553,7 +553,7 @@ def inn_checksum(factor, number)
553553
def spanish_cif_control_digit(organization_type, code)
554554
letters = %w[J A B C D E F G H I]
555555

556-
control = code.split('').each_with_index.inject(0) do |sum, (value, index)|
556+
control = code.chars.each_with_index.inject(0) do |sum, (value, index)|
557557
if (index + 1).even?
558558
sum + value.to_i
559559
else

lib/faker/default/finance.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def credit_card(*types)
2828

2929
# calculate the luhn checksum digit
3030
multiplier = 1
31-
luhn_sum = template.gsub(/[^0-9]/, '').split('').reverse.map(&:to_i).inject(0) do |sum, digit|
31+
luhn_sum = template.gsub(/[^0-9]/, '').chars.reverse.map(&:to_i).inject(0) do |sum, digit|
3232
multiplier = (multiplier == 2 ? 1 : 2)
33-
sum + (digit * multiplier).to_s.split('').map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
33+
sum + (digit * multiplier).to_s.chars.map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
3434
end
3535

3636
# the sum plus whatever the last digit is must be a multiple of 10. So, the

lib/faker/default/id_number.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def south_african_id_checksum_digit(id_number)
332332
.with_index { |_, i| (i + 1).odd? }
333333

334334
sum_of_odd_digits = odd_digits_without_last_character.map(&:to_i).reduce(:+)
335-
even_digits_times_two = (even_digits.join('').to_i * 2).to_s
335+
even_digits_times_two = (even_digits.join.to_i * 2).to_s
336336
sum_of_even_digits = even_digits_times_two.chars.map(&:to_i).reduce(:+)
337337

338338
total_sum = sum_of_odd_digits + sum_of_even_digits

lib/faker/default/internet.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
270270
# @example
271271
# Faker::Internet.domain_word #=> "senger"
272272
def domain_word
273-
with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
273+
with_locale(:en) { Char.prepare(Company.name.split.first) }
274274
end
275275

276276
## Returns the domain suffix e.g. com, org, co, biz, info etc.
@@ -613,10 +613,10 @@ def sanitize_email_local_part(local_part)
613613
Array('0'..'9'),
614614
Array('A'..'Z'),
615615
Array('a'..'z'),
616-
"!#$%&'*+-/=?^_`{|}~.".split(//)
616+
"!#$%&'*+-/=?^_`{|}~.".chars
617617
].flatten
618618

619-
local_part.split(//).map do |char|
619+
local_part.chars.map do |char|
620620
char_range.include?(char) ? char : '#'
621621
end.join
622622
end

lib/faker/default/markdown.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def headers
2727
# @faker.version 1.8.0
2828
def emphasis
2929
paragraph = Faker::Lorem.paragraph(sentence_count: 3)
30-
words = paragraph.split(' ')
30+
words = paragraph.split
3131
position = rand(0..words.length - 1)
3232
formatting = fetch('markdown.emphasis')
3333
words[position] = "#{formatting}#{words[position]}#{formatting}"
@@ -50,7 +50,7 @@ def ordered_list
5050
number.times do |i|
5151
result << "#{i}. #{Faker::Lorem.sentence(word_count: 1)} \n"
5252
end
53-
result.join('')
53+
result.join
5454
end
5555

5656
##
@@ -69,7 +69,7 @@ def unordered_list
6969
number.times do |_i|
7070
result << "* #{Faker::Lorem.sentence(word_count: 1)} \n"
7171
end
72-
result.join('')
72+
result.join
7373
end
7474

7575
##

lib/faker/default/nhs.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def british_number
2121
.chars
2222
.insert(3, ' ')
2323
.insert(7, ' ')
24-
.join('')
24+
.join
2525
end
2626

2727
##

lib/faker/default/vehicle.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Vehicle < Base
99
VIN_LETTERS = 'ABCDEFGHJKLMNPRSTUVWXYZ'
1010
VIN_MAP = '0123456789X'
1111
VIN_WEIGHTS = '8765432X098765432'
12-
VIN_REGEX = /^([A-HJ-NPR-Z0-9]){3}[A-HJ-NPR-Z0-9]{5}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-0]{1}[A-HJ-NPR-Z0-9]{1}\d{5}$/.freeze
12+
VIN_REGEX = /^([A-HJ-NPR-Z0-9]){3}[A-HJ-NPR-Z0-9]{5}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-]{1}[A-HJ-NPR-Z0-9]{1}\d{5}$/.freeze
1313
SG_CHECKSUM_WEIGHTS = [3, 14, 2, 12, 2, 11, 1].freeze
1414
SG_CHECKSUM_CHARS = 'AYUSPLJGDBZXTRMKHEC'
1515

@@ -333,22 +333,22 @@ def calculate_vin_check_digit(vin)
333333
end
334334

335335
def vin_char_to_number(char)
336-
index = VIN_LETTERS.split('').index(char)
336+
index = VIN_LETTERS.chars.index(char)
337337

338338
return char.to_i if index.nil?
339339

340340
VIN_MAP[index]
341341
end
342342

343343
def singapore_checksum(plate_number)
344-
padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').split('')
345-
padded_digits = format('%04d', plate_number[/\d+/]).split('').map(&:to_i)
344+
padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').chars
345+
padded_digits = format('%04d', plate_number[/\d+/]).chars.map(&:to_i)
346346
sum = [*padded_alphabets, *padded_digits].each_with_index.reduce(0) do |memo, (char, i)|
347347
value = char.is_a?(Integer) ? char : char.ord - 64
348348
memo + (SG_CHECKSUM_WEIGHTS[i] * value)
349349
end
350350

351-
SG_CHECKSUM_CHARS.split('')[sum % 19]
351+
SG_CHECKSUM_CHARS.chars[sum % 19]
352352
end
353353
end
354354
end

lib/faker/japanese_media/kamen_rider.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def eras
8383
end
8484

8585
def from_eras(*input_eras, field:)
86-
selected_eras = (ERAS & input_eras).yield_self do |selected|
86+
selected_eras = (ERAS & input_eras).then do |selected|
8787
selected.empty? ? eras : selected
8888
end.dup
8989
yield(selected_eras) if block_given?
9090

9191
raise UnavailableInEra, "#{field} is unavailable in the selected eras." if selected_eras.empty?
9292

93-
selected_eras.sample.yield_self do |era|
93+
selected_eras.sample.then do |era|
9494
fetch("kamen_rider.#{era}.#{field}")
9595
end
9696
end

lib/helpers/base58.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def self.encode(str)
77
base = alphabet.size
88

99
lv = 0
10-
str.split('').reverse.each_with_index { |v, i| lv += v.unpack1('C') * 256**i }
10+
str.chars.reverse.each_with_index { |v, i| lv += v.unpack1('C') * 256**i }
1111

1212
ret = +''
1313
while lv.positive?

script/txt2html

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ else
5454
exit!
5555
end
5656

57-
template = ERB.new(File.open(template).read)
57+
template = ERB.new(File.read(template))
5858

5959
title = nil
6060
body = nil

tasks/website.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ desc 'Upload website files to rubyforge'
1111
task :website_upload do
1212
remote_dir = '/var/www/gforge-projects/faker/'
1313
local_dir = 'website'
14-
sh %(rsync -acCv #{local_dir}/ #{ENV['USER']}@rubyforge.org:#{remote_dir})
14+
sh %(rsync -acCv #{local_dir}/ #{ENV.fetch('USER', nil)}@rubyforge.org:#{remote_dir})
1515
end
1616

1717
desc 'Generate and upload website files'

test/faker/default/test_alphanum.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def test_alphanumeric_with_invalid_mins
3434
end
3535

3636
def test_alphanumeric_with_min_alpha
37-
letters = @tester.alphanumeric(number: 5, min_alpha: 2).split('').map do |char|
37+
letters = @tester.alphanumeric(number: 5, min_alpha: 2).chars.map do |char|
3838
char =~ /[[:alpha:]]/
3939
end
4040
assert letters.compact.size >= 2
4141
end
4242

4343
def test_alphanumeric_with_min_numeric
44-
numbers = @tester.alphanumeric(number: 5, min_numeric: 4).split('').map do |char|
44+
numbers = @tester.alphanumeric(number: 5, min_numeric: 4).chars.map do |char|
4545
char =~ /[[:digit:]]/
4646
end
4747
assert numbers.compact.size >= 4

0 commit comments

Comments
 (0)