rubocop-config-captive 1.4.2 → 1.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: 6e7f4e97ec653176c49a0ed9626a7e310fa44db898b3579d96b13f09a9921057
4
- data.tar.gz: 16346168e3786b757d9e4140974f8cb9f9f9b9efc66b11ee2a70e96d27415235
3
+ metadata.gz: daad52b9ec57ffb696430f0f7b9a1c797b841afb97c64e86bd8610730fdaecaf
4
+ data.tar.gz: 82d299623bea48f72e8b71111309d051c829782b2f5b5648b3e5f49b3e67c780
5
5
  SHA512:
6
- metadata.gz: 7c1d1a707e4baab6a32e504414ebee681cf1438ad4970f25e8357e0c7ee3140833c4c3cafcb84dde46b14842a05fa75ebc1cdda8c21ba960b19f43912f46f7c0
7
- data.tar.gz: 25064974d91c54d661ab593f149fc0ad64063f8cde8171533208b585af2ea9bef77790d4ae31f45d9b4a6cc163ced59c95d38c766f5acdc6f33b195aa3b90a2e
6
+ metadata.gz: 2727c1c5c3f2d413e832167b303bb77ecb495a2c65e0fc82147a19882c511fa5235005f471c085f92e9204140b69a7c48e0ad14bbcd4289e1e746e3ab8f2839c
7
+ data.tar.gz: 0cb908ed58c39398e9bfa1c2f2b49e7ab7ffd96ec5c78518722db0afc992505ad1185064503f97cbe76e9fca604678ee7214bb32ae795f21071724e13b99c0a4
@@ -3,6 +3,7 @@ require:
3
3
  - ../lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
4
4
  - ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
5
5
  - ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
6
+ - ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
6
7
  - ../lib/rubocop/cop/captive/string_where_in_scope.rb
7
8
  - ../lib/rubocop/cop/captive/no_app_env.rb
8
9
 
@@ -28,6 +29,12 @@ Captive/Translation/KaminariI18nPresence:
28
29
  Include:
29
30
  - 'Gemfile'
30
31
 
32
+ # RSpec
33
+ Captive/RSpec/SpecifyBeforeParameter:
34
+ Description: 'Specify the parameter in `before` blocks. Example : before(:each) or before(:all)'
35
+ Include:
36
+ - 'spec/**/*'
37
+
31
38
  # other
32
39
  Captive/StringWhereInScope:
33
40
  Description: 'The `where` method should be used in a scope in a model.'
@@ -3,6 +3,6 @@
3
3
  module RuboCop
4
4
  module Captive
5
5
  # Version information for the the Airbnb RuboCop plugin.
6
- VERSION = '1.4.2'
6
+ VERSION = '1.5.0'
7
7
  end
8
8
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module RSpec
7
+ # This cop enforces specifying the parameter in RSpec `before` blocks.
8
+ #
9
+ # The cops was created because many people didn't know that `before`
10
+ # method has default parameter value : `:each`
11
+ #
12
+ # @example
13
+ # # bad
14
+ # before do
15
+ # ...
16
+ # end
17
+ #
18
+ # # good
19
+ # before(:each) do
20
+ # ...
21
+ # end
22
+ #
23
+ # before(:all) do
24
+ # ...
25
+ # end
26
+ #
27
+ class SpecifyBeforeParameter < RuboCop::Cop::Base
28
+ extend AutoCorrector
29
+
30
+ MSG = 'Specify the parameter in `before` blocks. Example : before(:each) or before(:all)'
31
+
32
+ def_node_matcher :before_block?, <<~PATTERN
33
+ (block
34
+ (send nil? :before ...)
35
+ ...
36
+ )
37
+ PATTERN
38
+
39
+ def_node_search :before_without_parameter?, <<~PATTERN
40
+ (send nil? :before)
41
+ PATTERN
42
+
43
+ def on_block(node)
44
+ return unless before_block?(node)
45
+ return unless before_without_parameter?(node)
46
+
47
+ add_offense(node, message: MSG) do |corrector|
48
+ corrector.replace(node.loc.expression, add_parameter(node))
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def add_parameter(node)
55
+ source = node.loc.expression.source
56
+ source.insert(source.index('before') + 6, '(:each)')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ 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: 1.4.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-05-26 00:00:00.000000000 Z
13
+ date: 2023-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -169,6 +169,7 @@ files:
169
169
  - lib/rubocop/captive/version.rb
170
170
  - lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb
171
171
  - lib/rubocop/cop/captive/no_app_env.rb
172
+ - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
172
173
  - lib/rubocop/cop/captive/string_where_in_scope.rb
173
174
  - lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
174
175
  - lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb