Class: RuboCop::Cop::YARD::MeaninglessTag

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
DocumentationComment, RangeHelp, Helper
Defined in:
lib/rubocop/cop/yard/meaningless_tag.rb

Overview

Examples:

meaningless tag

# bad
# @param [String] foo
# @option bar baz [String]
class Foo

# bad
# @param [String] foo
# @option bar baz [String]
CONST = 1

# good
class Foo

# good
CONST = 1

Instance Method Summary collapse

Methods included from Helper

#build_docstring, #each_types_explainer, #extract_tag_types, #inline_comment?, #parse_type, #styled_string

Instance Method Details

#check(node) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rubocop/cop/yard/meaningless_tag.rb', line 34

def check(node)
  preceding_lines = preceding_lines(node)
  return false unless preceding_comment?(node, preceding_lines.last)

  docstring = build_docstring(preceding_lines)
  return false unless docstring

  docstring.tags.each do |tag|
    next unless tag.tag_name == 'param' || tag.tag_name == 'option'

    comment = preceding_lines.find { |line| line.text.include?("@#{tag.tag_name}") }
    next unless comment

    add_offense(comment, message: "`@#{tag.tag_name}` is meaningless tag on #{node.type}") do |corrector|
      corrector.replace(comment, comment.text.gsub("@#{tag.tag_name}", tag.tag_name))
    end
  end
end

#on_class(node) ⇒ Object Also known as: on_module, on_casgn



28
29
30
# File 'lib/rubocop/cop/yard/meaningless_tag.rb', line 28

def on_class(node)
  check(node)
end