Skip to content

Commit 62f677e

Browse files
committed
Layout/ElseAlignment
This commit enables the Rubocop Layout/ElseAlignment cop. In some instances (like Puppet::Pal::TaskSignature.runable_with? and Puppet::Transaction::Report.initialize_from_hash), the new alignment pushed code past the 80 character line length recommended by the Ruby style guide and was reformatted to accomodate that.
1 parent 4e59f24 commit 62f677e

File tree

15 files changed

+131
-122
lines changed

15 files changed

+131
-122
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Layout/BeginEndAlignment:
2828
Exclude:
2929
- 'lib/puppet/provider/package/*.rb'
3030

31+
Layout/ElseAlignment:
32+
Enabled: true
33+
Exclude:
34+
- 'lib/puppet/provider/package/*.rb'
35+
3136
# puppet uses symbol booleans in types and providers to work around long standing
3237
# bugs when trying to manage falsey pararameters and properties
3338
Lint/BooleanSymbol:

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent:
2222
I18n/RailsI18n/DecorateString:
2323
Enabled: false
2424

25-
# This cop supports safe auto-correction (--auto-correct).
26-
Layout/ElseAlignment:
27-
Enabled: false
28-
2925
# This cop supports safe auto-correction (--auto-correct).
3026
Layout/EmptyLineAfterGuardClause:
3127
Enabled: false

lib/puppet/graph/simple_graph.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -507,26 +507,26 @@ def initialize_from_hash(hash)
507507
def to_data_hash
508508
hash = { 'edges' => edges.map(&:to_data_hash) }
509509
hash['vertices'] = if self.class.use_new_yaml_format
510-
vertices
511-
else
512-
# Represented in YAML using the old (version 2.6) format.
513-
result = {}
514-
vertices.each do |vertex|
515-
adjacencies = {}
516-
[:in, :out].each do |direction|
517-
direction_hash = {}
518-
adjacencies[direction.to_s] = direction_hash
519-
adjacent(vertex, :direction => direction, :type => :edges).each do |edge|
520-
other_vertex = direction == :in ? edge.source : edge.target
521-
(direction_hash[other_vertex.to_s] ||= []) << edge
522-
end
523-
direction_hash.each_pair { |key, edges| direction_hash[key] = edges.uniq.map(&:to_data_hash) }
524-
end
525-
vname = vertex.to_s
526-
result[vname] = { 'adjacencies' => adjacencies, 'vertex' => vname }
527-
end
528-
result
529-
end
510+
vertices
511+
else
512+
# Represented in YAML using the old (version 2.6) format.
513+
result = {}
514+
vertices.each do |vertex|
515+
adjacencies = {}
516+
[:in, :out].each do |direction|
517+
direction_hash = {}
518+
adjacencies[direction.to_s] = direction_hash
519+
adjacent(vertex, :direction => direction, :type => :edges).each do |edge|
520+
other_vertex = direction == :in ? edge.source : edge.target
521+
(direction_hash[other_vertex.to_s] ||= []) << edge
522+
end
523+
direction_hash.each_pair { |key, edges| direction_hash[key] = edges.uniq.map(&:to_data_hash) }
524+
end
525+
vname = vertex.to_s
526+
result[vname] = { 'adjacencies' => adjacencies, 'vertex' => vname }
527+
end
528+
result
529+
end
530530
hash
531531
end
532532

lib/puppet/pal/task_signature.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ def initialize(task)
2121
def runnable_with?(args_hash)
2222
params = @task.parameters
2323
params_type = if params.nil?
24-
T_GENERIC_TASK_HASH
25-
else
26-
Puppet::Pops::Types::TypeFactory.struct(params)
27-
end
24+
T_GENERIC_TASK_HASH
25+
else
26+
Puppet::Pops::Types::TypeFactory.struct(params)
27+
end
2828
return true if params_type.instance?(args_hash)
2929

3030
if block_given?
3131
tm = Puppet::Pops::Types::TypeMismatchDescriber.singleton
3232
error = if params.nil?
33-
tm.describe_mismatch('', params_type, Puppet::Pops::Types::TypeCalculator.infer_set(args_hash))
34-
else
35-
tm.describe_struct_signature(params_type, args_hash).flatten.map {|e| e.format }.join("\n")
36-
end
33+
tm.describe_mismatch('', params_type,
34+
Puppet::Pops::Types::TypeCalculator
35+
.infer_set(args_hash))
36+
else
37+
tm.describe_struct_signature(params_type, args_hash)
38+
.flatten
39+
.map {|e| e.format }
40+
.join("\n")
41+
end
3742
yield "Task #{@task.name}:\n#{error}"
3843
end
3944
false

lib/puppet/parser/scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def exist?(name)
298298
else
299299
other_scope.exist?(variable_name)
300300
end
301-
else
301+
else # rubocop:disable Layout/ElseAlignment
302302
next_scope = inherited_scope || enclosing_scope
303303
effective_symtable(true).include?(name) || next_scope && next_scope.exist?(name) || BUILT_IN_VARS.include?(name)
304304
end

lib/puppet/pops/evaluator/evaluator_impl.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,18 +1256,16 @@ def delete(x, y)
12561256
when Array
12571257
y = case y
12581258
when Array then y
1259-
when Hash then y.to_a
1260-
else
1261-
[y]
1262-
end
1259+
when Hash then y.to_a
1260+
else [y]
1261+
end
12631262
y.each {|e| result.delete(e) }
12641263
when Hash
12651264
y = case y
12661265
when Array then y
1267-
when Hash then y.keys
1268-
else
1269-
[y]
1270-
end
1266+
when Hash then y.keys
1267+
else [y]
1268+
end
12711269
y.each {|e| result.delete(e) }
12721270
else
12731271
raise ArgumentError.new(_("Can only delete from an Array or Hash."))

lib/puppet/pops/loaders.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,22 +281,22 @@ def load_main_manifest
281281
parser = Parser::EvaluatingParser.singleton
282282
parsed_code = Puppet[:code]
283283
program = if parsed_code != ""
284-
parser.parse_string(parsed_code, 'unknown-source-location')
285-
else
286-
file = @environment.manifest
287-
288-
# if the manifest file is a reference to a directory, parse and combine
289-
# all .pp files in that directory
290-
if file == Puppet::Node::Environment::NO_MANIFEST
291-
nil
292-
elsif File.directory?(file)
293-
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints directory '#{file}'. It must be a file"
294-
elsif File.exist?(file)
295-
parser.parse_file(file)
296-
else
297-
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints '#{file}'. It does not exist"
298-
end
299-
end
284+
parser.parse_string(parsed_code, 'unknown-source-location')
285+
else
286+
file = @environment.manifest
287+
288+
# if the manifest file is a reference to a directory, parse and
289+
# combine all .pp files in that directory
290+
if file == Puppet::Node::Environment::NO_MANIFEST
291+
nil
292+
elsif File.directory?(file)
293+
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints directory '#{file}'. It must be a file"
294+
elsif File.exist?(file)
295+
parser.parse_file(file)
296+
else
297+
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints '#{file}'. It does not exist"
298+
end
299+
end
300300
instantiate_definitions(program, public_environment_loader) unless program.nil?
301301
program
302302
rescue Puppet::ParseErrorWithIssue => detail

lib/puppet/pops/lookup/function_provider.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def load_function(lookup_invocation)
8484
loaders = lookup_invocation.scope.compiler.loaders
8585
typed_name = Loader::TypedName.new(:function, @function_name)
8686
loader = if typed_name.qualified?
87-
qualifier = typed_name.name_parts[0]
88-
qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
89-
else
90-
loaders.private_environment_loader
91-
end
87+
qualifier = typed_name.name_parts[0]
88+
qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
89+
else
90+
loaders.private_environment_loader
91+
end
9292
te = loader.load_typed(typed_name)
9393
if te.nil? || te.value.nil?
9494
@parent_data_provider.config(lookup_invocation).fail(Issues::HIERA_DATA_PROVIDER_FUNCTION_NOT_FOUND,

lib/puppet/pops/lookup/hiera_config.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,12 @@ def create_configured_data_providers(lookup_invocation, parent_data_provider, us
626626

627627
compiler = Puppet.lookup(:pal_compiler) { nil }
628628
config_key = if compiler.is_a?(Puppet::Pal::ScriptCompiler) && !@config[KEY_PLAN_HIERARCHY].nil?
629-
KEY_PLAN_HIERARCHY
630-
elsif use_default_hierarchy
631-
KEY_DEFAULT_HIERARCHY
632-
else
633-
KEY_HIERARCHY
634-
end
629+
KEY_PLAN_HIERARCHY
630+
elsif use_default_hierarchy
631+
KEY_DEFAULT_HIERARCHY
632+
else
633+
KEY_HIERARCHY
634+
end
635635
@config[config_key].each do |he|
636636
name = he[KEY_NAME]
637637
if data_providers.include?(name)

lib/puppet/pops/lookup/lookup_adapter.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,12 @@ def retrieve_lookup_options(module_name, lookup_invocation, merge_strategy)
353353
catch(:no_such_key) do
354354
module_opts = validate_lookup_options(lookup_in_module(LookupKey::LOOKUP_OPTIONS, meta_invocation, merge_strategy), module_name)
355355
opts = if opts.nil?
356-
module_opts
357-
elsif module_opts
358-
merge_strategy.lookup([GLOBAL_ENV_MERGE, "Module #{lookup_invocation.module_name}"], meta_invocation) do |n|
359-
meta_invocation.with(:scope, n) { meta_invocation.report_found(LOOKUP_OPTIONS, n == GLOBAL_ENV_MERGE ? opts : module_opts) }
360-
end
361-
end
356+
module_opts
357+
elsif module_opts
358+
merge_strategy.lookup([GLOBAL_ENV_MERGE, "Module #{lookup_invocation.module_name}"], meta_invocation) do |n|
359+
meta_invocation.with(:scope, n) { meta_invocation.report_found(LOOKUP_OPTIONS, n == GLOBAL_ENV_MERGE ? opts : module_opts) }
360+
end
361+
end
362362
end
363363
end
364364
compile_patterns(opts)

0 commit comments

Comments
 (0)