Class: RuboCop::Cop::Yardoc::ColumnParams

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ParamHelp, RuboCop::Cop::YardHelp
Defined in:
lib/rubocop/cop/yardoc/column_params.rb

Overview

Ensures @param tags are correctly formatted and aligned.

Rules enforced:

  • Type must appear in square brackets directly after the param name
  • All @param type columns must be aligned
  • All @param description columns must be aligned
  • Multiline descriptions must align with the first description character

Examples:

# bad
# @param foo [String] a foo
# @param longer_name [Integer] a number
# @param bar [String] A multiline, non aligned
#   description

# good
# @param foo         [String]  a foo
# @param longer_name [Integer] a number
# @param bar         [String]  A multiline, aligned
#                              description

Constant Summary collapse

MSG_TYPE_MISSING =
'@param `%<name>s` must have a type in [brackets].'
MSG_ALIGNMENT =
'@param tags must have aligned types and descriptions.'
MSG_MULTILINE =
'Multiline @param description must align with the first description character.'

Instance Method Summary collapse

Methods included from ParamHelp

#param_tags_and_positions, #start_tag_position

Instance Method Details

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

Executed for every method definition

Parameters:

  • node (RuboCop::AST::Node)

    The AST node



38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/yardoc/column_params.rb', line 38

def on_def(node)
  param_lines = extract_param_lines(node)
  return if param_lines.empty?

  check_types_present(node, param_lines) unless config.for_cop('Yardoc/ParamDocumentation')['Enabled']
  check_alignment(param_lines)
  check_multiline_alignment(node, param_lines)
end