Skip to content

Commit

Permalink
Add support @see tags in our document
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah authored and bbatsov committed Dec 22, 2022
1 parent 0c5b1ec commit a5f4a9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/rubocop/cop/layout/class_structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ module Layout
# end
# end
#
# @see https://rubystyle.guide#consistent-classes
class ClassStructure < Base
include VisibilityHelp
extend AutoCorrector
Expand Down
19 changes: 11 additions & 8 deletions lib/rubocop/cops_documentation_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def cops_of_department(department)
cops.with_department(department).sort!
end

def cops_body(cop, description, examples_objects, safety_objects, pars) # rubocop:disable Metrics/AbcSize
def cops_body(cop, description, examples_objects, safety_objects, see_objects, pars) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
check_examples_to_have_the_default_enforced_style!(examples_objects, cop)

content = h2(cop.cop_name)
Expand All @@ -43,7 +43,7 @@ def cops_body(cop, description, examples_objects, safety_objects, pars) # ruboco
content << safety_object(safety_objects) if safety_objects.any? { |s| !s.text.blank? }
content << examples(examples_objects) if examples_objects.any?
content << configurations(cop.department, pars)
content << references(cop)
content << references(cop, see_objects)
content
end

Expand Down Expand Up @@ -224,14 +224,16 @@ def wrap_backtick(value)
end
end

def references(cop)
def references(cop, see_objects) # rubocop:disable Metrics/AbcSize
cop_config = config.for_cop(cop)
urls = RuboCop::Cop::MessageAnnotator.new(config, cop.name, cop_config, {}).urls
return '' if urls.empty?
return '' if urls.empty? && see_objects.empty?

content = h3('References')
content << urls.map { |url| "* #{url}" }.join("\n")
content << "\n"
content << "\n" unless urls.empty?
content << see_objects.map { |see| "* #{see.name}" }.join("\n")
content << "\n" unless see_objects.empty?
content
end

Expand All @@ -257,21 +259,22 @@ def print_cops_of_department(department)
end
end

def print_cop_with_doc(cop)
def print_cop_with_doc(cop) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
cop_config = config.for_cop(cop)
non_display_keys = %w[
Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
VersionChanged
]
pars = cop_config.reject { |k| non_display_keys.include? k }
description = 'No documentation'
examples_object = safety_object = []
examples_object = safety_object = see_object = []
cop_code(cop) do |code_object|
description = code_object.docstring unless code_object.docstring.blank?
examples_object = code_object.tags('example')
safety_object = code_object.tags('safety')
see_object = code_object.tags('see')
end
cops_body(cop, description, examples_object, safety_object, pars)
cops_body(cop, description, examples_object, safety_object, see_object, pars)
end

def cop_code(cop)
Expand Down

0 comments on commit a5f4a9a

Please sign in to comment.