Class: RuboCop::Cop::Yardoc::ParamDescriptionCasing

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/yardoc/param_description_casing.rb

Overview

Ensure every "param" and "return" tag starts with an uppercased letter

It ignores description starting with non latin characters

Examples:

# bad
# @param x [Integer] desc
# @return [void] desc
def my_method(x); end

# good
# @param x [Integer] Desc
# @return [void] Desc
def my_method(x); end

Defined Under Namespace

Classes: CommentEntry

Constant Summary collapse

MSG =
'First letter of a @param or @return tag should be in uppercase'
PARAM_REGEXP =

Matches a "param" tag line

/(?<definition>\A#\s+@param\s+[^\[]+(?:\s+\[[^\]]+\])?\s+)(?<desc>[a-z].*)/
RETURN_REGEXP =

Matches a "return" tag line

/(?<definition>\A#\s+@return\s+(?:\[[^\]]+\])?\s+)(?<desc>[a-z].*)/

Instance Method Summary collapse

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubocop/cop/yardoc/param_description_casing.rb', line 46

def on_def(node)
  return unless documented? node

  processed_source.comments
                  .each do |line|
                    match = line.text.match(PARAM_REGEXP) || line.text.match(RETURN_REGEXP)
                    next unless match

                    range = offense_range(line, match[:definition])
                    add_offense(range) do |corrector|
                      corrector.replace(range, match[:desc][0].upcase)
                    end
                  end
end