Class: Nucop::ExplicitFactoryBotUsage
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Nucop::ExplicitFactoryBotUsage
- Extended by:
- RuboCop::Cop::AutoCorrector
- Includes:
- Helpers::FilePathHelper
- Defined in:
- lib/nucop/cops/explicit_factory_bot_usage.rb
Overview
This cop looks for usages of ‘FactoryGirl.create`, etc. See FactoryBotHelper::FACTORY_BOT_METHODS constant for a complete list.
The factory methods listed are included everywhere, so referencing the constant should rarely be necessary.
Constant Summary collapse
- MSG =
"Do not explicitly use `%<constant>s` to build objects. The factory method `%<method>s` is globally available."
Instance Method Summary collapse
Methods included from Helpers::FilePathHelper
#acceptance_or_spec_file?, #support_file?
Instance Method Details
#on_send(node) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/nucop/cops/explicit_factory_bot_usage.rb', line 28 def on_send(node) explicit_factory_bot_usage(node) do add_offense(node, message: format(MSG, constant: node.receiver.const_name, method: node.method_name)) do |corrector| corrector.replace(node.source_range, node.source.sub(/(?:FactoryGirl|FactoryBot)[.]/, "")) end end end |
#relevant_file?(file) ⇒ Boolean
36 37 38 |
# File 'lib/nucop/cops/explicit_factory_bot_usage.rb', line 36 def relevant_file?(file) acceptance_or_spec_file?(file) && super end |