Skip to content

Commit bdee6bd

Browse files
(PUP-11767) Fix Lambda violations and remove from todo list
1 parent a96b321 commit bdee6bd

File tree

12 files changed

+35
-52
lines changed

12 files changed

+35
-52
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -534,23 +534,6 @@ Style/InverseMethods:
534534
- 'lib/puppet/reference/providers.rb'
535535
- 'lib/puppet/type/file.rb'
536536

537-
# This cop supports safe auto-correction (--auto-correct).
538-
# Configuration parameters: EnforcedStyle.
539-
# SupportedStyles: line_count_dependent, lambda, literal
540-
Style/Lambda:
541-
Exclude:
542-
- 'lib/puppet/defaults.rb'
543-
- 'lib/puppet/functions/unique.rb'
544-
- 'lib/puppet/graph/relationship_graph.rb'
545-
- 'lib/puppet/http/session.rb'
546-
- 'lib/puppet/pops/lookup/interpolation.rb'
547-
- 'lib/puppet/pops/parser/lexer2.rb'
548-
- 'lib/puppet/provider/aix_object.rb'
549-
- 'lib/puppet/provider/service/upstart.rb'
550-
- 'lib/puppet/transaction.rb'
551-
- 'lib/puppet/util/command_line/puppet_option_parser.rb'
552-
- 'lib/puppet/util/symbolic_file_mode.rb'
553-
554537
# This cop supports safe auto-correction (--auto-correct).
555538
Style/LineEndConcatenation:
556539
Exclude:

lib/puppet/defaults.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def self.initialize_default_settings!(settings)
467467
EOT
468468
},
469469
:diff_args => {
470-
:default => lambda { default_diffargs },
470+
:default => -> { default_diffargs },
471471
:desc => "Which arguments to pass to the diff command when printing differences between
472472
files. The command to use can be chosen with the `diff` setting.",
473473
},
@@ -818,7 +818,7 @@ def self.initialize_default_settings!(settings)
818818
# We have to downcase the fqdn, because the current ssl stuff (as opposed to in master) doesn't have good facilities for
819819
# manipulating naming.
820820
:certname => {
821-
:default => lambda { Puppet::Settings.default_certname.downcase },
821+
:default => -> { Puppet::Settings.default_certname.downcase },
822822
:desc => "The name to use when handling certificates. When a node
823823
requests a certificate from the CA Puppet Server, it uses the value of the
824824
`certname` setting as its requested Subject CN.
@@ -1086,15 +1086,15 @@ def self.initialize_default_settings!(settings)
10861086
Default is `prime256v1`."
10871087
},
10881088
:digest_algorithm => {
1089-
:default => lambda { default_digest_algorithm },
1089+
:default => -> { default_digest_algorithm },
10901090
:type => :enum,
10911091
:values => valid_digest_algorithms,
10921092
:desc => "Which digest algorithm to use for file resources and the filebucket.
10931093
Valid values are #{valid_digest_algorithms.join(', ')}. Default is
10941094
#{default_digest_algorithm}.",
10951095
},
10961096
:supported_checksum_types => {
1097-
:default => lambda { default_file_checksum_types },
1097+
:default => -> { default_file_checksum_types },
10981098
:type => :array,
10991099
:desc => "Checksum types supported by this agent for use in file resources of a
11001100
static catalog. Values must be comma-separated. Valid types are
@@ -1129,7 +1129,7 @@ def self.initialize_default_settings!(settings)
11291129
:desc => "The name to use the Certificate Authority certificate.",
11301130
},
11311131
:cadir => {
1132-
:default => lambda { default_cadir },
1132+
:default => -> { default_cadir },
11331133
:type => :directory,
11341134
:desc => "The root directory for the certificate authority.",
11351135
},
@@ -1419,7 +1419,7 @@ def self.initialize_default_settings!(settings)
14191419
:desc => "File that provides mapping between custom SSL oids and user-friendly names"
14201420
},
14211421
:basemodulepath => {
1422-
:default => lambda { default_basemodulepath },
1422+
:default => -> { default_basemodulepath },
14231423
:type => :path,
14241424
:desc => "The search path for **global** modules. Should be specified as a
14251425
list of directories separated by the system path separator character. (The
@@ -1431,7 +1431,7 @@ def self.initialize_default_settings!(settings)
14311431
<https://puppet.com/docs/puppet/latest/environments_about.html>",
14321432
},
14331433
:vendormoduledir => {
1434-
:default => lambda { default_vendormoduledir },
1434+
:default => -> { default_vendormoduledir },
14351435
:type => :string,
14361436
:desc => "The directory containing **vendored** modules. These modules will
14371437
be used by _all_ environments like those in the `basemodulepath`. The only
@@ -1666,7 +1666,7 @@ def self.initialize_default_settings!(settings)
16661666
:desc => "Whether the server will search for SRV records in DNS for the current domain.",
16671667
},
16681668
:srv_domain => {
1669-
:default => lambda { Puppet::Settings.domain_fact },
1669+
:default => -> { Puppet::Settings.domain_fact },
16701670
:desc => "The domain which will be queried to find the SRV records of servers to use.",
16711671
},
16721672
:http_extra_headers => {

lib/puppet/functions/unique.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def unique_string(string, &block)
111111
end
112112

113113
def unique_hash(hash, &block)
114-
block = lambda { |v| v } unless block_given?
114+
block = ->(v) { v } unless block_given?
115115
result = Hash.new { |h, k| h[k] = { :keys => [], :values => [] } }
116116
hash.each_pair do |k, v|
117117
rc = result[block.call(v)]

lib/puppet/graph/relationship_graph.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def next_resource
9999
end
100100

101101
def traverse(options = {}, &block)
102-
continue_while = options[:while] || lambda { true }
103-
pre_process = options[:pre_process] || lambda { |resource| }
104-
overly_deferred_resource_handler = options[:overly_deferred_resource_handler] || lambda { |resource| }
105-
canceled_resource_handler = options[:canceled_resource_handler] || lambda { |resource| }
106-
teardown = options[:teardown] || lambda {}
107-
graph_cycle_handler = options[:graph_cycle_handler] || lambda { [] }
102+
continue_while = options[:while] || -> { true }
103+
pre_process = options[:pre_process] || ->(resource) {}
104+
overly_deferred_resource_handler = options[:overly_deferred_resource_handler] || ->(resource) {}
105+
canceled_resource_handler = options[:canceled_resource_handler] || ->(resource) {}
106+
teardown = options[:teardown] || -> {}
107+
graph_cycle_handler = options[:graph_cycle_handler] || -> { [] }
108108

109109
cycles = report_cycles_in_graph
110110
if cycles

lib/puppet/http/session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def route_to(name, url: nil, ssl_context: nil)
6262
return cached if cached
6363

6464
canceled = false
65-
canceled_handler = lambda { |cancel| canceled = cancel }
65+
canceled_handler = ->(cancel) { canceled = cancel }
6666

6767
@resolvers.each do |resolver|
6868
Puppet.debug("Resolving service '#{name}' using #{resolver.class}")

lib/puppet/pops/lookup/interpolation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def interpolate_method(method_key)
125125
:hiera => global_lookup, # this is just an alias for 'lookup'
126126
:alias => global_lookup, # same as 'lookup' but expression must be entire string and result is not subject to string substitution
127127
:scope => scope_lookup,
128-
:literal => lambda { |key, _, _| key }
128+
:literal => ->(key, _, _) { key }
129129
}.freeze
130130
end
131131
interpolate_method = @@interpolate_methods[method_key]

lib/puppet/pops/parser/lexer2.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ class Lexer2
187187

188188
def initialize
189189
@selector = {
190-
'.' => lambda { emit(TOKEN_DOT, @scanner.pos) },
191-
',' => lambda { emit(TOKEN_COMMA, @scanner.pos) },
190+
'.' => -> { emit(TOKEN_DOT, @scanner.pos) },
191+
',' => -> { emit(TOKEN_COMMA, @scanner.pos) },
192192
'[' => lambda do
193193
before = @scanner.pos
194194
# Must check the preceding character to see if it is whitespace.
@@ -202,7 +202,7 @@ def initialize
202202
emit(TOKEN_LBRACK, before)
203203
end
204204
end,
205-
']' => lambda { emit(TOKEN_RBRACK, @scanner.pos) },
205+
']' => -> { emit(TOKEN_RBRACK, @scanner.pos) },
206206
'(' => lambda do
207207
before = @scanner.pos
208208
# If first on a line, or only whitespace between start of line and '('
@@ -214,10 +214,10 @@ def initialize
214214
emit(TOKEN_LPAREN, before)
215215
end
216216
end,
217-
')' => lambda { emit(TOKEN_RPAREN, @scanner.pos) },
218-
';' => lambda { emit(TOKEN_SEMIC, @scanner.pos) },
219-
'?' => lambda { emit(TOKEN_QMARK, @scanner.pos) },
220-
'*' => lambda { emit(TOKEN_TIMES, @scanner.pos) },
217+
')' => -> { emit(TOKEN_RPAREN, @scanner.pos) },
218+
';' => -> { emit(TOKEN_SEMIC, @scanner.pos) },
219+
'?' => -> { emit(TOKEN_QMARK, @scanner.pos) },
220+
'*' => -> { emit(TOKEN_TIMES, @scanner.pos) },
221221
'%' => lambda do
222222
scn = @scanner
223223
before = scn.pos
@@ -345,7 +345,7 @@ def initialize
345345
emit(la[1] == '>' ? TOKEN_IN_EDGE_SUB : TOKEN_TILDE, scn.pos)
346346
end,
347347

348-
'#' => lambda { @scanner.skip(PATTERN_COMMENT); nil },
348+
'#' => -> { @scanner.skip(PATTERN_COMMENT); nil },
349349

350350
# TOKENS '/', '/*' and '/ regexp /'
351351
'/' => lambda do
@@ -491,10 +491,10 @@ def initialize
491491
ctx[:line_lexical_start] = @scanner.pos
492492
nil
493493
end,
494-
'' => lambda { nil } # when the peek(1) returns empty
494+
'' => -> { nil } # when the peek(1) returns empty
495495
}
496496

497-
[' ', "\t", "\r"].each { |c| @selector[c] = lambda { @scanner.skip(PATTERN_WS); nil } }
497+
[' ', "\t", "\r"].each { |c| @selector[c] = -> { @scanner.skip(PATTERN_WS); nil } }
498498

499499
('0'..'9').each do |c|
500500
@selector[c] = lambda do

lib/puppet/provider/aix_object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def mappings
9595
# NOTE: 'Impure' lambdas are useful in case we need to generate more specific error
9696
# messages or pass-in instance-specific command-line arguments.
9797
def mapping(info = {})
98-
identity_fn = lambda { |x| x }
98+
identity_fn = ->(x) { x }
9999
info[:aix_attribute] ||= info[:puppet_property]
100100
info[:property_to_attribute] ||= identity_fn
101101
info[:attribute_to_property] ||= identity_fn

lib/puppet/provider/service/upstart.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# We only want to use upstart as our provider if the upstart daemon is running.
3131
# This can be checked by running `initctl version --quiet` on a machine that has
3232
# upstart installed.
33-
confine :true => lambda { has_initctl? }
33+
confine :true => -> { has_initctl? }
3434

3535
def self.has_initctl?
3636
# Puppet::Util::Execution.execute does not currently work on jRuby.

lib/puppet/transaction.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def evaluate(&block)
107107

108108
Puppet.info _("Applying configuration version '%{version}'") % { version: catalog.version } if catalog.version
109109

110-
continue_while = lambda { !stop_processing? }
110+
continue_while = -> { !stop_processing? }
111111

112112
post_evalable_providers = Set.new
113113
pre_process = lambda do |resource|

0 commit comments

Comments
 (0)