Skip to content

Commit d068941

Browse files
authored
Merge pull request #9270 from AriaXLi/PUP-11993/style_cops_R
(PUP-11993) Style Cops - R
2 parents 95abb8a + be2c3e6 commit d068941

File tree

174 files changed

+1336
-1688
lines changed

Some content is hidden

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

174 files changed

+1336
-1688
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -646,52 +646,6 @@ Style/OptionalBooleanParameter:
646646
Style/PreferredHashMethods:
647647
Enabled: false
648648

649-
# This cop supports safe auto-correction (--auto-correct).
650-
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
651-
# SupportedStyles: compact, exploded
652-
Style/RaiseArgs:
653-
Enabled: false
654-
655-
# This cop supports safe auto-correction (--auto-correct).
656-
Style/RedundantAssignment:
657-
Exclude:
658-
- 'lib/puppet/file_serving/mount/locales.rb'
659-
- 'lib/puppet/file_serving/mount/pluginfacts.rb'
660-
- 'lib/puppet/file_serving/mount/plugins.rb'
661-
- 'lib/puppet/parameter.rb'
662-
- 'lib/puppet/parser/ast/pops_bridge.rb'
663-
- 'lib/puppet/pops/model/factory.rb'
664-
- 'lib/puppet/pops/parser/parser_support.rb'
665-
- 'lib/puppet/provider/nameservice/directoryservice.rb'
666-
- 'lib/puppet/provider/nameservice/objectadd.rb'
667-
- 'lib/puppet/provider/nameservice/pw.rb'
668-
- 'lib/puppet/settings.rb'
669-
- 'lib/puppet/type.rb'
670-
- 'lib/puppet/type/file/ensure.rb'
671-
- 'lib/puppet/util.rb'
672-
- 'lib/puppet/util/execution.rb'
673-
674-
# This cop supports safe auto-correction (--auto-correct).
675-
Style/RedundantBegin:
676-
Enabled: false
677-
678-
# This cop supports safe auto-correction (--auto-correct).
679-
Style/RedundantCondition:
680-
Exclude:
681-
- 'ext/windows/service/daemon.rb'
682-
- 'lib/puppet/application/describe.rb'
683-
- 'lib/puppet/environments.rb'
684-
- 'lib/puppet/external/dot.rb'
685-
- 'lib/puppet/graph/simple_graph.rb'
686-
- 'lib/puppet/indirector/request.rb'
687-
- 'lib/puppet/parser/templatewrapper.rb'
688-
- 'lib/puppet/provider/package/blastwave.rb'
689-
- 'lib/puppet/provider/package/pkgutil.rb'
690-
- 'lib/puppet/provider/package/portage.rb'
691-
- 'lib/puppet/type.rb'
692-
- 'lib/puppet/util/command_line/trollop.rb'
693-
- 'lib/puppet/util/inifile.rb'
694-
695649
# This cop supports safe auto-correction (--auto-correct).
696650
Style/RedundantConditional:
697651
Exclude:

ext/windows/service/daemon.rb

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,23 @@ def service_main(*argsv)
7575

7676
service = self
7777
@run_thread = Thread.new do
78-
begin
79-
while service.running? do
80-
runinterval = service.parse_runinterval(ruby_puppet_cmd)
81-
82-
if service.state == RUNNING or service.state == IDLE
83-
service.log_notice("Executing agent with arguments: #{args}")
84-
pid = Process.create(:command_line => "#{ruby_puppet_cmd} agent --onetime #{args}", :creation_flags => CREATE_NEW_CONSOLE).process_id
85-
service.log_debug("Process created: #{pid}")
86-
else
87-
service.log_debug("Service is paused. Not invoking Puppet agent")
88-
end
89-
90-
service.log_debug("Service worker thread waiting for #{runinterval} seconds")
91-
sleep(runinterval)
92-
service.log_debug('Service worker thread woken up')
78+
while service.running? do
79+
runinterval = service.parse_runinterval(ruby_puppet_cmd)
80+
81+
if service.state == RUNNING or service.state == IDLE
82+
service.log_notice("Executing agent with arguments: #{args}")
83+
pid = Process.create(:command_line => "#{ruby_puppet_cmd} agent --onetime #{args}", :creation_flags => CREATE_NEW_CONSOLE).process_id
84+
service.log_debug("Process created: #{pid}")
85+
else
86+
service.log_debug("Service is paused. Not invoking Puppet agent")
9387
end
94-
rescue Exception => e
95-
service.log_exception(e)
88+
89+
service.log_debug("Service worker thread waiting for #{runinterval} seconds")
90+
sleep(runinterval)
91+
service.log_debug('Service worker thread woken up')
9692
end
93+
rescue Exception => e
94+
service.log_exception(e)
9795
end
9896
@run_thread.join
9997
rescue Exception => e
@@ -142,20 +140,18 @@ def log(msg, level)
142140
end
143141

144142
def report_windows_event(type, id, message)
145-
begin
146-
eventlog = nil
147-
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
148-
eventlog.report_event(
149-
:event_type => type, # EVENTLOG_ERROR_TYPE, etc
150-
:event_id => id, # 0x01 or 0x02, 0x03 etc.
151-
:data => message # "the message"
152-
)
153-
rescue Exception
154-
# Ignore all errors
155-
ensure
156-
unless eventlog.nil?
157-
eventlog.close
158-
end
143+
eventlog = nil
144+
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
145+
eventlog.report_event(
146+
:event_type => type, # EVENTLOG_ERROR_TYPE, etc
147+
:event_id => id, # 0x01 or 0x02, 0x03 etc.
148+
:data => message # "the message"
149+
)
150+
rescue Exception
151+
# Ignore all errors
152+
ensure
153+
unless eventlog.nil?
154+
eventlog.close
159155
end
160156
end
161157

@@ -186,30 +182,28 @@ def parse_log_level(puppet_path, cmdline_debug)
186182
loglevel = :notice
187183
end
188184

189-
LEVELS.index(cmdline_debug ? cmdline_debug : loglevel.to_sym)
185+
LEVELS.index(cmdline_debug || loglevel.to_sym)
190186
end
191187

192188
private
193189

194190
def load_env(base_dir)
195-
begin
196-
# ENV that uses backward slashes
197-
ENV['FACTER_env_windows_installdir'] = base_dir.tr('/', '\\')
198-
ENV['PL_BASEDIR'] = base_dir.tr('/', '\\')
199-
ENV['PUPPET_DIR'] = File.join(base_dir, 'puppet').tr('/', '\\')
200-
ENV['OPENSSL_CONF'] = File.join(base_dir, 'puppet', 'ssl', 'openssl.cnf').tr('/', '\\')
201-
ENV['SSL_CERT_DIR'] = File.join(base_dir, 'puppet', 'ssl', 'certs').tr('/', '\\')
202-
ENV['SSL_CERT_FILE'] = File.join(base_dir, 'puppet', 'ssl', 'cert.pem').tr('/', '\\')
203-
ENV['Path'] = [
204-
File.join(base_dir, 'puppet', 'bin'),
205-
File.join(base_dir, 'bin'),
206-
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)
207-
208-
# ENV that uses forward slashes
209-
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
210-
rescue => e
211-
log_exception(e)
212-
end
191+
# ENV that uses backward slashes
192+
ENV['FACTER_env_windows_installdir'] = base_dir.tr('/', '\\')
193+
ENV['PL_BASEDIR'] = base_dir.tr('/', '\\')
194+
ENV['PUPPET_DIR'] = File.join(base_dir, 'puppet').tr('/', '\\')
195+
ENV['OPENSSL_CONF'] = File.join(base_dir, 'puppet', 'ssl', 'openssl.cnf').tr('/', '\\')
196+
ENV['SSL_CERT_DIR'] = File.join(base_dir, 'puppet', 'ssl', 'certs').tr('/', '\\')
197+
ENV['SSL_CERT_FILE'] = File.join(base_dir, 'puppet', 'ssl', 'cert.pem').tr('/', '\\')
198+
ENV['Path'] = [
199+
File.join(base_dir, 'puppet', 'bin'),
200+
File.join(base_dir, 'bin'),
201+
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)
202+
203+
# ENV that uses forward slashes
204+
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
205+
rescue => e
206+
log_exception(e)
213207
end
214208
end
215209

lib/puppet/application.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def find(application_name)
251251
################################################################
252252

253253
if clazz.nil?
254-
raise Puppet::Error.new(_("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name })
254+
raise Puppet::Error, _("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name }
255255
end
256256

257257
return clazz
@@ -481,12 +481,10 @@ def handle_logdest_arg(arg)
481481
Puppet[:logdest] = arg
482482

483483
logdest.each do |dest|
484-
begin
485-
Puppet::Util::Log.newdestination(dest)
486-
options[:setdest] = true
487-
rescue => detail
488-
Puppet.log_and_raise(detail, _("Could not set logdest to %{dest}.") % { dest: arg })
489-
end
484+
Puppet::Util::Log.newdestination(dest)
485+
options[:setdest] = true
486+
rescue => detail
487+
Puppet.log_and_raise(detail, _("Could not set logdest to %{dest}.") % { dest: arg })
490488
end
491489
end
492490

lib/puppet/application/describe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def wrap(txt, opts)
1111
return "" unless txt && !txt.empty?
1212

1313
work = (opts[:scrub] ? scrub(txt) : txt)
14-
indent = (opts[:indent] ? opts[:indent] : 0)
14+
indent = (opts[:indent] || 0)
1515
textLen = @width - indent
1616
patt = Regexp.new("\\A(.{0,#{textLen}})[ \n]")
1717
prefix = " " * indent

0 commit comments

Comments
 (0)