Skip to content

Commit 2191702

Browse files
authored
Merge pull request #2559 from mhashizume/maint/main/rubocop
(maint) RuboCop housekeeping
2 parents b578196 + ed487f6 commit 2191702

File tree

32 files changed

+61
-76
lines changed

32 files changed

+61
-76
lines changed

.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
inherit_from: .rubocop_todo.yml
33

44
AllCops:
5-
TargetRubyVersion: 2.3
5+
TargetRubyVersion: 2.5
66
Exclude:
77
- acceptance/**/*
88
- vendor/**/*
@@ -193,4 +193,4 @@ Style/HashTransformKeys:
193193
Enabled: false # not implemented in ruby 2.3
194194

195195
Style/HashTransformValues:
196-
Enabled: false # not implemented in ruby 2.3
196+
Enabled: false # not implemented in ruby 2.3

install.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def prepare_installation
153153
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
154154
# which is not generally where people expect executables to be installed
155155
# These settings are appropriate defaults for all OS X versions.
156-
RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/
156+
RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM.match?(/^universal-darwin[\d\.]+$/)
157157

158158
# if InstallOptions.configdir
159159
# configdir = InstallOptions.configdir
@@ -176,7 +176,7 @@ def prepare_installation
176176
sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
177177
if sitelibdir.nil?
178178
sitelibdir = File.join(libdir, 'site_ruby')
179-
elsif sitelibdir !~ Regexp.quote(version)
179+
elsif !sitelibdir&.match?(Regexp.quote(version))
180180
sitelibdir = File.join(sitelibdir, version)
181181
end
182182
end
@@ -232,7 +232,7 @@ def install_binfile(from, op_file, target)
232232
File.open(tmp_file.path, 'w') do |op|
233233
op.puts "#!#{ruby}"
234234
contents = ip.readlines
235-
contents.shift if contents[0] =~ /^#!/
235+
contents.shift if /^#!/.match?(contents[0])
236236
op.write contents.join
237237
end
238238
end

lib/facter/custom_facts/core/execution/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def log_stderr(msg, command, logger)
140140

141141
def builtin_command?(command)
142142
output, _status = Open3.capture2("type #{command}")
143-
output.chomp =~ /builtin/ ? true : false
143+
/builtin/.match?(output.chomp) ? true : false
144144
end
145145
end
146146
end

lib/facter/custom_facts/core/execution/posix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def expand_command(command)
4444

4545
return unless exe && (expanded = which(exe))
4646

47-
expanded = "'#{expanded}'" if expanded =~ /\s/
47+
expanded = "'#{expanded}'" if /\s/.match?(expanded)
4848
expanded << " #{args}" if args
4949

5050
expanded

lib/facter/custom_facts/core/execution/windows.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def search_paths
1111
def which(bin)
1212
# `echo` is allowed for facter 3.x compatibility, otherwise
1313
# all commands much be found on the PATH or absolute.
14-
return bin if /^echo$/i =~ bin
14+
return bin if /^echo$/i.match?(bin)
1515

1616
if absolute_path?(bin)
1717
return bin if File.executable?(bin)
@@ -56,7 +56,7 @@ def expand_command(command)
5656

5757
return unless exe && (expanded = which(exe))
5858

59-
expanded = "\"#{expanded}\"" if expanded =~ /\s+/
59+
expanded = "\"#{expanded}\"" if /\s+/.match?(expanded)
6060
expanded << " #{args}" if args
6161

6262
expanded

lib/facter/custom_facts/util/normalization.rb

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ def normalize(value)
3838
#
3939
# Attempt to normalize and validate the given string.
4040
#
41-
# On Ruby 1.8 the string is checked by stripping out all non UTF-8
42-
# characters and comparing the converted string to the original. If they
43-
# do not match then the string is considered invalid.
44-
#
45-
# On Ruby 1.9+, the string is validate by checking that the string encoding
41+
# The string is validated by checking that the string encoding
4642
# is UTF-8 and that the string content matches the encoding. If the string
4743
# is not an expected encoding then it is converted to UTF-8.
4844
#
@@ -51,27 +47,16 @@ def normalize(value)
5147
# @param value [String]
5248
# @return [void]
5349

54-
if RUBY_VERSION =~ /^1\.8/
55-
require 'iconv'
56-
57-
def normalize_string(value)
58-
converted = Iconv.conv('UTF-8//IGNORE', 'UTF-8', value)
59-
raise NormalizationError, "String #{value.inspect} is not valid UTF-8" if converted != value
50+
def normalize_string(value)
51+
value = value.encode(Encoding::UTF_8)
6052

61-
value
53+
unless value.valid_encoding?
54+
raise NormalizationError, "String #{value.inspect} doesn't match the reported encoding #{value.encoding}"
6255
end
63-
else
64-
def normalize_string(value)
65-
value = value.encode(Encoding::UTF_8)
6656

67-
unless value.valid_encoding?
68-
raise NormalizationError, "String #{value.inspect} doesn't match the reported encoding #{value.encoding}"
69-
end
70-
71-
value
72-
rescue EncodingError
73-
raise NormalizationError, "String encoding #{value.encoding} is not UTF-8 and could not be converted to UTF-8"
74-
end
57+
value
58+
rescue EncodingError
59+
raise NormalizationError, "String encoding #{value.encoding} is not UTF-8 and could not be converted to UTF-8"
7560
end
7661

7762
# Validate all elements of the array.

lib/facter/facts/debian/architecture.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Architecture
1010
def call_the_resolver
1111
fact_value = Facter::Resolvers::Uname.resolve(:machine)
1212
fact_value = 'amd64' if fact_value == 'x86_64'
13-
fact_value = 'i386' if fact_value =~ /i[3456]86|pentium/
13+
fact_value = 'i386' if /i[3456]86|pentium/.match?(fact_value)
1414

1515
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
1616
end

lib/facter/facts/linux/hypervisors/kvm.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def discover_provider
5252

5353
return { google: true } if manufacturer == 'Google'
5454

55-
return { openstack: true } if manufacturer =~ /^OpenStack/
55+
return { openstack: true } if /^OpenStack/.match?(manufacturer)
5656

57-
return { amazon: true } if manufacturer =~ /^Amazon/
57+
return { amazon: true } if /^Amazon/.match?(manufacturer)
5858

5959
{}
6060
end

lib/facter/facts/linux/os/architecture.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Architecture
1010
def call_the_resolver
1111
fact_value = Facter::Resolvers::Uname.resolve(:machine)
1212

13-
fact_value = 'i386' if fact_value =~ /i[3456]86|pentium/
13+
fact_value = 'i386' if /i[3456]86|pentium/.match?(fact_value)
1414

1515
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
1616
end

lib/facter/facts/windows/hypervisors/kvm.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def discover_provider
2727

2828
return { google: true } if manufacturer == 'Google'
2929

30-
return { openstack: true } if Facter::Resolvers::DMIComputerSystem.resolve(:name) =~ /^OpenStack/
30+
return { openstack: true } if /^OpenStack/.match?(Facter::Resolvers::DMIComputerSystem.resolve(:name))
3131

32-
return { amazon: true } if manufacturer =~ /^Amazon/
32+
return { amazon: true } if /^Amazon/.match?(manufacturer)
3333
end
3434
end
3535
end

0 commit comments

Comments
 (0)