From ee472fe357d5f94b91b112ae6927e9a04c3f3e99 Mon Sep 17 00:00:00 2001 From: Cory Virok Date: Fri, 9 Jun 2017 23:28:20 -0700 Subject: [PATCH 1/2] Fixed a bunch of style issues Codacy found. @jondeandres --- Gemfile | 2 +- lib/generators/rollbar/rollbar_generator.rb | 19 +++++++++---------- lib/rails/rollbar_runner.rb | 4 +--- lib/rollbar/capistrano3.rb | 3 ++- lib/rollbar/configuration.rb | 12 +++++------- lib/rollbar/delay/girl_friday.rb | 1 - lib/rollbar/delay/sucker_punch.rb | 1 - lib/rollbar/exception_reporter.rb | 4 ++-- lib/rollbar/item.rb | 3 +-- lib/rollbar/json.rb | 1 - lib/rollbar/json/oj.rb | 3 ++- lib/rollbar/middleware/rails/rollbar.rb | 2 +- lib/rollbar/plugins/goalie.rb | 4 ++-- .../plugins/rails/controller_methods.rb | 1 - lib/rollbar/plugins/rails/railtie32.rb | 1 - lib/rollbar/plugins/sidekiq/plugin.rb | 4 ++-- lib/rollbar/rails.rb | 1 - lib/rollbar/truncation.rb | 3 +-- lib/rollbar/truncation/min_body_strategy.rb | 1 - lib/rollbar/util.rb | 15 +++++---------- lib/tasks/tasks.rake | 6 +++--- rollbar.gemspec | 11 +++++------ 22 files changed, 42 insertions(+), 60 deletions(-) diff --git a/Gemfile b/Gemfile index 832e0fe9..45085292 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/lib/generators/rollbar/rollbar_generator.rb b/lib/generators/rollbar/rollbar_generator.rb index ba3b9fd7..024f75d5 100644 --- a/lib/generators/rollbar/rollbar_generator.rb +++ b/lib/generators/rollbar/rollbar_generator.rb @@ -10,10 +10,10 @@ 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 @@ -21,27 +21,26 @@ def create_initializer 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 diff --git a/lib/rails/rollbar_runner.rb b/lib/rails/rollbar_runner.rb index 757ed37a..7400d765 100644 --- a/lib/rails/rollbar_runner.rb +++ b/lib/rails/rollbar_runner.rb @@ -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 @@ -68,5 +68,3 @@ def railties_gem_dir end end end - - diff --git a/lib/rollbar/capistrano3.rb b/lib/rollbar/capistrano3.rb index 0beab9f4..5fbe22cf 100644 --- a/lib/rollbar/capistrano3.rb +++ b/lib/rollbar/capistrano3.rb @@ -1 +1,2 @@ -load File.expand_path("../tasks/rollbar.cap", __FILE__) \ No newline at end of file +load File.expand_path('../tasks/rollbar.cap', __FILE__) + diff --git a/lib/rollbar/configuration.rb b/lib/rollbar/configuration.rb index 7381c553..e2aae55a 100644 --- a/lib/rollbar/configuration.rb +++ b/lib/rollbar/configuration.rb @@ -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 = { @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/rollbar/delay/girl_friday.rb b/lib/rollbar/delay/girl_friday.rb index 7a7ba190..fd54dacd 100644 --- a/lib/rollbar/delay/girl_friday.rb +++ b/lib/rollbar/delay/girl_friday.rb @@ -1,7 +1,6 @@ module Rollbar module Delay class GirlFriday - class << self def queue_class ::GirlFriday::WorkQueue diff --git a/lib/rollbar/delay/sucker_punch.rb b/lib/rollbar/delay/sucker_punch.rb index ad2c4360..9bcf6ecd 100644 --- a/lib/rollbar/delay/sucker_punch.rb +++ b/lib/rollbar/delay/sucker_punch.rb @@ -4,7 +4,6 @@ module Rollbar module Delay class SuckerPunch - include ::SuckerPunch::Job class << self diff --git a/lib/rollbar/exception_reporter.rb b/lib/rollbar/exception_reporter.rb index 02fa603e..0b308652 100644 --- a/lib/rollbar/exception_reporter.rb +++ b/lib/rollbar/exception_reporter.rb @@ -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}" diff --git a/lib/rollbar/item.rb b/lib/rollbar/item.rb index 4cedc129..9cecabbb 100644 --- a/lib/rollbar/item.rb +++ b/lib/rollbar/item.rb @@ -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 diff --git a/lib/rollbar/json.rb b/lib/rollbar/json.rb index 53d92181..283f7f9c 100644 --- a/lib/rollbar/json.rb +++ b/lib/rollbar/json.rb @@ -63,4 +63,3 @@ def multi_json_adapter_module_name end end end - diff --git a/lib/rollbar/json/oj.rb b/lib/rollbar/json/oj.rb index fff52c2f..b48d823a 100644 --- a/lib/rollbar/json/oj.rb +++ b/lib/rollbar/json/oj.rb @@ -4,7 +4,8 @@ module Oj extend self def options - { :mode=> :compat, + { + :mode => :compat, :use_to_json => false, :symbol_keys => false, :circular => false diff --git a/lib/rollbar/middleware/rails/rollbar.rb b/lib/rollbar/middleware/rails/rollbar.rb index d48b7a13..4931c53a 100644 --- a/lib/rollbar/middleware/rails/rollbar.rb +++ b/lib/rollbar/middleware/rails/rollbar.rb @@ -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 diff --git a/lib/rollbar/plugins/goalie.rb b/lib/rollbar/plugins/goalie.rb index 9b2e9961..023fca2a 100644 --- a/lib/rollbar/plugins/goalie.rb +++ b/lib/rollbar/plugins/goalie.rb @@ -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 diff --git a/lib/rollbar/plugins/rails/controller_methods.rb b/lib/rollbar/plugins/rails/controller_methods.rb index bf9a2297..e372d0d7 100644 --- a/lib/rollbar/plugins/rails/controller_methods.rb +++ b/lib/rollbar/plugins/rails/controller_methods.rb @@ -34,7 +34,6 @@ def ratchetio_person_data def ratchetio_request_data rollbar_request_data end - end end end diff --git a/lib/rollbar/plugins/rails/railtie32.rb b/lib/rollbar/plugins/rails/railtie32.rb index 3266ea5a..e7bd11a3 100644 --- a/lib/rollbar/plugins/rails/railtie32.rb +++ b/lib/rollbar/plugins/rails/railtie32.rb @@ -15,4 +15,3 @@ class Railtie < ::Rails::Railtie end end end - diff --git a/lib/rollbar/plugins/sidekiq/plugin.rb b/lib/rollbar/plugins/sidekiq/plugin.rb index a92dee93..ef0b90d7 100644 --- a/lib/rollbar/plugins/sidekiq/plugin.rb +++ b/lib/rollbar/plugins/sidekiq/plugin.rb @@ -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) diff --git a/lib/rollbar/rails.rb b/lib/rollbar/rails.rb index 76555e53..8d96331a 100644 --- a/lib/rollbar/rails.rb +++ b/lib/rollbar/rails.rb @@ -1,5 +1,4 @@ module Rollbar module Rails - end end diff --git a/lib/rollbar/truncation.rb b/lib/rollbar/truncation.rb index 3b4abb37..793f9e57 100644 --- a/lib/rollbar/truncation.rb +++ b/lib/rollbar/truncation.rb @@ -13,8 +13,7 @@ module Truncation STRATEGIES = [RawStrategy, FramesStrategy, StringsStrategy, - MinBodyStrategy - ] + MinBodyStrategy] def self.truncate(payload) result = nil diff --git a/lib/rollbar/truncation/min_body_strategy.rb b/lib/rollbar/truncation/min_body_strategy.rb index 13446525..5edc3de9 100644 --- a/lib/rollbar/truncation/min_body_strategy.rb +++ b/lib/rollbar/truncation/min_body_strategy.rb @@ -22,7 +22,6 @@ def call(payload) body['trace'] = truncate_trace_data(body['trace']) end - dump(new_payload) end diff --git a/lib/rollbar/util.rb b/lib/rollbar/util.rb index 2cb20f0e..a88616a2 100644 --- a/lib/rollbar/util.rb +++ b/lib/rollbar/util.rb @@ -1,6 +1,5 @@ require 'rollbar/util/hash' - module Rollbar module Util def self.iterate_and_update(obj, block) @@ -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| @@ -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 @@ -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) diff --git a/lib/tasks/tasks.rake b/lib/tasks/tasks.rake index 691d2889..1a1ee839 100644 --- a/lib/tasks/tasks.rake +++ b/lib/tasks/tasks.rake @@ -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") diff --git a/rollbar.gemspec b/rollbar.gemspec index 97144494..27adca48 100644 --- a/rollbar.gemspec +++ b/rollbar.gemspec @@ -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' From c8cffe68f8bf853110ebbd9c895244abf8cc9390 Mon Sep 17 00:00:00 2001 From: Cory Virok Date: Sat, 10 Jun 2017 00:00:50 -0700 Subject: [PATCH 2/2] Fix some more Codacy issues --- lib/rollbar/capistrano3.rb | 1 - lib/rollbar/middleware/rails/rollbar.rb | 2 +- lib/rollbar/util.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/rollbar/capistrano3.rb b/lib/rollbar/capistrano3.rb index 5fbe22cf..cda22fe6 100644 --- a/lib/rollbar/capistrano3.rb +++ b/lib/rollbar/capistrano3.rb @@ -1,2 +1 @@ load File.expand_path('../tasks/rollbar.cap', __FILE__) - diff --git a/lib/rollbar/middleware/rails/rollbar.rb b/lib/rollbar/middleware/rails/rollbar.rb index 4931c53a..e056c448 100644 --- a/lib/rollbar/middleware/rails/rollbar.rb +++ b/lib/rollbar/middleware/rails/rollbar.rb @@ -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 diff --git a/lib/rollbar/util.rb b/lib/rollbar/util.rb index a88616a2..60871ada 100644 --- a/lib/rollbar/util.rb +++ b/lib/rollbar/util.rb @@ -82,7 +82,7 @@ def self.deep_merge(hash1, hash2) def self.truncate(str, length) ellipsis = '...' - return str if (str.length <= length || str.length <= ellipsis.length) + return str if str.length <= length || str.length <= ellipsis.length str.unpack('U*').slice(0, length - ellipsis.length).pack('U*') + ellipsis end