Skip to content

Commit fa629a1

Browse files
committed
(CONT-789) Rubocop Unsafe Autocorrect 7-10
- Style/GlobalStdStream - Style/NumericPredicate - Style/StringConcatenation - Style/SymbolProc
1 parent 5a76927 commit fa629a1

File tree

13 files changed

+26
-66
lines changed

13 files changed

+26
-66
lines changed

.rubocop_todo.yml

-40
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ RSpec/StubbedMock:
155155
- 'spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb'
156156
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'
157157

158-
# Offense count: 2
159-
# This cop supports unsafe autocorrection (--autocorrect-all).
160-
Style/GlobalStdStream:
161-
Exclude:
162-
- 'tasks/export.rb'
163-
- 'tasks/sql.rb'
164-
165158
# Offense count: 1
166159
# Configuration parameters: MinBranchesCount.
167160
Style/HashLikeCase:
@@ -174,43 +167,10 @@ Style/MixinUsage:
174167
- 'spec/spec_helper.rb'
175168
- 'spec/spec_helper_local.rb'
176169

177-
# Offense count: 8
178-
# This cop supports unsafe autocorrection (--autocorrect-all).
179-
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
180-
# SupportedStyles: predicate, comparison
181-
Style/NumericPredicate:
182-
Exclude:
183-
- 'spec/**/*'
184-
- 'lib/puppet/provider/mysql.rb'
185-
- 'lib/puppet/type/mysql_grant.rb'
186-
- 'lib/puppet/type/mysql_user.rb'
187-
188170
# Offense count: 2
189171
# Configuration parameters: AllowedMethods.
190172
# AllowedMethods: respond_to_missing?
191173
Style/OptionalBooleanParameter:
192174
Exclude:
193175
- 'lib/puppet/functions/mysql/password.rb'
194176
- 'lib/puppet/functions/mysql_password.rb'
195-
196-
# Offense count: 6
197-
# This cop supports unsafe autocorrection (--autocorrect-all).
198-
# Configuration parameters: Mode.
199-
Style/StringConcatenation:
200-
Exclude:
201-
- 'lib/puppet/functions/mysql/password.rb'
202-
- 'lib/puppet/provider/mysql.rb'
203-
- 'lib/puppet/provider/mysql_grant/mysql.rb'
204-
- 'lib/puppet/provider/mysql_login_path/mysql_login_path.rb'
205-
- 'lib/puppet/provider/mysql_plugin/mysql.rb'
206-
- 'lib/puppet/type/mysql_grant.rb'
207-
208-
# Offense count: 10
209-
# This cop supports unsafe autocorrection (--autocorrect-all).
210-
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
211-
# AllowedMethods: define_method
212-
Style/SymbolProc:
213-
Exclude:
214-
- 'lib/puppet/provider/mysql_login_path/inifile.rb'
215-
- 'spec/unit/puppet/provider/mysql_database/mysql_spec.rb'
216-
- 'spec/unit/puppet/provider/mysql_user/mysql_spec.rb'

lib/puppet/functions/mysql/password.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def password(password, sensitive = false)
2727
elsif password.empty?
2828
''
2929
else
30-
'*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(password)).upcase
30+
"*#{Digest::SHA1.hexdigest(Digest::SHA1.digest(password)).upcase}"
3131
end
3232

3333
if sensitive

lib/puppet/provider/mysql.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Puppet::Provider::Mysql < Puppet::Provider
66
initvars
77

88
# Make sure we find mysql commands on CentOS and FreeBSD
9-
ENV['PATH'] = ENV.fetch('PATH', nil) + ':/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'] = [
1111
ENV.fetch('LD_LIBRARY_PATH', nil),
1212
'/usr/lib',
@@ -90,7 +90,7 @@ def newer_than(forks_versions)
9090
end
9191

9292
def self.older_than(forks_versions)
93-
forks_versions.key?(mysqld_type) && Puppet::Util::Package.versioncmp(mysqld_version, forks_versions[mysqld_type]) < 0
93+
forks_versions.key?(mysqld_type) && Puppet::Util::Package.versioncmp(mysqld_version, forks_versions[mysqld_type]).negative?
9494
end
9595

9696
def older_than(forks_versions)

lib/puppet/provider/mysql_grant/mysql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.instances
4040
# split and sort the column_privileges in the parentheses and rejoin
4141
if priv.include?('(')
4242
type, col = priv.strip.split(%r{\s+|\b}, 2)
43-
type.upcase + ' (' + col.slice(1...-1).strip.split(%r{\s*,\s*}).sort.join(', ') + ')'
43+
"#{type.upcase} (#{col.slice(1...-1).strip.split(%r{\s*,\s*}).sort.join(', ')})"
4444
else
4545
# Once we split privileges up on the , we need to make sure we
4646
# shortern ALL PRIVILEGES to just all.

lib/puppet/provider/mysql_login_path/inifile.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def sections
325325
# Returns this IniFile.
326326
def freeze
327327
super
328-
@ini.each_value { |h| h.freeze }
328+
@ini.each_value(&:freeze)
329329
@ini.freeze
330330
self
331331
end
@@ -336,7 +336,7 @@ def freeze
336336
# Returns this IniFile.
337337
def taint
338338
super
339-
@ini.each_value { |h| h.taint }
339+
@ini.each_value(&:taint)
340340
@ini.taint
341341
self
342342
end

lib/puppet/provider/mysql_login_path/mysql_login_path.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def list_login_paths(context, uid)
121121
result.push(ensure: 'present',
122122
name: section,
123123
owner: uid.to_s,
124-
title: section + '-' + uid.to_s,
124+
title: "#{section}-#{uid}",
125125
host: ini[section]['host'].nil? ? nil : ini[section]['host'],
126126
user: ini[section]['user'].nil? ? nil : ini[section]['user'],
127127
password: ini[section]['password'].nil? ? nil : gen_pw(get_password(context, uid, section)),

lib/puppet/provider/mysql_plugin/mysql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.prefetch(resources)
2929
def create
3030
# Use plugin_name.so as soname if it's not specified. This won't work on windows as
3131
# there it should be plugin_name.dll
32-
@resource[:soname].nil? ? (soname = @resource[:name] + '.so') : (soname = @resource[:soname])
32+
@resource[:soname].nil? ? (soname = "#{@resource[:name]}.so") : (soname = @resource[:soname])
3333
self.class.mysql_caller("install plugin #{@resource[:name]} soname '#{soname}'", 'regular')
3434

3535
@property_hash[:ensure] = :present

lib/puppet/type/mysql_grant.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(*args)
2525
# split and sort the column_privileges in the parentheses and rejoin
2626
if priv.include?('(')
2727
type, col = priv.strip.split(%r{\s+|\b}, 2)
28-
type.upcase + ' (' + col.slice(1...-1).strip.split(%r{\s*,\s*}).sort.join(', ') + ')'
28+
"#{type.upcase} (#{col.slice(1...-1).strip.split(%r{\s*,\s*}).sort.join(', ')})"
2929
else
3030
priv.strip.upcase
3131
end
@@ -54,7 +54,7 @@ def initialize(*args)
5454

5555
validate do |value|
5656
mysql_version = Facter.value(:mysql_version)
57-
if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0') < 0
57+
if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0').negative?
5858
raise(ArgumentError, _('mysql_grant: PROXY user not supported on mysql versions < 5.5.0. Current version %{version}.') % { version: mysql_version })
5959
end
6060
end
@@ -100,9 +100,9 @@ def initialize(*args)
100100
# rubocop:enable Lint/UselessAssignment
101101
mysql_version = Facter.value(:mysql_version)
102102
unless mysql_version.nil?
103-
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
104-
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
105-
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
103+
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8').negative? && user_part.size > 16
104+
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0').negative? && user_part.size > 32
105+
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0').positive? && user_part.size > 80
106106
end
107107
end
108108

lib/puppet/type/mysql_user.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
# rubocop:enable Lint/AssignmentInCondition
3737
# rubocop:enable Lint/UselessAssignment
3838
unless mysql_version.nil?
39-
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
40-
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
41-
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
39+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8').negative? && user_part.size > 16
40+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0').negative? && user_part.size > 32
41+
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0').positive? && user_part.size > 80
4242
end
4343
end
4444

spec/unit/puppet/provider/mysql_database/mysql_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
raw_databases.each_line do |db|
3939
allow(provider.class).to receive(:mysql_caller).with(["show variables like '%_database'", db.chomp], 'regular').and_return("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Layout/LineLength
4040
end
41-
databases = provider.class.instances.map { |x| x.name }
41+
databases = provider.class.instances.map(&:name)
4242
expect(parsed_databases).to match_array(databases)
4343
end
4444
end

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
112112
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
113113

114-
usernames = provider.class.instances.map { |x| x.name }
114+
usernames = provider.class.instances.map(&:name)
115115
expect(parsed_users).to match_array(usernames)
116116
end
117117

@@ -120,7 +120,7 @@
120120
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
121121
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
122122

123-
usernames = provider.class.instances.map { |x| x.name }
123+
usernames = provider.class.instances.map(&:name)
124124
expect(parsed_users).to match_array(usernames)
125125
end
126126

@@ -129,7 +129,7 @@
129129
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
130130
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
131131

132-
usernames = provider.class.instances.map { |x| x.name }
132+
usernames = provider.class.instances.map(&:name)
133133
expect(parsed_users).to match_array(usernames)
134134
end
135135

@@ -138,7 +138,7 @@
138138
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
139139
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
140140

141-
usernames = provider.class.instances.map { |x| x.name }
141+
usernames = provider.class.instances.map(&:name)
142142
expect(parsed_users).to match_array(usernames)
143143
end
144144

@@ -147,7 +147,7 @@
147147
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
148148
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
149149

150-
usernames = provider.class.instances.map { |x| x.name }
150+
usernames = provider.class.instances.map(&:name)
151151
expect(parsed_users).to match_array(usernames)
152152
end
153153

@@ -156,7 +156,7 @@
156156
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
157157
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD, PLUGIN, AUTHENTICATION_STRING FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
158158

159-
usernames = provider.class.instances.map { |x| x.name }
159+
usernames = provider.class.instances.map(&:name)
160160
expect(parsed_users).to match_array(usernames)
161161
end
162162

@@ -165,7 +165,7 @@
165165
allow(provider.class).to receive(:mysql_caller).with("SELECT CONCAT(User, '@',Host) AS User FROM mysql.user", 'regular').and_return(raw_users)
166166
parsed_users.each { |user| allow(provider.class).to receive(:mysql_caller).with("SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'", 'regular').and_return('10 10 10 10 ') } # rubocop:disable Layout/LineLength
167167

168-
usernames = provider.class.instances.map { |x| x.name }
168+
usernames = provider.class.instances.map(&:name)
169169
expect(parsed_users).to match_array(usernames)
170170
end
171171
end

tasks/export.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get(file, database, user, password)
1717
{ status: stdout.strip }
1818
end
1919

20-
params = JSON.parse(STDIN.read)
20+
params = JSON.parse($stdin.read)
2121
database = params['database']
2222
user = params['user']
2323
password = params['password']

tasks/sql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get(sql, database, user, password)
1616
{ status: stdout.strip }
1717
end
1818

19-
params = JSON.parse(STDIN.read)
19+
params = JSON.parse($stdin.read)
2020
database = params['database']
2121
user = params['user']
2222
password = params['password']

0 commit comments

Comments
 (0)