Skip to content

Commit f9bcd09

Browse files
authored
Merge pull request #9233 from tvpartytonight/PUP-11767
(PUP-11767) Enable more rubocop styles
2 parents e05d91c + 121ed91 commit f9bcd09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+127
-115
lines changed

.rubocop.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,42 @@ Style/ColonMethodDefinition:
232232

233233
Style/DefWithParentheses:
234234
Enabled: true
235+
236+
Style/Dir:
237+
Enabled: true
238+
239+
Style/DocumentDynamicEvalDefinition:
240+
Enabled: true
241+
242+
Style/DoubleCopDisableDirective:
243+
Enabled: true
244+
245+
Style/EachForSimpleLoop:
246+
Enabled: true
247+
248+
Style/EachWithObject:
249+
Enabled: true
250+
251+
Style/EmptyBlockParameter:
252+
Enabled: true
253+
254+
Style/EmptyCaseCondition:
255+
Enabled: true
256+
257+
Style/EmptyLambdaParameter:
258+
Enabled: true
259+
260+
Style/EmptyLiteral:
261+
Enabled: true
262+
263+
Style/EvalWithLocation:
264+
Enabled: true
265+
266+
Style/EvenOdd:
267+
Enabled: true
268+
269+
Style/ExpandPathArguments:
270+
Enabled: true
271+
272+
Style/FetchEnvVar:
273+
Enabled: true

ext/windows/service/daemon.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WindowsDaemon < Puppet::Util::Windows::Daemon
1818
@run_thread = nil
1919
@LOG_TO_FILE = false
2020
@loglevel = 0
21-
LOG_FILE = File.expand_path(File.join(ENV['ALLUSERSPROFILE'], 'PuppetLabs', 'puppet', 'var', 'log', 'windows.log'))
21+
LOG_FILE = File.expand_path(File.join(ENV.fetch('ALLUSERSPROFILE', nil), 'PuppetLabs', 'puppet', 'var', 'log', 'windows.log'))
2222
LEVELS = [:debug, :info, :notice, :warning, :err, :alert, :emerg, :crit]
2323
LEVELS.each do |level|
2424
define_method("log_#{level}") do |msg|
@@ -203,10 +203,10 @@ def load_env(base_dir)
203203
ENV['Path'] = [
204204
File.join(base_dir, 'puppet', 'bin'),
205205
File.join(base_dir, 'bin'),
206-
].join(';').tr('/', '\\') + ';' + ENV['Path']
206+
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)
207207

208208
# ENV that uses forward slashes
209-
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV['RUBYLIB']}"
209+
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
210210
rescue => e
211211
log_exception(e)
212212
end

lib/puppet/application/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def handle_editing(text)
188188
tmpfile.puts text
189189

190190
# edit the content
191-
system(ENV["EDITOR"] || 'vi', tmpfile.path)
191+
system(ENV.fetch("EDITOR", nil) || 'vi', tmpfile.path)
192192

193193
# ...and, now, pass that file to puppet to apply. Because
194194
# many editors rename or replace the original file we need to

lib/puppet/confine/exists.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def message(value)
1616
end
1717

1818
def summary
19-
result.zip(values).inject([]) { |array, args| val, f = args; array << f unless val; array }
19+
result.zip(values).each_with_object([]) { |args, array| val, f = args; array << f unless val; }
2020
end
2121
end

lib/puppet/confine/variable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Puppet::Confine::Variable < Puppet::Confine
1212
# Only returns failed values, not all required values.
1313
def self.summarize(confines)
1414
result = Hash.new { |hash, key| hash[key] = [] }
15-
confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total }
15+
confines.each_with_object(result) { |confine, total| total[confine.name] += confine.values unless confine.valid?; }
1616
end
1717

1818
# This is set by ConfineCollection.

lib/puppet/defaults.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def self.default_cadir
4949
def self.default_basemodulepath
5050
if Puppet::Util::Platform.windows?
5151
path = ['$codedir/modules']
52-
installdir = ENV["FACTER_env_windows_installdir"]
52+
installdir = ENV.fetch("FACTER_env_windows_installdir", nil)
5353
if installdir
5454
path << "#{installdir}/puppet/modules"
5555
end
@@ -61,7 +61,7 @@ def self.default_basemodulepath
6161

6262
def self.default_vendormoduledir
6363
if Puppet::Util::Platform.windows?
64-
installdir = ENV["FACTER_env_windows_installdir"]
64+
installdir = ENV.fetch("FACTER_env_windows_installdir", nil)
6565
if installdir
6666
"#{installdir}\\puppet\\vendor_modules"
6767
else
@@ -373,7 +373,7 @@ def self.initialize_default_settings!(settings)
373373
Puppet::Util::Platform.default_paths.each do |path|
374374
next if paths.include?(path)
375375

376-
ENV['PATH'] = ENV['PATH'] + File::PATH_SEPARATOR + path
376+
ENV['PATH'] = ENV.fetch('PATH', nil) + File::PATH_SEPARATOR + path
377377
end
378378
value
379379
end

lib/puppet/face/epp.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@
180180
raise Puppet::Error, _("No input to parse given on command line or stdin")
181181
end
182182
else
183-
templates, missing_files = args.reduce([[], []]) do |memo, file|
183+
templates, missing_files = args.each_with_object([[], []]) do |file, memo|
184184
template_file = effective_template(file, compiler.environment)
185185
if template_file.nil?
186186
memo[1] << file
187187
else
188188
memo[0] << template_file
189189
end
190-
memo
191190
end
192191

193192
show_filename = templates.count > 1

lib/puppet/face/module/list.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ def unmet_dependencies(environment)
119119
# Prepare the unmet dependencies for display on the console.
120120
environment.modules.sort_by { |mod| mod.name }.each do |mod|
121121
unmet_grouped = Hash.new { |h, k| h[k] = [] }
122-
unmet_grouped = mod.unmet_dependencies.inject(unmet_grouped) do |acc, dep|
122+
unmet_grouped = mod.unmet_dependencies.each_with_object(unmet_grouped) do |dep, acc|
123123
acc[dep[:reason]] << dep
124-
acc
125124
end
126125
unmet_grouped.each do |type, deps|
127126
unless deps.empty?

lib/puppet/file_system/uniquefile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def try_convert_to_hash(h)
153153

154154
def tmpdir
155155
tmp = '.'
156-
for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp']
156+
for dir in [ENV.fetch('TMPDIR', nil), ENV.fetch('TMP', nil), ENV.fetch('TEMP', nil), @@systmpdir, '/tmp']
157157
stat = File.stat(dir) if dir
158158
if stat && stat.directory? && stat.writable?
159159
tmp = dir

lib/puppet/http/dns.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ def expired?(service_name)
146146
# @yields [[Resolv::DNS::Resource::IN::SRV]] a group of records of
147147
# the same priority
148148
def each_priority(records)
149-
pri_hash = records.inject({}) do |groups, element|
149+
pri_hash = records.each_with_object({}) do |element, groups|
150150
groups[element.priority] ||= []
151151
groups[element.priority] << element
152-
groups
153152
end
154153

155154
pri_hash.keys.sort.each do |key|

0 commit comments

Comments
 (0)