diff --git a/.rubocop.yml b/.rubocop.yml index cb19243c244..9692ff093f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 70b6dd5d7f1..bdc85014ef8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/lib/puppet/graph/simple_graph.rb b/lib/puppet/graph/simple_graph.rb index 6cb8d3bcd15..e07ccf4420d 100644 --- a/lib/puppet/graph/simple_graph.rb +++ b/lib/puppet/graph/simple_graph.rb @@ -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 diff --git a/lib/puppet/pal/task_signature.rb b/lib/puppet/pal/task_signature.rb index a126bd4150e..889cddf24f3 100644 --- a/lib/puppet/pal/task_signature.rb +++ b/lib/puppet/pal/task_signature.rb @@ -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 diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index a077f658be7..b8aee890f7b 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -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 diff --git a/lib/puppet/pops/loaders.rb b/lib/puppet/pops/loaders.rb index 389895b16d1..23103ea6531 100644 --- a/lib/puppet/pops/loaders.rb +++ b/lib/puppet/pops/loaders.rb @@ -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 diff --git a/lib/puppet/pops/lookup/function_provider.rb b/lib/puppet/pops/lookup/function_provider.rb index dffc3f5d86c..1d703e4b6ba 100644 --- a/lib/puppet/pops/lookup/function_provider.rb +++ b/lib/puppet/pops/lookup/function_provider.rb @@ -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, diff --git a/lib/puppet/pops/lookup/hiera_config.rb b/lib/puppet/pops/lookup/hiera_config.rb index 63ceda3f1cf..234fd12daac 100644 --- a/lib/puppet/pops/lookup/hiera_config.rb +++ b/lib/puppet/pops/lookup/hiera_config.rb @@ -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) diff --git a/lib/puppet/pops/lookup/lookup_adapter.rb b/lib/puppet/pops/lookup/lookup_adapter.rb index 72b778eb0cb..99bc880e4a1 100644 --- a/lib/puppet/pops/lookup/lookup_adapter.rb +++ b/lib/puppet/pops/lookup/lookup_adapter.rb @@ -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) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 25205eb4cf7..01fcbcaf771 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -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 diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 1e00a1ef193..f7ac9e0fb23 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -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 @@ -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. diff --git a/lib/puppet/util/command_line/trollop.rb b/lib/puppet/util/command_line/trollop.rb index e2d7374a73a..18bc3bfe457 100644 --- a/lib/puppet/util/command_line/trollop.rb +++ b/lib/puppet/util/command_line/trollop.rb @@ -536,7 +536,7 @@ def width #:nodoc: rescue Exception 80 end - else + else 80 end end diff --git a/lib/puppet/util/ldap/connection.rb b/lib/puppet/util/ldap/connection.rb index e72d779ffb1..4fd7df0c7c1 100644 --- a/lib/puppet/util/ldap/connection.rb +++ b/lib/puppet/util/ldap/connection.rb @@ -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