From 591f71da8c152941afedba573672fc096ef84aaf Mon Sep 17 00:00:00 2001 From: JP Simard Date: Sat, 24 Oct 2015 15:27:48 -0400 Subject: [PATCH] fix rubocop issues --- lib/jazzy/sourcekitten.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/jazzy/sourcekitten.rb b/lib/jazzy/sourcekitten.rb index 0233e8339..fd0b8fc41 100644 --- a/lib/jazzy/sourcekitten.rb +++ b/lib/jazzy/sourcekitten.rb @@ -312,19 +312,21 @@ def self.filter_excluded_files(json) end def self.names_and_urls(docs) - names_and_urls = docs.flat_map do |doc| + docs.flat_map do |doc| # FIXME: autolink more than just top-level items. - [{:name => doc.name, :url => doc.url}] # + names_and_urls(doc.children) + [{ name: doc.name, url: doc.url }] # + names_and_urls(doc.children) end end def self.autolink_text(text, data, url) - text.gsub(/\b(#{data.map { |d| Regexp.escape(d[:name]) }.join('|')})\b/) do - auto_url = data.find { |d| d[:name] == $1 }[:url] - unless auto_url == url # docs shouldn't autolink to themselves - "#{$1}" + regex = /\b(#{data.map { |d| Regexp.escape(d[:name]) }.join('|')})\b/ + text.gsub(regex) do + name = Regexp.last_match(1) + auto_url = data.find { |d| d[:name] == name }[:url] + if auto_url == url # docs shouldn't autolink to themselves + Regexp.last_match(0) else - $1 + "#{name}" end end end @@ -351,7 +353,7 @@ def self.parse(sourcekitten_output, min_acl, skip_undocumented) # than min_acl docs = docs.reject { |doc| doc.type.enum_element? } docs = make_doc_urls(docs, []) - docs = autolink(docs, names_and_urls(docs.flat_map { |d| d.children })) + docs = autolink(docs, names_and_urls(docs.flat_map(&:children))) [docs, doc_coverage, @undocumented_tokens] end end