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

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



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubocop/cop/yardoc/param_description_casing.rb', line 34

def on_def(node)
  return unless documented? node

  node_comments(node).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