From 6b38636254c868b9176bbab179f78f42f9e90627 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 3 Feb 2018 10:14:38 +0900 Subject: [PATCH] Ruby Warnings (#331) * :warning: shadowing outer local variable - t and actually this block variable `t` is not used inside the block * :warning: assigned but unused variable - e * :warning: assigned but unused variable - path, version, json, includes, name, duration * :warning: shadowing outer local variable - exceptions * :warning: ambiguous first argument; put parentheses or a space even after `/' operator * :warning: instance variable @backtrace_level, @orig_disable_profiling, @disable_profiling not initialized * :warning: instance variable @cycle_at not initialized seems that the ivar was named wrongly at the very beginning at 4273771d65f1a7411e3ef5843329308d0e2d257c * :warning: instance variable @already_initialized not initialized --- lib/mini_profiler/client_settings.rb | 2 ++ lib/mini_profiler/profiler.rb | 17 +++++++++-------- lib/mini_profiler/storage/file_store.rb | 2 +- lib/mini_profiler/storage/memory_store.rb | 4 ++-- lib/mini_profiler_rails/railtie.rb | 2 +- spec/lib/timer_struct/sql_timer_struct_spec.rb | 12 ++++++------ 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/mini_profiler/client_settings.rb b/lib/mini_profiler/client_settings.rb index 4afcc869..700e9890 100644 --- a/lib/mini_profiler/client_settings.rb +++ b/lib/mini_profiler/client_settings.rb @@ -19,6 +19,8 @@ def initialize(env, store, start) @cookie = request.cookies[COOKIE_NAME] @store = store @start = start + @backtrace_level = nil + @orig_disable_profiling = @disable_profiling = nil @allowed_tokens, @orig_auth_tokens = nil diff --git a/lib/mini_profiler/profiler.rb b/lib/mini_profiler/profiler.rb index 19d0fb3c..075f9d00 100644 --- a/lib/mini_profiler/profiler.rb +++ b/lib/mini_profiler/profiler.rb @@ -111,12 +111,13 @@ def serve_results(env) end def generate_html(page_struct, env, result_json = page_struct.to_json) - path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}" - version = MiniProfiler::ASSET_VERSION - json = result_json - includes = get_profile_script(env) - name = page_struct[:name] - duration = page_struct.duration_ms.round(1).to_s + # double-assigning to suppress "assigned but unused variable" warnings + path = path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}" + version = version = MiniProfiler::ASSET_VERSION + json = json = result_json + includes = includes = get_profile_script(env) + name = name = page_struct[:name] + duration = duration = page_struct.duration_ms.round(1).to_s MiniProfiler.share_template.result(binding) end @@ -413,8 +414,8 @@ def dump_exceptions(exceptions) body << "No exceptions raised" else body << "Exceptions: (#{exceptions.size} total)\n" - exceptions.group_by(&:class).each do |klass, exceptions| - body << " #{klass.name} (#{exceptions.size})\n" + exceptions.group_by(&:class).each do |klass, exceptions_per_class| + body << " #{klass.name} (#{exceptions_per_class.size})\n" end body << "\nBacktraces\n" diff --git a/lib/mini_profiler/storage/file_store.rb b/lib/mini_profiler/storage/file_store.rb index eebc2c52..9fe91d87 100644 --- a/lib/mini_profiler/storage/file_store.rb +++ b/lib/mini_profiler/storage/file_store.rb @@ -18,7 +18,7 @@ def [](key) begin data = ::File.open(path(key),"rb") {|f| f.read} return Marshal.load data - rescue => e + rescue return nil end end diff --git a/lib/mini_profiler/storage/memory_store.rb b/lib/mini_profiler/storage/memory_store.rb index 0fa860d1..7e42f1ac 100644 --- a/lib/mini_profiler/storage/memory_store.rb +++ b/lib/mini_profiler/storage/memory_store.rb @@ -52,7 +52,7 @@ def initialize(args = nil) args ||= {} @expires_in_seconds = args.fetch(:expires_in) { EXPIRES_IN_SECONDS } - @token1, @token2, @cycle_tokens_at = nil + @token1, @token2, @cycle_at = nil initialize_locks initialize_cleanup_thread(args) @@ -70,7 +70,7 @@ def initialize_locks def initialize_cleanup_thread(args={}) cleanup_interval = args.fetch(:cleanup_interval) { CLEANUP_INTERVAL } cleanup_cycle = args.fetch(:cleanup_cycle) { CLEANUP_CYCLE } - t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do |t| + t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do until Thread.current[:should_exit] do CacheCleanupThread.current.sleepy_run end diff --git a/lib/mini_profiler_rails/railtie.rb b/lib/mini_profiler_rails/railtie.rb index e5a9a766..7f481095 100644 --- a/lib/mini_profiler_rails/railtie.rb +++ b/lib/mini_profiler_rails/railtie.rb @@ -7,7 +7,7 @@ module Rack::MiniProfilerRails # call direct if needed to do a defer init def self.initialize!(app) - raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if @already_initialized + raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if defined?(@already_initialized) && @already_initialized c = Rack::MiniProfiler.config diff --git a/spec/lib/timer_struct/sql_timer_struct_spec.rb b/spec/lib/timer_struct/sql_timer_struct_spec.rb index 5368f96e..d1a79a12 100644 --- a/spec/lib/timer_struct/sql_timer_struct_spec.rb +++ b/spec/lib/timer_struct/sql_timer_struct_spec.rb @@ -28,37 +28,37 @@ it 'includes rspec in the trace (default is no filter)' do sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).to match /rspec/ + expect(sql[:stack_trace_snippet]).to match(/rspec/) end it "doesn't include rspec if we filter for only app" do Rack::MiniProfiler.config.backtrace_includes = [/\/app/] sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).not_to match /rspec/ + expect(sql[:stack_trace_snippet]).not_to match(/rspec/) end it "includes rspec if we filter for it" do Rack::MiniProfiler.config.backtrace_includes = [/\/(app|rspec)/] sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).to match /rspec/ + expect(sql[:stack_trace_snippet]).to match(/rspec/) end it "includes rspec if we filter for it along with something else" do Rack::MiniProfiler.config.backtrace_includes = [/rspec/, /something_else/] sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).to match /rspec/ + expect(sql[:stack_trace_snippet]).to match(/rspec/) end it "ignores rspec if we specifically ignore it" do Rack::MiniProfiler.config.backtrace_ignores = [/\/rspec/] sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).not_to match /rspec/ + expect(sql[:stack_trace_snippet]).not_to match(/rspec/) end it "ignores rspec if we specifically ignore it along with something else" do Rack::MiniProfiler.config.backtrace_ignores = [/\/rspec/, /something_else/] sql = Rack::MiniProfiler::TimerStruct::Sql.new("SELECT * FROM users", 200, @page, nil) - expect(sql[:stack_trace_snippet]).not_to match /rspec/ + expect(sql[:stack_trace_snippet]).not_to match(/rspec/) end it "should omit the backtrace if the query takes less than the threshold time" do