From 6301a43d573c67cf6c4bcd6eecb8a470bd139110 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 15 Aug 2014 03:24:55 +0530 Subject: [PATCH] Not initializing variable for looping if unused in loop --- app/controllers/admin/email_controller.rb | 2 +- app/jobs/regular/crawl_topic_link.rb | 4 ++-- app/models/post.rb | 2 +- app/models/post_analyzer.rb | 2 +- app/models/topic_link.rb | 4 ++-- app/models/user_action.rb | 2 +- config/environments/production.rb | 2 +- lib/admin_user_index_query.rb | 2 +- lib/autospec/manager.rb | 8 ++++---- lib/export/exporter.rb | 2 +- lib/import/importer.rb | 2 +- lib/middleware/anonymous_cache.rb | 2 +- lib/post_destroyer.rb | 2 +- lib/site_setting_extension.rb | 4 ++-- script/measure.rb | 2 +- 15 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 40df9cb304a..8d706b7c033 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -48,7 +48,7 @@ class Admin::EmailController < Admin::AdminController def delivery_settings action_mailer_settings - .reject { |k, v| k == :password } + .reject { |k, _| k == :password } .map { |k, v| { name: k, value: v }} end diff --git a/app/jobs/regular/crawl_topic_link.rb b/app/jobs/regular/crawl_topic_link.rb index 6501edb03ce..6c0bf6a9172 100644 --- a/app/jobs/regular/crawl_topic_link.rb +++ b/app/jobs/regular/crawl_topic_link.rb @@ -9,7 +9,7 @@ module Jobs # Retrieve a header regardless of case sensitivity def self.header_for(head, name) - header = head.headers.detect do |k, v| + header = head.headers.detect do |k, _| name == k.downcase end header[1] if header @@ -65,7 +65,7 @@ module Jobs return "" unless uri result = "" - streamer = lambda do |chunk, remaining_bytes, total_bytes| + streamer = lambda do |chunk, _, _| result << chunk # Using exceptions for flow control is really bad, but there really seems to diff --git a/app/models/post.rb b/app/models/post.rb index d7514d36888..e31d611c9b1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -206,7 +206,7 @@ class Post < ActiveRecord::Base def has_host_spam? return false if acting_user.present? && acting_user.has_trust_level?(:basic) - total_hosts_usage.each do |host, count| + total_hosts_usage.each do |_, count| return true if count >= SiteSetting.newuser_spam_host_threshold end diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index 7c38a8e2c97..dabb36733eb 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -11,7 +11,7 @@ class PostAnalyzer def cook(*args) cooked = PrettyText.cook(*args) - result = Oneboxer.apply(cooked) do |url, elem| + result = Oneboxer.apply(cooked) do |url, _| Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes] Oneboxer.cached_onebox url end diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index a2270f39e9f..8a0c99c95ac 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -105,8 +105,8 @@ class TopicLink < ActiveRecord::Base PrettyText .extract_links(post.cooked) .map{|u| [u, URI.parse(u.url)] rescue nil} - .reject{|u,p| p.nil?} - .uniq{|u,p| p} + .reject{|_, p| p.nil?} + .uniq{|_, p| p} .each do |link, parsed| begin diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 9a3c59a2338..4574a58752a 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -161,7 +161,7 @@ LEFT JOIN categories c on c.id = t.category_id # TODO there are conditions when this is called and user_id was already rolled back and is invalid. # protect against dupes, for some reason this is failing in some cases - action = self.find_by(hash.select { |k, v| required_parameters.include?(k) }) + action = self.find_by(hash.select { |k, _| required_parameters.include?(k) }) return action if action action = self.new(hash) diff --git a/config/environments/production.rb b/config/environments/production.rb index 9734f9e6da7..e92ffa87a8f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -38,7 +38,7 @@ Discourse::Application.configure do settings[:openssl_verify_mode] = GlobalSetting.smtp_openssl_verify_mode if GlobalSetting.smtp_openssl_verify_mode - config.action_mailer.smtp_settings = settings.reject{|x,y| y.nil?} + config.action_mailer.smtp_settings = settings.reject{|_, y| y.nil?} else config.action_mailer.delivery_method = :sendmail config.action_mailer.sendmail_settings = {arguments: '-i'} diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index 2b07fb20960..1568e1ff90a 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -18,7 +18,7 @@ class AdminUserIndexQuery end def filter_by_trust - levels = trust_levels.map { |key, value| key.to_s } + levels = trust_levels.map { |key, _| key.to_s } if levels.include?(params[:query]) @query.where('trust_level = ?', trust_levels[params[:query].to_sym]) end diff --git a/lib/autospec/manager.rb b/lib/autospec/manager.rb index e1052f8dd51..440961e0377 100644 --- a/lib/autospec/manager.rb +++ b/lib/autospec/manager.rb @@ -63,7 +63,7 @@ class Autospec::Manager def ensure_all_specs_will_run puts "@@@@@@@@@@@@ ensure_all_specs_will_run" if @debug @runners.each do |runner| - @queue << ['spec', 'spec', runner] unless @queue.any? { |f, s, r| s == "spec" && r == runner } + @queue << ['spec', 'spec', runner] unless @queue.any? { |_, s, r| s == "spec" && r == runner } end end @@ -152,7 +152,7 @@ class Autospec::Manager end Thread.start do - Listen.to('.', options) do |modified, added, removed| + Listen.to('.', options) do |modified, added, _| process_change([modified, added].flatten.compact) end end @@ -187,7 +187,7 @@ class Autospec::Manager end end # special watcher for styles/templates - Autospec::ReloadCss::WATCHERS.each do |k,v| + Autospec::ReloadCss::WATCHERS.each do |k, _| matches = [] matches << file if k.match(file) Autospec::ReloadCss.run_on_change(matches) if matches.present? @@ -220,7 +220,7 @@ class Autospec::Manager puts "@@@@@@@@@@@@ #{@queue}" if @debug specs.each do |file, spec, runner| # make sure there's no other instance of this spec in the queue - @queue.delete_if { |f, s, r| s.strip == spec.strip && r == runner } + @queue.delete_if { |_, s, r| s.strip == spec.strip && r == runner } # deal with focused specs if @queue.first && @queue.first[0] == "focus" focus = @queue.shift diff --git a/lib/export/exporter.rb b/lib/export/exporter.rb index 8a6debca15f..4de3e17b2ee 100644 --- a/lib/export/exporter.rb +++ b/lib/export/exporter.rb @@ -121,7 +121,7 @@ module Export end def sidekiq_has_running_jobs? - Sidekiq::Workers.new.each do |process_id, thread_id, worker| + Sidekiq::Workers.new.each do |_, _, worker| payload = worker.try(:payload) return true if payload.try(:all_sites) return true if payload.try(:current_site_id) == @current_db diff --git a/lib/import/importer.rb b/lib/import/importer.rb index 00ef164dd34..36e98718144 100644 --- a/lib/import/importer.rb +++ b/lib/import/importer.rb @@ -142,7 +142,7 @@ module Import end def sidekiq_has_running_jobs? - Sidekiq::Workers.new.each do |process_id, thread_id, worker| + Sidekiq::Workers.new.each do |_, _, worker| payload = worker.try(:payload) return true if payload.try(:all_sites) return true if payload.try(:current_site_id) == @current_db diff --git a/lib/middleware/anonymous_cache.rb b/lib/middleware/anonymous_cache.rb index 13c62adee3f..f80507ee510 100644 --- a/lib/middleware/anonymous_cache.rb +++ b/lib/middleware/anonymous_cache.rb @@ -84,7 +84,7 @@ module Middleware status,headers,response = result if status == 200 && cache_duration - headers_stripped = headers.dup.delete_if{|k,v| ["Set-Cookie","X-MiniProfiler-Ids"].include? k} + headers_stripped = headers.dup.delete_if{|k, _| ["Set-Cookie","X-MiniProfiler-Ids"].include? k} parts = [] response.each do |part| parts << part diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 56056925998..990bb114f1d 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -139,7 +139,7 @@ class PostDestroyer public_post_actions = PostAction.publics.where(post_id: @post.id) public_post_actions.each { |pa| pa.trash!(@user) } - f = PostActionType.public_types.map { |k,v| ["#{k}_count", 0] } + f = PostActionType.public_types.map { |k, _| ["#{k}_count", 0] } Post.with_deleted.where(id: @post.id).update_all(Hash[*f.flatten]) end diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index 31a18c97c04..4e7aacfde6a 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -105,7 +105,7 @@ module SiteSettingExtension def settings_hash result = {} - @defaults.each do |s, v| + @defaults.each do |s, _| result[s] = send(s).to_s end result @@ -124,7 +124,7 @@ module SiteSettingExtension # Retrieve all settings def all_settings(include_hidden=false) @defaults - .reject{|s, v| hidden_settings.include?(s) || include_hidden} + .reject{|s, _| hidden_settings.include?(s) || include_hidden} .map do |s, v| value = send(s) type = types[get_data_type(s, value)] diff --git a/script/measure.rb b/script/measure.rb index c4af5b96d16..d643625fb69 100644 --- a/script/measure.rb +++ b/script/measure.rb @@ -23,7 +23,7 @@ def profile_allocations(name) initial_size = ObjectSpace.count_objects yield changes = ObjectSpace.count_objects - changes.each do |k,v| + changes.each do |k, _| changes[k] -= initial_size[k] end puts "#{name} changes"