lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.3.1 vs lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.4.0

- old
+ new

@@ -26,20 +26,17 @@ # desc 'Do something' # task :do_something do # end # class Desc < Cop + include Helper::OnTask + MSG = 'Describe the task with `desc` method.' - def_node_matcher :task?, <<~PATTERN - (send nil? :task ...) - PATTERN - - def on_send(node) - return unless task?(node) + def on_task(node) return if task_with_desc?(node) - return if task_name(node) == :default + return if Helper::TaskName.task_name(node) == :default add_offense(node) end private def task_with_desc?(node) @@ -49,26 +46,9 @@ idx = parent.children.find_index(task) - 1 desc_candidate = parent.children[idx] return false unless desc_candidate desc_candidate.send_type? && desc_candidate.method_name == :desc - end - - private def task_name(node) - first_arg = node.arguments[0] - case first_arg&.type - when :sym, :str - return first_arg.value.to_sym - when :hash - return nil if first_arg.children.size != 1 - - pair = first_arg.children.first - key = pair.children.first - case key.type - when :sym, :str - key.value.to_sym - end - end end private def parent_and_task(task_node) parent = task_node.parent return nil, task_node unless parent