Skip to content

Commit 2bc53e6

Browse files
authored
Merge pull request #9263 from AriaXLi/PUP-11993/style_cops_N-Z
(PUP-11993) Style Cops (N-P)
2 parents f21358d + 6b5cb30 commit 2bc53e6

File tree

265 files changed

+1284
-1368
lines changed

Some content is hidden

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

265 files changed

+1284
-1368
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -629,175 +629,23 @@ Style/MultipleComparison:
629629
Style/MutableConstant:
630630
Enabled: false
631631

632-
# This cop supports safe auto-correction (--auto-correct).
633-
# Configuration parameters: EnforcedStyle.
634-
# SupportedStyles: both, prefix, postfix
635-
Style/NegatedIf:
636-
Enabled: false
637-
638-
# This cop supports safe auto-correction (--auto-correct).
639-
Style/NegatedWhile:
640-
Exclude:
641-
- 'lib/puppet/file_system/file_impl.rb'
642-
- 'lib/puppet/graph/simple_graph.rb'
643-
- 'lib/puppet/http/client.rb'
644-
- 'lib/puppet/pops/parser/heredoc_support.rb'
645-
- 'lib/puppet/pops/types/p_object_type.rb'
646-
- 'lib/puppet/scheduler/scheduler.rb'
647-
648-
# This cop supports safe auto-correction (--auto-correct).
649-
Style/NestedModifier:
650-
Exclude:
651-
- 'lib/puppet/util/command_line/trollop.rb'
652-
653-
# This cop supports safe auto-correction (--auto-correct).
654-
# Configuration parameters: AllowedMethods.
655-
# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
656-
Style/NestedParenthesizedCalls:
657-
Exclude:
658-
- 'lib/puppet/provider/user/directoryservice.rb'
659-
660-
# This cop supports safe auto-correction (--auto-correct).
661-
Style/NestedTernaryOperator:
662-
Exclude:
663-
- 'lib/puppet/external/dot.rb'
664-
- 'lib/puppet/module_tool/shared_behaviors.rb'
665-
- 'lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb'
666-
- 'lib/puppet/pops/lookup/hiera_config.rb'
667-
- 'lib/puppet/pops/parser/lexer2.rb'
668-
- 'lib/puppet/pops/types/string_converter.rb'
669-
- 'lib/puppet/pops/types/type_factory.rb'
670-
- 'lib/puppet/pops/types/types.rb'
671-
- 'lib/puppet/util/log.rb'
672-
673-
# This cop supports safe auto-correction (--auto-correct).
674-
# Configuration parameters: EnforcedStyle, MinBodyLength.
675-
# SupportedStyles: skip_modifier_ifs, always
676-
Style/Next:
677-
Enabled: false
678-
679-
# This cop supports safe auto-correction (--auto-correct).
680-
# Configuration parameters: EnforcedStyle.
681-
# SupportedStyles: predicate, comparison
682-
Style/NilComparison:
683-
Exclude:
684-
- 'lib/puppet/pops/types/type_factory.rb'
685-
- 'lib/puppet/pops/types/types.rb'
686-
- 'lib/puppet/provider/package/dnfmodule.rb'
687-
- 'lib/puppet/provider/package/nim.rb'
688-
- 'lib/puppet/provider/package/windows/exe_package.rb'
689-
- 'lib/puppet/provider/user/directoryservice.rb'
690-
- 'lib/puppet/type/file.rb'
691-
- 'lib/puppet/util/pidlock.rb'
692-
- 'lib/puppet/util/suidmanager.rb'
693-
694-
# This cop supports safe auto-correction (--auto-correct).
695-
# Configuration parameters: IncludeSemanticChanges.
696-
Style/NonNilCheck:
697-
Exclude:
698-
- 'lib/puppet/forge.rb'
699-
- 'lib/puppet/http/session.rb'
700-
- 'lib/puppet/network/http/request.rb'
701-
- 'lib/puppet/provider/package/pip.rb'
702-
703-
# This cop supports safe auto-correction (--auto-correct).
704-
Style/Not:
705-
Enabled: false
706-
707-
# This cop supports safe auto-correction (--auto-correct).
708-
# Configuration parameters: EnforcedOctalStyle.
709-
# SupportedOctalStyles: zero_with_o, zero_only
710-
Style/NumericLiteralPrefix:
711-
Enabled: false
712-
713-
# This cop supports safe auto-correction (--auto-correct).
714-
# Configuration parameters: Strict, AllowedNumbers.
715-
Style/NumericLiterals:
716-
MinDigits: 11
717-
718632
# This cop supports unsafe auto-correction (--auto-correct-all).
719633
# Configuration parameters: EnforcedStyle, IgnoredMethods.
720634
# SupportedStyles: predicate, comparison
721635
Style/NumericPredicate:
722636
Enabled: false
723637

724-
# This cop supports safe auto-correction (--auto-correct).
725-
# Configuration parameters: AlwaysCorrectToMultiline.
726-
Style/OneLineConditional:
727-
Exclude:
728-
- 'lib/puppet/pops/parser/evaluating_parser.rb'
729-
- 'lib/puppet/provider/package/yum.rb'
730-
- 'lib/puppet/provider/service/openwrt.rb'
731-
732638
# Configuration parameters: AllowedMethods.
733639
# AllowedMethods: respond_to_missing?
734640
Style/OptionalBooleanParameter:
735641
Enabled: false
736642

737-
# This cop supports safe auto-correction (--auto-correct).
738-
Style/OrAssignment:
739-
Exclude:
740-
- 'lib/puppet/application/lookup.rb'
741-
- 'lib/puppet/file_system/windows.rb'
742-
- 'lib/puppet/pops/parser/lexer2.rb'
743-
- 'lib/puppet/pops/types/types.rb'
744-
- 'lib/puppet/provider/user/directoryservice.rb'
745-
- 'lib/puppet/ssl/base.rb'
746-
- 'lib/puppet/util/errors.rb'
747-
- 'util/rspec_grouper'
748-
749-
# This cop supports safe auto-correction (--auto-correct).
750-
Style/ParallelAssignment:
751-
Exclude:
752-
- 'lib/puppet/configurer/downloader.rb'
753-
- 'lib/puppet/graph/rb_tree_map.rb'
754-
- 'lib/puppet/module_tool/shared_behaviors.rb'
755-
- 'lib/puppet/network/client_request.rb'
756-
- 'lib/puppet/parser/relationship.rb'
757-
- 'lib/puppet/provider/package/ports.rb'
758-
- 'lib/puppet/provider/service/smf.rb'
759-
- 'lib/puppet/provider/user/aix.rb'
760-
- 'lib/puppet/relationship.rb'
761-
- 'lib/puppet/settings/config_file.rb'
762-
- 'lib/puppet/type/file/ensure.rb'
763-
- 'lib/puppet/util/suidmanager.rb'
764-
- 'lib/puppet/util/windows/registry.rb'
765-
766-
# This cop supports safe auto-correction (--auto-correct).
767-
# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions.
768-
Style/ParenthesesAroundCondition:
769-
Enabled: false
770-
771-
# This cop supports safe auto-correction (--auto-correct).
772-
# Configuration parameters: PreferredDelimiters.
773-
Style/PercentLiteralDelimiters:
774-
Enabled: false
775-
776-
# This cop supports safe auto-correction (--auto-correct).
777-
# Configuration parameters: EnforcedStyle.
778-
# SupportedStyles: lower_case_q, upper_case_q
779-
Style/PercentQLiterals:
780-
Exclude:
781-
- 'lib/puppet/provider/package/dpkg.rb'
782-
- 'lib/puppet/provider/package/rpm.rb'
783-
784-
# This cop supports safe auto-correction (--auto-correct).
785-
Style/PerlBackrefs:
786-
Enabled: false
787-
788643
# This cop supports unsafe auto-correction (--auto-correct-all).
789644
# Configuration parameters: EnforcedStyle.
790645
# SupportedStyles: short, verbose
791646
Style/PreferredHashMethods:
792647
Enabled: false
793648

794-
# This cop supports safe auto-correction (--auto-correct).
795-
Style/Proc:
796-
Exclude:
797-
- 'lib/puppet/pops/evaluator/deferred_resolver.rb'
798-
- 'lib/puppet/pops/lookup/hiera_config.rb'
799-
- 'lib/puppet/util/windows/daemon.rb'
800-
801649
# This cop supports safe auto-correction (--auto-correct).
802650
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
803651
# SupportedStyles: compact, exploded

ext/windows/service/daemon.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def service_main(*argsv)
3636

3737
@LOG_TO_FILE = (argsv.index('--logtofile') ? true : false)
3838

39-
if (@LOG_TO_FILE)
39+
if @LOG_TO_FILE
4040
FileUtils.mkdir_p(File.dirname(LOG_FILE))
4141
args = args.gsub("--logtofile", "")
4242
end
@@ -131,7 +131,7 @@ def log_exception(e)
131131

132132
def log(msg, level)
133133
if LEVELS.index(level) >= @loglevel
134-
if (@LOG_TO_FILE)
134+
if @LOG_TO_FILE
135135
# without this change its possible that we get Encoding errors trying to write UTF-8 messages in current codepage
136136
File.open(LOG_FILE, 'a:UTF-8') { |f| f.puts("#{Time.now} Puppet (#{level}): #{msg}") }
137137
end
@@ -153,15 +153,15 @@ def report_windows_event(type, id, message)
153153
rescue Exception
154154
# Ignore all errors
155155
ensure
156-
if (!eventlog.nil?)
156+
unless eventlog.nil?
157157
eventlog.close
158158
end
159159
end
160160
end
161161

162162
def parse_runinterval(puppet_path)
163163
begin
164-
runinterval = %x{#{puppet_path} config --section agent --log_level notice print runinterval}.to_i
164+
runinterval = %x(#{puppet_path} config --section agent --log_level notice print runinterval).to_i
165165
if runinterval == 0
166166
runinterval = 1800
167167
log_err("Failed to determine runinterval, defaulting to #{runinterval} seconds")
@@ -176,7 +176,7 @@ def parse_runinterval(puppet_path)
176176

177177
def parse_log_level(puppet_path, cmdline_debug)
178178
begin
179-
loglevel = %x{#{puppet_path} config --section agent --log_level notice print log_level}.chomp
179+
loglevel = %x(#{puppet_path} config --section agent --log_level notice print log_level).chomp
180180
unless loglevel && respond_to?("log_#{loglevel}")
181181
loglevel = :notice
182182
log_err("Failed to determine loglevel, defaulting to #{loglevel}")

lib/puppet/agent/disabler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def enable
2626
def disable(msg = nil)
2727
data = {}
2828
Puppet.notice _("Disabling Puppet.")
29-
if (!msg.nil?)
29+
unless msg.nil?
3030
data[DISABLED_MESSAGE_JSON_KEY] = msg
3131
end
3232
disable_lockfile.lock(data)

lib/puppet/application.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def controlled_run(&block)
180180
def option(*options, &block)
181181
long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1').tr('-', '_')
182182
fname = "handle_#{long}".intern
183-
if (block_given?)
183+
if block_given?
184184
define_method(fname, &block)
185185
else
186186
define_method(fname) do |value|
@@ -242,7 +242,7 @@ def find(application_name)
242242
#### eventually we need to issue a deprecation warning here,
243243
#### and then get rid of this stanza in a subsequent release.
244244
################################################################
245-
if (clazz.nil?)
245+
if clazz.nil?
246246
class_name = application_name.capitalize
247247
clazz = try_load_class(class_name)
248248
end
@@ -284,7 +284,7 @@ def run_mode(mode_name = nil)
284284
Puppet.settings.preferred_run_mode = mode_name
285285
end
286286

287-
return @run_mode if @run_mode and not mode_name
287+
return @run_mode if @run_mode and !mode_name
288288

289289
require_relative '../puppet/util/run_mode'
290290
@run_mode = Puppet::Util::RunMode[mode_name || Puppet.settings.preferred_run_mode]
@@ -452,7 +452,7 @@ def setup
452452
# @return [void]
453453
# @api public
454454
def setup_logs
455-
handle_logdest_arg(Puppet[:logdest]) if !options[:setdest]
455+
handle_logdest_arg(Puppet[:logdest]) unless options[:setdest]
456456

457457
unless options[:setdest]
458458
if options[:debug] || options[:verbose]

lib/puppet/application/agent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def onetime(daemon)
441441

442442
daemon.stop(:exit => false)
443443

444-
if not exitstatus
444+
if !exitstatus
445445
exit(1)
446446
elsif options[:detailed_exitcodes] then
447447
exit(exitstatus)
@@ -509,7 +509,7 @@ def enable_disable_client(agent)
509509
end
510510

511511
def setup_agent
512-
agent = Puppet::Agent.new(Puppet::Configurer, (not(Puppet[:onetime])))
512+
agent = Puppet::Agent.new(Puppet::Configurer, (!(Puppet[:onetime])))
513513

514514
enable_disable_client(agent) if options[:enable] or options[:disable]
515515

lib/puppet/application/apply.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def main
276276

277277
exit_status = apply_catalog(catalog)
278278

279-
if not exit_status
279+
if !exit_status
280280
exit(1)
281281
elsif options[:detailed_exitcodes] then
282282
exit(exit_status)

lib/puppet/application/describe.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def wrap(txt, opts)
2020

2121
while work.length > textLen
2222
if work =~ patt
23-
res << $1
24-
work.slice!(0, $MATCH.length)
23+
res << ::Regexp.last_match(1)
24+
work.slice!(0, ::Regexp.last_match(0).length)
2525
else
2626
res << work.slice!(0, textLen)
2727
end
@@ -43,7 +43,7 @@ def scrub(text)
4343
# If we can match an indentation, then just remove that same level of
4444
# indent from every line.
4545
if text =~ /^(\s+)/
46-
indent = $1
46+
indent = ::Regexp.last_match(1)
4747
return text.gsub(/^#{indent}/, '')
4848
else
4949
return text

lib/puppet/application/face_base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def parse_options
8888
# when we get there. --daniel 2011-04-04
8989
if option.takes_argument? and !item.index('=')
9090
index += 1 unless
91-
(option.optional_argument? and command_line.args[index + 1] =~ /^-/)
91+
option.optional_argument? and command_line.args[index + 1] =~ /^-/
9292
end
9393
else
9494
option = find_global_settings_argument(item)
@@ -103,7 +103,7 @@ def parse_options
103103
else
104104
option = find_application_argument(item)
105105
if option
106-
index += 1 if (option[:argument] and not option[:optional])
106+
index += 1 if option[:argument] and !(option[:optional])
107107
else
108108
raise OptionParser::InvalidOption.new(item.sub(/=.*$/, ''))
109109
end

lib/puppet/application/filebucket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def help
213213
def run_command
214214
@args = command_line.args
215215
command = args.shift
216-
return send(command) if %w{get backup restore diff list}.include? command
216+
return send(command) if %w[get backup restore diff list].include? command
217217

218218
help
219219
end

lib/puppet/application/lookup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def generate_scope
354354
given_facts = Puppet::Util::Yaml.safe_load_file(fact_file)
355355
else
356356
given_facts = Puppet::Util::Json.load_file_if_valid(fact_file)
357-
given_facts = Puppet::Util::Yaml.safe_load_file_if_valid(fact_file) unless given_facts
357+
given_facts ||= Puppet::Util::Yaml.safe_load_file_if_valid(fact_file)
358358
end
359359

360360
unless given_facts.instance_of?(Hash)

lib/puppet/application/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def parse_args(args)
211211
params = {}
212212
args.each do |setting|
213213
if setting =~ /^(\w+)=(.+)$/
214-
params[$1] = $2
214+
params[::Regexp.last_match(1)] = ::Regexp.last_match(2)
215215
else
216216
raise _("Invalid parameter setting %{setting}") % { setting: setting }
217217
end

lib/puppet/application/ssl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def main
160160

161161
clean(certname)
162162
when 'bootstrap'
163-
if !Puppet::Util::Log.sendlevel?(:info)
163+
unless Puppet::Util::Log.sendlevel?(:info)
164164
Puppet::Util::Log.level = :info
165165
end
166166
@machine.ensure_client_certificate

lib/puppet/configurer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def retrieve_catalog(facts, query_options)
8383
else
8484
result = retrieve_new_catalog(facts, query_options)
8585

86-
if !result
87-
if !Puppet[:usecacheonfailure]
86+
unless result
87+
unless Puppet[:usecacheonfailure]
8888
Puppet.warning _("Not using cache on failed catalog")
8989
return nil
9090
end
@@ -390,7 +390,7 @@ def run_internal(options)
390390
configured_environment = Puppet[:environment] if Puppet.settings.set_by_config?(:environment)
391391

392392
# We only need to find out the environment to run in if we don't already have a catalog
393-
unless (cached_catalog || options[:catalog] || Puppet.settings.set_by_cli?(:environment) || Puppet[:strict_environment_mode])
393+
unless cached_catalog || options[:catalog] || Puppet.settings.set_by_cli?(:environment) || Puppet[:strict_environment_mode]
394394
Puppet.debug(_("Environment not passed via CLI and no catalog was given, attempting to find out the last server-specified environment"))
395395
initial_environment, loaded_last_environment = last_server_specified_environment
396396

@@ -442,7 +442,7 @@ def run_internal(options)
442442
# facts may be used to determine which catalog we get, we need to
443443
# rerun the process if the environment is changed.
444444
tries = 0
445-
while catalog.environment and not catalog.environment.empty? and catalog.environment != @environment
445+
while catalog.environment and !catalog.environment.empty? and catalog.environment != @environment
446446
if tries > 3
447447
raise Puppet::Error, _("Catalog environment didn't stabilize after %{tries} fetches, aborting run") % { tries: tries }
448448
end

0 commit comments

Comments
 (0)