Class: RuboCop::Cop::Betterment::UseGlobalStrictLoading::ForAssociations
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Betterment::UseGlobalStrictLoading::ForAssociations
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/betterment/use_global_strict_loading.rb
Overview
This cop ensures that ‘strict_loading: <any value>` is not set in ActiveRecord associations.
Constant Summary collapse
- MSG =
'Do not set `:strict_loading` in ActiveRecord associations.'
- ASSOCIATION_METHODS =
%i(belongs_to has_and_belongs_to_many has_many has_one).freeze
Instance Method Summary collapse
- #association_with_strict_loading?(node) ⇒ Object
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#association_with_strict_loading?(node) ⇒ Object
39 40 41 |
# File 'lib/rubocop/cop/betterment/use_global_strict_loading.rb', line 39 def_node_matcher :association_with_strict_loading?, <<~PATTERN (send nil? {#{ASSOCIATION_METHODS.map(&:inspect).join(' ')}} ... (hash <$(pair (sym :strict_loading) ...) ...>)) PATTERN |
#on_send(node) ⇒ Object Also known as: on_csend
43 44 45 46 47 48 49 |
# File 'lib/rubocop/cop/betterment/use_global_strict_loading.rb', line 43 def on_send(node) association_with_strict_loading?(node) do |pair| add_offense(node) do |corrector| corrector.remove(range_with_surrounding_comma(range_with_surrounding_space(range: pair.source_range, side: :left), :left)) end end end |