Skip to content

Commit e08ba15

Browse files
committed
(PUP-11993) Style/SpecialGlobalVars
This commit enables the Style/SpecialGlobalVars cop and fixes 41 (unsafe) autocorrectable offenses. Additionally, this commit includes => e when rescuing so there is a local reference to the exception and ERROR_INFO is not needed.
1 parent b16f8e7 commit e08ba15

File tree

24 files changed

+69
-72
lines changed

24 files changed

+69
-72
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,6 @@ Style/SingleLineMethods:
693693
Style/SoleNestedConditional:
694694
Enabled: false
695695

696-
# This cop supports safe auto-correction (--auto-correct).
697-
# Configuration parameters: RequireEnglish, EnforcedStyle.
698-
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
699-
Style/SpecialGlobalVars:
700-
Enabled: false
701-
702696
# This cop supports safe auto-correction (--auto-correct).
703697
Style/StderrPuts:
704698
Exclude:

ext/windows/service/daemon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ def load_env(base_dir)
207207
end
208208
end
209209

210-
if __FILE__ == $0
210+
if __FILE__ == $PROGRAM_NAME
211211
WindowsDaemon.mainloop
212212
end

lib/puppet/daemon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def close_streams
8383
def reexec
8484
raise Puppet::DevError, _("Cannot reexec unless ARGV arguments are set") unless argv
8585

86-
command = $0 + " " + argv.join(" ")
86+
command = $PROGRAM_NAME + " " + argv.join(" ")
8787
Puppet.notice "Restarting with '#{command}'"
8888
stop(:exit => false)
8989
exec(command)

lib/puppet/file_serving/fileset.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def initialize_from_hash(options)
104104
method = option.to_s + "="
105105
begin
106106
send(method, value)
107-
rescue NoMethodError
108-
raise ArgumentError, _("Invalid option '%{option}'") % { option: option }, $!.backtrace
107+
rescue NoMethodError => e
108+
raise ArgumentError, _("Invalid option '%{option}'") % { option: option }, e.backtrace
109109
end
110110
end
111111
end

lib/puppet/file_system/uniquefile.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'English'
34
require_relative '../../puppet/file_system'
45
require 'delegate'
56
require 'tmpdir'
@@ -110,7 +111,7 @@ def make_tmpname(prefix_suffix, n)
110111
raise ArgumentError, _("unexpected prefix_suffix: %{value}") % { value: prefix_suffix.inspect }
111112
end
112113
t = Time.now.strftime("%Y%m%d")
113-
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
114+
path = "#{prefix}#{t}-#{$PROCESS_ID}-#{rand(0x100000000).to_s(36)}"
114115
path << "-#{n}" if n
115116
path << suffix
116117
end

lib/puppet/provider/package/ports.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def latest
2929

3030
begin
3131
output = portversion(*cmd)
32-
rescue Puppet::ExecutionFailure
33-
raise Puppet::Error.new(output, $!)
32+
rescue Puppet::ExecutionFailure => e
33+
raise Puppet::Error.new(output, e)
3434
end
3535
line = output.split("\n").pop
3636

lib/puppet/provider/package/portupgrade.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def self.instances
4646
cmdline = ["-aoQ"]
4747
begin
4848
output = portinfo(*cmdline)
49-
rescue Puppet::ExecutionFailure
50-
raise Puppet::Error.new(output, $!)
49+
rescue Puppet::ExecutionFailure => e
50+
raise Puppet::Error.new(output, e)
5151
end
5252

5353
# split output and match it and populate temp hash
@@ -88,8 +88,8 @@ def install
8888
# FIXME: it's possible that portinstall prompts for data so locks up.
8989
begin
9090
output = portinstall(*cmdline)
91-
rescue Puppet::ExecutionFailure
92-
raise Puppet::Error.new(output, $!)
91+
rescue Puppet::ExecutionFailure => e
92+
raise Puppet::Error.new(output, e)
9393
end
9494

9595
if output =~ /\*\* No such /
@@ -111,8 +111,8 @@ def latest
111111

112112
begin
113113
output = portversion(*cmdline)
114-
rescue Puppet::ExecutionFailure
115-
raise Puppet::Error.new(output, $!)
114+
rescue Puppet::ExecutionFailure => e
115+
raise Puppet::Error.new(output, e)
116116
end
117117

118118
# Check: output format.
@@ -166,8 +166,8 @@ def query
166166
cmdline = ["-qO", @resource[:name]]
167167
begin
168168
output = portinfo(*cmdline)
169-
rescue Puppet::ExecutionFailure
170-
raise Puppet::Error.new(output, $!)
169+
rescue Puppet::ExecutionFailure => e
170+
raise Puppet::Error.new(output, e)
171171
end
172172

173173
# Check: if output isn't in the right format, return nil
@@ -196,8 +196,8 @@ def uninstall
196196
cmdline = ["-qO", @resource[:name]]
197197
begin
198198
output = portinfo(*cmdline)
199-
rescue Puppet::ExecutionFailure
200-
raise Puppet::Error.new(output, $!)
199+
rescue Puppet::ExecutionFailure => e
200+
raise Puppet::Error.new(output, e)
201201
end
202202

203203
if output =~ /^(\S+)/
@@ -214,17 +214,17 @@ def update
214214
cmdline = ["-qO", @resource[:name]]
215215
begin
216216
output = portinfo(*cmdline)
217-
rescue Puppet::ExecutionFailure
218-
raise Puppet::Error.new(output, $!)
217+
rescue Puppet::ExecutionFailure => e
218+
raise Puppet::Error.new(output, e)
219219
end
220220

221221
if output =~ /^(\S+)/
222222
# output matches, so upgrade the software
223223
cmdline = ["-M BATCH=yes", Regexp.last_match(1)]
224224
begin
225225
output = portupgrade(*cmdline)
226-
rescue Puppet::ExecutionFailure
227-
raise Puppet::Error.new(output, $!)
226+
rescue Puppet::ExecutionFailure => e
227+
raise Puppet::Error.new(output, e)
228228
end
229229
end
230230
end

lib/puppet/provider/package/puppetserver_gem.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'English'
34
unless Puppet::Util::Platform.jruby_fips?
45
require 'rubygems/commands/list_command'
56
end
@@ -158,7 +159,7 @@ def self.execute_rubygems_list_command(command_options)
158159
gem_env['GEM_HOME'] = puppetserver_conf['jruby-puppet'].key?('gem-home') ? puppetserver_conf['jruby-puppet']['gem-home'] : puppetserver_default_gem_home
159160
gem_env['GEM_PATH'] = puppetserver_conf['jruby-puppet'].key?('gem-path') ? puppetserver_conf['jruby-puppet']['gem-path'].join(':') : puppetserver_default_gem_path
160161
end
161-
gem_env['GEM_SPEC_CACHE'] = "/tmp/#{$$}"
162+
gem_env['GEM_SPEC_CACHE'] = "/tmp/#{$PROCESS_ID}"
162163

163164
# Remove the 'gem' from the command_options
164165
command_options.shift

lib/puppet/provider/package/rpm.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def self.instances
7171
# now turn each returned line into a package object
7272
nevra_to_multiversion_hash(process).each { |hash| packages << new(hash) }
7373
}
74-
rescue Puppet::ExecutionFailure
75-
raise Puppet::Error, _("Failed to list packages"), $!.backtrace
74+
rescue Puppet::ExecutionFailure => e
75+
raise Puppet::Error, _("Failed to list packages"), e.backtrace
7676
end
7777

7878
packages

lib/puppet/provider/service/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def stop
122122
end
123123
begin
124124
output = kill pid
125-
rescue Puppet::ExecutionFailure
126-
@resource.fail Puppet::Error, "Could not kill #{name}, PID #{pid}: #{output}", $!
125+
rescue Puppet::ExecutionFailure => e
126+
@resource.fail Puppet::Error, "Could not kill #{name}, PID #{pid}: #{output}", e
127127
end
128128
true
129129
end

0 commit comments

Comments
 (0)