Skip to content

Commit 500c601

Browse files
authored
Merge pull request #9284 from AriaXLi/PUP-11993/more_style_cops
(PUP-11993) Even more Style cops!
2 parents 62b1cd6 + 8d42434 commit 500c601

File tree

175 files changed

+378
-504
lines changed

Some content is hidden

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

175 files changed

+378
-504
lines changed

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ Style/RedundantSelfAssignment:
5151
Exclude:
5252
- 'lib/puppet/context.rb'
5353

54+
# Enabling this cop causes failures in rb_tree_map_spec relating to important
55+
# function slike being unable to delete nodes and returning nil when the key
56+
# cannot be found
57+
Style/PreferredHashMethods:
58+
Enabled: false
59+
5460
# Explicitly enables this cop new in 1.7
5561
Layout/SpaceBeforeBrackets:
5662
Enabled: true

.rubocop_todo.yml

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

649-
# This cop supports unsafe auto-correction (--auto-correct-all).
650-
# Configuration parameters: EnforcedStyle.
651-
# SupportedStyles: short, verbose
652-
Style/PreferredHashMethods:
653-
Enabled: false
654-
655649
# This cop supports safe auto-correction (--auto-correct).
656650
# Configuration parameters: EnforcedStyle.
657651
# SupportedStyles: implicit, explicit
@@ -664,19 +658,6 @@ Style/RescueStandardError:
664658
Style/SafeNavigation:
665659
Enabled: false
666660

667-
# This cop supports safe auto-correction (--auto-correct).
668-
Style/SelfAssignment:
669-
Exclude:
670-
- 'lib/puppet/pops/evaluator/access_operator.rb'
671-
- 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb'
672-
- 'lib/puppet/pops/evaluator/epp_evaluator.rb'
673-
- 'lib/puppet/pops/parser/epp_parser.rb'
674-
- 'lib/puppet/pops/parser/parser_support.rb'
675-
- 'lib/puppet/pops/time/timestamp.rb'
676-
- 'lib/puppet/pops/types/recursion_guard.rb'
677-
- 'lib/puppet/property/ordered_list.rb'
678-
- 'lib/puppet/util/autoload.rb'
679-
680661
# This cop supports safe auto-correction (--auto-correct).
681662
# Configuration parameters: AllowAsExpressionSeparator.
682663
Style/Semicolon:
@@ -712,12 +693,6 @@ Style/SingleLineMethods:
712693
Style/SoleNestedConditional:
713694
Enabled: false
714695

715-
# This cop supports safe auto-correction (--auto-correct).
716-
# Configuration parameters: RequireEnglish, EnforcedStyle.
717-
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
718-
Style/SpecialGlobalVars:
719-
Enabled: false
720-
721696
# This cop supports safe auto-correction (--auto-correct).
722697
Style/StderrPuts:
723698
Exclude:
@@ -747,77 +722,18 @@ Style/StringConcatenation:
747722
Style/StringLiterals:
748723
Enabled: false
749724

750-
# This cop supports safe auto-correction (--auto-correct).
751-
# Configuration parameters: EnforcedStyle.
752-
# SupportedStyles: single_quotes, double_quotes
753-
Style/StringLiteralsInInterpolation:
754-
Enabled: false
755-
756-
# This cop supports safe auto-correction (--auto-correct).
757-
Style/StructInheritance:
758-
Exclude:
759-
- 'lib/puppet/settings.rb'
760-
761725
# This cop supports safe auto-correction (--auto-correct).
762726
# Configuration parameters: EnforcedStyle, MinSize.
763727
# SupportedStyles: percent, brackets
764728
Style/SymbolArray:
765729
Enabled: false
766730

767-
# This cop supports safe auto-correction (--auto-correct).
768-
Style/SymbolLiteral:
769-
Exclude:
770-
- 'lib/puppet/functions/defined.rb'
771-
772-
# This cop supports unsafe auto-correction (--auto-correct-all).
773-
# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods, AllowComments.
774-
# IgnoredMethods: respond_to, define_method
775-
Style/SymbolProc:
776-
Enabled: false
777-
778731
# This cop supports safe auto-correction (--auto-correct).
779732
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
780733
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
781734
Style/TernaryParentheses:
782735
Enabled: false
783736

784-
# This cop supports safe auto-correction (--auto-correct).
785-
# Configuration parameters: EnforcedStyleForMultiline.
786-
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
787-
Style/TrailingCommaInArguments:
788-
Exclude:
789-
- 'lib/puppet/defaults.rb'
790-
- 'lib/puppet/ffi/windows/functions.rb'
791-
- 'lib/puppet/ffi/windows/structs.rb'
792-
- 'lib/puppet/http/service/compiler.rb'
793-
- 'lib/puppet/http/service/report.rb'
794-
- 'lib/puppet/indirector/file_bucket_file/rest.rb'
795-
- 'lib/puppet/indirector/file_content/rest.rb'
796-
- 'lib/puppet/indirector/file_metadata/rest.rb'
797-
- 'lib/puppet/pops/types/p_uri_type.rb'
798-
- 'lib/puppet/util/windows/adsi.rb'
799-
- 'lib/puppet/util/windows/service.rb'
800-
801-
# This cop supports safe auto-correction (--auto-correct).
802-
# Configuration parameters: EnforcedStyleForMultiline.
803-
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
804-
Style/TrailingCommaInArrayLiteral:
805-
Exclude:
806-
- 'ext/windows/service/daemon.rb'
807-
- 'lib/puppet/functions.rb'
808-
- 'lib/puppet/parser/compiler.rb'
809-
- 'lib/puppet/pops/types/p_uri_type.rb'
810-
- 'lib/puppet/pops/types/string_converter.rb'
811-
- 'lib/puppet/pops/types/types.rb'
812-
- 'lib/puppet/provider/package/windows/exe_package.rb'
813-
- 'lib/puppet/provider/service/upstart.rb'
814-
- 'lib/puppet/settings.rb'
815-
- 'lib/puppet/ssl/certificate_request.rb'
816-
- 'lib/puppet/ssl/oids.rb'
817-
- 'lib/puppet/transaction/persistence.rb'
818-
- 'lib/puppet/util/at_fork/solaris.rb'
819-
- 'lib/puppet/util/windows/registry.rb'
820-
821737
# This cop supports safe auto-correction (--auto-correct).
822738
# Configuration parameters: EnforcedStyleForMultiline.
823739
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
@@ -846,39 +762,10 @@ Style/TrailingUnderscoreVariable:
846762
Style/TrivialAccessors:
847763
Enabled: false
848764

849-
# This cop supports safe auto-correction (--auto-correct).
850-
Style/UnlessElse:
851-
Exclude:
852-
- 'lib/puppet/application/lookup.rb'
853-
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
854-
- 'lib/puppet/pops/types/type_mismatch_describer.rb'
855-
- 'lib/puppet/provider/package/aix.rb'
856-
- 'lib/puppet/provider/package/yum.rb'
857-
- 'lib/puppet/ssl/openssl_loader.rb'
858-
- 'lib/puppet/type/exec.rb'
859-
- 'lib/puppet/util/command_line/trollop.rb'
860-
861-
# This cop supports safe auto-correction (--auto-correct).
862-
Style/UnpackFirst:
863-
Exclude:
864-
- 'lib/puppet/file_serving/http_metadata.rb'
865-
- 'lib/puppet/provider/nameservice/directoryservice.rb'
866-
- 'lib/puppet/provider/user/directoryservice.rb'
867-
868-
# This cop supports safe auto-correction (--auto-correct).
869-
Style/VariableInterpolation:
870-
Exclude:
871-
- 'lib/puppet/util/command_line/trollop.rb'
872-
- 'lib/puppet/util/rdoc/generators/puppet_generator.rb'
873-
874765
# This cop supports safe auto-correction (--auto-correct).
875766
Style/WhenThen:
876767
Enabled: false
877768

878-
# This cop supports safe auto-correction (--auto-correct).
879-
Style/WhileUntilDo:
880-
Enabled: false
881-
882769
# This cop supports safe auto-correction (--auto-correct).
883770
Style/WhileUntilModifier:
884771
Exclude:
@@ -889,12 +776,6 @@ Style/WhileUntilModifier:
889776
- 'lib/puppet/pops/types/p_object_type.rb'
890777
- 'lib/puppet/util/windows/process.rb'
891778

892-
# This cop supports safe auto-correction (--auto-correct).
893-
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
894-
# SupportedStyles: percent, brackets
895-
Style/WordArray:
896-
Enabled: false
897-
898779
# This cop supports unsafe auto-correction (--auto-correct-all).
899780
# Configuration parameters: EnforcedStyle.
900781
# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only

ext/windows/service/daemon.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def service_main(*argsv)
7575

7676
service = self
7777
@run_thread = Thread.new do
78-
while service.running? do
78+
while service.running?
7979
runinterval = service.parse_runinterval(ruby_puppet_cmd)
8080

8181
if service.state == RUNNING or service.state == IDLE
@@ -197,7 +197,7 @@ def load_env(base_dir)
197197
ENV['SSL_CERT_FILE'] = File.join(base_dir, 'puppet', 'ssl', 'cert.pem').tr('/', '\\')
198198
ENV['Path'] = [
199199
File.join(base_dir, 'puppet', 'bin'),
200-
File.join(base_dir, 'bin'),
200+
File.join(base_dir, 'bin')
201201
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)
202202

203203
# ENV that uses forward slashes
@@ -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/application/face_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def parse_options
7474
# non-option word to use as the action.
7575
action_name = nil
7676
index = -1
77-
until action_name or (index += 1) >= command_line.args.length do
77+
until action_name or (index += 1) >= command_line.args.length
7878
item = command_line.args[index]
7979
if item =~ /^-/
8080
option = @face.options.find do |name|

lib/puppet/application/lookup.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Puppet::Application::Lookup < Puppet::Application
99
RUN_HELP = _("Run 'puppet lookup --help' for more details").freeze
1010
DEEP_MERGE_OPTIONS = '--knock-out-prefix, --sort-merged-arrays, and --merge-hash-arrays'
11-
TRUSTED_INFORMATION_FACTS = ["hostname", "domain", "fqdn", "clientcert"].freeze
11+
TRUSTED_INFORMATION_FACTS = %w[hostname domain fqdn clientcert].freeze
1212

1313
run_mode :server
1414

@@ -369,7 +369,9 @@ def generate_scope
369369
end
370370
end
371371

372-
unless node.is_a?(Puppet::Node) # to allow unit tests to pass a node instance
372+
if node.is_a?(Puppet::Node)
373+
node.add_extra_facts(given_facts) if given_facts
374+
else # to allow unit tests to pass a node instance
373375
facts = retrieve_node_facts(node, given_facts)
374376
ni = Puppet::Node.indirection
375377
tc = ni.terminus_class
@@ -399,8 +401,6 @@ def generate_scope
399401
node = ni.find(node, facts: facts, environment: Puppet[:environment])
400402
ni.terminus_class = tc
401403
end
402-
else
403-
node.add_extra_facts(given_facts) if given_facts
404404
end
405405
node.environment = Puppet[:environment] if Puppet.settings.set_by_cli?(:environment)
406406
Puppet[:code] = 'undef' unless options[:compile]

lib/puppet/coercion.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ def self.boolean(value)
3737
# @raise
3838
# @api private
3939
def self.boolean_values
40-
['true', 'false', 'yes', 'no']
40+
%w[true false yes no]
4141
end
4242
end

lib/puppet/confine/feature.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Puppet::Confine::Feature < Puppet::Confine
66
def self.summarize(confines)
7-
confines.collect { |c| c.values }.flatten.uniq.find_all { |value| !confines[0].pass?(value) }
7+
confines.collect(&:values).flatten.uniq.find_all { |value| !confines[0].pass?(value) }
88
end
99

1010
# Is the named feature available?

lib/puppet/confine/variable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(values)
2929
end
3030

3131
def message(value)
32-
"facter value '#{test_value}' for '#{name}' not in required list '#{values.join(",")}'"
32+
"facter value '#{test_value}' for '#{name}' not in required list '#{values.join(',')}'"
3333
end
3434

3535
# Compare the passed-in value to the retrieved value.

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/defaults.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def self.initialize_default_settings!(settings)
132132
:log_level => {
133133
:default => 'notice',
134134
:type => :enum,
135-
:values => ["debug","info","notice","warning","err","alert","emerg","crit"],
135+
:values => %w[debug info notice warning err alert emerg crit],
136136
:desc => "Default logging level for messages from Puppet. Allowed values are:
137137
138138
* debug
@@ -1298,7 +1298,7 @@ def self.initialize_default_settings!(settings)
12981298
:sourceaddress => {
12991299
:default => nil,
13001300
:desc => "The address the agent should use to initiate requests.",
1301-
},
1301+
}
13021302
)
13031303

13041304
settings.define_settings(:environment,

lib/puppet/environments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def get_conf(name)
313313
end
314314

315315
def clear_all
316-
@loaders.each { |loader| loader.clear_all }
316+
@loaders.each(&:clear_all)
317317
end
318318
end
319319

lib/puppet/external/dot.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ def change_tab(t)
100100

101101
# options for graph declaration
102102

103-
GRAPH_OPTS = [
104-
'bgcolor',
105-
'center', 'clusterrank', 'color', 'concentrate',
106-
'fontcolor', 'fontname', 'fontsize',
107-
'label', 'layerseq',
108-
'margin', 'mclimit',
109-
'nodesep', 'nslimit',
110-
'ordering', 'orientation',
111-
'page',
112-
'rank', 'rankdir', 'ranksep', 'ratio',
113-
'size'
103+
GRAPH_OPTS = %w[
104+
bgcolor
105+
center clusterrank color concentrate
106+
fontcolor fontname fontsize
107+
label layerseq
108+
margin mclimit
109+
nodesep nslimit
110+
ordering orientation
111+
page
112+
rank rankdir ranksep ratio
113+
size
114114
]
115115

116116
# a root class for any element in dot notation

lib/puppet/face/catalog/select.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
if value.nil? then
4545
_("no matching resources found")
4646
else
47-
value.map { |x| x.to_s }.join("\n")
47+
value.map(&:to_s).join("\n")
4848
end
4949
end
5050
end

lib/puppet/face/help.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def horribly_extract_summary_from(appname)
207207
# depends on the implementation coincidence of how our pages are
208208
# formatted. If we can't match the pattern we expect we return the empty
209209
# string to ensure we don't blow up in the summary. --daniel 2011-04-11
210-
while line = help.shift do # rubocop:disable Lint/AssignmentInCondition
210+
while line = help.shift # rubocop:disable Lint/AssignmentInCondition
211211
md = /^puppet-#{appname}\([^)]+\) -- (.*)$/.match(line)
212212
if md
213213
return md[1]

lib/puppet/face/module/changes.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
else
3939
Puppet.warning _("%{count} files modified") % { count: return_value.size }
4040
end
41-
return_value.map do |changed_file|
42-
changed_file.to_s
43-
end.join("\n")
41+
return_value.map(&:to_s).join("\n")
4442
end
4543
end
4644
end

lib/puppet/face/module/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def unmet_dependencies(environment)
117117
end
118118

119119
# Prepare the unmet dependencies for display on the console.
120-
environment.modules.sort_by { |mod| mod.name }.each do |mod|
120+
environment.modules.sort_by(&:name).each do |mod|
121121
unmet_grouped = Hash.new { |h, k| h[k] = [] }
122122
unmet_grouped = mod.unmet_dependencies.each_with_object(unmet_grouped) do |dep, acc|
123123
acc[dep[:reason]] << dep

0 commit comments

Comments
 (0)