From a294430137758455d0a4ec0d45f08cb5aa50d5d6 Mon Sep 17 00:00:00 2001 From: Walt Jones Date: Thu, 8 Jul 2021 09:11:57 -0700 Subject: [PATCH] Resolve various Lint/Style/Layout violations (#1060) * style: resolve rubocop Bundler/DuplicatedGem violations * style: resolve rubocop Layout/ExtraSpacing violations * style: resolve rubocop Layout/SpaceAfterComma violations * style: resolve rubocopLint/BinaryOperatorWithIdenticalOperands violations * style: resolve rubocop Lint/EmptyFile violations * style: resolve rubocop Lint/NonDeterministicRequireOrder violations * style: resolve rubocop Lint/ShadowedException violations * style: resolve rubocop Naming/MemoizedInstanceVariableName violations * style: resolve rubocop Style/ConditionalAssignment violations * style: resolve rubocop Style/ModuleFunction violations * style: resolve rubocop Style/SymbolProc violations * style: resolve rubocop Layout/EmptyLineAfterGuardClause violations * style: resolve rubocop Lint/AmbiguousBlockAssociation violations --- gemfiles/rails41.gemfile | 1 - lib/rollbar/json.rb | 2 +- lib/rollbar/middleware/js.rb | 16 +++++++--------- lib/rollbar/plugins/delayed_job/plugin.rb | 2 +- lib/rollbar/plugins/rails/controller_methods.rb | 2 +- .../truncation/remove_any_key_strategy.rb | 1 + lib/rollbar/truncation/remove_extra_strategy.rb | 1 + spec/delayed/backend/test.rb | 2 +- spec/delayed/serialization/test.rb | 2 ++ .../generators/rollbar/rollbar_generator_spec.rb | 12 ++++++++---- spec/requests/home_spec.rb | 2 +- spec/rollbar/notifier_spec.rb | 2 +- spec/rollbar_spec.rb | 4 +--- spec/spec_helper.rb | 2 +- spec/support/deploy_api/update.rb | 1 + 15 files changed, 28 insertions(+), 24 deletions(-) diff --git a/gemfiles/rails41.gemfile b/gemfiles/rails41.gemfile index dedda252..2b2cf2b2 100644 --- a/gemfiles/rails41.gemfile +++ b/gemfiles/rails41.gemfile @@ -45,6 +45,5 @@ gem 'rspec-command' gem 'webmock', :require => false gem 'aws-sdk-sqs' -gem 'resque' gemspec :path => '../' diff --git a/lib/rollbar/json.rb b/lib/rollbar/json.rb index 6563c0a3..003f5c08 100644 --- a/lib/rollbar/json.rb +++ b/lib/rollbar/json.rb @@ -3,7 +3,7 @@ module Rollbar module JSON # :nodoc: - extend self + module_function attr_writer :options_module diff --git a/lib/rollbar/middleware/js.rb b/lib/rollbar/middleware/js.rb index eb8563d9..25ebe2de 100644 --- a/lib/rollbar/middleware/js.rb +++ b/lib/rollbar/middleware/js.rb @@ -164,15 +164,13 @@ def js_snippet end def script_tag(content, env) - if (nonce = rails5_nonce(env)) - script_tag_content = "\n" - elsif (nonce = secure_headers_nonce(env)) - script_tag_content = "\n" - else - script_tag_content = "\n" - end + nonce = rails5_nonce(env) || secure_headers_nonce(env) + script_tag_content = if nonce + "\n" + else + "\n" + end html_safe_if_needed(script_tag_content) end diff --git a/lib/rollbar/plugins/delayed_job/plugin.rb b/lib/rollbar/plugins/delayed_job/plugin.rb index c940ed1e..64783d7e 100644 --- a/lib/rollbar/plugins/delayed_job/plugin.rb +++ b/lib/rollbar/plugins/delayed_job/plugin.rb @@ -17,7 +17,7 @@ class RollbarPlugin < ::Delayed::Plugin if job.class.method_defined? :error if job.error ::Rollbar.scope(:request => data) - .error(job.error,:use_exception_level_filters => true) + .error(job.error, :use_exception_level_filters => true) end elsif job.last_error ::Rollbar.scope(:request => data).error( diff --git a/lib/rollbar/plugins/rails/controller_methods.rb b/lib/rollbar/plugins/rails/controller_methods.rb index 2ef46eec..d66e9f96 100644 --- a/lib/rollbar/plugins/rails/controller_methods.rb +++ b/lib/rollbar/plugins/rails/controller_methods.rb @@ -34,7 +34,7 @@ def rollbar_person_data else {} end - rescue NoMethodError, NameError + rescue NameError {} end diff --git a/lib/rollbar/truncation/remove_any_key_strategy.rb b/lib/rollbar/truncation/remove_any_key_strategy.rb index 06f2d17f..d75efd62 100644 --- a/lib/rollbar/truncation/remove_any_key_strategy.rb +++ b/lib/rollbar/truncation/remove_any_key_strategy.rb @@ -93,6 +93,7 @@ def extract_title(body) return extract_title_from_trace(body['trace']) if body['trace'] return unless body['trace_chain'] && body['trace_chain'][0] + extract_title_from_trace(body['trace_chain'][0]) end diff --git a/lib/rollbar/truncation/remove_extra_strategy.rb b/lib/rollbar/truncation/remove_extra_strategy.rb index 39afb108..c89ea07f 100644 --- a/lib/rollbar/truncation/remove_extra_strategy.rb +++ b/lib/rollbar/truncation/remove_extra_strategy.rb @@ -25,6 +25,7 @@ def delete_message_extra(body) def delete_trace_chain_extra(body) return unless body['trace_chain'] && body['trace_chain'][0]['extra'] + body['trace_chain'][0].delete('extra') end diff --git a/spec/delayed/backend/test.rb b/spec/delayed/backend/test.rb index a2d77206..43c994cd 100644 --- a/spec/delayed/backend/test.rb +++ b/spec/delayed/backend/test.rb @@ -41,7 +41,7 @@ def initialize(hash = {}) end def self.all - @jobs ||= [] + @all ||= [] end def self.count diff --git a/spec/delayed/serialization/test.rb b/spec/delayed/serialization/test.rb index e69de29b..3e24e1b0 100644 --- a/spec/delayed/serialization/test.rb +++ b/spec/delayed/serialization/test.rb @@ -0,0 +1,2 @@ +# The tests at spec/rollbar/plugins/delayed_job_spec.rb +# expect to find a file here. diff --git a/spec/generators/rollbar/rollbar_generator_spec.rb b/spec/generators/rollbar/rollbar_generator_spec.rb index b1801cc3..19dab07e 100644 --- a/spec/generators/rollbar/rollbar_generator_spec.rb +++ b/spec/generators/rollbar/rollbar_generator_spec.rb @@ -20,7 +20,7 @@ end it 'outputs a help message and generates Rollbar initializer with ENV' do - expect(destination_root).to have_structure { + structure = proc do directory 'config' do directory 'initializers' do file 'rollbar.rb' do @@ -28,7 +28,9 @@ end end end - } + end + + expect(destination_root).to have_structure(&structure) end end @@ -38,7 +40,7 @@ end it 'generates a Rollbar initializer with access token' do - expect(destination_root).to have_structure { + structure = proc do directory 'config' do directory 'initializers' do file 'rollbar.rb' do @@ -47,7 +49,9 @@ end end end - } + end + + expect(destination_root).to have_structure(&structure) end end end diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index b42c34e5..ac6e397a 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -45,7 +45,7 @@ expect { get '/current_user' }.to raise_exception(NoMethodError) body = Rollbar.last_report[:body] - trace = body[:trace] && body[:trace] || body[:trace_chain][0] + trace = body[:trace] || body[:trace_chain][0] trace[:exception][:class].should eq('NoMethodError') trace[:exception][:message].should =~ /^undefined method `-'/ diff --git a/spec/rollbar/notifier_spec.rb b/spec/rollbar/notifier_spec.rb index 9205531b..ac2d81db 100644 --- a/spec/rollbar/notifier_spec.rb +++ b/spec/rollbar/notifier_spec.rb @@ -253,7 +253,7 @@ let(:payload) { { 'data' => { 'failsafe' => true } } } it 'does not pass the message on' do - error_message = '[Rollbar] Error processing the item: ' \ + error_message = '[Rollbar] Error processing the item: ' \ "SocketError, SocketError. Item: #{payload.inspect}" expect(notifier) .to receive(:log_error) diff --git a/spec/rollbar_spec.rb b/spec/rollbar_spec.rb index 97d3f28f..007920c1 100644 --- a/spec/rollbar_spec.rb +++ b/spec/rollbar_spec.rb @@ -1742,9 +1742,7 @@ def backtrace # Reset state before Rollbar.configure Rollbar::Delay::Thread.options = nil - Rollbar.configure do |config| - config.use_thread - end + Rollbar.configure(&:use_thread) thread = Rollbar::Delay::Thread.call(payload) sleep(1) # More reliable than Thread.pass to let the thread set its priority. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f574fce0..5f0584be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,7 +50,7 @@ Rake::Task['dummy:db:test:prepare'].invoke end -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } RSpec.configure do |config| config.extend(Helpers) diff --git a/spec/support/deploy_api/update.rb b/spec/support/deploy_api/update.rb index 134800b2..3cab0ba6 100644 --- a/spec/support/deploy_api/update.rb +++ b/spec/support/deploy_api/update.rb @@ -31,6 +31,7 @@ def access_token?(request) def access_token(request) return if CGI.parse(request.env['QUERY_STRING'])['access_token'].empty? + CGI.parse(request.env['QUERY_STRING'])['access_token'][0] end