rubocop-factory_bot 2.26.1 → 2.28.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: 60519b0d051edd3ba23a10f3dfb346dc5aaed4964c489bcfabdb7d16c084cb63
4
- data.tar.gz: effac41ed4215d5cb27295cdb0a37d8c7021c309e97a8f8e6f8fdf6e385e8226
3
+ metadata.gz: 9a5c117626f22cbe451b7044b247be8b9be8aecaa460f64ea87eb948d54cb6f5
4
+ data.tar.gz: eff63053af204522a4c23f814c4be844ffb985daf357751a7b411ad35b2051ec
5
5
  SHA512:
6
- metadata.gz: ee33ad705e93ffa3a68240adabd9de50735819d4d82bbf66868f2efa80d489a0032fd045878bf8fd539dc7677fed9bbf9ef0e3755340b81b4fc1881220e0b24c
7
- data.tar.gz: 89936fe77a9c8f3ff5dad656b9e30455ec2f6467ac7cba1c678e63fca22396825c3859bc1830f6e766a90109cbae3eca68f64d5a110e3bbd8cebd229cf3218e9
6
+ metadata.gz: ef628bbb79001d540c0f21ff8d978b05bf37d3a7f9942f4a75d6348589d4c9349b5ce86406123cbc2e4c2aaa276aad488dc31c4f2058ed3d3c7f1be24604bdbb
7
+ data.tar.gz: 57f5195ad3056db88fe3f5c76f2085b16db8c3ba65bc27357042e22be9c7d421621fc6fefcb5be3be6380e9e70e3401230e0218e1199c567989b1cf6af8426d6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.28.0 (2025-11-12)
6
+
7
+ - Fix an error for `FactoryBot/AssociationStyle` cop when `trait` is not inside `factory` block. ([@viralpraxis])
8
+ - Fix an error for `FactoryBot/ConsistentParenthesesStyle` cop when using keyword splat argument. ([@viralpraxis])
9
+ - Fix a false negative for `FactoryBot/SyntaxMethods` when method is used inside a module. ([@lovro-bikic])
10
+
11
+ ## 2.27.1 (2025-03-12)
12
+
13
+ - Fix incorrect plugin version. ([@koic])
14
+
15
+ ## 2.27.0 (2025-03-06)
16
+
17
+ - Fix a false positive for `FactoryBot/ConsistentParenthesesStyle` when using traits and omitting hash values. ([@thejonroberts])
18
+ - Make RuboCop FactoryBot work as a RuboCop plugin. ([@bquorning])
19
+
5
20
  ## 2.26.1 (2024-06-12)
6
21
 
7
22
  - Bump RuboCop requirement to +1.61. ([@ydah])
@@ -100,8 +115,10 @@
100
115
  [@jaydorsey]: https://github.com/jaydorsey
101
116
  [@jfragoulis]: https://github.com/jfragoulis
102
117
  [@jonatas]: https://github.com/jonatas
118
+ [@koic]: https://github.com/koic
103
119
  [@leoarnold]: https://github.com/leoarnold
104
120
  [@liberatys]: https://github.com/Liberatys
121
+ [@lovro-bikic]: https://github.com/lovro-bikic
105
122
  [@morissetcl]: https://github.com/morissetcl
106
123
  [@ngouy]: https://github.com/ngouy
107
124
  [@owst]: https://github.com/owst
@@ -110,6 +127,8 @@
110
127
  [@seanpdoyle]: https://github.com/seanpdoyle
111
128
  [@tdeo]: https://github.com/tdeo
112
129
  [@tejasbubane]: https://github.com/tejasbubane
130
+ [@thejonroberts]: https://github.com/thejonroberts
131
+ [@viralpraxis]: https://github.com/viralpraxis
113
132
  [@vzvu3k6k]: https://github.com/vzvu3k6k
114
133
  [@walf443]: https://github.com/walf443
115
134
  [@ybiquitous]: https://github.com/ybiquitous
data/README.md CHANGED
@@ -31,13 +31,13 @@ ways to do this:
31
31
  Put this into your `.rubocop.yml`.
32
32
 
33
33
  ```yaml
34
- require: rubocop-factory_bot
34
+ plugins: rubocop-factory_bot
35
35
  ```
36
36
 
37
37
  Alternatively, use the following array notation when specifying multiple extensions.
38
38
 
39
39
  ```yaml
40
- require:
40
+ plugins:
41
41
  - rubocop-other-extension
42
42
  - rubocop-factory_bot
43
43
  ```
@@ -45,17 +45,20 @@ require:
45
45
  Now you can run `rubocop` and it will automatically load the RuboCop factory_bot
46
46
  cops together with the standard cops.
47
47
 
48
+ > [!NOTE]
49
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
50
+
48
51
  ### Command line
49
52
 
50
53
  ```bash
51
- rubocop --require rubocop-factory_bot
54
+ rubocop --plugin rubocop-factory_bot
52
55
  ```
53
56
 
54
57
  ### Rake task
55
58
 
56
59
  ```ruby
57
60
  RuboCop::RakeTask.new do |task|
58
- task.requires << 'rubocop-factory_bot'
61
+ task.plugins << 'rubocop-factory_bot'
59
62
  end
60
63
  ```
61
64
 
@@ -65,14 +65,6 @@ module RuboCop
65
65
 
66
66
  include ConfigurableEnforcedStyle
67
67
 
68
- DEFAULT_NON_IMPLICIT_ASSOCIATION_METHOD_NAMES = %w[
69
- association
70
- factory
71
- sequence
72
- skip_create
73
- traits_for_enum
74
- ].freeze
75
-
76
68
  RESTRICT_ON_SEND = %i[factory trait].freeze
77
69
  KEYWORDS = %i[alias and begin break case class def defined? do
78
70
  else elsif end ensure false for if in module
@@ -175,7 +167,9 @@ module RuboCop
175
167
  def bad?(node)
176
168
  if style == :explicit
177
169
  implicit_association?(node) &&
178
- !trait_within_trait?(node)
170
+ (factory_node = trait_factory_node(node)) && !trait_within_trait?(
171
+ node, factory_node
172
+ )
179
173
  else
180
174
  explicit_association?(node) &&
181
175
  !with_strategy_build_option?(node) &&
@@ -226,7 +220,7 @@ module RuboCop
226
220
  end
227
221
 
228
222
  def non_implicit_association_method_names
229
- DEFAULT_NON_IMPLICIT_ASSOCIATION_METHOD_NAMES +
223
+ RuboCop::FactoryBot.reserved_methods.map(&:to_s) +
230
224
  (cop_config['NonImplicitAssociationMethodNames'] || [])
231
225
  end
232
226
 
@@ -247,12 +241,14 @@ module RuboCop
247
241
  options
248
242
  end
249
243
 
250
- def trait_within_trait?(node)
251
- factory_node = node.ancestors.reverse.find do |ancestor|
244
+ def trait_within_trait?(node, factory_node)
245
+ trait_name(factory_node).include?(node.method_name)
246
+ end
247
+
248
+ def trait_factory_node(node)
249
+ node.ancestors.reverse.find do |ancestor|
252
250
  ancestor.method?(:factory) if ancestor.block_type?
253
251
  end
254
-
255
- trait_name(factory_node).include?(node.method_name)
256
252
  end
257
253
  end
258
254
  end
@@ -79,9 +79,9 @@ module RuboCop
79
79
  def_node_matcher :omit_hash_value?, <<~PATTERN
80
80
  (send
81
81
  #factory_call? %FACTORY_CALLS
82
- {sym str send lvar}
82
+ {sym str send lvar} _*
83
83
  (hash
84
- <value_omission? ...>
84
+ <[!kwsplat value_omission?] ...>
85
85
  )
86
86
  )
87
87
  PATTERN
@@ -99,19 +99,9 @@ module RuboCop
99
99
  end
100
100
 
101
101
  def inside_example_group?(node)
102
- return spec_group?(node) if example_group_root?(node)
103
-
104
- root = node.ancestors.find { |parent| example_group_root?(parent) }
105
-
106
- spec_group?(root)
107
- end
108
-
109
- def example_group_root?(node)
110
- node.parent.nil? || example_group_root_with_siblings?(node.parent)
111
- end
112
-
113
- def example_group_root_with_siblings?(node)
114
- node.begin_type? && node.parent.nil?
102
+ spec_group?(node) || node.each_ancestor.any? do |parent|
103
+ spec_group?(parent)
104
+ end
115
105
  end
116
106
  end
117
107
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module FactoryBot
7
+ # A plugin that integrates RuboCop FactoryBot with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ # :nocov:
10
+ def about
11
+ LintRoller::About.new(
12
+ name: 'rubocop-factory_bot',
13
+ version: Version::STRING,
14
+ homepage: 'https://github.com/rubocop/rubocop-factory_bot',
15
+ description: 'Code style checking for FactoryBot test files.'
16
+ )
17
+ end
18
+ # :nocov:
19
+
20
+ def supported?(context)
21
+ context.engine == :rubocop
22
+ end
23
+
24
+ def rules(_context)
25
+ project_root = Pathname.new(__dir__).join('../../..')
26
+
27
+ obsoletion = project_root.join('config', 'obsoletion.yml')
28
+ ConfigObsoletion.files << obsoletion if obsoletion.exist?
29
+
30
+ LintRoller::Rules.new(
31
+ type: :path,
32
+ config_format: :rubocop,
33
+ value: project_root.join('config/default.yml')
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module FactoryBot
5
5
  # Version information for the factory_bot RuboCop plugin.
6
6
  module Version
7
- STRING = '2.26.1'
7
+ STRING = '2.28.0'
8
8
  end
9
9
  end
10
10
  end
@@ -7,12 +7,9 @@ require 'rubocop'
7
7
 
8
8
  require_relative 'rubocop/factory_bot/factory_bot'
9
9
  require_relative 'rubocop/factory_bot/language'
10
+ require_relative 'rubocop/factory_bot/plugin'
11
+ require_relative 'rubocop/factory_bot/version'
10
12
 
11
13
  require_relative 'rubocop/cop/factory_bot/mixin/configurable_explicit_only'
12
14
 
13
15
  require_relative 'rubocop/cop/factory_bot_cops'
14
-
15
- project_root = File.join(__dir__, '..')
16
- RuboCop::ConfigLoader.inject_defaults!(project_root)
17
- obsoletion = File.join(project_root, 'config', 'obsoletion.yml')
18
- RuboCop::ConfigObsoletion.files << obsoletion if File.exist?(obsoletion)
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.26.1
4
+ version: 2.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
@@ -9,29 +9,47 @@ authors:
9
9
  - Phil Pirozhkov
10
10
  - Maxim Krizhanovsky
11
11
  - Andrew Bromwich
12
- autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2024-06-11 00:00:00.000000000 Z
14
+ date: 1980-01-02 00:00:00.000000000 Z
16
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: lint_roller
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
17
30
  - !ruby/object:Gem::Dependency
18
31
  name: rubocop
19
32
  requirement: !ruby/object:Gem::Requirement
20
33
  requirements:
21
34
  - - "~>"
22
35
  - !ruby/object:Gem::Version
23
- version: '1.61'
36
+ version: '1.72'
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.72.1
24
40
  type: :runtime
25
41
  prerelease: false
26
42
  version_requirements: !ruby/object:Gem::Requirement
27
43
  requirements:
28
44
  - - "~>"
29
45
  - !ruby/object:Gem::Version
30
- version: '1.61'
46
+ version: '1.72'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.72.1
31
50
  description: |
32
51
  Code style checking for factory_bot files.
33
52
  A plugin for the RuboCop code style enforcing & linting tool.
34
- email:
35
53
  executables: []
36
54
  extensions: []
37
55
  extra_rdoc_files:
@@ -62,6 +80,7 @@ files:
62
80
  - lib/rubocop/factory_bot/description_extractor.rb
63
81
  - lib/rubocop/factory_bot/factory_bot.rb
64
82
  - lib/rubocop/factory_bot/language.rb
83
+ - lib/rubocop/factory_bot/plugin.rb
65
84
  - lib/rubocop/factory_bot/version.rb
66
85
  homepage: https://github.com/rubocop/rubocop-factory_bot
67
86
  licenses:
@@ -70,7 +89,7 @@ metadata:
70
89
  changelog_uri: https://github.com/rubocop/rubocop-factory_bot/blob/master/CHANGELOG.md
71
90
  documentation_uri: https://docs.rubocop.org/rubocop-factory_bot/
72
91
  rubygems_mfa_required: 'true'
73
- post_install_message:
92
+ default_lint_roller_plugin: RuboCop::FactoryBot::Plugin
74
93
  rdoc_options: []
75
94
  require_paths:
76
95
  - lib
@@ -85,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
104
  - !ruby/object:Gem::Version
86
105
  version: '0'
87
106
  requirements: []
88
- rubygems_version: 3.5.9
89
- signing_key:
107
+ rubygems_version: 3.6.9
90
108
  specification_version: 4
91
109
  summary: Code style checking for factory_bot files
92
110
  test_files: []