Skip to content

Commit

Permalink
Layout/ElseAlignment
Browse files Browse the repository at this point in the history
This commit enables the Rubocop Layout/ElseAlignment cop.
  • Loading branch information
mhashizume committed Dec 18, 2023
1 parent 9c92126 commit 68c7711
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 96 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Layout/CommentIndentation:
Layout/DotPosition:
Enabled: true

Layout/ElseAlignment:
Enabled: true
Exclude:
- 'lib/puppet/provider/package/*.rb'

# puppet uses symbol booleans in types and providers to work around long standing
# bugs when trying to manage falsey pararameters and properties
Lint/BooleanSymbol:
Expand Down
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ Layout/CaseIndentation:
Layout/ClosingHeredocIndentation:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/ElseAlignment:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Enabled: false
Expand Down
40 changes: 20 additions & 20 deletions lib/puppet/graph/simple_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,26 +507,26 @@ def initialize_from_hash(hash)
def to_data_hash
hash = { 'edges' => edges.map(&:to_data_hash) }
hash['vertices'] = if self.class.use_new_yaml_format
vertices
else
# Represented in YAML using the old (version 2.6) format.
result = {}
vertices.each do |vertex|
adjacencies = {}
[:in, :out].each do |direction|
direction_hash = {}
adjacencies[direction.to_s] = direction_hash
adjacent(vertex, :direction => direction, :type => :edges).each do |edge|
other_vertex = direction == :in ? edge.source : edge.target
(direction_hash[other_vertex.to_s] ||= []) << edge
end
direction_hash.each_pair { |key, edges| direction_hash[key] = edges.uniq.map(&:to_data_hash) }
end
vname = vertex.to_s
result[vname] = { 'adjacencies' => adjacencies, 'vertex' => vname }
end
result
end
vertices
else
# Represented in YAML using the old (version 2.6) format.
result = {}
vertices.each do |vertex|
adjacencies = {}
[:in, :out].each do |direction|
direction_hash = {}
adjacencies[direction.to_s] = direction_hash
adjacent(vertex, :direction => direction, :type => :edges).each do |edge|
other_vertex = direction == :in ? edge.source : edge.target
(direction_hash[other_vertex.to_s] ||= []) << edge
end
direction_hash.each_pair { |key, edges| direction_hash[key] = edges.uniq.map(&:to_data_hash) }
end
vname = vertex.to_s
result[vname] = { 'adjacencies' => adjacencies, 'vertex' => vname }
end
result
end
hash
end

Expand Down
21 changes: 13 additions & 8 deletions lib/puppet/pal/task_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ def initialize(task)
def runnable_with?(args_hash)
params = @task.parameters
params_type = if params.nil?
T_GENERIC_TASK_HASH
else
Puppet::Pops::Types::TypeFactory.struct(params)
end
T_GENERIC_TASK_HASH
else
Puppet::Pops::Types::TypeFactory.struct(params)
end
return true if params_type.instance?(args_hash)

if block_given?
tm = Puppet::Pops::Types::TypeMismatchDescriber.singleton
error = if params.nil?
tm.describe_mismatch('', params_type, Puppet::Pops::Types::TypeCalculator.infer_set(args_hash))
else
tm.describe_struct_signature(params_type, args_hash).flatten.map {|e| e.format }.join("\n")
end
tm.describe_mismatch('', params_type,
Puppet::Pops::Types::TypeCalculator
.infer_set(args_hash))
else
tm.describe_struct_signature(params_type, args_hash)
.flatten
.map {|e| e.format }
.join("\n")
end
yield "Task #{@task.name}:\n#{error}"
end
false
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def exist?(name)
else
other_scope.exist?(variable_name)
end
else
else # rubocop:disable Layout/ElseAlignment
next_scope = inherited_scope || enclosing_scope
effective_symtable(true).include?(name) || next_scope && next_scope.exist?(name) || BUILT_IN_VARS.include?(name)
end
Expand Down
32 changes: 16 additions & 16 deletions lib/puppet/pops/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,22 @@ def load_main_manifest
parser = Parser::EvaluatingParser.singleton
parsed_code = Puppet[:code]
program = if parsed_code != ""
parser.parse_string(parsed_code, 'unknown-source-location')
else
file = @environment.manifest

# if the manifest file is a reference to a directory, parse and combine
# all .pp files in that directory
if file == Puppet::Node::Environment::NO_MANIFEST
nil
elsif File.directory?(file)
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints directory '#{file}'. It must be a file"
elsif File.exist?(file)
parser.parse_file(file)
else
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints '#{file}'. It does not exist"
end
end
parser.parse_string(parsed_code, 'unknown-source-location')
else
file = @environment.manifest

# if the manifest file is a reference to a directory, parse and
# combine all .pp files in that directory
if file == Puppet::Node::Environment::NO_MANIFEST
nil
elsif File.directory?(file)
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints directory '#{file}'. It must be a file"
elsif File.exist?(file)
parser.parse_file(file)
else
raise Puppet::Error, "manifest of environment '#{@environment.name}' appoints '#{file}'. It does not exist"
end
end
instantiate_definitions(program, public_environment_loader) unless program.nil?
program
rescue Puppet::ParseErrorWithIssue => detail
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/pops/lookup/function_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def load_function(lookup_invocation)
loaders = lookup_invocation.scope.compiler.loaders
typed_name = Loader::TypedName.new(:function, @function_name)
loader = if typed_name.qualified?
qualifier = typed_name.name_parts[0]
qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
else
loaders.private_environment_loader
end
qualifier = typed_name.name_parts[0]
qualifier == 'environment' ? loaders.private_environment_loader : loaders.private_loader_for_module(qualifier)
else
loaders.private_environment_loader
end
te = loader.load_typed(typed_name)
if te.nil? || te.value.nil?
@parent_data_provider.config(lookup_invocation).fail(Issues::HIERA_DATA_PROVIDER_FUNCTION_NOT_FOUND,
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/pops/lookup/hiera_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,12 @@ def create_configured_data_providers(lookup_invocation, parent_data_provider, us

compiler = Puppet.lookup(:pal_compiler) { nil }
config_key = if compiler.is_a?(Puppet::Pal::ScriptCompiler) && !@config[KEY_PLAN_HIERARCHY].nil?
KEY_PLAN_HIERARCHY
elsif use_default_hierarchy
KEY_DEFAULT_HIERARCHY
else
KEY_HIERARCHY
end
KEY_PLAN_HIERARCHY
elsif use_default_hierarchy
KEY_DEFAULT_HIERARCHY
else
KEY_HIERARCHY
end
@config[config_key].each do |he|
name = he[KEY_NAME]
if data_providers.include?(name)
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/pops/lookup/lookup_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ def retrieve_lookup_options(module_name, lookup_invocation, merge_strategy)
catch(:no_such_key) do
module_opts = validate_lookup_options(lookup_in_module(LookupKey::LOOKUP_OPTIONS, meta_invocation, merge_strategy), module_name)
opts = if opts.nil?
module_opts
elsif module_opts
merge_strategy.lookup([GLOBAL_ENV_MERGE, "Module #{lookup_invocation.module_name}"], meta_invocation) do |n|
meta_invocation.with(:scope, n) { meta_invocation.report_found(LOOKUP_OPTIONS, n == GLOBAL_ENV_MERGE ? opts : module_opts) }
end
end
module_opts
elsif module_opts
merge_strategy.lookup([GLOBAL_ENV_MERGE, "Module #{lookup_invocation.module_name}"], meta_invocation) do |n|
meta_invocation.with(:scope, n) { meta_invocation.report_found(LOOKUP_OPTIONS, n == GLOBAL_ENV_MERGE ? opts : module_opts) }
end
end
end
end
compile_patterns(opts)
Expand Down
15 changes: 10 additions & 5 deletions lib/puppet/transaction/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ def initialize_from_hash(data)
@resource_statuses = {}
data['resource_statuses'].map do |key, rs|
@resource_statuses[key] = if rs == Puppet::Resource::EMPTY_HASH
nil
else
# Older versions contain tags that causes Psych to create instances directly
rs.is_a?(Puppet::Resource::Status) ? rs : Puppet::Resource::Status.from_data_hash(rs)
end
nil
else
# Older versions contain tags that causes
# Psych to create instances directly
if rs.is_a?(Puppet::Resource::Status)
rs
else
Puppet::Resource::Status.from_data_hash(rs)
end
end
end
end

Expand Down
36 changes: 18 additions & 18 deletions lib/puppet/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1793,20 +1793,20 @@ def self.provide(name, options = {}, &block)

pname = options[:parent]
parent = if pname
options.delete(:parent)
if pname.is_a? Class
pname
else
provider = self.provider(pname)
if provider
provider
else
raise Puppet::DevError, _("Could not find parent provider %{parent} of %{name}") % { parent: pname, name: name }
end
end
else
Puppet::Provider
end
options.delete(:parent)
if pname.is_a? Class
pname
else
provider = self.provider(pname)
if provider
provider
else
raise Puppet::DevError, _("Could not find parent provider %{parent} of %{name}") % { parent: pname, name: name }
end
end
else
Puppet::Provider
end

options[:resource_type] ||= self

Expand Down Expand Up @@ -2518,10 +2518,10 @@ def parent
return @parent if @parent
parents = catalog.adjacent(self, :direction => :in)
@parent = if parents
parents.shift
else
nil
end
parents.shift
else
nil
end
end

# Returns a reference to this as a string in "Type[name]" format.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/command_line/trollop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def width #:nodoc:
rescue Exception
80
end
else
else
80
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/util/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Puppet::Util::Ldap::Connection
# Return a default connection, using our default settings.
def self.instance
ssl = if Puppet[:ldaptls]
:tls
elsif Puppet[:ldapssl]
true
else
false
end
:tls
elsif Puppet[:ldapssl]
true
else
false
end

options = {}
options[:ssl] = ssl
Expand Down

0 comments on commit 68c7711

Please sign in to comment.