Class: Rubocop::Cop::InternalAffairs::CopDescriptionWithExample

Inherits:
RuboCop::Cop::InternalAffairs::CopDescription
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::Cop::DocumentationComment
Defined in:
lib/rubocop/cop/internal_affairs/cop_description_with_example.rb

Overview

Enforces the cop description to start with a word such as verb, and to include good and bad examples

Examples:

# bad
# This cop checks ....
# @example
#   # bad
#   !array.empty?
#
#   # good
#   array.any?
class SomeCop < Base
  ....
end

# bad
# Checks ...
class SomeCop < Base
  ...
end

# good
# Checks ...
#
# @example
#   # bad
#   !array.empty?
#
#   # good
#   array.any?
#
class SomeCop < Base
  ...
end

Constant Summary collapse

MSG_MISSING_EXAMPLES =
'Description should include good and bad examples'
MSG_MISSING_DESCRIPTION =
'Must include a description'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubocop/cop/internal_affairs/cop_description_with_example.rb', line 50

def on_class(node)
  super

  module_node = node.parent

  return unless module_node && node.parent_class

  return if description_includes_example?(node)

  description_beginning = first_comment_line(module_node)

  if description_beginning.nil?
    register_offense_for_missing_description(node)
  else
    register_offense_for_missing_examples(module_node, description_beginning)
  end
end