Skip to content
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
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'
16 changes: 16 additions & 0 deletions lib/rubocop/cop/bugcrowd/prevent_bugsnag_usage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module RuboCop
module Cop
module Bugcrowd
class PreventBugsnagUsage < RuboCop::Cop::Base
MSG = 'Do not use Bugsnag in the codebase, as its integration has been removed. ' \
'Use ErrorTrackingService for reporting errors.'

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'
49 changes: 49 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,49 @@
# frozen_string_literal: true

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

let(:message) do
'Do not use Bugsnag in the codebase, as its integration has been removed. ' \
'Use ErrorTrackingService for reporting errors.'
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 ErrorTrackingService' do
expect_no_offenses(<<~RUBY)
ErrorTrackingService.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