class RuboCop::Cop::Rake::MethodDefinitionInTask


end
task :foo do
end
def helper_method
# but it looks expected behavior.
# good - It is also defined to the top level,
end
end
do_something
def helper_method
namespace :foo do
# bad
end
end
do_something
def helper_method
task :foo do
# bad
@example
but actually it is defined to the top level.
It is confusing because the scope looks in the task or namespace,
because it is defined to the top level.
This cop detects method definition in a task or namespace,

def on_def(node)

def on_def(node)
  return if Helper::ClassDefinition.in_class_definition?(node)
  return unless Helper::TaskDefinition.in_task_or_namespace?(node)
  add_offense(node)
end