Skip to content

Commit

Permalink
Improve a bit the code style in Rails/RelativeDateConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Apr 3, 2017
1 parent 212f68b commit 2dc72ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rubocop/cop/rails/relative_date_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ class RelativeDateConstant < Cop
RELATIVE_DATE_METHODS = %i[ago from_now since until].freeze

def on_casgn(node)
return if node.children.last.lambda_or_proc?
_scope, _constant, rhs = *node

bad_node = node.descendants.find { |n| bad_method?(n) }
return if rhs.lambda_or_proc?

bad_node = node.descendants.find { |n| relative_date_method?(n) }
return unless bad_node

add_offense(node, :expression, format(MSG, bad_node.method_name))
end

private

def bad_method?(node)
def relative_date_method?(node)
node.send_type? &&
RELATIVE_DATE_METHODS.include?(node.method_name) &&
node.method_args.empty?
Expand Down

0 comments on commit 2dc72ae

Please sign in to comment.