From 8211b38304543e5e2733ab2fcdafb91545966b93 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:04:38 -0300 Subject: [PATCH 01/14] Rename erb template Rubocop skips erb templates since it doesn't support them --- lib/generators/exception_notification/install_generator.rb | 2 +- ...{exception_notification.rb => exception_notification.rb.erb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/generators/exception_notification/templates/{exception_notification.rb => exception_notification.rb.erb} (100%) diff --git a/lib/generators/exception_notification/install_generator.rb b/lib/generators/exception_notification/install_generator.rb index d4f78b38..52d5b2f0 100644 --- a/lib/generators/exception_notification/install_generator.rb +++ b/lib/generators/exception_notification/install_generator.rb @@ -8,7 +8,7 @@ class InstallGenerator < Rails::Generators::Base class_option :sidekiq, type: :boolean, desc: 'Add support for sending notifications when errors occur in Sidekiq jobs.' def copy_initializer - template 'exception_notification.rb', 'config/initializers/exception_notification.rb' + template 'exception_notification.rb.erb', 'config/initializers/exception_notification.rb' end end end diff --git a/lib/generators/exception_notification/templates/exception_notification.rb b/lib/generators/exception_notification/templates/exception_notification.rb.erb similarity index 100% rename from lib/generators/exception_notification/templates/exception_notification.rb rename to lib/generators/exception_notification/templates/exception_notification.rb.erb From 5ede10fbbb0fd78c393b09bbc2f2c28bfaa9ba39 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:09:23 -0300 Subject: [PATCH 02/14] Fix Style/UnneededInterpolation offense --- lib/exception_notifier/email_notifier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/exception_notifier/email_notifier.rb b/lib/exception_notifier/email_notifier.rb index c4eaeac3..b28d013c 100644 --- a/lib/exception_notifier/email_notifier.rb +++ b/lib/exception_notifier/email_notifier.rb @@ -58,7 +58,7 @@ def background_exception_notification(exception, options = {}, default_options = private def compose_subject - subject = "#{@options[:email_prefix]}" + subject = @options[:email_prefix].to_s.dup subject << "(#{@options[:accumulated_errors_count]} times)" if @options[:accumulated_errors_count].to_i > 1 subject << "#{@kontroller.controller_name} #{@kontroller.action_name}" if @kontroller && @options[:include_controller_and_action_names_in_subject] subject << " (#{@exception.class})" From a70ec5014b2969257bad27106ef6d19260b4299b Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:09:57 -0300 Subject: [PATCH 03/14] Fix Layout/ClosingParenthesisIndentation offense --- test/exception_notifier/irc_notifier_test.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/exception_notifier/irc_notifier_test.rb b/test/exception_notifier/irc_notifier_test.rb index dacb989d..824ae29a 100644 --- a/test/exception_notifier/irc_notifier_test.rb +++ b/test/exception_notifier/irc_notifier_test.rb @@ -102,11 +102,13 @@ class IrcNotifierTest < ActiveSupport::TestCase prefix: '[test notification]' } - CarrierPigeon.expects(:send).with(has_entries( - ssl: true, - join: true, - notice: true - )) do |v| + entries = { + ssl: true, + join: true, + notice: true + } + + CarrierPigeon.expects(:send).with(has_entries(entries)) do |v| /\[test notification\]/.match(v[:message]) end From c0cbde576010a9d963166c3f4d8a1389bd31af5c Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:10:15 -0300 Subject: [PATCH 04/14] Fix syntax error and Style/TrailingCommaInLiteral offense --- lib/exception_notification/resque.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/exception_notification/resque.rb b/lib/exception_notification/resque.rb index 40b9743b..288f117d 100644 --- a/lib/exception_notification/resque.rb +++ b/lib/exception_notification/resque.rb @@ -13,7 +13,7 @@ def save failed_at: Time.now.to_s, payload: payload, queue: queue, - worker: worker.to_s, + worker: worker.to_s } ExceptionNotifier.notify_exception(exception, data: { resque: data }) From b43d2f47ac4898b909e8e79c422e8bdfb15a1487 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:12:07 -0300 Subject: [PATCH 05/14] Fix Lint/AssignmentInCondition offenses --- .rubocop_todo.yml | 6 ------ lib/exception_notifier/modules/error_grouping.rb | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 566eec83..ae54c158 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -29,12 +29,6 @@ Layout/RescueEnsureAlignment: - 'lib/exception_notifier/modules/error_grouping.rb' - 'test/exception_notifier/webhook_notifier_test.rb' -# Offense count: 2 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'lib/exception_notifier/modules/error_grouping.rb' - # Offense count: 12 Lint/RescueException: Exclude: diff --git a/lib/exception_notifier/modules/error_grouping.rb b/lib/exception_notifier/modules/error_grouping.rb index 4f6c2cc2..3aefff0e 100644 --- a/lib/exception_notifier/modules/error_grouping.rb +++ b/lib/exception_notifier/modules/error_grouping.rb @@ -46,13 +46,13 @@ def group_error!(exception, options) message_based_key = "exception:#{Zlib.crc32("#{exception.class.name}\nmessage:#{exception.message}")}" accumulated_errors_count = 1 - if count = error_count(message_based_key) + if (count = error_count(message_based_key)) accumulated_errors_count = count + 1 save_error_count(message_based_key, accumulated_errors_count) else backtrace_based_key = "exception:#{Zlib.crc32("#{exception.class.name}\npath:#{exception.backtrace.try(:first)}")}" - if count = error_grouping_cache.read(backtrace_based_key) + if (count = error_grouping_cache.read(backtrace_based_key)) accumulated_errors_count = count + 1 save_error_count(backtrace_based_key, accumulated_errors_count) else From 996544f37bec112114ac991a4b47f57e68c8a67c Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:17:43 -0300 Subject: [PATCH 06/14] Fix Layout/EndAlignment offenses --- .rubocop_todo.yml | 9 --------- lib/exception_notifier/campfire_notifier.rb | 2 +- lib/exception_notifier/hipchat_notifier.rb | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae54c158..24f33f1e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,15 +13,6 @@ Gemspec/RequiredRubyVersion: Exclude: - 'exception_notification.gemspec' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'lib/exception_notifier/campfire_notifier.rb' - - 'lib/exception_notifier/hipchat_notifier.rb' - # Offense count: 2 # Cop supports --auto-correct. Layout/RescueEnsureAlignment: diff --git a/lib/exception_notifier/campfire_notifier.rb b/lib/exception_notifier/campfire_notifier.rb index bf7c743f..881f8965 100644 --- a/lib/exception_notifier/campfire_notifier.rb +++ b/lib/exception_notifier/campfire_notifier.rb @@ -22,7 +22,7 @@ def call(exception, options = {}) "The exception occurred #{options[:accumulated_errors_count]} times: '#{exception.message}'" else "A new exception occurred: '#{exception.message}'" - end + end message += " on '#{exception.backtrace.first}'" if exception.backtrace send_notice(exception, options, message) do |msg, _| @room.paste msg diff --git a/lib/exception_notifier/hipchat_notifier.rb b/lib/exception_notifier/hipchat_notifier.rb index 9d851037..b45cc588 100644 --- a/lib/exception_notifier/hipchat_notifier.rb +++ b/lib/exception_notifier/hipchat_notifier.rb @@ -20,7 +20,7 @@ def initialize(options) "The exception occurred #{errors_count} times: '#{Rack::Utils.escape_html(exception.message)}'" else "A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}'" - end + end msg += " on '#{exception.backtrace.first}'" if exception.backtrace msg } From e4a1d98ef77a98b63fbb1bbe4a7d8e8ac5771ab9 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:24:15 -0300 Subject: [PATCH 07/14] Fix some Lint/RescueException offenses --- .rubocop_todo.yml | 7 ------- examples/sinatra/sinatra_app.rb | 2 +- test/exception_notifier/campfire_notifier_test.rb | 2 +- test/exception_notifier/hipchat_notifier_test.rb | 4 ++-- test/exception_notifier/irc_notifier_test.rb | 2 +- test/exception_notifier/slack_notifier_test.rb | 2 +- test/exception_notifier/sns_notifier_test.rb | 2 +- test/exception_notifier/webhook_notifier_test.rb | 2 +- 8 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 24f33f1e..48a72f71 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -23,16 +23,9 @@ Layout/RescueEnsureAlignment: # Offense count: 12 Lint/RescueException: Exclude: - - 'examples/sinatra/sinatra_app.rb' - 'lib/exception_notification/rack.rb' - 'lib/exception_notification/sidekiq.rb' - 'lib/exception_notifier.rb' - - 'test/exception_notifier/campfire_notifier_test.rb' - - 'test/exception_notifier/hipchat_notifier_test.rb' - - 'test/exception_notifier/irc_notifier_test.rb' - - 'test/exception_notifier/slack_notifier_test.rb' - - 'test/exception_notifier/sns_notifier_test.rb' - - 'test/exception_notifier/webhook_notifier_test.rb' # Offense count: 2 # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. diff --git a/examples/sinatra/sinatra_app.rb b/examples/sinatra/sinatra_app.rb index 65d31bbf..6e0dec51 100644 --- a/examples/sinatra/sinatra_app.rb +++ b/examples/sinatra/sinatra_app.rb @@ -28,7 +28,7 @@ class SinatraApp < Sinatra::Base get '/background_notification' do begin 1 / 0 - rescue Exception => e + rescue StandardError => e ExceptionNotifier.notify_exception(e, data: { msg: 'Cannot divide by zero!' }) end 'Check email at mailcatcher.' diff --git a/test/exception_notifier/campfire_notifier_test.rb b/test/exception_notifier/campfire_notifier_test.rb index 2594f7cc..e3065a97 100644 --- a/test/exception_notifier/campfire_notifier_test.rb +++ b/test/exception_notifier/campfire_notifier_test.rb @@ -101,7 +101,7 @@ def fake_notification def fake_exception 5 / 0 - rescue Exception => e + rescue StandardError => e e end diff --git a/test/exception_notifier/hipchat_notifier_test.rb b/test/exception_notifier/hipchat_notifier_test.rb index c69d7ab0..b5e944bf 100644 --- a/test/exception_notifier/hipchat_notifier_test.rb +++ b/test/exception_notifier/hipchat_notifier_test.rb @@ -197,13 +197,13 @@ def fake_body def fake_exception 5 / 0 - rescue Exception => e + rescue StandardError => e e end def fake_exception_with_html_characters raise StandardError, 'an error with characters' - rescue Exception => e + rescue StandardError => e e end diff --git a/test/exception_notifier/irc_notifier_test.rb b/test/exception_notifier/irc_notifier_test.rb index 824ae29a..32d0095e 100644 --- a/test/exception_notifier/irc_notifier_test.rb +++ b/test/exception_notifier/irc_notifier_test.rb @@ -127,7 +127,7 @@ class IrcNotifierTest < ActiveSupport::TestCase def fake_exception 5 / 0 - rescue Exception => e + rescue StandardError => e e end diff --git a/test/exception_notifier/slack_notifier_test.rb b/test/exception_notifier/slack_notifier_test.rb index c4636674..69ca489c 100644 --- a/test/exception_notifier/slack_notifier_test.rb +++ b/test/exception_notifier/slack_notifier_test.rb @@ -173,7 +173,7 @@ def setup def fake_exception 5 / 0 - rescue Exception => e + rescue StandardError => e e end diff --git a/test/exception_notifier/sns_notifier_test.rb b/test/exception_notifier/sns_notifier_test.rb index a68813ab..8d3ae40a 100644 --- a/test/exception_notifier/sns_notifier_test.rb +++ b/test/exception_notifier/sns_notifier_test.rb @@ -100,7 +100,7 @@ class ExamplesController < ActionController::Base; end def fake_exception 1 / 0 - rescue Exception => e + rescue StandardError => e e end diff --git a/test/exception_notifier/webhook_notifier_test.rb b/test/exception_notifier/webhook_notifier_test.rb index 010f0a52..26c6903f 100644 --- a/test/exception_notifier/webhook_notifier_test.rb +++ b/test/exception_notifier/webhook_notifier_test.rb @@ -86,7 +86,7 @@ def fake_params def fake_exception @fake_exception ||= begin 5 / 0 - rescue Exception => e + rescue StandardError => e e end end From 6f380aa9bc60753638585126dc7a8a629c4e3f49 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:29:15 -0300 Subject: [PATCH 08/14] Fix Lint/UselessAccessModifier offenses --- .rubocop_todo.yml | 7 ------- lib/exception_notifier/datadog_notifier.rb | 2 -- test/exception_notifier/datadog_notifier_test.rb | 2 -- 3 files changed, 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 48a72f71..f2d4420b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -27,13 +27,6 @@ Lint/RescueException: - 'lib/exception_notification/sidekiq.rb' - 'lib/exception_notifier.rb' -# Offense count: 2 -# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. -Lint/UselessAccessModifier: - Exclude: - - 'lib/exception_notifier/datadog_notifier.rb' - - 'test/exception_notifier/datadog_notifier_test.rb' - # Offense count: 1 Lint/UselessAssignment: Exclude: diff --git a/lib/exception_notifier/datadog_notifier.rb b/lib/exception_notifier/datadog_notifier.rb index 1697474d..9fc3dbf8 100644 --- a/lib/exception_notifier/datadog_notifier.rb +++ b/lib/exception_notifier/datadog_notifier.rb @@ -22,8 +22,6 @@ def datadog_event(exception, options = {}) ).event end - private - class DatadogExceptionEvent include ExceptionNotifier::BacktraceCleaner diff --git a/test/exception_notifier/datadog_notifier_test.rb b/test/exception_notifier/datadog_notifier_test.rb index 78cc7804..556d1098 100644 --- a/test/exception_notifier/datadog_notifier_test.rb +++ b/test/exception_notifier/datadog_notifier_test.rb @@ -92,8 +92,6 @@ def setup assert_equal event.aggregation_key, [event.msg_title] end - private - class FakeDatadogClient def emit_event(event); end end From 580ca0604b8a09f7acfc88a03ec17c9c4f8ed2a5 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:31:24 -0300 Subject: [PATCH 09/14] Fix Lint/UselessAssignment offense --- .rubocop_todo.yml | 5 ----- lib/exception_notifier/sns_notifier.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f2d4420b..d60f73ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -27,11 +27,6 @@ Lint/RescueException: - 'lib/exception_notification/sidekiq.rb' - 'lib/exception_notifier.rb' -# Offense count: 1 -Lint/UselessAssignment: - Exclude: - - 'lib/exception_notifier/sns_notifier.rb' - # Offense count: 18 Metrics/AbcSize: Max: 97 diff --git a/lib/exception_notifier/sns_notifier.rb b/lib/exception_notifier/sns_notifier.rb index b1d67332..9e74145a 100644 --- a/lib/exception_notifier/sns_notifier.rb +++ b/lib/exception_notifier/sns_notifier.rb @@ -59,7 +59,7 @@ def build_message(exception, options) if exception.backtrace formatted_backtrace = exception.backtrace.first(options[:backtrace_lines]).join("\n").to_s - text += "Backtrace:\n#{formatted_backtrace}\n" + text + "Backtrace:\n#{formatted_backtrace}\n" end end From 13e9e13ae6bc68bf2011203b1ed20348c11ae060 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:34:12 -0300 Subject: [PATCH 10/14] Fix Style/NumericPredicate offense --- .rubocop_todo.yml | 9 --------- test/exception_notifier/modules/error_grouping_test.rb | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d60f73ed..b297e69e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,15 +130,6 @@ Style/NestedTernaryOperator: - 'lib/exception_notifier/slack_notifier.rb' - 'lib/exception_notifier/sns_notifier.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'test/exception_notifier/modules/error_grouping_test.rb' - # Offense count: 253 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/test/exception_notifier/modules/error_grouping_test.rb b/test/exception_notifier/modules/error_grouping_test.rb index 56270e07..1365cd0b 100644 --- a/test/exception_notifier/modules/error_grouping_test.rb +++ b/test/exception_notifier/modules/error_grouping_test.rb @@ -155,7 +155,7 @@ module TestModule end test 'use specified trigger in .send_notification?' do - trigger = proc { |_exception, count| count % 4 == 0 } + trigger = proc { |_exception, count| (count % 4).zero? } TestModule.stubs(:notification_trigger).returns(trigger) count = 16 From 1e54aa229dd4d06f5a2b7c347ae71b7cf773d743 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:38:34 -0300 Subject: [PATCH 11/14] Fix Style/NestedTernaryOperator offenses --- .rubocop_todo.yml | 6 ------ lib/exception_notifier/slack_notifier.rb | 8 +++++++- lib/exception_notifier/sns_notifier.rb | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b297e69e..e31c15da 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -124,12 +124,6 @@ Style/MultilineBlockChain: Exclude: - 'lib/exception_notifier/email_notifier.rb' -# Offense count: 2 -Style/NestedTernaryOperator: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - - 'lib/exception_notifier/sns_notifier.rb' - # Offense count: 253 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/lib/exception_notifier/slack_notifier.rb b/lib/exception_notifier/slack_notifier.rb index 8202ef52..05005d90 100644 --- a/lib/exception_notifier/slack_notifier.rb +++ b/lib/exception_notifier/slack_notifier.rb @@ -57,7 +57,13 @@ def attchs(exception, clean_message, options) def information_from_options(exception_class, options) errors_count = options[:accumulated_errors_count].to_i - measure_word = errors_count > 1 ? errors_count : (exception_class.to_s =~ /^[aeiou]/i ? 'An' : 'A') + + measure_word = if errors_count > 1 + errors_count + else + exception_class.to_s =~ /^[aeiou]/i ? 'An' : 'A' + end + exception_name = "*#{measure_word}* `#{exception_class.to_s}`" env = options[:env] diff --git a/lib/exception_notifier/sns_notifier.rb b/lib/exception_notifier/sns_notifier.rb index 9e74145a..fbd7f72e 100644 --- a/lib/exception_notifier/sns_notifier.rb +++ b/lib/exception_notifier/sns_notifier.rb @@ -65,7 +65,13 @@ def build_message(exception, options) def accumulated_exception_name(exception, options) errors_count = options[:accumulated_errors_count].to_i - measure_word = errors_count > 1 ? errors_count : (exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A') + + measure_word = if errors_count > 1 + errors_count + else + exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A' + end + "#{measure_word} #{exception.class}" end From 54a7fa63c733f5b5793437a3425a38de7070022b Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:47:50 -0300 Subject: [PATCH 12/14] Fix Style/MultilineBlockChain offense --- .rubocop_todo.yml | 5 ----- lib/exception_notifier/email_notifier.rb | 7 +++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e31c15da..e0dc2beb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -119,11 +119,6 @@ Style/MissingRespondToMissing: - 'lib/exception_notifier/mattermost_notifier.rb' - 'lib/exception_notifier/teams_notifier.rb' -# Offense count: 1 -Style/MultilineBlockChain: - Exclude: - - 'lib/exception_notifier/email_notifier.rb' - # Offense count: 253 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/lib/exception_notifier/email_notifier.rb b/lib/exception_notifier/email_notifier.rb index b28d013c..ede9b1cb 100644 --- a/lib/exception_notifier/email_notifier.rb +++ b/lib/exception_notifier/email_notifier.rb @@ -141,7 +141,8 @@ def initialize(options) mailer_settings_key = "#{delivery_method}_settings".to_sym options[:mailer_settings] = options.delete(mailer_settings_key) - options.reverse_merge(EmailNotifier.default_options).select do |k, _v| + merged_opts = options.reverse_merge(EmailNotifier.default_options) + filtered_opts = merged_opts.select do |k, _v| %i[ sender_address exception_recipients pre_callback post_callback email_prefix email_format @@ -149,7 +150,9 @@ def initialize(options) include_controller_and_action_names_in_subject delivery_method mailer_settings email_headers mailer_parent template_path deliver_with ].include?(k) - end .each { |k, v| send("#{k}=", v) } + end + + filtered_opts.each { |k, v| send("#{k}=", v) } end def options From ffff62fee99d526ffb8a0647cb62812210585046 Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Sun, 30 Dec 2018 16:52:34 -0300 Subject: [PATCH 13/14] Re-generate .rubocop_todo.yml using Rubocop 0.50.0 --- .rubocop_todo.yml | 121 +++++++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 40 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e0dc2beb..73b2f152 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,43 +1,73 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-12-18 20:02:43 -0300 using RuboCop version 0.59.2. +# on 2019-01-23 23:57:48 -0300 using RuboCop version 0.50.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 -# Configuration parameters: Include. -# Include: **/*.gemspec -Gemspec/RequiredRubyVersion: +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'lib/exception_notifier/slack_notifier.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'lib/exception_notifier/slack_notifier.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SupportedStylesForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: Exclude: - - 'exception_notification.gemspec' + - 'lib/exception_notifier/slack_notifier.rb' # Offense count: 2 # Cop supports --auto-correct. -Layout/RescueEnsureAlignment: +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: Exclude: - - 'lib/exception_notifier/modules/error_grouping.rb' - - 'test/exception_notifier/webhook_notifier_test.rb' + - 'lib/exception_notifier/slack_notifier.rb' -# Offense count: 12 +# Offense count: 4 Lint/RescueException: Exclude: - 'lib/exception_notification/rack.rb' - 'lib/exception_notification/sidekiq.rb' - 'lib/exception_notifier.rb' +# Offense count: 1 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Exclude: + - 'lib/exception_notifier/slack_notifier.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/exception_notifier/slack_notifier.rb' + # Offense count: 18 Metrics/AbcSize: - Max: 97 + Max: 98 # Offense count: 3 # Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine Metrics/BlockLength: Max: 88 -# Offense count: 10 +# Offense count: 11 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 186 @@ -46,8 +76,14 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 24 -# Offense count: 28 -# Configuration parameters: CountComments, ExcludedMethods. +# Offense count: 253 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 226 + +# Offense count: 29 +# Configuration parameters: CountComments. Metrics/MethodLength: Max: 90 @@ -57,7 +93,17 @@ Metrics/PerceivedComplexity: # Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. +Performance/StringReplacement: + Exclude: + - 'lib/exception_notifier/slack_notifier.rb' + +# Offense count: 1 +Style/CaseEquality: + Exclude: + - 'test/exception_notification/resque_test.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: @@ -69,7 +115,7 @@ Style/ClassVars: - 'lib/exception_notifier.rb' - 'test/exception_notifier/modules/error_grouping_test.rb' -# Offense count: 28 +# Offense count: 29 Style/Documentation: Enabled: false @@ -78,11 +124,6 @@ Style/DoubleNegation: Exclude: - 'lib/exception_notifier/irc_notifier.rb' -# Offense count: 1 -Style/EvalWithLocation: - Exclude: - - 'test/exception_notifier_test.rb' - # Offense count: 6 # Configuration parameters: MinBodyLength. Style/GuardClause: @@ -94,33 +135,33 @@ Style/GuardClause: - 'lib/exception_notifier/slack_notifier.rb' - 'lib/exception_notifier/sns_notifier.rb' -# Offense count: 7 +# Offense count: 1 # Cop supports --auto-correct. -Style/IfUnlessModifier: +Style/MethodCallWithoutArgsParentheses: Exclude: - - 'lib/exception_notification/rack.rb' - - 'lib/exception_notifier/datadog_notifier.rb' - - 'lib/exception_notifier/google_chat_notifier.rb' - - 'lib/exception_notifier/webhook_notifier.rb' - - 'test/dummy/test/functional/posts_controller_test.rb' - - 'test/exception_notifier/email_notifier_test.rb' + - 'test/exception_notification/resque_test.rb' # Offense count: 3 -Style/MethodMissingSuper: +Style/MethodMissing: Exclude: - 'lib/exception_notifier/email_notifier.rb' - 'lib/exception_notifier/mattermost_notifier.rb' - 'lib/exception_notifier/teams_notifier.rb' -# Offense count: 3 -Style/MissingRespondToMissing: +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: Exclude: - - 'lib/exception_notifier/email_notifier.rb' - - 'lib/exception_notifier/mattermost_notifier.rb' - - 'lib/exception_notifier/teams_notifier.rb' + - 'lib/exception_notifier/slack_notifier.rb' -# Offense count: 253 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 226 +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'lib/exception_notifier/datadog_notifier.rb' + - 'lib/exception_notifier/slack_notifier.rb' + - 'test/exception_notification/resque_test.rb' + - 'test/exception_notifier/datadog_notifier_test.rb' From d5b23121a65767ba54e6a47d0f9a6ef71497f50f Mon Sep 17 00:00:00 2001 From: Emilio Cristalli Date: Thu, 24 Jan 2019 00:00:06 -0300 Subject: [PATCH 14/14] Fix slack_notifier offenses --- .rubocop_todo.yml | 59 ------------------------ lib/exception_notifier/slack_notifier.rb | 12 ++--- 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 73b2f152..56b6555a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,38 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -Layout/SpaceAfterComma: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, SupportedStylesForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - # Offense count: 4 Lint/RescueException: Exclude: @@ -45,19 +13,6 @@ Lint/RescueException: - 'lib/exception_notification/sidekiq.rb' - 'lib/exception_notifier.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - # Offense count: 18 Metrics/AbcSize: Max: 98 @@ -91,12 +46,6 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 24 -# Offense count: 1 -# Cop supports --auto-correct. -Performance/StringReplacement: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - # Offense count: 1 Style/CaseEquality: Exclude: @@ -148,13 +97,6 @@ Style/MethodMissing: - 'lib/exception_notifier/mattermost_notifier.rb' - 'lib/exception_notifier/teams_notifier.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/exception_notifier/slack_notifier.rb' - # Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. @@ -162,6 +104,5 @@ Style/PercentLiteralDelimiters: Style/StringLiterals: Exclude: - 'lib/exception_notifier/datadog_notifier.rb' - - 'lib/exception_notifier/slack_notifier.rb' - 'test/exception_notification/resque_test.rb' - 'test/exception_notifier/datadog_notifier_test.rb' diff --git a/lib/exception_notifier/slack_notifier.rb b/lib/exception_notifier/slack_notifier.rb index 05005d90..fe9ab7a1 100644 --- a/lib/exception_notifier/slack_notifier.rb +++ b/lib/exception_notifier/slack_notifier.rb @@ -20,13 +20,13 @@ def initialize(options) end end - def call(exception, options={}) - clean_message = exception.message.gsub("`", "'") + def call(exception, options = {}) + clean_message = exception.message.tr('`', "'") attchs = attchs(exception, clean_message, options) if valid? args = [exception, options, clean_message, @message_opts.merge(attachments: attchs)] - send_notice(*args) do |msg, message_opts| + send_notice(*args) do |_msg, message_opts| @notifier.ping '', message_opts end end @@ -52,7 +52,7 @@ def attchs(exception, clean_message, options) text, data = information_from_options(exception.class, options) fields = fields(clean_message, exception.backtrace, data) - [color: @color, text: text, fields: fields, mrkdwn_in: %w(text fields)] + [color: @color, text: text, fields: fields, mrkdwn_in: %w[text fields]] end def information_from_options(exception_class, options) @@ -64,7 +64,7 @@ def information_from_options(exception_class, options) exception_class.to_s =~ /^[aeiou]/i ? 'An' : 'A' end - exception_name = "*#{measure_word}* `#{exception_class.to_s}`" + exception_name = "*#{measure_word}* `#{exception_class}`" env = options[:env] if env.nil? @@ -96,7 +96,7 @@ def fields(clean_message, backtrace, data) unless data.empty? deep_reject(data, @ignore_data_if) if @ignore_data_if.is_a?(Proc) - data_string = data.map{|k,v| "#{k}: #{v}"}.join("\n") + data_string = data.map { |k, v| "#{k}: #{v}" }.join("\n") fields << { title: 'Data', value: "```#{data_string}```" } end