From c031a6182bef7f689b2d80f418ae1b80669168a3 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 14 Mar 2016 11:53:05 -0700 Subject: fix some UselessAssignment cases --- chef-config/lib/chef-config/path_helper.rb | 4 ++-- lib/chef/application/apply.rb | 2 +- lib/chef/application/windows_service.rb | 4 ++-- lib/chef/client.rb | 2 -- lib/chef/config_fetcher.rb | 4 ++-- lib/chef/cookbook_loader.rb | 6 +++--- lib/chef/cookbook_site_streaming_uploader.rb | 1 - lib/chef/deprecation/warnings.rb | 1 - lib/chef/file_access_control/windows.rb | 4 ++-- lib/chef/http/validate_content_length.rb | 1 - lib/chef/knife/cookbook_bulk_delete.rb | 2 +- lib/chef/knife/cookbook_metadata.rb | 1 - lib/chef/knife/cookbook_site_download.rb | 2 +- lib/chef/knife/core/custom_manifest_loader.rb | 2 +- 14 files changed, 15 insertions(+), 21 deletions(-) diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 0c00e116ea..0304694516 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -66,7 +66,7 @@ module ChefConfig args.flatten.inject() do |joined_path, component| joined_path = joined_path.sub(trailing_slashes, "") component = component.sub(leading_slashes, "") - joined_path += "#{path_separator}#{component}" + joined_path + "#{path_separator}#{component}" end end @@ -250,7 +250,7 @@ module ChefConfig # Determine if the given path is protected by OS X System Integrity Protection. def self.is_sip_path?(path, node) - if node["platform"] == "mac_os_x" and Gem::Version.new(node["platform_version"]) >= Gem::Version.new("10.11") + if node["platform"] == "mac_os_x" && Gem::Version.new(node["platform_version"]) >= Gem::Version.new("10.11") # todo: parse rootless.conf for this? sip_paths = [ "/System", "/bin", "/sbin", "/usr" diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb index 38b00f293c..03c86b86f2 100644 --- a/lib/chef/application/apply.rb +++ b/lib/chef/application/apply.rb @@ -204,7 +204,7 @@ class Chef::Application::Apply < Chef::Application parse_options run_chef_recipe Chef::Application.exit! "Exiting", 0 - rescue SystemExit => e + rescue SystemExit raise rescue Exception => e Chef::Application.debug_stacktrace(e) diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 0328a65487..fca1ed3689 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -312,13 +312,13 @@ class Chef else ::File.open(config[:config_file]) { |f| apply_config(f.path) } end - rescue Errno::ENOENT => error + rescue Errno::ENOENT Chef::Log.warn("*****************************************") Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.") Chef::Log.warn("*****************************************") Chef::Config.merge!(config) - rescue SocketError => error + rescue SocketError Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2) rescue Chef::Exceptions::ConfigurationError => error Chef::Application.fatal!("Error processing config file #{Chef::Config[:config_file]} with error #{error.message}", 2) diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 7d2dcf8057..8ca0fd5e89 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -312,9 +312,7 @@ class Chef events.run_failed(run_error) ensure Chef::RequestID.instance.reset_request_id - request_id = nil @run_status = nil - run_context = nil runlock.release end diff --git a/lib/chef/config_fetcher.rb b/lib/chef/config_fetcher.rb index 13f9fc3825..acd2f07f5e 100644 --- a/lib/chef/config_fetcher.rb +++ b/lib/chef/config_fetcher.rb @@ -45,9 +45,9 @@ class Chef def read_local_config ::File.read(config_location) - rescue Errno::ENOENT => error + rescue Errno::ENOENT Chef::Application.fatal!("Cannot load configuration from #{config_location}", 2) - rescue Errno::EACCES => error + rescue Errno::EACCES Chef::Application.fatal!("Permissions are incorrect on #{config_location}. Please chmod a+r #{config_location}", 2) end diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb index 72c878618e..bff77fa13b 100644 --- a/lib/chef/cookbook_loader.rb +++ b/lib/chef/cookbook_loader.rb @@ -47,7 +47,7 @@ class Chef @cookbooks_paths = Hash.new { |h, k| h[k] = [] } # for deprecation warnings @chefignores = {} @repo_paths = repo_paths.map do |repo_path| - repo_path = File.expand_path(repo_path) + File.expand_path(repo_path) end @preloaded_cookbooks = false @@ -121,7 +121,7 @@ class Chef end def [](cookbook) - if @cookbooks_by_name.has_key?(cookbook.to_sym) or load_cookbook(cookbook.to_sym) + if @cookbooks_by_name.has_key?(cookbook.to_sym) || load_cookbook(cookbook.to_sym) @cookbooks_by_name[cookbook.to_sym] else raise Exceptions::CookbookNotFoundInRepo, "Cannot find a cookbook named #{cookbook}; did you forget to add metadata to a cookbook? (https://docs.chef.io/config_rb_metadata.html)" @@ -179,7 +179,7 @@ class Chef @all_files_in_repo_paths ||= begin @repo_paths.inject([]) do |all_children, repo_path| - all_children += Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(repo_path), "*")] + all_children + Dir[File.join(Chef::Util::PathHelper.escape_glob_dir(repo_path), "*")] end end end diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index d6a270b033..9fb8d0d4bc 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -77,7 +77,6 @@ class Chef parts = [] content_file = nil - timestamp = Time.now.utc.iso8601 secret_key = OpenSSL::PKey::RSA.new(File.read(secret_key_filename)) unless params.nil? || params.empty? diff --git a/lib/chef/deprecation/warnings.rb b/lib/chef/deprecation/warnings.rb index b015669625..411e95ea39 100644 --- a/lib/chef/deprecation/warnings.rb +++ b/lib/chef/deprecation/warnings.rb @@ -22,7 +22,6 @@ class Chef def add_deprecation_warnings_for(method_names) method_names.each do |name| - m = instance_method(name) define_method(name) do |*args| message = [] message << "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef 13." diff --git a/lib/chef/file_access_control/windows.rb b/lib/chef/file_access_control/windows.rb index 7f27ef8df0..6b7184bbd3 100644 --- a/lib/chef/file_access_control/windows.rb +++ b/lib/chef/file_access_control/windows.rb @@ -319,7 +319,7 @@ class Chef def target_group return nil if resource.group.nil? - sid = get_sid(resource.group) + get_sid(resource.group) end def target_inherits @@ -328,7 +328,7 @@ class Chef def target_owner return nil if resource.owner.nil? - sid = get_sid(resource.owner) + get_sid(resource.owner) end end end diff --git a/lib/chef/http/validate_content_length.rb b/lib/chef/http/validate_content_length.rb index 81d3b0fb74..c1073867d3 100644 --- a/lib/chef/http/validate_content_length.rb +++ b/lib/chef/http/validate_content_length.rb @@ -84,7 +84,6 @@ class Chef def validate(http_response, response_length) content_length = response_content_length(http_response) transfer_encoding = http_response["transfer-encoding"] - content_encoding = http_response["content-encoding"] if content_length.nil? Chef::Log.debug "HTTP server did not include a Content-Length header in response, cannot identify truncated downloads." diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb index 6c2ad5a53f..bd1c8a22cc 100644 --- a/lib/chef/knife/cookbook_bulk_delete.rb +++ b/lib/chef/knife/cookbook_bulk_delete.rb @@ -61,7 +61,7 @@ class Chef cookbooks_names.each do |cookbook_name| versions = rest.get("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map { |v| v["version"] }.flatten versions.each do |version| - object = rest.delete("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}") + rest.delete("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}") ui.info("Deleted cookbook #{cookbook_name.ljust(25)} [#{version}]") end end diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index bfae9d8814..29eba6a36a 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -80,7 +80,6 @@ class Chef File.open(json_file, "w") do |f| f.write(Chef::JSONCompat.to_json_pretty(md)) end - generated = true Chef::Log.debug("Generated #{json_file}") rescue Exceptions::ObsoleteDependencySyntax, Exceptions::InvalidVersionConstraint => e ui.stderr.puts "ERROR: The cookbook '#{cookbook}' contains invalid or obsolete metadata syntax." diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index 21a251a011..7d0e21791d 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -98,7 +98,7 @@ class Chef end def replacement_cookbook - replacement = File.basename(current_cookbook_data["replacement"]) + File.basename(current_cookbook_data["replacement"]) end def specific_cookbook_version_url diff --git a/lib/chef/knife/core/custom_manifest_loader.rb b/lib/chef/knife/core/custom_manifest_loader.rb index e5ebce2585..9fe51599af 100644 --- a/lib/chef/knife/core/custom_manifest_loader.rb +++ b/lib/chef/knife/core/custom_manifest_loader.rb @@ -61,7 +61,7 @@ class Chef end def subcommand_files - subcommand_files ||= (find_subcommands_via_manifest.values + site_subcommands).flatten.uniq + @subcommand_files ||= (find_subcommands_via_manifest.values + site_subcommands).flatten.uniq end end end -- cgit v1.2.1