rubocop-factory_bot 2.24.0 → 2.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/config/default.yml +17 -5
- data/lib/rubocop/cop/factory_bot/attribute_defined_statically.rb +1 -1
- data/lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb +12 -0
- data/lib/rubocop/cop/factory_bot/excessive_create_list.rb +52 -0
- data/lib/rubocop/cop/factory_bot/factory_name_style.rb +8 -1
- data/lib/rubocop/cop/factory_bot_cops.rb +1 -0
- data/lib/rubocop/factory_bot/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40e3398e9038a03648df8c412610ed3d1ad3d4934a46df77667c6f0d225ddcc
|
4
|
+
data.tar.gz: 68d463bcc67e2f2fd3b38869a7267509db90cda9d7b8e6550367458d73f0f255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166d045079cffb99cfcdef9b192e0ad8c90ba6b789f1539de8b5e697625a26d44ca6bafef56eb007b7c9ba9a78a655f29ba9688874a6e0081d43f1c9048b996e
|
7
|
+
data.tar.gz: 891d54b5c41e9ad51eec8a1e1ec2ecda863b9f6b700420af7de8cd26494444df8c31e57f78e2783bd949871d0df2bcab15a2ecfbda13e6188d2c370d7bcc11fd
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.25.0 (2024-01-04)
|
6
|
+
|
7
|
+
- Fix a false positive for `FactoryBot/FactoryNameStyle` when namespaced models. ([@ydah])
|
8
|
+
- Add new `FactoryBot/ExcessiveCreateList` cop. ([@ddieulivol])
|
9
|
+
- Fix a false positive for `FactoryBot/ConsistentParenthesesStyle` when hash pinning. ([@ydah])
|
10
|
+
|
5
11
|
## 2.24.0 (2023-09-18)
|
6
12
|
|
7
13
|
- Fix `FactoryBot/AssociationStyle` cop to ignore explicit associations with `strategy: :build`. ([@pirj])
|
@@ -31,7 +37,7 @@
|
|
31
37
|
|
32
38
|
## Previously (see [rubocop-rspec's changelist](https://github.com/rubocop/rubocop-rspec/blob/70a97b1895ce4b9bcd6ff336d5d343ddc6175fe6/CHANGELOG.md) for details)
|
33
39
|
|
34
|
-
- Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on ([@dmitrytsepelev])
|
40
|
+
- Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` inside `&&`, `||` and `:?` when `omit_parentheses` is on. ([@dmitrytsepelev])
|
35
41
|
- Add new `RSpec/FactoryBot/FactoryNameStyle` cop. ([@ydah])
|
36
42
|
- Fix wrong autocorrection in `n_times` style on `RSpec/FactoryBot/CreateList`. ([@r7kamura])
|
37
43
|
- Fix a false positive for `RSpec/FactoryBot/ConsistentParenthesesStyle` when using `generate` with multiple arguments. ([@ydah])
|
@@ -74,6 +80,7 @@
|
|
74
80
|
[@bquorning]: https://github.com/bquorning
|
75
81
|
[@composerinteralia]: https://github.com/composerinteralia
|
76
82
|
[@darhazer]: https://github.com/Darhazer
|
83
|
+
[@ddieulivol]: https://github.com/ddieulivol
|
77
84
|
[@dmitrytsepelev]: https://github.com/dmitrytsepelev
|
78
85
|
[@harrylewis]: https://github.com/harrylewis
|
79
86
|
[@jfragoulis]: https://github.com/jfragoulis
|
data/config/default.yml
CHANGED
@@ -14,7 +14,7 @@ FactoryBot/AssociationStyle:
|
|
14
14
|
Enabled: pending
|
15
15
|
Safe: false
|
16
16
|
VersionAdded: '2.23'
|
17
|
-
VersionChanged:
|
17
|
+
VersionChanged: '2.24'
|
18
18
|
EnforcedStyle: implicit
|
19
19
|
SupportedStyles:
|
20
20
|
- explicit
|
@@ -26,7 +26,7 @@ FactoryBot/AttributeDefinedStatically:
|
|
26
26
|
Description: Always declare attribute values as blocks.
|
27
27
|
Enabled: true
|
28
28
|
VersionAdded: '1.28'
|
29
|
-
VersionChanged:
|
29
|
+
VersionChanged: '2.24'
|
30
30
|
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/AttributeDefinedStatically
|
31
31
|
|
32
32
|
FactoryBot/ConsistentParenthesesStyle:
|
@@ -61,9 +61,21 @@ FactoryBot/CreateList:
|
|
61
61
|
ExplicitOnly: false
|
62
62
|
SafeAutoCorrect: false
|
63
63
|
VersionAdded: '1.25'
|
64
|
-
VersionChanged:
|
64
|
+
VersionChanged: '2.24'
|
65
65
|
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/CreateList
|
66
66
|
|
67
|
+
FactoryBot/ExcessiveCreateList:
|
68
|
+
Description: Check for excessive model creation in a list.
|
69
|
+
Enabled: pending
|
70
|
+
Include:
|
71
|
+
- "**/*_spec.rb"
|
72
|
+
- "**/spec/**/*"
|
73
|
+
- "**/test/**/*"
|
74
|
+
- "**/features/support/factories/**/*.rb"
|
75
|
+
MaxAmount: 10
|
76
|
+
VersionAdded: '2.25'
|
77
|
+
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/ExcessiveCreateList
|
78
|
+
|
67
79
|
FactoryBot/FactoryAssociationWithStrategy:
|
68
80
|
Description: Use definition in factory association instead of hard coding a strategy.
|
69
81
|
Enabled: pending
|
@@ -80,7 +92,7 @@ FactoryBot/FactoryClassName:
|
|
80
92
|
Description: Use string value when setting the class attribute explicitly.
|
81
93
|
Enabled: true
|
82
94
|
VersionAdded: '1.37'
|
83
|
-
VersionChanged:
|
95
|
+
VersionChanged: '2.24'
|
84
96
|
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/FactoryClassName
|
85
97
|
|
86
98
|
FactoryBot/FactoryNameStyle:
|
@@ -103,7 +115,7 @@ FactoryBot/FactoryNameStyle:
|
|
103
115
|
FactoryBot/IdSequence:
|
104
116
|
Description: Do not create a FactoryBot sequence for an id column.
|
105
117
|
Enabled: pending
|
106
|
-
VersionAdded:
|
118
|
+
VersionAdded: '2.24'
|
107
119
|
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/IdSequence
|
108
120
|
|
109
121
|
FactoryBot/RedundantFactoryOption:
|
@@ -75,6 +75,17 @@ module RuboCop
|
|
75
75
|
)
|
76
76
|
PATTERN
|
77
77
|
|
78
|
+
# @!method omit_hash_value?(node)
|
79
|
+
def_node_matcher :omit_hash_value?, <<~PATTERN
|
80
|
+
(send
|
81
|
+
#factory_call? %FACTORY_CALLS
|
82
|
+
{sym str send lvar}
|
83
|
+
(hash
|
84
|
+
<value_omission? ...>
|
85
|
+
)
|
86
|
+
)
|
87
|
+
PATTERN
|
88
|
+
|
78
89
|
def self.autocorrect_incompatible_with
|
79
90
|
[Style::MethodCallWithArgsParentheses]
|
80
91
|
end
|
@@ -97,6 +108,7 @@ module RuboCop
|
|
97
108
|
def register_offense_with_parentheses(node)
|
98
109
|
return if style == :require_parentheses || !node.parenthesized?
|
99
110
|
return unless same_line?(node, node.first_argument)
|
111
|
+
return if omit_hash_value?(node)
|
100
112
|
|
101
113
|
add_offense(node.loc.selector,
|
102
114
|
message: MSG_OMIT_PARENS) do |corrector|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module FactoryBot
|
6
|
+
# Check for excessive model creation in a list.
|
7
|
+
#
|
8
|
+
# @example MaxAmount: 10 (default)
|
9
|
+
# # We do not allow more than 10 items to be created
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# create_list(:merge_request, 1000, state: :opened)
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# create_list(:merge_request, 10, state: :opened)
|
16
|
+
#
|
17
|
+
# @example MaxAmount: 20
|
18
|
+
# # We do not allow more than 20 items to be created
|
19
|
+
#
|
20
|
+
# # bad
|
21
|
+
# create_list(:merge_request, 1000, state: :opened)
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# create_list(:merge_request, 15, state: :opened)
|
25
|
+
#
|
26
|
+
class ExcessiveCreateList < ::RuboCop::Cop::Base
|
27
|
+
include ConfigurableExplicitOnly
|
28
|
+
|
29
|
+
MESSAGE =
|
30
|
+
'Avoid using `create_list` with more than %<max_amount>s items.'
|
31
|
+
|
32
|
+
# @!method create_list?(node)
|
33
|
+
def_node_matcher :create_list?, <<~PATTERN
|
34
|
+
(send #factory_call? :create_list {sym str} $(int _) ...)
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
RESTRICT_ON_SEND = %i[create_list].freeze
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
number_node = create_list?(node)
|
41
|
+
return unless number_node
|
42
|
+
|
43
|
+
max_amount = cop_config['MaxAmount']
|
44
|
+
return if number_node.value <= max_amount
|
45
|
+
|
46
|
+
add_offense(number_node, message:
|
47
|
+
format(MESSAGE, max_amount: max_amount))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -14,6 +14,9 @@ module RuboCop
|
|
14
14
|
# create(:user)
|
15
15
|
# build :user, username: "NAME"
|
16
16
|
#
|
17
|
+
# # good - namespaced models
|
18
|
+
# create('users/internal')
|
19
|
+
#
|
17
20
|
# @example EnforcedStyle: string
|
18
21
|
# # bad
|
19
22
|
# create(:user)
|
@@ -76,13 +79,17 @@ module RuboCop
|
|
76
79
|
private
|
77
80
|
|
78
81
|
def offense_for_symbol_style?(name)
|
79
|
-
name.str_type? && style == :symbol
|
82
|
+
name.str_type? && style == :symbol && !namespaced?(name)
|
80
83
|
end
|
81
84
|
|
82
85
|
def offense_for_string_style?(name)
|
83
86
|
name.sym_type? && style == :string
|
84
87
|
end
|
85
88
|
|
89
|
+
def namespaced?(name)
|
90
|
+
name.value.include?('/')
|
91
|
+
end
|
92
|
+
|
86
93
|
def register_offense(name, prefer)
|
87
94
|
add_offense(name,
|
88
95
|
message: format(MSG, prefer: style.to_s)) do |corrector|
|
@@ -4,6 +4,7 @@ require_relative 'factory_bot/association_style'
|
|
4
4
|
require_relative 'factory_bot/attribute_defined_statically'
|
5
5
|
require_relative 'factory_bot/consistent_parentheses_style'
|
6
6
|
require_relative 'factory_bot/create_list'
|
7
|
+
require_relative 'factory_bot/excessive_create_list'
|
7
8
|
require_relative 'factory_bot/factory_association_with_strategy'
|
8
9
|
require_relative 'factory_bot/factory_class_name'
|
9
10
|
require_relative 'factory_bot/factory_name_style'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-factory_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rubocop
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/rubocop/cop/factory_bot/attribute_defined_statically.rb
|
49
49
|
- lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb
|
50
50
|
- lib/rubocop/cop/factory_bot/create_list.rb
|
51
|
+
- lib/rubocop/cop/factory_bot/excessive_create_list.rb
|
51
52
|
- lib/rubocop/cop/factory_bot/factory_association_with_strategy.rb
|
52
53
|
- lib/rubocop/cop/factory_bot/factory_class_name.rb
|
53
54
|
- lib/rubocop/cop/factory_bot/factory_name_style.rb
|
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
84
|
- !ruby/object:Gem::Version
|
84
85
|
version: '0'
|
85
86
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.4.22
|
87
88
|
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: Code style checking for factory_bot files
|