lib/orthoses/yard.rb in orthoses-yard-0.5.0 vs lib/orthoses/yard.rb in orthoses-yard-0.6.0
- old
+ new
@@ -8,15 +8,17 @@
class YARD
# @param loader
# @param [<String>, String] parse Target files
# @param [Boolean] use_cache Use cache .yardoc
# @param [Symbol, nil] log_level Set YARD log level
- def initialize(loader, parse:, use_cache: true, log_level: nil)
+ # @param [Boolean] allow_empty_doc Generate RBS also from empty doc
+ def initialize(loader, parse:, use_cache: true, log_level: nil, allow_empty_doc: false)
@loader = loader
@parse = Array(parse)
@use_cache = use_cache
@log_level = log_level
+ @allow_empty_doc = allow_empty_doc
end
# @return [void]
def call
@loader.call.tap do |store|
@@ -34,16 +36,17 @@
# Skip external doc (e.g. pry-doc)
next unless @parse.any? { |pattern| File.fnmatch(pattern, yardoc.file, File::FNM_EXTGLOB | File::FNM_PATHNAME) }
case yardoc.type
when :class, :module
- YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs|
- comment = docstring.each_line.map { |line| "# #{line}" }.join
+ YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs, skippable|
+ next if skippable && !@allow_empty_doc
+ comment = docstring.empty? ? '' : "# #{docstring.gsub("\n", "\n# ")}"
if rbs.nil? && comment && !store.has_key?(namespace)
store[namespace].comment = comment
else
Orthoses.logger.debug("#{namespace} << #{rbs}")
- store[namespace] << "#{comment}\n#{rbs}"
+ store[namespace] << "#{comment.chomp}\n#{rbs}"
end
end
end
end
end