Skip to content

Commit a1b3132

Browse files
committed
(CONT-789) Rubocop Auto Fixes 16-20
- Style/Encoding - Style/ExplicitBlockArgument - Style/FetchEnvVar - Style/HashAsLastArrayItem - Style/IfUnlessModifier
1 parent c6868fc commit a1b3132

File tree

11 files changed

+17
-78
lines changed

11 files changed

+17
-78
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -197,59 +197,19 @@ Style/CommentedKeyword:
197197
Exclude:
198198
- 'lib/puppet/provider/mysql_login_path/inifile.rb'
199199

200-
# Offense count: 1
201-
# This cop supports safe autocorrection (--autocorrect).
202-
Style/Encoding:
203-
Exclude:
204-
- 'lib/puppet/provider/mysql_login_path/inifile.rb'
205-
206-
# Offense count: 1
207-
# This cop supports safe autocorrection (--autocorrect).
208-
Style/ExplicitBlockArgument:
209-
Exclude:
210-
- 'lib/puppet/provider/mysql_login_path/inifile.rb'
211-
212-
# Offense count: 3
213-
# This cop supports safe autocorrection (--autocorrect).
214-
# Configuration parameters: AllowedVars.
215-
Style/FetchEnvVar:
216-
Exclude:
217-
- 'lib/puppet/provider/mysql.rb'
218-
- 'lib/puppet/provider/mysql_datadir/mysql.rb'
219-
220200
# Offense count: 2
221201
# This cop supports unsafe autocorrection (--autocorrect-all).
222202
Style/GlobalStdStream:
223203
Exclude:
224204
- 'tasks/export.rb'
225205
- 'tasks/sql.rb'
226206

227-
# Offense count: 1
228-
# This cop supports safe autocorrection (--autocorrect).
229-
# Configuration parameters: EnforcedStyle.
230-
# SupportedStyles: braces, no_braces
231-
Style/HashAsLastArrayItem:
232-
Exclude:
233-
- 'spec/functions/mysql_normalise_and_deepmerge_spec.rb'
234-
235207
# Offense count: 1
236208
# Configuration parameters: MinBranchesCount.
237209
Style/HashLikeCase:
238210
Exclude:
239211
- 'lib/puppet/provider/mysql_login_path/inifile.rb'
240212

241-
# Offense count: 10
242-
# This cop supports safe autocorrection (--autocorrect).
243-
Style/IfUnlessModifier:
244-
Exclude:
245-
- 'lib/puppet/functions/mysql/normalise_and_deepmerge.rb'
246-
- 'lib/puppet/functions/mysql/password.rb'
247-
- 'lib/puppet/provider/mysql_datadir/mysql.rb'
248-
- 'lib/puppet/provider/mysql_grant/mysql.rb'
249-
- 'lib/puppet/provider/mysql_login_path/mysql_login_path.rb'
250-
- 'lib/puppet/type/mysql_grant.rb'
251-
- 'lib/puppet/type/mysql_user.rb'
252-
253213
# Offense count: 2
254214
Style/MixinUsage:
255215
Exclude:

lib/puppet/functions/mysql/normalise_and_deepmerge.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@
2121
# The given hash normalised
2222
#
2323
def normalise_and_deepmerge(*args)
24-
if args.length < 2
25-
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length }
26-
end
24+
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length } if args.length < 2
2725

2826
result = {}
2927
args.each do |arg|
3028
next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef
3129
# If the argument was not a hash, skip it.
32-
unless arg.is_a?(Hash)
33-
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge: unexpected argument type %{arg_class}, only expects hash arguments.') % { args_class: args.class }
34-
end
30+
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge: unexpected argument type %{arg_class}, only expects hash arguments.') % { args_class: args.class } unless arg.is_a?(Hash)
3531

3632
# We need to make a copy of the hash since it is frozen by puppet
3733
current = deep_copy(arg)

lib/puppet/functions/mysql/password.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
end
2121

2222
def password(password, sensitive = false)
23-
if password.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
24-
password = password.unwrap
25-
end
23+
password = password.unwrap if password.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
2624

2725
result_string = if %r{\*[A-F0-9]{40}$}.match?(password)
2826
password

lib/puppet/provider/mysql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class Puppet::Provider::Mysql < Puppet::Provider
66
initvars
77

88
# Make sure we find mysql commands on CentOS and FreeBSD
9-
ENV['PATH'] = ENV['PATH'] + ':/usr/libexec:/usr/local/libexec:/usr/local/bin'
9+
ENV['PATH'] = ENV.fetch('PATH', nil) + ':/usr/libexec:/usr/local/libexec:/usr/local/bin'
1010
ENV['LD_LIBRARY_PATH'] = [
11-
ENV['LD_LIBRARY_PATH'],
11+
ENV.fetch('LD_LIBRARY_PATH', nil),
1212
'/usr/lib',
1313
'/usr/lib64',
1414
'/opt/rh/rh-mysql56/root/usr/lib',

lib/puppet/provider/mysql_datadir/mysql.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Make sure we find mysqld on CentOS and mysql_install_db on Gentoo and Solaris 11
1010
ENV['PATH'] = [
11-
ENV['PATH'],
11+
ENV.fetch('PATH', nil),
1212
'/usr/libexec',
1313
'/usr/share/mysql/scripts',
1414
'/opt/rh/rh-mysql80/root/usr/bin',
@@ -47,9 +47,7 @@ def create
4747
log_error = @resource.value(:log_error) || '/var/tmp/mysqld_initialize.log'
4848
# rubocop:enable Lint/UselessAssignment
4949
unless defaults_extra_file.nil?
50-
unless File.exist?(defaults_extra_file)
51-
raise ArgumentError, _('Defaults-extra-file %{file} is missing.') % { file: defaults_extra_file }
52-
end
50+
raise ArgumentError, _('Defaults-extra-file %{file} is missing.') % { file: defaults_extra_file } unless File.exist?(defaults_extra_file)
5351

5452
defaults_extra_file = "--defaults-extra-file=#{defaults_extra_file}"
5553
end

lib/puppet/provider/mysql_grant/mysql.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,8 @@ def diff_privileges(privileges_old, privileges_new)
200200

201201
def privileges=(privileges)
202202
diff = diff_privileges(@property_hash[:privileges], privileges)
203-
unless diff[:revoke].empty?
204-
revoke(@property_hash[:user], @property_hash[:table], diff[:revoke])
205-
end
206-
unless diff[:grant].empty?
207-
grant(@property_hash[:user], @property_hash[:table], diff[:grant], @property_hash[:options])
208-
end
203+
revoke(@property_hash[:user], @property_hash[:table], diff[:revoke]) unless diff[:revoke].empty?
204+
grant(@property_hash[:user], @property_hash[:table], diff[:grant], @property_hash[:options]) unless diff[:grant].empty?
209205
@property_hash[:privileges] = privileges
210206
self.privileges
211207
end

lib/puppet/provider/mysql_login_path/inifile.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: UTF-8
21
# frozen_string_literal: true
32

43
# See: https://github.com/puppetlabs/puppet/blob/main/lib/puppet/util/inifile.rb
@@ -242,10 +241,10 @@ def each
242241
# end
243242
#
244243
# Returns this IniFile.
245-
def each_section
246-
return unless block_given?
244+
def each_section(&block)
245+
return unless block
247246

248-
@ini.each_key { |section| yield section }
247+
@ini.each_key(&block)
249248
self
250249
end
251250

lib/puppet/provider/mysql_login_path/mysql_login_path.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def get_password(context, uid, name)
7979
result = ''
8080
output = my_print_defaults_cmd(context, uid, '-s', name)
8181
output.split("\n").each do |line|
82-
if %r{\-\-password}.match?(line)
83-
result = line.sub(%r{\-\-password=}, '')
84-
end
82+
result = line.sub(%r{\-\-password=}, '') if %r{\-\-password}.match?(line)
8583
end
8684
result
8785
end
@@ -158,9 +156,7 @@ def delete(context, name)
158156

159157
def canonicalize(_context, resources)
160158
resources.each do |r|
161-
if r.key?(:password) && r[:password].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
162-
r[:password] = gen_pw(extract_pw(r[:password]))
163-
end
159+
r[:password] = gen_pw(extract_pw(r[:password])) if r.key?(:password) && r[:password].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
164160
end
165161
end
166162
end

lib/puppet/type/mysql_grant.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ def initialize(*args)
1616
# 'ALL'. This can't be done in the munge in the property as that iterates
1717
# over the array and there's no way to replace the entire array before it's
1818
# returned to the provider.
19-
if self[:ensure] == :present && Array(self[:privileges]).size > 1 && self[:privileges].to_s.include?('ALL')
20-
self[:privileges] = 'ALL'
21-
end
19+
self[:privileges] = 'ALL' if self[:ensure] == :present && Array(self[:privileges]).size > 1 && self[:privileges].to_s.include?('ALL')
2220
# Sort the privileges array in order to ensure the comparision in the provider
2321
# self.instances method match. Otherwise this causes it to keep resetting the
2422
# privileges.

lib/puppet/type/mysql_user.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ def should_to_s(_newvalue)
9797
validate do |value|
9898
value = [value] unless value.is_a?(Array)
9999
if value.include?('NONE') || value.include?('SSL') || value.include?('X509')
100-
if value.length > 1
101-
raise(ArgumentError, _('`tls_options` `property`: The values NONE, SSL and X509 cannot be used with other options, you may only pick one of them.'))
102-
end
100+
raise(ArgumentError, _('`tls_options` `property`: The values NONE, SSL and X509 cannot be used with other options, you may only pick one of them.')) if value.length > 1
103101
else
104102
value.each do |opt|
105103
o = opt.match(%r{^(CIPHER|ISSUER|SUBJECT)}i)

spec/functions/mysql_normalise_and_deepmerge_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
expect(subject).to run.with_params({}, {}, {}).and_return({})
3838
end
3939

40-
expected_values_two = [1, 2, 'four' => 4]
40+
expected_values_two = [1, 2, { 'four' => 4 }]
4141
it 'merges subhashes' do
4242
hash = subject.execute({ 'one' => 1 }, 'two' => 2, 'three' => { 'four' => 4 })
4343
index_values.each_with_index do |index, expected|

0 commit comments

Comments
 (0)