summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-07 15:19:21 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-07 15:19:21 -0700
commit1485a862053fb20ade1f93bb82c6918cd4078975 (patch)
tree21ae9d81524f56a4b52449424550259422b1b9a5
parent3e9e6d41a31bd1ac932f7f4100102466b4fdfe05 (diff)
downloadchef-1485a862053fb20ade1f93bb82c6918cd4078975.tar.gz
Avoid assigning variables before returning if we don't have to
These seemed pretty straight forward. There's a new Rubocop cop for these. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/chef_fs/data_handler/organization_data_handler.rb3
-rw-r--r--lib/chef/cookbook/remote_file_vendor.rb4
-rw-r--r--lib/chef/cookbook/syntax_check.rb3
-rw-r--r--lib/chef/data_bag.rb3
-rw-r--r--lib/chef/environment.rb3
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb3
-rw-r--r--lib/chef/mixin/openssl_helper.rb3
-rw-r--r--lib/chef/provider/package/snap.rb3
-rw-r--r--lib/chef/resource/chocolatey_feature.rb3
-rw-r--r--lib/chef/resource/openssl_x509_certificate.rb25
-rw-r--r--lib/chef/resource/openssl_x509_crl.rb3
-rw-r--r--lib/chef/role.rb3
-rw-r--r--lib/chef/win32/registry.rb3
13 files changed, 23 insertions, 39 deletions
diff --git a/lib/chef/chef_fs/data_handler/organization_data_handler.rb b/lib/chef/chef_fs/data_handler/organization_data_handler.rb
index f107e8920b..01d227ffaf 100644
--- a/lib/chef/chef_fs/data_handler/organization_data_handler.rb
+++ b/lib/chef/chef_fs/data_handler/organization_data_handler.rb
@@ -5,14 +5,13 @@ class Chef
module DataHandler
class OrganizationDataHandler < DataHandlerBase
def normalize(organization, entry)
- result = normalize_hash(organization, {
+ normalize_hash(organization, {
"name" => entry.org,
"full_name" => entry.org,
"org_type" => "Business",
"clientname" => "#{entry.org}-validator",
"billing_plan" => "platform-free",
})
- result
end
def preserve_key?(key)
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb
index e2a9798c8a..a6a6e96e06 100644
--- a/lib/chef/cookbook/remote_file_vendor.rb
+++ b/lib/chef/cookbook/remote_file_vendor.rb
@@ -72,10 +72,8 @@ class Chef
Chef::Log.trace("Current checksum: #{current_checksum}; manifest checksum: #{found_manifest_record["checksum"]})")
end
- full_path_cache_filename = Chef::FileCache.load(cache_filename, false)
-
# return the filename, not the contents (second argument= false)
- full_path_cache_filename
+ Chef::FileCache.load(cache_filename, false)
end
def validate_cached_copy(cache_filename)
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index a654103a53..8b593eea81 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -120,8 +120,7 @@ class Chef
path = Chef::Util::PathHelper.escape_glob_dir(cookbook_path)
files = Dir[File.join(path, "**", "*.rb")]
files = remove_ignored_files(files)
- files = remove_uninteresting_ruby_files(files)
- files
+ remove_uninteresting_ruby_files(files)
end
def untested_ruby_files
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 6be18dad58..af0560a640 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -59,12 +59,11 @@ class Chef
end
def to_h
- result = {
+ {
"name" => @name,
"json_class" => self.class.name,
"chef_type" => "data_bag",
}
- result
end
alias_method :to_hash, :to_h
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index 8a143632f1..c121e37880 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -119,7 +119,7 @@ class Chef
end
def to_h
- result = {
+ {
"name" => @name,
"description" => @description,
"cookbook_versions" => @cookbook_versions,
@@ -128,7 +128,6 @@ class Chef
"default_attributes" => @default_attributes,
"override_attributes" => @override_attributes,
}
- result
end
alias_method :to_hash, :to_h
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index 63d5ef9b51..8469879022 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -52,8 +52,7 @@ class Chef
# will be interpreted by ruby later and do the right thing.
def cleanpath(path)
path = Pathname.new(path).cleanpath.to_s
- path = path.gsub(File::SEPARATOR, '\\')
- path
+ path.gsub(File::SEPARATOR, '\\')
end
def validation_key
diff --git a/lib/chef/mixin/openssl_helper.rb b/lib/chef/mixin/openssl_helper.rb
index a30ccb5f69..1321bccfee 100644
--- a/lib/chef/mixin/openssl_helper.rb
+++ b/lib/chef/mixin/openssl_helper.rb
@@ -369,8 +369,7 @@ class Chef
revoked.add_extension(ext)
crl.add_revoked(revoked)
- crl = renew_x509_crl(crl, ca_private_key, info)
- crl
+ renew_x509_crl(crl, ca_private_key, info)
end
# renew a X509 crl given
diff --git a/lib/chef/provider/package/snap.rb b/lib/chef/provider/package/snap.rb
index 338f2ec510..921227ad06 100644
--- a/lib/chef/provider/package/snap.rb
+++ b/lib/chef/provider/package/snap.rb
@@ -304,7 +304,7 @@ class Chef
SNAP_OPTION
end
- multipart_form_data = <<~SNAP_S
+ <<~SNAP_S
Host:
Content-Type: multipart/form-data; boundary=#{snap_name}
Content-Length: #{content_length}
@@ -320,7 +320,6 @@ class Chef
<#{content_length} bytes of snap file data>
--#{snap_name}
SNAP_S
- multipart_form_data
end
# Constructs json to post for snap changes
diff --git a/lib/chef/resource/chocolatey_feature.rb b/lib/chef/resource/chocolatey_feature.rb
index 3b24ebbc9c..66752fbd5d 100644
--- a/lib/chef/resource/chocolatey_feature.rb
+++ b/lib/chef/resource/chocolatey_feature.rb
@@ -89,8 +89,7 @@ class Chef
# @param [String] action the name of the action to perform
# @return [String] the choco feature command string
def choco_cmd(action)
- cmd = "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\bin\\choco feature #{action} --name #{new_resource.feature_name}"
- cmd
+ "#{ENV["ALLUSERSPROFILE"]}\\chocolatey\\bin\\choco feature #{action} --name #{new_resource.feature_name}"
end
end
end
diff --git a/lib/chef/resource/openssl_x509_certificate.rb b/lib/chef/resource/openssl_x509_certificate.rb
index a81b50d9b9..7b54ad2d6b 100644
--- a/lib/chef/resource/openssl_x509_certificate.rb
+++ b/lib/chef/resource/openssl_x509_certificate.rb
@@ -206,12 +206,11 @@ class Chef
end
def request
- request = if new_resource.csr_file.nil?
- gen_x509_request(subject, key)
- else
- OpenSSL::X509::Request.new ::File.read(new_resource.csr_file)
- end
- request
+ if new_resource.csr_file.nil?
+ gen_x509_request(subject, key)
+ else
+ OpenSSL::X509::Request.new ::File.read(new_resource.csr_file)
+ end
end
def subject
@@ -227,12 +226,11 @@ class Chef
end
def ca_private_key
- ca_private_key = if new_resource.csr_file.nil?
- key
- else
- OpenSSL::PKey.read ::File.read(new_resource.ca_key_file), new_resource.ca_key_pass
- end
- ca_private_key
+ if new_resource.csr_file.nil?
+ key
+ else
+ OpenSSL::PKey.read ::File.read(new_resource.ca_key_file), new_resource.ca_key_pass
+ end
end
def ca_info
@@ -258,8 +256,7 @@ class Chef
end
def cert
- cert = gen_x509_cert(request, extensions, ca_info, ca_private_key)
- cert
+ gen_x509_cert(request, extensions, ca_info, ca_private_key)
end
end
end
diff --git a/lib/chef/resource/openssl_x509_crl.rb b/lib/chef/resource/openssl_x509_crl.rb
index 0a1abf577f..bd3c650c40 100644
--- a/lib/chef/resource/openssl_x509_crl.rb
+++ b/lib/chef/resource/openssl_x509_crl.rb
@@ -113,8 +113,7 @@ class Chef
end
def ca_private_key
- ca_private_key = ::OpenSSL::PKey.read ::File.read(new_resource.ca_key_file), new_resource.ca_key_pass
- ca_private_key
+ ::OpenSSL::PKey.read ::File.read(new_resource.ca_key_file), new_resource.ca_key_pass
end
def crl
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index 6125139ffe..9142f85d15 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -133,7 +133,7 @@ class Chef
def to_h
env_run_lists_without_default = @env_run_lists.dup
env_run_lists_without_default.delete("_default")
- result = {
+ {
"name" => @name,
"description" => @description,
"json_class" => self.class.name,
@@ -149,7 +149,6 @@ class Chef
accumulator
end,
}
- result
end
alias_method :to_hash, :to_h
diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb
index c31ae50e0b..6a9f229b27 100644
--- a/lib/chef/win32/registry.rb
+++ b/lib/chef/win32/registry.rb
@@ -341,7 +341,7 @@ class Chef
end
def get_type_from_num(val_type)
- value = {
+ {
3 => ::Win32::Registry::REG_BINARY,
1 => ::Win32::Registry::REG_SZ,
7 => ::Win32::Registry::REG_MULTI_SZ,
@@ -350,7 +350,6 @@ class Chef
5 => ::Win32::Registry::REG_DWORD_BIG_ENDIAN,
11 => ::Win32::Registry::REG_QWORD,
}[val_type]
- value
end
def create_missing(key_path)