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

Inherits:
RuboCop::Cop::YardocBase show all
Includes:
NodeNameHelp, RuboCop::Cop::YardHelp, VisibilityHelp
Defined in:
lib/rubocop/cop/yardoc/method_description.rb

Overview

Ensures all 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:

DocumentPrivate: true (default)

# bad

def my_method; end

# bad

# @param name [String] The name
def some_method(name); end

# good

# Does something useful.
def my_other_method; end

private

# good

# Does something useful.
# def my_other_other_method; end

DocumentPrivate: true

private

# good

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rubocop/cop/yardoc/method_description.rb', line 96

def on_def(node) # rubocop:disable Metrics/AbcSize
  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) && !yard_docstring(node).text.strip.empty?

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