File tree Expand file tree Collapse file tree 4 files changed +72
-0
lines changed
spec/rubocop/cop/bugcrowd Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Original file line number Diff line number Diff 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'
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 3838require_relative 'bugcrowd/no_event_deprecated_publish'
3939require_relative 'bugcrowd/sidekiq_testing_inline'
4040require_relative 'bugcrowd/prevent_reindex_full_es_document_cop'
41+ require_relative 'bugcrowd/prevent_bugsnag_usage'
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments