rubocop-config-captive 2.2.1 → 2.3.2

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: b792b47ba1dab2270b0e7509cf6533a85cd27e4d9ecb865de1659f27176c86ce
4
- data.tar.gz: 2ad3adee19ed6fe6d4ef07b0b4c7e68e349a732fe22ec1d4cc1baabcd74a6841
3
+ metadata.gz: e6e241d8e2f2940bd47fb5a13a7d238b98c0c388f515b419f6d49048db256454
4
+ data.tar.gz: 4397f473aa4dd470c04af9375cb4fb2ec0df4c3bf5d3291fecf480f8dc753d19
5
5
  SHA512:
6
- metadata.gz: 3f890d61085363edcb57cdf460127f07f5f3b31b29cd560dd14728d026faddf596495bb0d4654659071289278beac58dfc84a325b11cbdb519550bbf364e87a8
7
- data.tar.gz: f96ed6a1a39f61a0c131220631d4c7e33503d8791cf00985ecac62a483478316b952770838b13921cd7ffde299a4fa5c69634c8dbf65df3c18b7745a287ee3cd
6
+ metadata.gz: 2392bcf75ab610f0843941fa557e88fcf7722db46a2bb754cf0832416b259d2ca9ada821ebc8f8c64ec7888d2744708aef25155740556b4ce9fd7cb43821c7af
7
+ data.tar.gz: 50314af7b98f89a4a7a37a914fe4da5d035b6c2d0e044e690900d7f63e741af6e37c24dbbd050ea162f86665885bccaaf688902e275bc8247a4e247bcf209a19
data/Gemfile CHANGED
@@ -4,10 +4,14 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ group :development, :test do
8
+ gem "rake", "13.4.2"
9
+ end
10
+
7
11
  group :development do
8
12
  gem "yard", "~> 0.9.34"
9
13
  end
10
14
 
11
15
  group :test do
12
- gem "pry", "0.16.0"
16
+ gem "pry", "0.16.1"
13
17
  end
@@ -137,7 +137,7 @@ Lint/MissingCopEnableDirective:
137
137
  # a = 1
138
138
  # # rubocop:enable SomeCop
139
139
  # .inf for any size
140
- MaximumRangeSize: .inf
140
+ MaxRangeSize: .inf
141
141
  Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`'
142
142
  Enabled: true
143
143
 
@@ -4,6 +4,7 @@ require:
4
4
  - ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
5
5
  - ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
6
6
  - ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
7
+ - ../lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
7
8
  - ../lib/rubocop/cop/captive/rails/after_commit_not_allowed.rb
8
9
  - ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
9
10
  - ../lib/rubocop/cop/captive/rails/migration_methods.rb
@@ -43,6 +44,21 @@ Captive/RSpec/SpecifyBeforeParameter:
43
44
  Include:
44
45
  - 'spec/**/*'
45
46
 
47
+ Captive/RSpec/NoDbInUnitSpecs:
48
+ Description: 'Do not hit the database in unit tests. Use `instance_double` or `Model.new` instead. If testing a scope, move to spec/integration.'
49
+ Enabled: true
50
+ Include:
51
+ - 'spec/**/*'
52
+ AllowedPaths:
53
+ - 'spec/requests'
54
+ - 'spec/system'
55
+ - 'spec/features'
56
+ - 'spec/integration'
57
+ - 'spec/factories'
58
+ - 'spec/services'
59
+ - 'spec/jobs'
60
+ - 'spec/support'
61
+
46
62
  # Rails
47
63
  Captive/Rails/AfterCommitNotAllowed:
48
64
  Description: "Interdit l'utilisation de `after_commit` dans les modèles Rails."
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-magic_numbers
3
3
 
4
4
  MagicNumbers/NoArgument:
@@ -15,7 +15,7 @@ MagicNumbers/NoArgument:
15
15
  - '**/*_spec.rb'
16
16
  - '**/*_test.rb'
17
17
  - '**/config/**/*'
18
- - db/migrate/*.rb
18
+ - db/migrate/**/*.rb
19
19
 
20
20
  # Cette règle empeche de pouvoir faire des variables d'instances qui servent de compteur
21
21
  MagicNumbers/NoAssignment:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Captive
5
- VERSION = "2.2.1"
5
+ VERSION = "2.3.2"
6
6
  end
7
7
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module RSpec
7
+ # Do not create database records in unit tests.
8
+ # Use `build`, `instance_double`, or stubs instead.
9
+ class NoDbInUnitSpecs < Base
10
+ MSG =
11
+ "Do not hit the database in unit tests. " \
12
+ "Use `instance_double` or `Model.new` instead. " \
13
+ "If testing a scope, move to spec/integration."
14
+
15
+ DEFAULT_ALLOWED_PATHS = %w[
16
+ spec/requests spec/system spec/features spec/integration
17
+ spec/factories spec/services spec/jobs spec/support
18
+ ].freeze
19
+
20
+ def_node_matcher :factory_bot_db?, <<~PATTERN
21
+ (send (const nil? :FactoryBot) {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
22
+ PATTERN
23
+
24
+ def_node_matcher :standalone_factory_bot_db?, <<~PATTERN
25
+ (send nil? {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
26
+ PATTERN
27
+
28
+ def_node_matcher :ar_create?, <<~PATTERN
29
+ (send (const nil? _) {:create :create!} ...)
30
+ PATTERN
31
+
32
+ def_node_matcher :ar_save?, <<~PATTERN
33
+ (send _ {:save :save!} ...)
34
+ PATTERN
35
+
36
+ def on_send(node)
37
+ return unless unit_spec?
38
+ return unless db_creation?(node)
39
+
40
+ add_offense(node)
41
+ end
42
+
43
+ private
44
+
45
+ def unit_spec?
46
+ path = processed_source.path
47
+ return false unless path&.include?("spec/")
48
+
49
+ allowed_paths.none? { |allowed| path.include?(allowed) }
50
+ end
51
+
52
+ def allowed_paths
53
+ cop_config.fetch("AllowedPaths", DEFAULT_ALLOWED_PATHS)
54
+ end
55
+
56
+ def db_creation?(node)
57
+ factory_bot_db?(node) ||
58
+ standalone_factory_bot_db?(node) ||
59
+ ar_create?(node) ||
60
+ ar_save?(node)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -28,9 +28,10 @@ Gem::Specification.new do |gem|
28
28
  gem.add_dependency("rubocop-rake", "~> 0.7")
29
29
  gem.add_dependency("rubocop-rails", "~> 2.32")
30
30
  gem.add_dependency("rubocop-rspec", "~> 3.6")
31
- gem.add_dependency("rubocop-capybara", "~> 2.22")
31
+ gem.add_dependency("rubocop-capybara", "~> 3.0")
32
32
  gem.add_dependency("rubocop-factory_bot", "~> 2.27")
33
- gem.add_dependency("rubocop-magic_numbers", "~> 0.5")
33
+ # Version exacte : les mineures 0.x élargissent les cops et cassent la CI des projets
34
+ gem.add_dependency("rubocop-magic_numbers", "0.8.0")
34
35
  gem.add_dependency("rubocop-rails-omakase", "~> 1.1")
35
36
  gem.add_development_dependency("rspec", "~> 3.12")
36
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-config-captive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '2.22'
90
+ version: '3.0'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '2.22'
97
+ version: '3.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rubocop-factory_bot
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: rubocop-magic_numbers
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: '0.5'
118
+ version: 0.8.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - '='
124
124
  - !ruby/object:Gem::Version
125
- version: '0.5'
125
+ version: 0.8.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rubocop-rails-omakase
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
203
203
  - lib/rubocop/cop/captive/rails/no_float_price_columns.rb
204
204
  - lib/rubocop/cop/captive/rails/no_has_many_attached.rb
205
+ - lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
205
206
  - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
206
207
  - lib/rubocop/cop/captive/string_where_in_scope.rb
207
208
  - lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
227
  - !ruby/object:Gem::Version
227
228
  version: '0'
228
229
  requirements: []
229
- rubygems_version: 4.0.10
230
+ rubygems_version: 4.0.20
230
231
  specification_version: 4
231
232
  summary: Shared rubocop configurations
232
233
  test_files: []