summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2024-12-17 03:34:56 +0800
committergit <svn-admin@ruby-lang.org>2024-12-16 19:35:00 +0000
commita6fd6cb72f22531cc3cc976de99c5f9eccbf7101 (patch)
tree70c7090d4e5fca60926509e4c62f2755a246bc22 /lib
parent80b8feb929be08bd718518a57d2b549c8dab80b3 (diff)
[ruby/rdoc] Print warnings for rdoc-ref links that can't be resolved
(https://github.com/ruby/rdoc/pull/1241) https://github.com/ruby/rdoc/commit/4a5206ae56
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc/markup/to_html_crossref.rb34
-rw-r--r--lib/rdoc/options.rb16
2 files changed, 38 insertions, 12 deletions
diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 9b5de62fd6..172518c7f9 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -58,7 +58,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# Creates a link to the reference +name+ if the name exists. If +text+ is
# given it is used as the link text, otherwise +name+ is used.
- def cross_reference name, text = nil, code = true
+ def cross_reference name, text = nil, code = true, rdoc_ref: false
lookup = name
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
@@ -70,7 +70,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
text ||= name
end
- link lookup, text, code
+ link lookup, text, code, rdoc_ref: rdoc_ref
end
##
@@ -92,7 +92,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
return name if name =~ /\A[a-z]*\z/
end
- cross_reference name
+ cross_reference name, rdoc_ref: false
end
##
@@ -100,9 +100,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# handle other schemes.
def handle_regexp_HYPERLINK target
- return cross_reference $' if target.text =~ /\Ardoc-ref:/
+ url = target.text
- super
+ case url
+ when /\Ardoc-ref:/
+ cross_reference $', rdoc_ref: true
+ else
+ super
+ end
end
##
@@ -117,8 +122,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
url = target.text
case url
- when /\Ardoc-ref:/ then
- cross_reference $'
+ when /\Ardoc-ref:/
+ cross_reference $', rdoc_ref: true
else
super
end
@@ -129,16 +134,18 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# RDoc::Markup::ToHtml to handle other schemes.
def gen_url url, text
- return super unless url =~ /\Ardoc-ref:/
-
- name = $'
- cross_reference name, text, name == text
+ if url =~ /\Ardoc-ref:/
+ name = $'
+ cross_reference name, text, name == text, rdoc_ref: true
+ else
+ super
+ end
end
##
# Creates an HTML link to +name+ with the given +text+.
- def link name, text, code = true
+ def link name, text, code = true, rdoc_ref: false
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
name = $1
label = $'
@@ -148,6 +155,9 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
case ref
when String then
+ if rdoc_ref && @options.warn_missing_rdoc_ref
+ puts "#{@from_path}: `rdoc-ref:#{name}` can't be resolved for `#{text}`"
+ end
ref
else
path = ref ? ref.as_href(@from_path) : +""
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index a607a76d56..f35467e312 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -326,6 +326,12 @@ class RDoc::Options
attr_accessor :verbosity
##
+ # Warn if rdoc-ref links can't be resolved
+ # Default is +false+
+
+ attr_accessor :warn_missing_rdoc_ref
+
+ ##
# URL of web cvs frontend
attr_accessor :webcvs
@@ -393,6 +399,7 @@ class RDoc::Options
@update_output_dir = true
@verbosity = 1
@visibility = :protected
+ @warn_missing_rdoc_ref = false
@webcvs = nil
@write_options = false
@encoding = Encoding::UTF_8
@@ -457,6 +464,8 @@ class RDoc::Options
@visibility = map['visibility'] if map.has_key?('visibility')
@webcvs = map['webcvs'] if map.has_key?('webcvs')
+ @warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref')
+
if map.has_key?('rdoc_include')
@rdoc_include = sanitize_path map['rdoc_include']
end
@@ -1104,6 +1113,13 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
+ opt.on("--warn-missing-rdoc-ref",
+ "Warn if rdoc-ref links can't be resolved") do |value|
+ @warn_missing_rdoc_ref = value
+ end
+
+ opt.separator nil
+
opt.on("--[no-]ignore-invalid",
"Ignore invalid options and continue",
"(default true).") do |value|