Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codacy cleanup #599

Merged
merged 2 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source 'https://rubygems.org'

is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby')

gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
gem 'appraisal'
Expand Down
19 changes: 9 additions & 10 deletions lib/generators/rollbar/rollbar_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,37 @@ class RollbarGenerator < ::Rails::Generators::Base
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))

def create_initializer
say "creating initializer..."
say 'creating initializer...'
if access_token_configured?
say "It looks like you've already configured Rollbar."
say "To re-create the config file, remove it first: config/initializers/rollbar.rb"
say 'To re-create the config file, remove it first: config/initializers/rollbar.rb'
exit
end

begin
require 'ey_config'
rescue LoadError
end

if defined? EY::Config
say "Access token will be read from Engine Yard configuration"
say 'Access token will be read from Engine Yard configuration'
else
if access_token === :use_env_sentinel
say "Generator run without an access token; assuming you want to configure using an environment variable."
say 'Generator run without an access token; assuming you want to configure using an environment variable.'
say "You'll need to add an environment variable ROLLBAR_ACCESS_TOKEN with your access token:"
say "\n$ export ROLLBAR_ACCESS_TOKEN=yourtokenhere"
say "\nIf that's not what you wanted to do:"
say "\n$ rm config/initializers/rollbar.rb"
say "$ rails generate rollbar yourtokenhere"
say '$ rails generate rollbar yourtokenhere'
say "\n"
else
say "access token: " << access_token
say 'access token: ' << access_token
end
end

template 'initializer.rb', 'config/initializers/rollbar.rb',
:assigns => { :access_token => access_token_expr }
template 'initializer.rb', 'config/initializers/rollbar.rb', :assigns => { :access_token => access_token_expr }

# TODO run rake test task
# TODO: run rake test task
end

def access_token_expr
Expand Down
4 changes: 1 addition & 3 deletions lib/rails/rollbar_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def prepare_environment
def eval_runner
string_to_eval = File.read(runner_path)

::Rails.module_eval(<<-EOL,__FILE__,__LINE__ + 2)
::Rails.module_eval(<<-EOL, __FILE__, __LINE__ + 2)
#{string_to_eval}
EOL
end
Expand Down Expand Up @@ -68,5 +68,3 @@ def railties_gem_dir
end
end
end


2 changes: 1 addition & 1 deletion lib/rollbar/capistrano3.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
load File.expand_path("../tasks/rollbar.cap", __FILE__)
load File.expand_path('../tasks/rollbar.cap', __FILE__)
12 changes: 5 additions & 7 deletions lib/rollbar/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def initialize
@disable_core_monkey_patch = false
@disable_rack_monkey_patch = false
@dj_threshold = 0
@enabled = nil # set to true when configure is called
@enabled = nil # set to true when configure is called
@endpoint = DEFAULT_ENDPOINT
@environment = nil
@exception_level_filters = {
Expand All @@ -101,7 +101,7 @@ def initialize
@js_options = {}
@scrub_fields = [:passwd, :password, :password_confirmation, :secret,
:confirm_password, :password_confirmation, :secret_token,
:api_key, :access_token ]
:api_key, :access_token]
@scrub_user = true
@scrub_password = true
@randomize_scrub_length = true
Expand Down Expand Up @@ -172,7 +172,7 @@ def use_resque(options = {})
end

def use_sidekiq=(value)
deprecation_message = "#use_sidekiq=(value) has been deprecated in favor of #use_sidekiq(options = {}). Please update your rollbar configuration."
deprecation_message = '#use_sidekiq=(value) has been deprecated in favor of #use_sidekiq(options = {}). Please update your rollbar configuration.'
defined?(ActiveSupport) ? ActiveSupport::Deprecation.warn(deprecation_message) : puts(deprecation_message)

value.is_a?(Hash) ? use_sidekiq(value) : use_sidekiq
Expand All @@ -191,7 +191,7 @@ def use_sucker_punch
end

def use_sucker_punch=(value)
deprecation_message = "#use_sucker_punch=(value) has been deprecated in favor of #use_sucker_punch. Please update your rollbar configuration."
deprecation_message = '#use_sucker_punch=(value) has been deprecated in favor of #use_sucker_punch. Please update your rollbar configuration.'
defined?(ActiveSupport) ? ActiveSupport::Deprecation.warn(deprecation_message) : puts(deprecation_message)

use_sucker_punch
Expand All @@ -205,9 +205,7 @@ def use_eventmachine=(value)
def project_gems=(gems)
@project_gem_paths = gems.map do |name|
found = Gem::Specification.each.select { |spec| name === spec.name }
if found.empty?
puts "[Rollbar] No gems found matching #{name.inspect}"
end
puts "[Rollbar] No gems found matching #{name.inspect}" if found.empty?
found
end.flatten.uniq.map(&:gem_dir)
end
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/delay/girl_friday.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Rollbar
module Delay
class GirlFriday

class << self
def queue_class
::GirlFriday::WorkQueue
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/delay/sucker_punch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Rollbar
module Delay
class SuckerPunch

include ::SuckerPunch::Job

class << self
Expand Down
4 changes: 2 additions & 2 deletions lib/rollbar/exception_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def report_exception_to_rollbar(env, exception)
env['rollbar.exception_uuid'] = exception_data[:uuid]
Rollbar.log_debug "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
elsif exception_data == 'disabled'
Rollbar.log_debug "[Rollbar] Exception not reported because Rollbar is disabled"
Rollbar.log_debug '[Rollbar] Exception not reported because Rollbar is disabled'
elsif exception_data == 'ignored'
Rollbar.log_debug "[Rollbar] Exception not reported because it was ignored"
Rollbar.log_debug '[Rollbar] Exception not reported because it was ignored'
end
rescue => e
Rollbar.log_warning "[Rollbar] Exception while reporting exception to Rollbar: #{e.message}"
Expand Down
3 changes: 1 addition & 2 deletions lib/rollbar/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def build_backtrace_body
backtrace = Backtrace.new(exception,
:message => message,
:extra => build_extra,
:configuration => configuration
)
:configuration => configuration)

backtrace.to_h
end
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ def multi_json_adapter_module_name
end
end
end

3 changes: 2 additions & 1 deletion lib/rollbar/json/oj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Oj
extend self

def options
{ :mode=> :compat,
{
:mode => :compat,
:use_to_json => false,
:symbol_keys => false,
:circular => false
Expand Down
2 changes: 1 addition & 1 deletion lib/rollbar/middleware/rails/rollbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def extract_request_data(env)

def person_data_proc(env)
block = proc { extract_person_data_from_controller(env) }
return block unless(defined?(ActiveRecord::Base) && ActiveRecord::Base.connected?)
return block unless defined?(ActiveRecord::Base) && ActiveRecord::Base.connected?

proc { ActiveRecord::Base.connection_pool.with_connection(&block) }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rollbar/plugins/goalie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def render_exception_with_rollbar(env, exception)
env['rollbar.exception_uuid'] = exception_data[:uuid]
Rollbar.log_info "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
elsif exception_data == 'disabled'
Rollbar.log_info "[Rollbar] Exception not reported because Rollbar is disabled"
Rollbar.log_info '[Rollbar] Exception not reported because Rollbar is disabled'
elsif exception_data == 'ignored'
Rollbar.log_info "[Rollbar] Exception not reported because it was ignored"
Rollbar.log_info '[Rollbar] Exception not reported because it was ignored'
end

# now continue as normal
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/plugins/rails/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def ratchetio_person_data
def ratchetio_request_data
rollbar_request_data
end

end
end
end
1 change: 0 additions & 1 deletion lib/rollbar/plugins/rails/railtie32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ class Railtie < ::Rails::Railtie
end
end
end

4 changes: 2 additions & 2 deletions lib/rollbar/plugins/sidekiq/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def self.scrub_params(params)
end

def self.skip_report?(msg_or_context, e)
msg_or_context.is_a?(Hash) && msg_or_context["retry"] &&
msg_or_context["retry_count"] && msg_or_context["retry_count"] < ::Rollbar.configuration.sidekiq_threshold
msg_or_context.is_a?(Hash) && msg_or_context['retry'] &&
msg_or_context['retry_count'] && msg_or_context['retry_count'] < ::Rollbar.configuration.sidekiq_threshold
end

def call(worker, msg, queue)
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/rails.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Rollbar
module Rails

end
end
3 changes: 1 addition & 2 deletions lib/rollbar/truncation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ module Truncation
STRATEGIES = [RawStrategy,
FramesStrategy,
StringsStrategy,
MinBodyStrategy
]
MinBodyStrategy]

def self.truncate(payload)
result = nil
Expand Down
1 change: 0 additions & 1 deletion lib/rollbar/truncation/min_body_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def call(payload)
body['trace'] = truncate_trace_data(body['trace'])
end


dump(new_payload)
end

Expand Down
15 changes: 5 additions & 10 deletions lib/rollbar/util.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'rollbar/util/hash'


module Rollbar
module Util
def self.iterate_and_update(obj, block)
Expand Down Expand Up @@ -28,9 +27,7 @@ def self.iterate_and_update(obj, block)
obj[k] = block.call(v)
end

if new_key != k
key_updates.push([k, new_key])
end
key_updates.push([k, new_key]) if new_key != k
end

key_updates.each do |old_key, new_key|
Expand All @@ -53,12 +50,12 @@ def self.iterate_and_update_hash(hash, block)
def self.deep_copy(obj)
if obj.is_a?(::Hash)
result = obj.clone
obj.each {|k, v| result[k] = deep_copy(v)}
obj.each { |k, v| result[k] = deep_copy(v)}
result
elsif obj.is_a?(Array)
result = obj.clone
result.clear
obj.each {|v| result << deep_copy(v)}
obj.each { |v| result << deep_copy(v)}
result
else
obj
Expand All @@ -85,11 +82,9 @@ def self.deep_merge(hash1, hash2)
def self.truncate(str, length)
ellipsis = '...'

if str.length <= length or str.length <= ellipsis.length
return str
end
return str if str.length <= length || str.length <= ellipsis.length

str.unpack("U*").slice(0, length - ellipsis.length).pack("U*") + ellipsis
str.unpack('U*').slice(0, length - ellipsis.length).pack('U*') + ellipsis
end

def self.uuid_rollbar_url(data, configuration)
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ require 'fileutils'

desc 'Update rollbar.js snippet'
task :update_snippet do
input_path = File.expand_path("../../../rollbar.js/dist/rollbar.snippet.js", __FILE__)
output_path = File.expand_path("../../../data/rollbar.snippet.js", __FILE__)
output_dir = File.expand_path("../../../data/", __FILE__)
input_path = File.expand_path('../../../rollbar.js/dist/rollbar.snippet.js', __FILE__)
output_path = File.expand_path('../../../data/rollbar.snippet.js', __FILE__)
output_dir = File.expand_path('../../../data/', __FILE__)

$stdout.write("Copying #{input_path} to #{output_path}\n")

Expand Down
11 changes: 5 additions & 6 deletions rollbar.gemspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/rollbar/version', __FILE__)


Gem::Specification.new do |gem|
is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)

gem.authors = ["Rollbar, Inc."]
gem.email = ["support@rollbar.com"]
gem.authors = ['Rollbar, Inc.']
gem.email = ['support@rollbar.com']
gem.description = %q{Easy and powerful exception tracking for Ruby}
gem.executables = ['rollbar-rails-runner']
gem.summary = %q{Reports exceptions to Rollbar}
gem.homepage = "https://rollbar.com"
gem.homepage = 'https://rollbar.com'
gem.license = 'MIT'

gem.files = `git ls-files`.split($\)
gem.test_files = gem.files.grep(%r{^(spec)/})
gem.name = "rollbar"
gem.require_paths = ["lib"]
gem.name = 'rollbar'
gem.require_paths = ['lib']
gem.version = Rollbar::VERSION

gem.add_runtime_dependency 'multi_json'
Expand Down