Class: RuboCop::Cop::Rake::Desc

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
Helper::OnTask
Defined in:
lib/rubocop/cop/rake/desc.rb

Overview

Rake task definition should have a description with ‘desc` method. It is useful as a documentation of task. And Rake does not display task that does not have `desc` by `rake -T`.

Note: This cop does not require description for the default task,

because the default task is executed with `rake` without command.

Examples:

# bad
task :do_something

# bad
task :do_something do
end

# good
desc 'Do something'
task :do_something

# good
desc 'Do something'
task :do_something do
end

Constant Summary collapse

MSG =
'Describe the task with `desc` method.'

Instance Method Summary collapse

Methods included from Helper::OnTask

#on_send

Instance Method Details

#on_task(node) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/rubocop/cop/rake/desc.rb', line 40

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