Skip to content

Commit 9e2f51d

Browse files
[BC-26568] Add rubocop warning for the use of Bugsnag (#38)
* [BC-26568] Added rubocop warning for the use of Bugsnag * [BC-26568] Added rubocop warning for the use of Bugsnag * [BC-26568] Added rubocop warning for the use of Bugsnag * Updated rspec * Updated rspec * Updated rspec * Updated rspec * Updating rspec
1 parent 4d9b297 commit 9e2f51d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

config/default.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,9 @@ BugcrowdCops/PreventReindexFullESDocumentCop:
7676
Enabled: true
7777
Include:
7878
- 'app/**/*.rb'
79+
80+
BugcrowdCops/PreventBugsnagUsage:
81+
Enabled: true
82+
Include:
83+
- 'app/**/*.rb'
84+
- 'lib/**/*.rb'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module RuboCop
4+
module Cop
5+
module Bugcrowd
6+
class PreventBugsnagUsage < RuboCop::Cop::Base
7+
MSG = 'Do not use Bugsnag in the codebase, as its integration has been removed. ' \
8+
'Use ErrorTrackingService for reporting errors.'
9+
10+
def on_send(node)
11+
add_offense(node, message: MSG) if node.receiver&.const_name == 'Bugsnag'
12+
end
13+
end
14+
end
15+
end
16+
end

lib/rubocop/cop/bugcrowd_cops.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
require_relative 'bugcrowd/no_event_deprecated_publish'
3939
require_relative 'bugcrowd/sidekiq_testing_inline'
4040
require_relative 'bugcrowd/prevent_reindex_full_es_document_cop'
41+
require_relative 'bugcrowd/prevent_bugsnag_usage'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RuboCop::Cop::Bugcrowd::PreventBugsnagUsage, :config do
4+
subject(:cop) { described_class.new(config) }
5+
6+
let(:message) do
7+
'Do not use Bugsnag in the codebase, as its integration has been removed. ' \
8+
'Use ErrorTrackingService for reporting errors.'
9+
end
10+
11+
it 'registers an offense when Bugsnag is used' do
12+
expect_offense(<<~RUBY)
13+
Bugsnag.error('Error')
14+
^^^^^^^^^^^^^^^^^^^^^^ #{message}
15+
RUBY
16+
end
17+
18+
it 'registers an offense when Bugsnag.notify is used' do
19+
expect_offense(<<~RUBY)
20+
Bugsnag.notify('Error')
21+
^^^^^^^^^^^^^^^^^^^^^^^ #{message}
22+
RUBY
23+
end
24+
25+
it 'does not register an offense for ErrorTrackingService' do
26+
expect_no_offenses(<<~RUBY)
27+
ErrorTrackingService.notify('Error')
28+
RUBY
29+
end
30+
31+
it 'does not register an offense for unrelated constants' do
32+
expect_no_offenses(<<~RUBY)
33+
SomeOtherService.notify('Error')
34+
RUBY
35+
end
36+
37+
it 'does not register an offense for lowercase bugsnag' do
38+
expect_no_offenses(<<~RUBY)
39+
bugsnag.error('Error')
40+
RUBY
41+
end
42+
43+
it 'does not register an offense for local variable named Bugsnag' do
44+
expect_no_offenses(<<~RUBY)
45+
bugsnag = SomeService.new
46+
bugsnag.error('Error')
47+
RUBY
48+
end
49+
end

0 commit comments

Comments
 (0)