Skip to content

Commit a75a37e

Browse files
committed
Add PreventReindexFullESDocumentCop
1 parent a959359 commit a75a37e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

config/default.yml

+4
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ Bugcrowd/AvoidSampleInSpecs:
7272
Enabled: true
7373
Include:
7474
- 'spec/**/*.rb'
75+
BugcrowdCops/PreventReindexFullESDocumentCop:
76+
Enabled: true
77+
Include:
78+
- 'app/**/*.rb'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

lib/rubocop/cop/bugcrowd_cops.rb

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@
3737
require_relative 'bugcrowd/no_include_run_in_transaction'
3838
require_relative 'bugcrowd/no_event_deprecated_publish'
3939
require_relative 'bugcrowd/sidekiq_testing_inline'
40+
require_relative 'bugcrowd/prevent_reindex_full_es_document_cop.rb'

0 commit comments

Comments
 (0)