Class: RuboCop::Cop::FactoryBot::ConsistentParenthesesStyle
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::FactoryBot::ConsistentParenthesesStyle
show all
- Extended by:
- AutoCorrector
- Includes:
- ConfigurableEnforcedStyle, ConfigurableExplicitOnly
- Defined in:
- lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb
Overview
Use a consistent style for parentheses in factory_bot calls.
Constant Summary
collapse
- MSG_REQUIRE_PARENS =
'Prefer method call with parentheses'
- MSG_OMIT_PARENS =
'Prefer method call without parentheses'
- FACTORY_CALLS =
RuboCop::FactoryBot::Language::METHODS
- RESTRICT_ON_SEND =
FACTORY_CALLS
FactoryBot::Language::METHODS
Class Method Summary
collapse
Instance Method Summary
collapse
#explicit_only?, #factory_call?
#factory_bot?
Class Method Details
.autocorrect_incompatible_with ⇒ Object
89
90
91
|
# File 'lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb', line 89
def self.autocorrect_incompatible_with
[Style::MethodCallWithArgsParentheses]
end
|
Instance Method Details
#factory_call(node) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb', line 71
def_node_matcher :factory_call, <<~PATTERN
(send
#factory_call? %FACTORY_CALLS
{sym str send lvar} _*
)
PATTERN
|
#omit_hash_value?(node) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb', line 79
def_node_matcher :omit_hash_value?, <<~PATTERN
(send
#factory_call? %FACTORY_CALLS
{sym str send lvar}
(hash
<value_omission? ...>
)
)
PATTERN
|
#on_send(node) ⇒ Object
93
94
95
96
97
|
# File 'lib/rubocop/cop/factory_bot/consistent_parentheses_style.rb', line 93
def on_send(node)
return if ambiguous_without_parentheses?(node)
factory_call(node) { register_offense(node) }
end
|