Class: RuboCop::Cop::InternalAffairs::MissingCopDepartment

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/internal_affairs/missing_cop_department.rb

Overview

Enforces the use of explicit department names for cop rules.

Examples:

# bad
module RuboCop
  module Cop
    class Implicit
    end
  end
end

module RuboCop
  module Cop
    module Cop
      class Explicit
      end
    end
  end
end

# good
module RuboCop
  module Cop
    module Foo
      class Implicit
      end
    end
  end
end

module RuboCop
  module Cop
    module Foo
      class Explicit
      end
    end
  end
end

Constant Summary collapse

MSG =
'Define a proper department. Using `Cop/` as department is discourged.'
COP_DEPARTMENT =
'Cop'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/internal_affairs/missing_cop_department.rb', line 49

def on_class(node)
  namespace = full_namespace(node)

  # Skip top-level RuboCop::Cop
  names = namespace.drop(2)

  add_offense(node.loc.name) if names.size < 2 || names.first == COP_DEPARTMENT
end