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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5bf29bc90d6b4e9d037c6d5c0d1bd61f3a17937a3025499bc84e0e5f41e6dff
4
- data.tar.gz: fb894cbb90402223e398e636112b3468760fb4e2d19b3347b397e38be4288aab
3
+ metadata.gz: fd09f4e7858d5143a39f3666e79cb20bf1f458720decf82b23149d4f7aba71e1
4
+ data.tar.gz: b35dc71c87ff97229dda37d0daa3e2c1c5f5003b52b4d3c6649bcde166c9bb7c
5
5
  SHA512:
6
- metadata.gz: 3783811394dd7f47e822e6a6c6f6938df1689def2052b7eaeed15f68e12689e5a4fc7d78a8b8cf08288e7329848fac2c406d64d05979dc801c3cedfb546d182d
7
- data.tar.gz: 9cdb3be8d6d6f9e5745732f9e3f518efb1a44919c5c623b1e3f406f7c5b3a44925c9123b8be4251f168e7d547e79b770b929aeadd22e4636351ab9ade197d323
6
+ metadata.gz: 006b209f8bf36036bf7a902c7377793c8b73c2d7683ff94dd5d175dd93f94ccef005f9fc40c8cc6e3401c24874f357c83dbaf221097be62f8e1cee7d1bc39d57
7
+ data.tar.gz: 99e00ad5963e97f95041879c72e37e34b1fb7412706d547e90652408337c62143a334dd8a6202dac9ae55c8d2f6d964f0d08ace104ec00fc7276a45183486cd7
@@ -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
@@ -7,5 +7,5 @@
7
7
  #
8
8
 
9
9
  module Simplycop
10
- VERSION = '2.3.3'
10
+ VERSION = '2.5.0'
11
11
  end
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.3.3
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