simplycop 2.3.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.custom_simplycop.yml +8 -0
- data/lib/simplycop/custom_cops/no_foreground_indices.rb +46 -0
- data/lib/simplycop/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd09f4e7858d5143a39f3666e79cb20bf1f458720decf82b23149d4f7aba71e1
|
4
|
+
data.tar.gz: b35dc71c87ff97229dda37d0daa3e2c1c5f5003b52b4d3c6649bcde166c9bb7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 006b209f8bf36036bf7a902c7377793c8b73c2d7683ff94dd5d175dd93f94ccef005f9fc40c8cc6e3401c24874f357c83dbaf221097be62f8e1cee7d1bc39d57
|
7
|
+
data.tar.gz: 99e00ad5963e97f95041879c72e37e34b1fb7412706d547e90652408337c62143a334dd8a6202dac9ae55c8d2f6d964f0d08ace104ec00fc7276a45183486cd7
|
data/.custom_simplycop.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require:
|
2
2
|
- './lib/simplycop/custom_cops/timecop_without_block.rb'
|
3
3
|
- './lib/simplycop/custom_cops/dont_print_all_env.rb'
|
4
|
+
- './lib/simplycop/custom_cops/no_foreground_indices.rb'
|
4
5
|
|
5
6
|
AllCops:
|
6
7
|
ExtraDetails: true
|
@@ -15,3 +16,10 @@ CustomCops/DontPrintAllEnv:
|
|
15
16
|
Enabled: true
|
16
17
|
Details: >-
|
17
18
|
This cop checks if someone accidentally print all environment variables as they may contain secrets.
|
19
|
+
|
20
|
+
CustomCops/NoForegroundIndices:
|
21
|
+
Enabled: true
|
22
|
+
Details: We want to prevent adding Mongoid indices that are not in background, otherwise the collection will lock during indexing.
|
23
|
+
|
24
|
+
Include:
|
25
|
+
- app/models/*
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomCops
|
4
|
+
# This cop checks for the presence of Mongoid indexes that have not been
|
5
|
+
# flagged with the flag `background: true`.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# #bad
|
9
|
+
# index(reference: 1)
|
10
|
+
#
|
11
|
+
# #good
|
12
|
+
# index({ reference: 1 }, { background: true })
|
13
|
+
#
|
14
|
+
class NoForegroundIndices < RuboCop::Cop::Cop
|
15
|
+
MSG = 'Do not create indices that lack the background flag.'
|
16
|
+
|
17
|
+
def_node_matcher :model_index?, <<~PATTERN
|
18
|
+
(send nil? :index $...)
|
19
|
+
PATTERN
|
20
|
+
|
21
|
+
def_node_matcher :hash?, <<~PATTERN
|
22
|
+
(hash $...)
|
23
|
+
PATTERN
|
24
|
+
|
25
|
+
def_node_matcher :background_pair?, <<~PATTERN
|
26
|
+
(pair
|
27
|
+
(sym :background)
|
28
|
+
(:true)
|
29
|
+
)
|
30
|
+
PATTERN
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
model_index?(node) do |_fields, options|
|
34
|
+
add_offense(node, location: :selector) unless background_enabled?(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def background_enabled?(hash)
|
41
|
+
return false if hash.nil? || !hash?(hash)
|
42
|
+
|
43
|
+
hash.pairs.any? { |pair| background_pair?(pair) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/simplycop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplycop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- lib/simplycop/custom_cops/dont_print_all_env.rb
|
219
219
|
- lib/simplycop/custom_cops/instance_eval.rb
|
220
220
|
- lib/simplycop/custom_cops/method_missing.rb
|
221
|
+
- lib/simplycop/custom_cops/no_foreground_indices.rb
|
221
222
|
- lib/simplycop/custom_cops/timecop_without_block.rb
|
222
223
|
- lib/simplycop/custom_cops/variable_name_shadowing_method.rb
|
223
224
|
- lib/simplycop/security/check_for_vulnerable_code.rb
|