lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.5.1 vs lib/rubocop/cop/rake/desc.rb in rubocop-rake-0.6.0
- old
+ new
@@ -25,19 +25,27 @@
# # good
# desc 'Do something'
# task :do_something do
# end
#
- class Desc < Cop
+ class Desc < Base
include Helper::OnTask
+ extend AutoCorrector
MSG = 'Describe the task with `desc` method.'
+ def_node_matcher :prerequisites, <<~PATTERN
+ (send nil? :task (hash (pair _ $_)))
+ PATTERN
+
def on_task(node)
return if task_with_desc?(node)
return if Helper::TaskName.task_name(node) == :default
+ requirements = prerequisites(node)
+ return if requirements&.array_type?
+
add_offense(node)
end
private def task_with_desc?(node)
parent, task = parent_and_task(node)
@@ -46,10 +54,10 @@
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
+ desc_candidate.send_type? && desc_candidate.method?(:desc)
end
private def parent_and_task(task_node)
parent = task_node.parent
return nil, task_node unless parent