Class: RuboCop::Cop::Yardoc::ConstantDescription

Inherits:
RuboCop::Cop::YardocBase show all
Includes:
NodeNameHelp
Defined in:
lib/rubocop/cop/yardoc/constant_description.rb

Overview

Ensures all constants have YARD documentation.

They can be ignored via Ignore, by providing the name or a regexp

Examples:

# bad

MY_CONST = 10

# good

# That's 9 + 1
MY_CONST = 10

Ignores: ['MY_CONST']

# bad

A_CONST = 'something'

# good (ignored)

MY_CONST = 10

class MyClass
  # good (ignored)

  MY_CONST
end

Ignores: ['/^MY_CONST/']

# bad

A_CONST = 'something'

# good (ignored)

MY_CONST = 10

class MyClass
  # bad

  MY_CONST
end

Ignores: ['MyClass::MY_CONST']

# bad

A_CONST = 'something'

# bad

MY_CONST = 10

class MyClass
  # good (ignored)

  MY_CONST
end

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from NodeNameHelp

#fully_qualified_name

Instance Method Details

#on_casgn(node) ⇒ Object

Executed for each constant definition

Parameters:

  • node (RuboCop::AST::Node)

    The AST node



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

def on_casgn(node)
  _scope, name, = node.children
  name = 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 documented?(node)

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