File tree 3 files changed +45
-0
lines changed
3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,7 @@ Bugcrowd/AvoidSampleInSpecs:
72
72
Enabled : true
73
73
Include :
74
74
- ' spec/**/*.rb'
75
+ BugcrowdCops/PreventReindexFullESDocumentCop :
76
+ Enabled : true
77
+ Include :
78
+ - ' app/**/*.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 PreventReindexFullESDocumentCop < Cop
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # ```
12
+ # Reindexing a full ES document would reindex all the resource ids
13
+ # ```
14
+ # ValisCommands::ReindexDocument.call(document_type: 'SubmissionDocument')
15
+ #
16
+ # # good
17
+ # Reindex only a specific resource ID instead
18
+ # ```
19
+ # ValisReindexWorker.new.perform([submission.id], Submission.to_s)
20
+ # ```
21
+ #
22
+
23
+ MSG = 'Avoid reindexing the full Elasticsearch document. Consider reindexing only specific resource ids.'
24
+
25
+ def_node_matcher :valis_reindex_document? , <<-PATTERN
26
+ (send
27
+ (const
28
+ (const nil? :ValisCommands) :ReindexDocument) :call
29
+ (hash $...))
30
+ PATTERN
31
+
32
+ def on_send ( node )
33
+ if valis_reindex_document? ( node )
34
+ add_offense ( node , message : MSG )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
Original file line number Diff line number Diff line change 37
37
require_relative 'bugcrowd/no_include_run_in_transaction'
38
38
require_relative 'bugcrowd/no_event_deprecated_publish'
39
39
require_relative 'bugcrowd/sidekiq_testing_inline'
40
+ require_relative 'bugcrowd/prevent_reindex_full_es_document_cop.rb'
You can’t perform that action at this time.
0 commit comments