From c0411a2581c5b24ad8d01388444f8762fe5bc1e9 Mon Sep 17 00:00:00 2001 From: Rocela Durazo Date: Tue, 19 Oct 2021 18:07:00 -0700 Subject: [PATCH 1/5] Add rubocop gem --- .rubocop.yml | 6 ++++++ heartcheck-newrelic.gemspec | 1 + 2 files changed, 7 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..64812ac --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +Style/Documentation: + Enabled: false + +AllCops: + Exclude: + - 'heartcheck-newrelic.gemspec' diff --git a/heartcheck-newrelic.gemspec b/heartcheck-newrelic.gemspec index 2d0204a..fa7b2b2 100644 --- a/heartcheck-newrelic.gemspec +++ b/heartcheck-newrelic.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rubocop' spec.required_ruby_version = '>= 2.3' end From a84d933362fc44ae56c40f83fbdb044fd5892560 Mon Sep 17 00:00:00 2001 From: Rocela Durazo Date: Tue, 19 Oct 2021 18:07:23 -0700 Subject: [PATCH 2/5] Run rubocop and solve offenses --- Gemfile | 2 ++ Rakefile | 2 ++ bin/console | 1 + bin/rspec | 13 +++++++------ lib/heartcheck/checks/newrelic.rb | 4 +++- lib/heartcheck/newrelic.rb | 2 ++ lib/heartcheck/newrelic/version.rb | 4 +++- spec/heartcheck/checks/newrelic_spec.rb | 2 ++ spec/spec_helper.rb | 4 +++- 9 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df1..7f4f5e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index 4c774a2..82bb534 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/bin/console b/bin/console index 3771eab..c1523c2 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'heartcheck/newrelic' diff --git a/bin/rspec b/bin/rspec index d738b23..c593896 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,5 +1,6 @@ #!/usr/bin/env ruby # frozen_string_literal: true + # # This file was generated by Bundler. # @@ -7,11 +8,11 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("rspec-core", "rspec") +load Gem.bin_path('rspec-core', 'rspec') diff --git a/lib/heartcheck/checks/newrelic.rb b/lib/heartcheck/checks/newrelic.rb index e5c9796..f62880b 100644 --- a/lib/heartcheck/checks/newrelic.rb +++ b/lib/heartcheck/checks/newrelic.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module Heartcheck module Checks class Newrelic < Base def validate NewRelic::Agent.increment_metric('Custom/NewRelicMonitoring') - rescue => e + rescue StandardError => e append_error('could not report to New Relic server.') append_error(e.message) end diff --git a/lib/heartcheck/newrelic.rb b/lib/heartcheck/newrelic.rb index 6d4e18c..10dc449 100644 --- a/lib/heartcheck/newrelic.rb +++ b/lib/heartcheck/newrelic.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'newrelic_rpm' require 'heartcheck' require 'heartcheck/checks/newrelic' diff --git a/lib/heartcheck/newrelic/version.rb b/lib/heartcheck/newrelic/version.rb index 56c78a8..7af5877 100644 --- a/lib/heartcheck/newrelic/version.rb +++ b/lib/heartcheck/newrelic/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Heartcheck module Newrelic - VERSION = '0.2.0'.freeze + VERSION = '0.2.0' end end diff --git a/spec/heartcheck/checks/newrelic_spec.rb b/spec/heartcheck/checks/newrelic_spec.rb index 8cc004b..ac31e61 100644 --- a/spec/heartcheck/checks/newrelic_spec.rb +++ b/spec/heartcheck/checks/newrelic_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Heartcheck::Checks::Newrelic do describe '#validate' do it 'does not record an error when everything is fine' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1af51b7..3b7bd37 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,6 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +# frozen_string_literal: true + +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'heartcheck/newrelic' RSpec.configure do |config| From 2d4fe6313bde096b0af54c3c3f7b515be602df33 Mon Sep 17 00:00:00 2001 From: Rocela Durazo Date: Tue, 19 Oct 2021 18:11:46 -0700 Subject: [PATCH 3/5] Fix issue with variable name 'e' --- lib/heartcheck/checks/newrelic.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/heartcheck/checks/newrelic.rb b/lib/heartcheck/checks/newrelic.rb index f62880b..4b243cf 100644 --- a/lib/heartcheck/checks/newrelic.rb +++ b/lib/heartcheck/checks/newrelic.rb @@ -5,9 +5,9 @@ module Checks class Newrelic < Base def validate NewRelic::Agent.increment_metric('Custom/NewRelicMonitoring') - rescue StandardError => e + rescue StandardError => exception append_error('could not report to New Relic server.') - append_error(e.message) + append_error(exception.message) end private From b23653fa7920fe8fe80fdd9018f5e1121be9f89b Mon Sep 17 00:00:00 2001 From: Rocela Durazo Date: Tue, 19 Oct 2021 18:14:01 -0700 Subject: [PATCH 4/5] fix rubocop issue: - Naming/RescuedExceptionsVariableName: Use e instead of exception. --- lib/heartcheck/checks/newrelic.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/heartcheck/checks/newrelic.rb b/lib/heartcheck/checks/newrelic.rb index 4b243cf..f62880b 100644 --- a/lib/heartcheck/checks/newrelic.rb +++ b/lib/heartcheck/checks/newrelic.rb @@ -5,9 +5,9 @@ module Checks class Newrelic < Base def validate NewRelic::Agent.increment_metric('Custom/NewRelicMonitoring') - rescue StandardError => exception + rescue StandardError => e append_error('could not report to New Relic server.') - append_error(exception.message) + append_error(e.message) end private From ede35edaab7388f823dcb3e2f316c2f97796dd97 Mon Sep 17 00:00:00 2001 From: Rocela Durazo Date: Wed, 20 Oct 2021 10:19:43 -0700 Subject: [PATCH 5/5] update rubocop file to disable Naming/RescuedExceptionsVariableName --- .rubocop.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 64812ac..d30c3ec 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,9 @@ -Style/Documentation: - Enabled: false - AllCops: Exclude: - 'heartcheck-newrelic.gemspec' + +Style/Documentation: + Enabled: false + +Naming/RescuedExceptionsVariableName: + Enabled: false