lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.5.0 vs lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.5.1
- old
+ new
@@ -40,10 +40,11 @@
end
private def task_with_desc?(node)
parent, task = parent_and_task(node)
return false unless parent
+ return true unless can_insert_desc_to?(parent)
idx = parent.children.find_index(task) - 1
desc_candidate = parent.children[idx]
return false unless desc_candidate
@@ -53,18 +54,20 @@
private def parent_and_task(task_node)
parent = task_node.parent
return nil, task_node unless parent
return parent, task_node unless parent.block_type?
- # rubocop:disable Style/GuardClause
if parent.children.find_index(task_node) == 0
# when task {}
- return parent.parent, parent
+ [parent.parent, parent]
else
# when something { task }
- return parent, task_node
+ [parent, task_node]
end
- # rubocop:enable Style/GuardClause
+ end
+
+ private def can_insert_desc_to?(parent)
+ parent.begin_type? || parent.block_type? || parent.kwbegin_type?
end
end
end
end
end