Skip to content

Commit 7b22a5e

Browse files
committed
Add standard 'unsafe' fixes
1 parent 7f605ca commit 7b22a5e

31 files changed

+41
-45
lines changed

lib/honeybadger/backtrace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_source(file, number, radius = 2)
104104
f.gets
105105
l += 1
106106
}
107-
return Hash[duration.times.map { (line = f.gets) ? [(l += 1), line] : nil }.compact]
107+
return duration.times.map { (line = f.gets) ? [(l += 1), line] : nil }.compact.to_h
108108
end
109109
else
110110
{}

lib/honeybadger/breadcrumbs/active_support.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.default_notifications
1919
transform: lambda do |data|
2020
if data[:sql]
2121
connection = data.delete(:connection)
22-
adapter = (connection && connection.adapter_name.downcase) || active_record_connection_db_config[:adapter]
22+
adapter = connection&.adapter_name&.downcase || active_record_connection_db_config[:adapter]
2323
data[:sql] = Util::SQL.obfuscate(data[:sql], adapter)
2424
end
2525
data

lib/honeybadger/cli/heroku.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def detect_heroku_app(prompt_on_default = true)
7878
apps.values.first
7979
else
8080
say "We detected a Heroku app named #{apps.values.first}. Do you want to load the config? (y/yes or n/no)"
81-
if STDIN.gets.chomp =~ /(y|yes)/i
81+
if $stdin.gets.chomp =~ /(y|yes)/i
8282
apps.values.first
8383
end
8484
end
@@ -87,7 +87,7 @@ def detect_heroku_app(prompt_on_default = true)
8787
apps.each_with_index { |a, i| say "\s\s#{i + 1}. #{a[1]}" }
8888
say "\s\s#{apps.size + 1}. Use default"
8989
say "Please select an option (1-#{apps.size + 1}):"
90-
apps.values[STDIN.gets.chomp.to_i - 1]
90+
apps.values[$stdin.gets.chomp.to_i - 1]
9191
end
9292
end
9393
end
@@ -107,7 +107,7 @@ def read_heroku_env(app = nil)
107107
cmd << "--app #{app}" if app
108108
output = run(cmd.join("\s"))
109109
return false unless $?.to_i == 0
110-
Hash[output.scan(/(HONEYBADGER_[^:]+):\s*(\S.*)\s*$/)]
110+
output.scan(/(HONEYBADGER_[^:]+):\s*(\S.*)\s*$/).to_h
111111
end
112112

113113
def set_env_from_heroku(app = nil)

lib/honeybadger/cli/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Test
1212
exception_name = ENV["EXCEPTION"] || "HoneybadgerTestingException"
1313
Object.const_get(exception_name)
1414
rescue
15-
Object.const_set(exception_name, Class.new(Exception))
15+
Object.const_set(exception_name, Class.new(RuntimeError))
1616
end.new('Testing honeybadger via "honeybadger test". If you can see this, it works.')
1717

1818
class TestBackend
@@ -90,7 +90,7 @@ def test_exception_class
9090
exception_name = ENV["EXCEPTION"] || "HoneybadgerTestingException"
9191
Object.const_get(exception_name)
9292
rescue
93-
Object.const_set(exception_name, Class.new(Exception))
93+
Object.const_set(exception_name, Class.new(RuntimeError))
9494
end
9595

9696
def run_standalone_test

lib/honeybadger/config.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
require "honeybadger/config/defaults"
1111
require "honeybadger/util/http"
1212
require "honeybadger/util/revision"
13-
require "honeybadger/logging"
1413

1514
module Honeybadger
1615
# @api private

lib/honeybadger/config/defaults.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class Boolean; end
291291
},
292292
"exceptions.rescue_rake": {
293293
description: "Enable reporting exceptions in rake tasks.",
294-
default: !STDOUT.tty?,
294+
default: !$stdout.tty?,
295295
type: Boolean
296296
},
297297
"exceptions.notify_at_exit": {
@@ -519,6 +519,6 @@ class Boolean; end
519519
}
520520
}.freeze
521521

522-
DEFAULTS = Hash[OPTIONS.map { |k, v| [k, v[:default]] }].freeze
522+
DEFAULTS = OPTIONS.map { |k, v| [k, v[:default]] }.to_h.freeze
523523
end
524524
end

lib/honeybadger/config/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Honeybadger
44
class Config
55
module Env
66
CONFIG_KEY = /\AHONEYBADGER_(.+)\Z/.freeze
7-
CONFIG_MAPPING = Hash[DEFAULTS.keys.map { |k| [k.to_s.upcase.gsub(KEY_REPLACEMENT, "_"), k] }].freeze
7+
CONFIG_MAPPING = DEFAULTS.keys.map { |k| [k.to_s.upcase.gsub(KEY_REPLACEMENT, "_"), k] }.to_h.freeze
88
ARRAY_VALUES = Regexp.new('\s*,\s*').freeze
99
IGNORED_TYPES = Set[Hash]
1010

lib/honeybadger/config/ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def mash?(method)
4646
end
4747

4848
def setter?(method_name)
49-
return false unless method_name.to_s =~ /=\z/
49+
return false unless method_name.to_s.end_with?("=")
5050
key = key(method_name)
5151
KEYS.any? { |k| k == key }
5252
end

lib/honeybadger/events_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def shutdown(force = false)
8484
# Blocks until queue is processed up to this point in time.
8585
def flush
8686
mutex.synchronize do
87-
if thread && thread.alive?
87+
if thread&.alive?
8888
queue.push(FLUSH)
8989
queue.push(marker)
9090
marker.wait(mutex)

lib/honeybadger/instrumentation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ def gauge(name, *args)
143143

144144
# @api private
145145
def extract_attributes(args)
146-
args.select { |a| a.is_a?(Hash) }.first || {}
146+
args.find { |a| a.is_a?(Hash) } || {}
147147
end
148148

149149
# @api private
150150
def extract_callable(args)
151-
args.select { |a| a.respond_to?(:call) }.first
151+
args.find { |a| a.respond_to?(:call) }
152152
end
153153
end
154154
end

0 commit comments

Comments
 (0)