Sha256: cf3a5ac62fcdd37dfaab8347969070fb12feee3f864f8baf355cc56726aa2532
Contents?: true
Size: 1.2 KB
Versions: 5
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Rake # 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 # class ClassDefinitionInTask < Cop MSG = 'Do not define a %<type>s in rake task, because it will be defined to the top level.' def on_class(node) return if Helper::ClassDefinition.in_class_definition?(node) return unless Helper::TaskDefinition.in_task_or_namespace?(node) add_offense(node) end def message(node) format(MSG, type: node.type) end alias on_module on_class end end end end
Version data entries
5 entries across 5 versions & 1 rubygems