Class: RuboCop::Cop::Airbnb::FactoryAttrReferencesClass

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/airbnb/factory_attr_references_class.rb

Overview

Cop to enforce “attr { CONST }” instead of “attr CONST” in factories, because the latter forces autoload, which slows down spec startup time and Zeus reload time after touching a model.

Constant Summary collapse

MSG =
"Instead of attr_name MyClass::MY_CONST, use attr_name { MyClass::MY_CONST }. " \
"This enables faster spec startup time and Zeus reload time.".freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

Look for “attr CONST” expressions in factories or traits. In RuboCop, this is a ‘send` node, sending the attr method.



17
18
19
20
21
22
# File 'lib/rubocop/cop/airbnb/factory_attr_references_class.rb', line 17

def on_send(node)
  return unless in_factory_file?(node)
  return unless in_factory_or_trait?(node)

  add_const_offenses(node)
end