Skip to content

Commit

Permalink
Fix slack_notifier offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioCristalli committed Jan 24, 2019
1 parent ffff62f commit d5b2312
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 65 deletions.
59 changes: 0 additions & 59 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,13 @@
# 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:
- '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: 98
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -148,20 +97,12 @@ 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.
# 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'
12 changes: 6 additions & 6 deletions lib/exception_notifier/slack_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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?
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d5b2312

Please sign in to comment.