Skip to content

Commit

Permalink
[#494] Better function names
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Jan 5, 2024
1 parent a384ec3 commit 4631bb2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions custom_cops/required_inverse_of_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class RequiredInverseOfRelations < RuboCop::Cop::Base
RESTRICT_ON_SEND = %i[has_many belongs_to].freeze
ASSOCIATION_METHODS = RESTRICT_ON_SEND.to_set

def_node_matcher :missing_inverse_of_no_arguments?, <<~PATTERN
def_node_matcher :association_expression_no_arguments?, <<~PATTERN
(send nil? ASSOCIATION_METHODS (sym _))
PATTERN

def_node_matcher :missing_inverse_of_with_arguments?, <<~PATTERN
def_node_matcher :association_expression_with_arguments?, <<~PATTERN
(send nil? ASSOCIATION_METHODS (sym _) (hash $...))
PATTERN

def on_send(node)
return add_offense(node) if missing_inverse_of_no_arguments?(node)
return add_offense(node) if association_expression_no_arguments?(node)

return unless (hash_pairs = missing_inverse_of_with_arguments?(node))
return unless (hash_pairs = association_expression_with_arguments?(node))

add_offense(node) unless contain_inverse_of?(hash_pairs)
end
Expand Down

0 comments on commit 4631bb2

Please sign in to comment.