Class: RuboCop::Cop::Yardoc::MethodDescription

Inherits:
Base
  • Object
show all
Includes:
NodeNameHelp, VisibilityHelp
Defined in:
lib/rubocop/cop/yardoc/method_description.rb

Overview

Ensures all public methods have a description.

This does not ensure parameters and other documentation, only the description

Private/protected methods are skipped unless DocumentPrivate: true. Methods can be ignored via Ignore.

Examples:

# bad
def my_method; end

# good
# Does something useful.
def my_method; end

DocumentPrivate: true

# bad
private

def secret; end

Ignore: [a_method]

# bad
def something; end

# good (ignored)
def a_method; end

class MyClass
  # good (ignored)
  def a_method; end
end

Ignore: [/^a_m/]

# bad
def something; end

# good (ignored)
def a_method; end

class MyClass
  # good (ignored)
  def a_method; end
end

Ignore: [MyClass::a_method]

# bad
def something; end

# bad
def a_method; end

class MyClass
  # good (ignored)
  def a_method; end
end

Constant Summary collapse

MSG =
'Missing YARD documentation for method `%<name>s`.'

Instance Method Summary collapse

Methods included from NodeNameHelp

#fully_qualified_name

Instance Method Details

#on_def(node) ⇒ Object Also known as: on_defs

Executed for each method definition

Parameters:

  • node (RuboCop::AST::Node)

    The AST node



71
72
73
74
75
76
77
78
79
80
# File 'lib/rubocop/cop/yardoc/method_description.rb', line 71

def on_def(node)
  name = node.method_name.to_s
  full_name = fully_qualified_name(node)
  full_name += "::#{name}"
  return if ignored?(name, ignore_list) || ignored?(full_name, ignore_list)
  return if skip_private? && node_visibility(node) == :private
  return if documented?(node)

  add_offense(node, message: format(MSG, name: name))
end