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

32 files changed

+61
-76
lines changed

.rubocop.yml

+2-2
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

+3-3
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

+1-1
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

+1-1
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

+2-2
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

+8-23
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

+1-1
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

+2-2
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

+1-1
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

+2-2
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

lib/facter/framework/config/fact_groups.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_group_ttls(group_name)
6464
def get_fact(fact_name)
6565
return @facts_ttls[fact_name] if @facts_ttls[fact_name]
6666

67-
result = @facts_ttls.select { |name, fact| break fact if fact_name =~ /^#{name}\..*/ }
67+
result = @facts_ttls.select { |name, fact| break fact if /^#{name}\..*/.match?(fact_name) }
6868
return nil if result == {}
6969

7070
result

lib/facter/framework/core/fact_loaders/fact_loader.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def construct_reject_lists(blocked_facts, facts)
103103

104104
blocked_facts.each do |blocked|
105105
facts.each do |fact|
106-
next unless fact.name =~ /^#{blocked}\..*|^#{blocked}$/
106+
next unless /^#{blocked}\..*|^#{blocked}$/.match?(fact.name)
107107

108108
if fact.type == :core
109109
reject_list_core << fact

lib/facter/framework/formatters/legacy_fact_formatter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def remove_comma_and_quotation(output)
9595
# quotation marks that come after \ are not removed
9696
@log.debug('Remove unnecessary comma and quotation marks on root facts')
9797
output.split("\n")
98-
.map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|(?<!\\)\"/, '').gsub('\\"', '"') }.join("\n")
98+
.map! { |line| /^[\s]+/.match?(line) ? line : line.gsub(/,$|(?<!\\)\"/, '').gsub('\\"', '"') }.join("\n")
9999
end
100100
end
101101
end

lib/facter/framework/formatters/yaml_fact_formatter.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def unquote_keys(fact_hash)
5252
end
5353

5454
def needs_quote?(value)
55-
return false if value =~ /true|false/
55+
return false if /true|false/.match?(value)
5656
return false if value[/^[0-9]+$/]
57-
return true if value =~ /y|Y|yes|Yes|YES|n|N|no|No|NO|True|TRUE|False|FALSE|on|On|ON|off|Off|OFF|:/
57+
return true if /y|Y|yes|Yes|YES|n|N|no|No|NO|True|TRUE|False|FALSE|on|On|ON|off|Off|OFF|:/.match?(value)
5858
return false if value[/[a-zA-Z]/]
5959
return false if value[/[0-9]+\.[0-9]+/]
6060

lib/facter/patches/sysfilesystem/sys/statvfs.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Statvfs < FFI::Struct
1010
# it the second time will make FFI log a warning message.
1111
remove_instance_variable(:@layout) if @layout
1212

13-
if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
13+
if /darwin|osx|mach/i.match?(RbConfig::CONFIG['host_os'])
1414
layout(
1515
:f_bsize, :ulong,
1616
:f_frsize, :ulong,
@@ -24,7 +24,7 @@ class Statvfs < FFI::Struct
2424
:f_flag, :ulong,
2525
:f_namemax, :ulong
2626
)
27-
elsif RbConfig::CONFIG['host'] =~ /bsd/i
27+
elsif /bsd/i.match?(RbConfig::CONFIG['host'])
2828
layout(
2929
:f_bavail, :uint64,
3030
:f_bfree, :uint64,
@@ -38,7 +38,7 @@ class Statvfs < FFI::Struct
3838
:f_fsid, :ulong,
3939
:f_namemax, :ulong
4040
)
41-
elsif RbConfig::CONFIG['host'] =~ /sunos|solaris/i
41+
elsif /sunos|solaris/i.match?(RbConfig::CONFIG['host'])
4242
layout(
4343
:f_bsize, :ulong,
4444
:f_frsize, :ulong,
@@ -55,7 +55,7 @@ class Statvfs < FFI::Struct
5555
:f_fstr, [:char, 32],
5656
:f_filler, [:ulong, 16]
5757
)
58-
elsif RbConfig::CONFIG['host'] =~ /i686/i
58+
elsif /i686/i.match?(RbConfig::CONFIG['host'])
5959
layout(
6060
:f_bsize, :ulong,
6161
:f_frsize, :ulong,

lib/facter/resolvers/aix/filesystem.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def read_vtf_file(fact_name)
1818
return if file_content.empty?
1919

2020
file_content = file_content.map do |line|
21-
next if line =~ /#|%/ # skip lines that are comments or defaultvfs line
21+
next if /#|%/.match?(line) # skip lines that are comments or defaultvfs line
2222

2323
line.split(' ').first
2424
end

lib/facter/resolvers/aix/memory.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def execute_svmon(fact_name)
2525

2626
result.each_line do |line|
2727
@fact_list[:system] = populate_system(line, pagesize) if line.include?('memory')
28-
@fact_list[:swap] = populate_swap(line, pagesize) if line =~ /pg\sspace/
28+
@fact_list[:swap] = populate_swap(line, pagesize) if /pg\sspace/.match?(line)
2929
end
3030

3131
@fact_list[fact_name]

lib/facter/resolvers/aix/mountpoints.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def read_mount(fact_name)
1919
@fact_list[:mountpoints] = {}
2020
output = Facter::Core::Execution.execute('mount', logger: log)
2121
output.split("\n").drop(2).map do |line|
22-
next if line =~ /procfs|ahafs/
22+
next if /procfs|ahafs/.match?(line)
2323

2424
add_mount_points_fact(line)
2525
end
@@ -40,7 +40,7 @@ def add_mount_points_fact(line)
4040
def retrieve_sizes_for_mounts
4141
output = Facter::Core::Execution.execute('df -P', logger: log)
4242
output.split("\n").drop(1).map do |line|
43-
next if line =~ /-\s+-\s+-/
43+
next if /-\s+-\s+-/.match?(line)
4444

4545
mount_info = line.split("\s")
4646
mount_info[3] = translate_to_bytes(mount_info[3])

lib/facter/resolvers/aix/networking.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def build_bindings(name, ip, mask_length, is_ipv4)
4343
def populate_with_mtu_and_mac!(interfaces)
4444
output = Facter::Core::Execution.execute('netstat -in', logger: log)
4545
output.each_line do |line|
46-
next if line =~ /Name\s/
46+
next if /Name\s/.match?(line)
4747

4848
info = line.split("\s")
4949
interface_name = info[0]

lib/facter/resolvers/aix/partitions.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def populate_from_lslv(name)
5050
}
5151
mount = info_hash['MOUNT POINT']
5252
label = info_hash['LABEL']
53-
part_info[:mount] = mount unless %r{N/A} =~ mount
54-
part_info[:label] = label.strip unless /None/ =~ label
53+
part_info[:mount] = mount unless %r{N/A}.match?(mount)
54+
part_info[:label] = label.strip unless /None/.match?(label)
5555
part_info
5656
end
5757

lib/facter/resolvers/lspci.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def lspci_command(fact_name)
2626
end
2727

2828
def retrieve_vm(output)
29-
output.each_line { |line| REGEX_VALUES.each { |key, value| return value if line =~ /#{key}/ } }
29+
output.each_line { |line| REGEX_VALUES.each { |key, value| return value if /#{key}/.match?(line) } }
3030

3131
nil
3232
end

lib/facter/resolvers/networking.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def extract_mac(raw_data, parsed_interface_data)
7171
end
7272

7373
def extract_dhcp(interface_name, raw_data, parsed_interface_data)
74-
return unless raw_data =~ /status:\s+active/
74+
return unless /status:\s+active/.match?(raw_data)
7575

7676
result = Facter::Core::Execution.execute("ipconfig getoption #{interface_name} " \
7777
'server_identifier', logger: log)

lib/facter/resolvers/open_vz.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def read_proc_status
2929
parts = line.split("\s")
3030
next unless parts.size.equal?(2)
3131

32-
next unless /^envID:/ =~ parts[0]
32+
next unless /^envID:/.match?(parts[0])
3333

3434
@fact_list[:id] = parts[1]
3535

lib/facter/resolvers/os_release.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ def fill_fact_list(pairs)
6363
def process_version_id
6464
return unless @fact_list[:version_id]
6565

66-
@fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless @fact_list[:version_id] =~ /\./
66+
@fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless /\./.match?(@fact_list[:version_id])
6767
end
6868

6969
def process_id
7070
return unless @fact_list[:id]
7171

72-
@fact_list[:id] = 'opensuse' if @fact_list[:id] =~ /opensuse/i
72+
@fact_list[:id] = 'opensuse' if /opensuse/i.match?(@fact_list[:id])
7373
end
7474

7575
def process_name

lib/facter/resolvers/selinux.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def selinux_mountpoint
2626
mountpoint = ''
2727

2828
output.each_line do |line|
29-
next unless line =~ /selinuxfs/
29+
next unless /selinuxfs/.match?(line)
3030

3131
mountpoint = line.split("\s")[1]
3232
break
@@ -54,8 +54,8 @@ def read_selinux_config
5454
file_lines = Facter::Util::FileHelper.safe_readlines('/etc/selinux/config')
5555

5656
file_lines.map do |line|
57-
@fact_list[:config_mode] = line.split('=').last.strip if line =~ /^SELINUX=/
58-
@fact_list[:config_policy] = line.split('=').last.strip if line =~ /^SELINUXTYPE=/
57+
@fact_list[:config_mode] = line.split('=').last.strip if /^SELINUX=/.match?(line)
58+
@fact_list[:config_policy] = line.split('=').last.strip if /^SELINUXTYPE=/.match?(line)
5959
end
6060

6161
!file_lines.empty? ? true : false

lib/facter/resolvers/solaris/filesystems.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def read_sysdef_file(fact_name)
1818

1919
file_content = Facter::Core::Execution.execute('/usr/sbin/sysdef', logger: log)
2020
files = file_content.split("\n").map do |line|
21-
line.split('/').last if line =~ /^fs\.*/
21+
line.split('/').last if /^fs\.*/.match?(line)
2222
end
2323

2424
@fact_list[:file_systems] = files.compact.sort.join(',')

0 commit comments

Comments
 (0)