From bfdb813a5001821f44837112e0395299158153b0 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Tue, 9 Apr 2024 09:55:18 -0700 Subject: [PATCH 1/2] Simplify conditional in static loader Prior to this commit the static loader class used variable assignment in conditionals unnecessarily and made a comparison (name_authority == Pcore::RUNTIME_NAME_AUTHORITY) that was always true. This commit simplifies the conditionals to both remove the redundant comparison and variable assignment in conditional. --- lib/puppet/pops/loader/static_loader.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/pops/loader/static_loader.rb b/lib/puppet/pops/loader/static_loader.rb index 04f04308b81..7e24e844c27 100644 --- a/lib/puppet/pops/loader/static_loader.rb +++ b/lib/puppet/pops/loader/static_loader.rb @@ -46,9 +46,9 @@ def initialize def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY) # Static loader only contains runtime types - return EMPTY_ARRAY unless type == :type && name_authority == name_authority = Pcore::RUNTIME_NAME_AUTHORITY + return EMPTY_ARRAY unless type == :type && name_authority == Pcore::RUNTIME_NAME_AUTHORITY - typed_names = type == :type && name_authority == Pcore::RUNTIME_NAME_AUTHORITY ? @loaded.keys : EMPTY_ARRAY + typed_names = @loaded.keys block_given? ? typed_names.select { |tn| yield(tn) } : typed_names end From 0cf25bb48e655a6aeba4c820536b9340b6db19d9 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Mon, 8 Apr 2024 13:02:58 -0700 Subject: [PATCH 2/2] Lint/AssignmentInCondition This commit takes variable assignments in conditionals and wraps them in parentheses to make the intention more explicit. --- lib/puppet/util/windows/com.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/util/windows/com.rb b/lib/puppet/util/windows/com.rb index dd38a1de688..b26acd34c01 100644 --- a/lib/puppet/util/windows/com.rb +++ b/lib/puppet/util/windows/com.rb @@ -141,7 +141,7 @@ def initialize(pointer) self::VTBL.members.each do |name| define_method(name) do |*args| - if Puppet::Util::Windows::COM.FAILED(result = @vtbl[name].call(self, *args)) + if Puppet::Util::Windows::COM.FAILED((result = @vtbl[name].call(self, *args))) raise Puppet::Util::Windows::Error.new(_("Failed to call %{klass}::%{name} with HRESULT: %{result}.") % { klass: self, name: name, result: result }, result) end @@ -183,7 +183,7 @@ def initialize(opts = {}) self::VTBL.members.each do |name| define_method(name) do |*args| - if Puppet::Util::Windows::COM.FAILED(result = @vtbl[name].call(self, *args)) + if Puppet::Util::Windows::COM.FAILED((result = @vtbl[name].call(self, *args))) raise Puppet::Util::Windows::Error.new(_("Failed to call %{klass}::%{name} with HRESULT: %{result}.") % { klass: self, name: name, result: result }, result) end