Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ BugcrowdCops/PreventReindexFullESDocumentCop:
Enabled: true
Include:
- 'app/**/*.rb'

BugcrowdCops/PreventBugsnagUsage:
Enabled: true
Include:
- 'app/**/*.rb'
- 'lib/**/*.rb'
17 changes: 17 additions & 0 deletions lib/rubocop/cop/bugcrowd/prevent_bugsnag_usage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module RuboCop
module Cop
module Bugcrowd
class PreventBugsnagUsage < RuboCop::Cop::Base
MSG = 'Avoid using Bugsnag in the codebase. ' \
'It has been replaced with ErrorNotifierService for error ' \
'notification handling. Please use ErrorNotifierService instead.'

def on_send(node)
add_offense(node, message: MSG) if node.receiver&.const_name == 'Bugsnag'
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/rubocop/cop/bugcrowd_cops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
require_relative 'bugcrowd/no_event_deprecated_publish'
require_relative 'bugcrowd/sidekiq_testing_inline'
require_relative 'bugcrowd/prevent_reindex_full_es_document_cop'
require_relative 'bugcrowd/prevent_bugsnag_usage'
50 changes: 50 additions & 0 deletions spec/rubocop/cop/bugcrowd/prevent_bugsnag_usage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage, :config do
subject(:cop) { described_class.new(config) }

let(:message) do
'Avoid using Bugsnag in the codebase. ' \
'It has been replaced with ErrorNotifierService for error ' \
'notification handling. Please use ErrorNotifierService instead.'
end

it 'registers an offense when Bugsnag is used' do
expect_offense(<<~RUBY)
Bugsnag.error('Error')
^^^^^^^^^^^^^^^^^^^^^^ #{message}
RUBY
end

it 'registers an offense when Bugsnag.notify is used' do
expect_offense(<<~RUBY)
Bugsnag.notify('Error')
^^^^^^^^^^^^^^^^^^^^^^^ #{message}
RUBY
end

it 'does not register an offense for ErrorNotifierService' do
expect_no_offenses(<<~RUBY)
ErrorNotifierService.notify('Error')
RUBY
end

it 'does not register an offense for unrelated constants' do
expect_no_offenses(<<~RUBY)
SomeOtherService.notify('Error')
RUBY
end

it 'does not register an offense for lowercase bugsnag' do
expect_no_offenses(<<~RUBY)
bugsnag.error('Error')
RUBY
end

it 'does not register an offense for local variable named Bugsnag' do
expect_no_offenses(<<~RUBY)
bugsnag = SomeService.new
bugsnag.error('Error')
RUBY
end
end