diff --git a/CHANGELOG.md b/CHANGELOG.md index 29947efe..929a8549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Master (Unreleased) +- Fix a false positive for `FactoryBot/ConsistentParenthesesStyle` when using traits and omitting hash values. + ## 2.26.1 (2024-06-12) - Bump RuboCop requirement to +1.61. ([@ydah]) diff --git a/lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb b/lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb index 1a346ce2..60a8ffc5 100644 --- a/lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb +++ b/lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb @@ -79,7 +79,7 @@ class ConsistentParenthesesStyle < ::RuboCop::Cop::Base def_node_matcher :omit_hash_value?, <<~PATTERN (send #factory_call? %FACTORY_CALLS - {sym str send lvar} + {sym str send lvar} _* (hash ) diff --git a/spec/rubocop/cop/factory_bot/consistent_parentheses_style_spec.rb b/spec/rubocop/cop/factory_bot/consistent_parentheses_style_spec.rb index baeaba17..27cddcfd 100644 --- a/spec/rubocop/cop/factory_bot/consistent_parentheses_style_spec.rb +++ b/spec/rubocop/cop/factory_bot/consistent_parentheses_style_spec.rb @@ -418,6 +418,7 @@ expect_no_offenses(<<~RUBY) create(:user, name:) create(:user, name:, client:) + create(:user, :trait, name:, client:) RUBY end @@ -426,6 +427,8 @@ expect_no_offenses(<<~RUBY) create(:user, client:, name: 'foo') create(:user, client: 'foo', name:) + create(:user, :trait, client:, name: 'foo') + create(:user, :trait, client: 'foo', name:) RUBY end @@ -434,10 +437,13 @@ expect_offense(<<~RUBY) create(:user, name: 'foo') ^^^^^^ Prefer method call without parentheses + create(:user, :trait, name: 'foo') + ^^^^^^ Prefer method call without parentheses RUBY expect_correction(<<~RUBY) create :user, name: 'foo' + create :user, :trait, name: 'foo' RUBY end @@ -446,10 +452,13 @@ expect_offense(<<~RUBY) create(:user, foo(name:)) ^^^^^^ Prefer method call without parentheses + create(:user, :trait, foo(name:)) + ^^^^^^ Prefer method call without parentheses RUBY expect_correction(<<~RUBY) create :user, foo(name:) + create :user, :trait, foo(name:) RUBY end end