class RuboCop::Cop::Rake::ClassDefinitionInTask

This cop detects class or module definition in a task or namespace, because it is defined to the top level. It is confusing because the scope looks in the task or namespace, but actually it is defined to the top level.

@example

# bad
task :foo do
  class C
  end
end

# bad
namespace :foo do
  module M
  end
end

# good - It is also defined to the top level,
#        but it looks expected behavior.
class C
end
task :foo do
end

Constants

MSG

Public Instance Methods

on_class(node) click to toggle source
# File lib/rubocop/cop/rake/class_definition_in_task.rb, line 34
def on_class(node)
  return if Helper::ClassDefinition.in_class_definition?(node)
  return unless Helper::TaskDefinition.in_task_or_namespace?(node)

  add_offense(node, message: format(MSG, type: node.type))
end
Also aliased as: on_module
on_module(node)
Alias for: on_class