[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
This commit is contained in:
parent
80b8feb929
commit
a6fd6cb72f
@ -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
|
# 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.
|
# 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
|
lookup = name
|
||||||
|
|
||||||
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
||||||
@ -70,7 +70,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
text ||= name
|
text ||= name
|
||||||
end
|
end
|
||||||
|
|
||||||
link lookup, text, code
|
link lookup, text, code, rdoc_ref: rdoc_ref
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -92,7 +92,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
return name if name =~ /\A[a-z]*\z/
|
return name if name =~ /\A[a-z]*\z/
|
||||||
end
|
end
|
||||||
|
|
||||||
cross_reference name
|
cross_reference name, rdoc_ref: false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -100,10 +100,15 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
# handle other schemes.
|
# handle other schemes.
|
||||||
|
|
||||||
def handle_regexp_HYPERLINK target
|
def handle_regexp_HYPERLINK target
|
||||||
return cross_reference $' if target.text =~ /\Ardoc-ref:/
|
url = target.text
|
||||||
|
|
||||||
|
case url
|
||||||
|
when /\Ardoc-ref:/
|
||||||
|
cross_reference $', rdoc_ref: true
|
||||||
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# +target+ is an rdoc-schemed link that will be converted into a hyperlink.
|
# +target+ is an rdoc-schemed link that will be converted into a hyperlink.
|
||||||
@ -117,8 +122,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
url = target.text
|
url = target.text
|
||||||
|
|
||||||
case url
|
case url
|
||||||
when /\Ardoc-ref:/ then
|
when /\Ardoc-ref:/
|
||||||
cross_reference $'
|
cross_reference $', rdoc_ref: true
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
@ -129,16 +134,18 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
# RDoc::Markup::ToHtml to handle other schemes.
|
# RDoc::Markup::ToHtml to handle other schemes.
|
||||||
|
|
||||||
def gen_url url, text
|
def gen_url url, text
|
||||||
return super unless url =~ /\Ardoc-ref:/
|
if url =~ /\Ardoc-ref:/
|
||||||
|
|
||||||
name = $'
|
name = $'
|
||||||
cross_reference name, text, name == text
|
cross_reference name, text, name == text, rdoc_ref: true
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Creates an HTML link to +name+ with the given +text+.
|
# 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 =~ /(.*[^#:])?@/
|
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
|
||||||
name = $1
|
name = $1
|
||||||
label = $'
|
label = $'
|
||||||
@ -148,6 +155,9 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||||||
|
|
||||||
case ref
|
case ref
|
||||||
when String then
|
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
|
ref
|
||||||
else
|
else
|
||||||
path = ref ? ref.as_href(@from_path) : +""
|
path = ref ? ref.as_href(@from_path) : +""
|
||||||
|
@ -325,6 +325,12 @@ class RDoc::Options
|
|||||||
|
|
||||||
attr_accessor :verbosity
|
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
|
# URL of web cvs frontend
|
||||||
|
|
||||||
@ -393,6 +399,7 @@ class RDoc::Options
|
|||||||
@update_output_dir = true
|
@update_output_dir = true
|
||||||
@verbosity = 1
|
@verbosity = 1
|
||||||
@visibility = :protected
|
@visibility = :protected
|
||||||
|
@warn_missing_rdoc_ref = false
|
||||||
@webcvs = nil
|
@webcvs = nil
|
||||||
@write_options = false
|
@write_options = false
|
||||||
@encoding = Encoding::UTF_8
|
@encoding = Encoding::UTF_8
|
||||||
@ -457,6 +464,8 @@ class RDoc::Options
|
|||||||
@visibility = map['visibility'] if map.has_key?('visibility')
|
@visibility = map['visibility'] if map.has_key?('visibility')
|
||||||
@webcvs = map['webcvs'] if map.has_key?('webcvs')
|
@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')
|
if map.has_key?('rdoc_include')
|
||||||
@rdoc_include = sanitize_path map['rdoc_include']
|
@rdoc_include = sanitize_path map['rdoc_include']
|
||||||
end
|
end
|
||||||
@ -1104,6 +1113,13 @@ Usage: #{opt.program_name} [options] [names...]
|
|||||||
|
|
||||||
opt.separator nil
|
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",
|
opt.on("--[no-]ignore-invalid",
|
||||||
"Ignore invalid options and continue",
|
"Ignore invalid options and continue",
|
||||||
"(default true).") do |value|
|
"(default true).") do |value|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
require_relative 'xref_test_case'
|
require_relative 'xref_test_case'
|
||||||
|
|
||||||
class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
class RDocMarkupToHtmlCrossrefTest < XrefTestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
@options.hyperlink_all = true
|
@options.hyperlink_all = true
|
||||||
|
@options.warn_missing_rdoc_ref = true
|
||||||
|
|
||||||
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
|
||||||
end
|
end
|
||||||
@ -67,6 +68,16 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
|||||||
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_convert_RDOCLINK_rdoc_ref_not_found
|
||||||
|
result = nil
|
||||||
|
stdout, _ = capture_output do
|
||||||
|
result = @to.convert 'rdoc-ref:FOO'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal para("FOO"), result
|
||||||
|
assert_include stdout, "index.html: `rdoc-ref:FOO` can't be resolved for `FOO`"
|
||||||
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref_method
|
def test_convert_RDOCLINK_rdoc_ref_method
|
||||||
result = @to.convert 'rdoc-ref:C1#m'
|
result = @to.convert 'rdoc-ref:C1#m'
|
||||||
|
|
||||||
@ -153,6 +164,14 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
|||||||
@to.gen_url('http://example', 'HTTP example')
|
@to.gen_url('http://example', 'HTTP example')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_gen_url_rdoc_ref_not_found
|
||||||
|
stdout, _ = capture_output do
|
||||||
|
@to.gen_url 'rdoc-ref:FOO', 'FOO'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_include stdout, "index.html: `rdoc-ref:FOO` can't be resolved for `FOO`"
|
||||||
|
end
|
||||||
|
|
||||||
def test_handle_regexp_CROSSREF
|
def test_handle_regexp_CROSSREF
|
||||||
assert_equal "<a href=\"C2/C3.html\"><code>C2::C3</code></a>", REGEXP_HANDLING('C2::C3')
|
assert_equal "<a href=\"C2/C3.html\"><code>C2::C3</code></a>", REGEXP_HANDLING('C2::C3')
|
||||||
end
|
end
|
||||||
|
@ -82,6 +82,7 @@ class TestRDocOptions < RDoc::TestCase
|
|||||||
'template_stylesheets' => [],
|
'template_stylesheets' => [],
|
||||||
'title' => nil,
|
'title' => nil,
|
||||||
'visibility' => :protected,
|
'visibility' => :protected,
|
||||||
|
'warn_missing_rdoc_ref' => false,
|
||||||
'webcvs' => nil,
|
'webcvs' => nil,
|
||||||
'skip_tests' => true,
|
'skip_tests' => true,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user