From d6561ce8921a577865eae2d124fc17e760358aaa Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:23 +0100 Subject: [PATCH 01/19] Fix rubocop Style/SpaceInsideBrackets Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 30592284..8cb226d9 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -47,7 +47,7 @@ module Puppet::Parser::Functions else result = Hash[enumerable.map do |k,v| k = k.to_s - [ prefix && !k.start_with?(prefix) ? prefix + k : k, v ] + [prefix && !k.start_with?(prefix) ? prefix + k : k, v] end] end From fc9f4a3e90767c77820b6cf7a73fda622bd3b828 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:24 +0100 Subject: [PATCH 02/19] Fix rubocop Style/SpaceAfterComma Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 8cb226d9..3aea35f4 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -45,7 +45,7 @@ module Puppet::Parser::Functions prefix && !i.start_with?(prefix) ? prefix + i : i end else - result = Hash[enumerable.map do |k,v| + result = Hash[enumerable.map do |k, v| k = k.to_s [prefix && !k.start_with?(prefix) ? prefix + k : k, v] end] From 12acd17e4c1ed5054c18dd6a90647fae1ea881b7 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:25 +0100 Subject: [PATCH 03/19] Fix rubocop Style/EmptyLinesAroundBlockBody Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 690f069c..6f353334 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -133,5 +133,4 @@ def uninstall def update install(false) end - end From 8c7d31d095289eb3f2dead132b41bdde729a02fe Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:26 +0100 Subject: [PATCH 04/19] Rubocop: Indentation fixes The following cops are fixed in this commit. `Style/ClosingParenthesisIndentation` `Style/CaseIndentation` `Style/IndentationWidth` `Style/IndentationConsistency` Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- .../parser/functions/to_hash_settings.rb | 2 +- lib/puppet/provider/package/pear.rb | 36 +++++++++---------- lib/puppet/provider/package/pecl.rb | 10 +++--- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 3aea35f4..50464613 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -19,7 +19,7 @@ module Puppet::Parser::Functions Will return: ['p.a', 'p.b', 'p.c'] EOS - ) do |arguments| + ) do |arguments| raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' + "given (#{arguments.size} for 2)") if arguments.size < 2 diff --git a/lib/puppet/parser/functions/to_hash_settings.rb b/lib/puppet/parser/functions/to_hash_settings.rb index 70975ec7..e78326a3 100644 --- a/lib/puppet/parser/functions/to_hash_settings.rb +++ b/lib/puppet/parser/functions/to_hash_settings.rb @@ -24,7 +24,7 @@ module Puppet::Parser::Functions 'foo: b' => {'key' => 'b', 'value' => 2} } EOS - ) do |arguments| + ) do |arguments| hash, id = arguments id = (id.nil? ? '' : "#{id}: ") diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 6f353334..47b14c57 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -59,19 +59,19 @@ def self.pearsplit(desc, channel) desc.strip! case desc - when %r{^$} then return nil - when %r{^INSTALLED}i then return nil - when %r{no packages installed}i then return nil - when %r{^=} then return nil - when %r{^PACKAGE}i then return nil - when %r{^(\S+)\s+(\S+)\s+(\S+)\s*$} then - name = $1 - version = $2 - state = $3 - return { - name: "#{channel}/#{name}", - ensure: state == 'stable' ? version : state - } + when %r{^$} then return nil + when %r{^INSTALLED}i then return nil + when %r{no packages installed}i then return nil + when %r{^=} then return nil + when %r{^PACKAGE}i then return nil + when %r{^(\S+)\s+(\S+)\s+(\S+)\s*$} then + name = $1 + version = $2 + state = $3 + return { + name: "#{channel}/#{name}", + ensure: state == 'stable' ? version : state + } else Puppet.debug "Could not match '%s'" % desc nil @@ -109,12 +109,12 @@ def latest # This always gets the latest version available. version = '' command = [command(:pearcmd), 'remote-info', @resource[:name]] - list = execute(command).split("\n") - list = list.collect do |set| - if set =~ %r{^Latest} - version = set.split[1] - end + list = execute(command).split("\n") + list = list.collect do |set| + if set =~ %r{^Latest} + version = set.split[1] end + end version end diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 66035d65..d7999452 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -8,10 +8,10 @@ has_feature :upgradeable case Facter.value(:operatingsystem) - when 'Solaris' - commands peclcmd: '/opt/coolstack/php5/bin/pecl' + when 'Solaris' + commands peclcmd: '/opt/coolstack/php5/bin/pecl' else - commands peclcmd: 'pecl' + commands peclcmd: 'pecl' end def self.pecllist(hash) @@ -98,8 +98,8 @@ def install(useversion = true) end if pipe = @resource[:pipe] - command << '<<<' - command << @resource[:pipe] + command << '<<<' + command << @resource[:pipe] end peclcmd(*command) From 0b0c1b7c8d79bce24dd2da8d26e9736a4a9fec39 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:27 +0100 Subject: [PATCH 05/19] Fix rubocop Style/ElseAlignment Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pecl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index d7999452..2aee66a9 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -10,7 +10,7 @@ case Facter.value(:operatingsystem) when 'Solaris' commands peclcmd: '/opt/coolstack/php5/bin/pecl' - else + else commands peclcmd: 'pecl' end From ea5b7ec55f4285e9f2f2213f67446a731029b362 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:28 +0100 Subject: [PATCH 06/19] Fix rubocop Lint/BlockAlignment Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 47b14c57..c540dd91 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -111,10 +111,10 @@ def latest command = [command(:pearcmd), 'remote-info', @resource[:name]] list = execute(command).split("\n") list = list.collect do |set| - if set =~ %r{^Latest} - version = set.split[1] + if set =~ %r{^Latest} + version = set.split[1] + end end - end version end From 5a357fffcc80a4dba1e211bb6907574834377fc3 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:29 +0100 Subject: [PATCH 07/19] Fix rubocop Style/LineEndConcatenation Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 50464613..e28d9363 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -21,7 +21,7 @@ module Puppet::Parser::Functions EOS ) do |arguments| - raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' + + raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' \ "given (#{arguments.size} for 2)") if arguments.size < 2 enumerable = arguments[0] From ea4e94d944339617d327c717da3af4dc00243b2f Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:29 +0100 Subject: [PATCH 08/19] Fix rubocop Style/AndOr Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- lib/puppet/provider/package/pear.rb | 2 +- lib/puppet/provider/package/pecl.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index e28d9363..a56caee3 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -26,7 +26,7 @@ module Puppet::Parser::Functions enumerable = arguments[0] - unless enumerable.is_a?(Array) or enumerable.is_a?(Hash) + unless enumerable.is_a?(Array) || enumerable.is_a?(Hash) raise Puppet::ParseError, "ensure_prefix(): expected first argument to be an Array or a Hash, got #{enumerable.inspect}" end diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index c540dd91..26d96100 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -95,7 +95,7 @@ def install(useversion = true) if source = @resource[:source] command << source else - if (!@resource.should(:ensure).is_a? Symbol) and useversion + if (!@resource.should(:ensure).is_a? Symbol) && useversion command << "#{@resource[:name]}-#{@resource.should(:ensure)}" else command << @resource[:name] diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 2aee66a9..98e9e628 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -89,7 +89,7 @@ def install(useversion = true) if source = @resource[:source] command << source else - if (!@resource.should(:ensure).is_a? Symbol) and useversion + if (!@resource.should(:ensure).is_a? Symbol) && useversion command << '-f' command << "#{peclname}-#{@resource.should(:ensure)}" else From 8f304b103a16b814c1bb9744265d9482b4d78600 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:30 +0100 Subject: [PATCH 09/19] Fix rubocop Style/ExtraSpacing Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pecl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 98e9e628..e6cb7585 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -58,7 +58,7 @@ def self.peclsplit(desc) when %r{No packages installed from channel}i then return nil when %r{^=} then return nil when %r{^PACKAGE} then return nil - when %r{\[1m} then return nil # Newer versions of PEAR use colorized output + when %r{\[1m} then return nil # Newer versions of PEAR use colorized output when %r{^(\S+)\s+(\S+)\s+\S+} then name = $1 version = $2 From e53ec47a39490d6ea0f687c3cd5bd56ea518b496 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:31 +0100 Subject: [PATCH 10/19] Fix rubocop Style/FormatString Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 4 ++-- lib/puppet/provider/package/pecl.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 26d96100..05940f8f 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -45,7 +45,7 @@ def self.pearlist(hash) end.reject { |p| p.nil? } rescue Puppet::ExecutionFailure => detail - raise Puppet::Error, 'Could not list pears: %s' % detail + raise Puppet::Error, format('Could not list pears: %s', detail) end if hash[:justme] @@ -73,7 +73,7 @@ def self.pearsplit(desc, channel) ensure: state == 'stable' ? version : state } else - Puppet.debug "Could not match '%s'" % desc + Puppet.debug format("Could not match '%s'", desc) nil end end diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index e6cb7585..a1eb1372 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -40,7 +40,7 @@ def self.pecllist(hash) end end.reject { |p| p.nil? } rescue Puppet::ExecutionFailure => detail - raise Puppet::Error, 'Could not list pecls: %s' % detail + raise Puppet::Error, format('Could not list pecls: %s', detail) end if hash[:justme] @@ -68,7 +68,7 @@ def self.peclsplit(desc) ensure: version } else - Puppet.warning 'Could not match %s' % desc + Puppet.warning format('Could not match %s', desc) nil end end From 9e07a186e76f3cf64d17d35b9941b04849bfa9d2 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:32 +0100 Subject: [PATCH 11/19] Fix rubocop Style/PerlBackrefs Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 6 +++--- lib/puppet/provider/package/pecl.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 05940f8f..d9939d98 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -65,9 +65,9 @@ def self.pearsplit(desc, channel) when %r{^=} then return nil when %r{^PACKAGE}i then return nil when %r{^(\S+)\s+(\S+)\s+(\S+)\s*$} then - name = $1 - version = $2 - state = $3 + name = Regexp.last_match(1) + version = Regexp.last_match(2) + state = Regexp.last_match(3) return { name: "#{channel}/#{name}", ensure: state == 'stable' ? version : state diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index a1eb1372..311c7208 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -60,8 +60,8 @@ def self.peclsplit(desc) when %r{^PACKAGE} then return nil when %r{\[1m} then return nil # Newer versions of PEAR use colorized output when %r{^(\S+)\s+(\S+)\s+\S+} then - name = $1 - version = $2 + name = Regexp.last_match(1) + version = Regexp.last_match(2) return { name: "pecl-#{name.downcase}", From 6593116472a6d25b237b9e8f31b2f3d5857970c9 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:33 +0100 Subject: [PATCH 12/19] Fix rubocop Style/CollectionMethods Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 2 +- lib/puppet/provider/package/pear.rb | 6 +++--- lib/puppet/provider/package/pecl.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index a56caee3..611aef65 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -40,7 +40,7 @@ module Puppet::Parser::Functions if enumerable.is_a?(Array) # Turn everything into string same as join would do ... - result = enumerable.collect do |i| + result = enumerable.map do |i| i = i.to_s prefix && !i.start_with?(prefix) ? prefix + i : i end diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index d9939d98..732c463b 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -21,7 +21,7 @@ def self.pearlist(hash) begin list = execute(command).split("\n") - list = list.collect do |set| + list = list.map do |set| if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) channel = match[1].downcase end @@ -79,7 +79,7 @@ def self.pearsplit(desc, channel) end def self.instances - pearlist(local: true).collect do |hash| + pearlist(local: true).map do |hash| new(hash) end end @@ -110,7 +110,7 @@ def latest version = '' command = [command(:pearcmd), 'remote-info', @resource[:name]] list = execute(command).split("\n") - list = list.collect do |set| + list = list.map do |set| if set =~ %r{^Latest} version = set.split[1] end diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 311c7208..82115c37 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -18,7 +18,7 @@ def self.pecllist(hash) command = [command(:peclcmd), 'list'] begin - list = execute(command).split("\n").collect do |set| + list = execute(command).split("\n").map do |set| if hash[:justme] if %r{^#{hash[:justme]}$}i.match(set) if peclhash = peclsplit(set) @@ -74,7 +74,7 @@ def self.peclsplit(desc) end def self.instances - pecllist(local: true).collect do |hash| + pecllist(local: true).map do |hash| new(hash) end end From f45de7b9bcd11d95995ee11b1f5252c31ede56de Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:34 +0100 Subject: [PATCH 13/19] Fix rubocop Style/GuardClause Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 12 +++--------- lib/puppet/provider/package/pecl.rb | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 732c463b..04faaed6 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -48,11 +48,8 @@ def self.pearlist(hash) raise Puppet::Error, format('Could not list pears: %s', detail) end - if hash[:justme] - return list.shift - else - return list - end + return list.shift if hash[:justme] + list end def self.pearsplit(desc, channel) @@ -124,10 +121,7 @@ def query def uninstall output = pearcmd 'uninstall', @resource[:name] - if output =~ %r{^uninstall ok} - else - raise Puppet::Error, output - end + raise Puppet::Error, output unless output =~ %r{^uninstall ok} end def update diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 82115c37..812d3f67 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -43,11 +43,8 @@ def self.pecllist(hash) raise Puppet::Error, format('Could not list pecls: %s', detail) end - if hash[:justme] - return list.shift - else - return list - end + return list.shift if hash[:justme] + list end def self.peclsplit(desc) @@ -123,10 +120,7 @@ def query def uninstall output = peclcmd 'uninstall', peclname - if output =~ %r{^uninstall ok} - else - raise Puppet::Error, output - end + raise Puppet::Error, output unless output =~ %r{^uninstall ok} end def update From 28263eecc17edcf3d2d62b87460c280837bf20fc Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:35 +0100 Subject: [PATCH 14/19] Rubocop fix Lint/UselessAssignment Refactored `lib/puppet/provider/package/pear.rb` `latest` method to match `latest` in `lib/puppet/provider/package/pecl.rb`. Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 4 ++-- lib/puppet/provider/package/pecl.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 04faaed6..6409cdb8 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -106,12 +106,12 @@ def latest # This always gets the latest version available. version = '' command = [command(:pearcmd), 'remote-info', @resource[:name]] - list = execute(command).split("\n") - list = list.map do |set| + execute(command).each_line do |set| if set =~ %r{^Latest} version = set.split[1] end end + version end diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 812d3f67..6b0026eb 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -94,7 +94,7 @@ def install(useversion = true) end end - if pipe = @resource[:pipe] + if pipe == @resource[:pipe] command << '<<<' command << @resource[:pipe] end @@ -105,7 +105,7 @@ def install(useversion = true) def latest version = '' command = [command(:peclcmd), 'remote-info', peclname] - list = execute(command).each_line do |set| + execute(command).each_line do |set| if set =~ %r{^Latest} version = set.split[1] end From 520f0329b53e29157a0fd233804a9ed77dd7178e Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:31:35 +0100 Subject: [PATCH 15/19] Fix rubocop Style/ConditionalAssignment Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 24 ++++++++-------- lib/puppet/provider/package/pear.rb | 30 ++++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 611aef65..5be2ef55 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -38,18 +38,18 @@ module Puppet::Parser::Functions end end - if enumerable.is_a?(Array) - # Turn everything into string same as join would do ... - result = enumerable.map do |i| - i = i.to_s - prefix && !i.start_with?(prefix) ? prefix + i : i - end - else - result = Hash[enumerable.map do |k, v| - k = k.to_s - [prefix && !k.start_with?(prefix) ? prefix + k : k, v] - end] - end + result = if enumerable.is_a?(Array) + # Turn everything into string same as join would do ... + enumerable.map do |i| + i = i.to_s + prefix && !i.start_with?(prefix) ? prefix + i : i + end + else + Hash[enumerable.map do |k, v| + k = k.to_s + [prefix && !k.start_with?(prefix) ? prefix + k : k, v] + end] + end return result end diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 6409cdb8..0c59ff58 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -83,21 +83,21 @@ def self.instances def install(useversion = true) command = ['-D', 'auto_discover=1', 'upgrade'] - if @resource[:install_options] - command << @resource[:install_options] - else - command << '--alldeps' - end - - if source = @resource[:source] - command << source - else - if (!@resource.should(:ensure).is_a? Symbol) && useversion - command << "#{@resource[:name]}-#{@resource.should(:ensure)}" - else - command << @resource[:name] - end - end + command << if @resource[:install_options] + @resource[:install_options] + else + '--alldeps' + end + + command << if source = @resource[:source] + source + else + if (!@resource.should(:ensure).is_a? Symbol) && useversion + "#{@resource[:name]}-#{@resource.should(:ensure)}" + else + @resource[:name] + end + end pearcmd(*command) end From 420e37f56d7fe9553495102c2495ab1c4e2ab144 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:40:39 +0100 Subject: [PATCH 16/19] Rubocop fix Lint/AssignmentInCondition I've disabled the cop on the instances where `assignment in condition` seemed to make very good sense. Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 8 ++++---- lib/puppet/provider/package/pecl.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 0c59ff58..104ee2c2 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -22,7 +22,7 @@ def self.pearlist(hash) begin list = execute(command).split("\n") list = list.map do |set| - if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) + if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) # rubocop:disable Lint/AssignmentInCondition channel = match[1].downcase end @@ -35,7 +35,7 @@ def self.pearlist(hash) nil end else - if pearhash = pearsplit(set, channel) + if pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition pearhash[:provider] = :pear pearhash else @@ -89,8 +89,8 @@ def install(useversion = true) '--alldeps' end - command << if source = @resource[:source] - source + command << if @resource[:source] + @resource[:source] else if (!@resource.should(:ensure).is_a? Symbol) && useversion "#{@resource[:name]}-#{@resource.should(:ensure)}" diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 6b0026eb..14ee7a63 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -21,7 +21,7 @@ def self.pecllist(hash) list = execute(command).split("\n").map do |set| if hash[:justme] if %r{^#{hash[:justme]}$}i.match(set) - if peclhash = peclsplit(set) + if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition peclhash[:provider] = :peclcmd peclhash else @@ -31,7 +31,7 @@ def self.pecllist(hash) nil end else - if peclhash = peclsplit(set) + if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition peclhash[:provider] = :peclcmd peclhash else @@ -83,8 +83,8 @@ def peclname def install(useversion = true) command = ['upgrade'] - if source = @resource[:source] - command << source + if @resource[:source] + command << @resource[:source] else if (!@resource.should(:ensure).is_a? Symbol) && useversion command << '-f' From fbd0a39139ac93e390f1a9b7cba385bcfbdd0e6d Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:54:59 +0100 Subject: [PATCH 17/19] Fix rubocop Style/IfUnlessModifier Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 4 +--- lib/puppet/provider/package/pecl.rb | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 104ee2c2..21c36123 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -107,9 +107,7 @@ def latest version = '' command = [command(:pearcmd), 'remote-info', @resource[:name]] execute(command).each_line do |set| - if set =~ %r{^Latest} - version = set.split[1] - end + version = set.split[1] if set =~ %r{^Latest} end version diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index 14ee7a63..fbfd9476 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -106,9 +106,7 @@ def latest version = '' command = [command(:peclcmd), 'remote-info', peclname] execute(command).each_line do |set| - if set =~ %r{^Latest} - version = set.split[1] - end + version = set.split[1] if set =~ %r{^Latest} end version From 2538e109a3d0b8617cf6dea6b23d65027fdd7b99 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 18:57:36 +0100 Subject: [PATCH 18/19] Fix rubocop Style/EmptyLinesAroundBlockBody Signed-off-by: Alexander Fisher --- lib/puppet/parser/functions/ensure_prefix.rb | 1 - lib/puppet/parser/functions/to_hash_settings.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_prefix.rb b/lib/puppet/parser/functions/ensure_prefix.rb index 5be2ef55..58bf4135 100644 --- a/lib/puppet/parser/functions/ensure_prefix.rb +++ b/lib/puppet/parser/functions/ensure_prefix.rb @@ -20,7 +20,6 @@ module Puppet::Parser::Functions ['p.a', 'p.b', 'p.c'] EOS ) do |arguments| - raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' \ "given (#{arguments.size} for 2)") if arguments.size < 2 diff --git a/lib/puppet/parser/functions/to_hash_settings.rb b/lib/puppet/parser/functions/to_hash_settings.rb index e78326a3..576180c8 100644 --- a/lib/puppet/parser/functions/to_hash_settings.rb +++ b/lib/puppet/parser/functions/to_hash_settings.rb @@ -25,7 +25,6 @@ module Puppet::Parser::Functions } EOS ) do |arguments| - hash, id = arguments id = (id.nil? ? '' : "#{id}: ") From 6bbdc78177b53b84b6e6e7f27eb0edb21309e6ae Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 23 Sep 2016 19:00:56 +0100 Subject: [PATCH 19/19] Fix rubocop Style/EmptyElse Signed-off-by: Alexander Fisher --- lib/puppet/provider/package/pear.rb | 4 ---- lib/puppet/provider/package/pecl.rb | 6 ------ 2 files changed, 10 deletions(-) diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 21c36123..8150db24 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -31,15 +31,11 @@ def self.pearlist(hash) pearhash = pearsplit(set, channel) pearhash[:provider] = :pear pearhash - else - nil end else if pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition pearhash[:provider] = :pear pearhash - else - nil end end end.reject { |p| p.nil? } diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index fbfd9476..bb4de994 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -24,18 +24,12 @@ def self.pecllist(hash) if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition peclhash[:provider] = :peclcmd peclhash - else - nil end - else - nil end else if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition peclhash[:provider] = :peclcmd peclhash - else - nil end end end.reject { |p| p.nil? }