" % @head.inspect
end
#----------------------------------------------------------------------
@@ -92,21 +91,18 @@ def initialize(preproc = nil, postproc = nil)
@postproc = postproc
end
- attr_accessor :preproc
- attr_accessor :postproc
+ attr_accessor :preproc, :postproc
def search(chrs, opt = nil)
return self if chrs.empty?
ch = chrs.shift
- if node = @Tree[ch]
+ if (node = @Tree[ch])
node.search(chrs, opt)
+ elsif opt
+ chrs.unshift ch
+ create_subnode(chrs)
else
- if opt
- chrs.unshift ch
- self.create_subnode(chrs)
- else
- raise "node nothing"
- end
+ raise "node nothing"
end
end
@@ -124,7 +120,7 @@ def create_subnode(chrs, preproc = nil, postproc = nil)
end
ch = chrs.shift
- if node = @Tree[ch]
+ if (node = @Tree[ch])
if chrs.empty?
if node.postproc
DebugLogger.pp node
@@ -164,32 +160,26 @@ def match(chrs, op = "")
if @preproc.nil? || @preproc.call(op, chrs)
DOUT.printf(D_DETAIL, "op1: %s\n", op)
@postproc.call(op, chrs)
- else
- nil
end
else
ch = chrs.shift
- if node = @Tree[ch]
- if ret = node.match(chrs, op+ch)
- return ret
+ if (node = @Tree[ch])
+ if (ret = node.match(chrs, op + ch))
+ ret
else
chrs.unshift ch
- if @postproc and @preproc.nil? || @preproc.call(op, chrs)
+ if @postproc && (@preproc.nil? || @preproc.call(op, chrs))
DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
- ret = @postproc.call(op, chrs)
- return ret
- else
- return nil
+ @postproc.call(op, chrs)
+
end
end
else
chrs.unshift ch
- if @postproc and @preproc.nil? || @preproc.call(op, chrs)
+ if @postproc && (@preproc.nil? || @preproc.call(op, chrs))
DOUT.printf(D_DETAIL, "op3: %s\n", op)
@postproc.call(op, chrs)
- return ""
- else
- return nil
+ ""
end
end
end
@@ -198,9 +188,7 @@ def match(chrs, op = "")
def match_io(io, op = "")
if op == ""
ch = io.getc
- if ch == nil
- return nil
- end
+ return nil if ch.nil?
else
ch = io.getc_of_rests
end
@@ -208,31 +196,23 @@ def match_io(io, op = "")
if @preproc.nil? || @preproc.call(op, io)
D_DETAIL.printf("op1: %s\n", op)
@postproc.call(op, io)
- else
- nil
end
- else
- if node = @Tree[ch]
- if ret = node.match_io(io, op+ch)
- ret
- else
- io.ungetc ch
- if @postproc and @preproc.nil? || @preproc.call(op, io)
- DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
- @postproc.call(op, io)
- else
- nil
- end
- end
+ elsif (node = @Tree[ch])
+ if (ret = node.match_io(io, op + ch))
+ ret
else
io.ungetc ch
- if @postproc and @preproc.nil? || @preproc.call(op, io)
- D_DETAIL.printf("op3: %s\n", op)
+ if @postproc && (@preproc.nil? || @preproc.call(op, io))
+ DOUT.exec_if { D_DETAIL.printf "op2: %s\n", op.inspect }
@postproc.call(op, io)
- else
- nil
end
end
+ else
+ io.ungetc ch
+ if @postproc && (@preproc.nil? || @preproc.call(op, io))
+ D_DETAIL.printf("op3: %s\n", op)
+ @postproc.call(op, io)
+ end
end
end
end
@@ -240,14 +220,14 @@ def match_io(io, op = "")
end
# :startdoc:
-if $0 == __FILE__
+if $PROGRAM_NAME == __FILE__
case $1
when "1"
tr = SLex.new
print "0: ", tr.inspect, "\n"
- tr.def_rule("=") {print "=\n"}
+ tr.def_rule("=") { print "=\n" }
print "1: ", tr.inspect, "\n"
- tr.def_rule("==") {print "==\n"}
+ tr.def_rule("==") { print "==\n" }
print "2: ", tr.inspect, "\n"
print "case 1:\n"
@@ -260,9 +240,9 @@ def match_io(io, op = "")
when "2"
tr = SLex.new
print "0: ", tr.inspect, "\n"
- tr.def_rule("=") {print "=\n"}
+ tr.def_rule("=") { print "=\n" }
print "1: ", tr.inspect, "\n"
- tr.def_rule("==", proc{false}) {print "==\n"}
+ tr.def_rule("==", proc { false }) { print "==\n" }
print "2: ", tr.inspect, "\n"
print "case 1:\n"
diff --git a/lib/yard/parser/ruby/legacy/statement.rb b/lib/yard/parser/ruby/legacy/statement.rb
index e02fb34b6..4fa6e865d 100644
--- a/lib/yard/parser/ruby/legacy/statement.rb
+++ b/lib/yard/parser/ruby/legacy/statement.rb
@@ -3,14 +3,12 @@ module YARD
module Parser::Ruby::Legacy
class Statement
attr_reader :tokens, :comments, :block
- attr_accessor :comments_range
+ attr_accessor :comments_range, :comments_hash_flag
# @deprecated Groups are now defined by directives
# @see Tags::GroupDirective
attr_accessor :group
- attr_accessor :comments_hash_flag
-
def initialize(tokens, block = nil, comments = nil)
@tokens = tokens
@block = block
@@ -19,7 +17,7 @@ def initialize(tokens, block = nil, comments = nil)
end
def first_line
- to_s.split(/\n/)[0]
+ to_s.split("\n")[0]
end
alias signature first_line
@@ -33,7 +31,7 @@ def to_s(include_block = true)
def inspect
l = line - 1
- to_s(false).split(/\n/).map do |text|
+ to_s(false).split("\n").map do |text|
"\t#{l += 1}: #{text}"
end.join("\n")
end
@@ -60,7 +58,7 @@ def clean_tokens(tokens)
tokens.reject do |tk|
tk.is_a?(RubyToken::TkNL) ||
(last_tk.is_a?(RubyToken::TkSPACE) &&
- last_tk.class == tk.class) && last_tk = tk
+ last_tk.instance_of?(tk.class) && last_tk = tk)
end
end
end
diff --git a/lib/yard/parser/ruby/legacy/statement_list.rb b/lib/yard/parser/ruby/legacy/statement_list.rb
index 14e212db2..5a0a48281 100644
--- a/lib/yard/parser/ruby/legacy/statement_list.rb
+++ b/lib/yard/parser/ruby/legacy/statement_list.rb
@@ -88,7 +88,7 @@ def next_statement
stmt
elsif @comments
@statement << TkCOMMENT.new(@comments_line, 0)
- @statement.first.set_text("# " + @comments.join("\n# "))
+ @statement.first.set_text("# #{@comments.join("\n# ")}")
Statement.new(@statement, nil, @comments)
end
end
@@ -134,7 +134,7 @@ def process_token(tk)
return if process_initial_comment(tk)
return if @statement.empty? && [TkSPACE, TkNL, TkCOMMENT].include?(tk.class)
@comments_last_line = nil
- if @statement.empty? && tk.class == TkALIAS
+ if @statement.empty? && tk.instance_of?(TkALIAS)
@state = :alias_statement
@alias_values = []
push_token(tk)
@@ -154,9 +154,7 @@ def process_token(tk)
@alias_values << tk unless [TkSPACE, TkNL, TkCOMMENT].include?(tk.class)
if @alias_values.size == 2
@state = :first_statement
- if [NilClass, TkNL, TkEND_OF_SCRIPT, TkSEMICOLON].include?(peek_no_space.class)
- @done = true
- end
+ @done = true if [NilClass, TkNL, TkEND_OF_SCRIPT, TkSEMICOLON].include?(peek_no_space.class)
end
when :balance
@statement << tk
@@ -169,12 +167,12 @@ def process_token(tk)
process_statement_end(tk)
when :pre_block
@current_block = nil
- process_block_token(tk) unless tk.class == TkSEMICOLON
+ process_block_token(tk) unless tk.instance_of?(TkSEMICOLON)
@state = :block
when :block
process_block_token(tk)
when :post_block
- if tk.class == TkSPACE
+ if tk.instance_of?(TkSPACE)
@statement << tk
return
end
@@ -183,9 +181,7 @@ def process_token(tk)
@state = :block
end
- if @first_line == tk.line_no && !@statement.empty? && TkCOMMENT === tk
- process_initial_comment(tk)
- end
+ process_initial_comment(tk) if @first_line == tk.line_no && !@statement.empty? && TkCOMMENT === tk
end
# Processes a token in a block
@@ -199,9 +195,7 @@ def process_block_token(tk)
elsif @block_num > 1 || (@block.empty? && [TkSPACE, TkNL].include?(tk.class))
@statement << tk
else
- if @block.empty?
- @statement << TkBlockContents.new(tk.line_no, tk.char_no)
- end
+ @statement << TkBlockContents.new(tk.line_no, tk.char_no) if @block.empty?
@block << tk
end
end
@@ -211,11 +205,9 @@ def process_block_token(tk)
# @param [RubyToken::Token] tk the token to process
# @return [Boolean] whether or not +tk+ was processed as an initial comment
def process_initial_comment(tk)
- if @statement.empty? && (@comments_last_line || 0) < tk.line_no - 2
- @comments = nil
- end
+ @comments = nil if @statement.empty? && (@comments_last_line || 0) < tk.line_no - 2
- return unless tk.class == TkCOMMENT
+ return unless tk.instance_of?(TkCOMMENT)
case tk.text
when Parser::SourceParser::SHEBANG_LINE
@@ -224,7 +216,7 @@ def process_initial_comment(tk)
return
end
when Parser::SourceParser::ENCODING_LINE
- if (@last_ns_tk.class == TkCOMMENT && @last_ns_tk.text == @shebang_line) ||
+ if (@last_ns_tk.instance_of?(TkCOMMENT) && @last_ns_tk.text == @shebang_line) ||
!@last_ns_tk
@encoding_line = tk.text
return
@@ -304,13 +296,13 @@ def process_complex_block_opener(tk)
# @param [RubyToken::Token] tk the token to process
def process_statement_end(tk)
# Whitespace means that we keep the same value of @new_statement as last token
- return if tk.class == TkSPACE
+ return if tk.instance_of?(TkSPACE)
return unless
# We might be coming after a statement-ending token...
(@last_tk && [TkSEMICOLON, TkNL, TkEND_OF_SCRIPT].include?(tk.class)) ||
# Or we might be at the beginning of an argument list
- (@current_block == TkDEF && tk.class == TkRPAREN)
+ (@current_block == TkDEF && tk.instance_of?(TkRPAREN))
# Continue line ending on . or ::
return if @last_tk && [EXPR_DOT].include?(@last_tk.lex_state)
@@ -333,7 +325,7 @@ def process_statement_end(tk)
@last_tk.lex_state != EXPR_BEG)
# Continue with the statement if we've hit a comma in a def
- return if @current_block == TkDEF && peek_no_space.class == TkCOMMA
+ return if @current_block == TkDEF && peek_no_space.instance_of?(TkCOMMA)
if [TkEND_OF_SCRIPT, TkNL, TkSEMICOLON].include?(tk.class) && @state == :block_statement &&
[TkRBRACE, TkEND].include?(@last_ns_tk.class) && @level == 0
@@ -360,11 +352,11 @@ def process_statement_end(tk)
# @return [Boolean] whether or not the current statement's parentheses and blocks
# are balanced after +tk+
def balances?(tk)
- unless [TkALIAS, TkDEF].include?(@last_ns_tk.class) || @before_last_ns_tk.class == TkALIAS
+ unless [TkALIAS, TkDEF].include?(@last_ns_tk.class) || @before_last_ns_tk.instance_of?(TkALIAS)
if [TkLPAREN, TkLBRACK, TkLBRACE, TkDO, TkBEGIN].include?(tk.class)
@level += 1
elsif OPEN_BLOCK_TOKENS.include?(tk.class)
- @level += 1 unless tk.class == TkELSIF
+ @level += 1 unless tk.instance_of?(TkELSIF)
elsif [TkRPAREN, TkRBRACK, TkRBRACE, TkEND].include?(tk.class) && @level > 0
@level -= 1
end
@@ -386,7 +378,7 @@ def push_token(tk)
#
# @return [RubyToken::Token] the next non-space token
def peek_no_space
- return @tokens.first unless @tokens.first.class == TkSPACE
+ return @tokens.first unless @tokens.first.instance_of?(TkSPACE)
@tokens[1]
end
end
diff --git a/lib/yard/parser/ruby/legacy/token_list.rb b/lib/yard/parser/ruby/legacy/token_list.rb
index 05e15a892..bec70a5a5 100644
--- a/lib/yard/parser/ruby/legacy/token_list.rb
+++ b/lib/yard/parser/ruby/legacy/token_list.rb
@@ -20,11 +20,12 @@ def to_s(full_statement = false, show_block = true)
# is parsed with {RubyLex}.
def push(*tokens)
tokens.each do |tok|
- if tok.is_a?(TokenList) || tok.is_a?(Array)
+ case tok
+ when TokenList, Array
concat tok
- elsif tok.is_a?(Token)
- super tok
- elsif tok.is_a?(String)
+ when Token
+ super(tok)
+ when String
parse_content(tok)
else
raise ArgumentError, "Expecting token, list of tokens or string of code to be tokenized. Got #{tok.class}"
diff --git a/lib/yard/parser/ruby/ruby_parser.rb b/lib/yard/parser/ruby/ruby_parser.rb
index 57831b5fe..a2bdb64f1 100644
--- a/lib/yard/parser/ruby/ruby_parser.rb
+++ b/lib/yard/parser/ruby/ruby_parser.rb
@@ -25,8 +25,7 @@ def frozen_string_line; @parser.frozen_string_line end
# Internal parser class
# @since 0.5.6
class RipperParser < Ripper
- attr_reader :ast, :charno, :comments, :file, :tokens
- attr_reader :shebang_line, :encoding_line, :frozen_string_line
+ attr_reader :ast, :charno, :comments, :file, :tokens, :shebang_line, :encoding_line, :frozen_string_line
alias root ast
def initialize(source, filename, *args)
@@ -114,7 +113,7 @@ def file_encoding
:return0 => "return",
:sclass => "class",
:string_embexpr => :embexpr_beg,
- :string_literal => [:tstring_beg, :heredoc_beg],
+ :string_literal => %i(tstring_beg heredoc_beg),
:super => "super",
:symbol => :symbeg,
:top_const_ref => "::",
@@ -130,14 +129,14 @@ def file_encoding
}
REV_MAPPINGS = {}
- AST_TOKENS = [:CHAR, :backref, :const, :cvar, :gvar, :heredoc_end, :ident,
- :int, :float, :ivar, :label, :period, :regexp_end, :tstring_content, :backtick]
+ AST_TOKENS = %i(CHAR backref const cvar gvar heredoc_end ident
+ int float ivar label period regexp_end tstring_content backtick)
- COMMENT_SKIP_NODE_TYPES = [
- :comment,
- :void_stmt,
- :list
- ].freeze
+ COMMENT_SKIP_NODE_TYPES = %i(
+ comment
+ void_stmt
+ list
+ ).freeze
MAPPINGS.each do |k, v|
if Array === v
@@ -150,61 +149,61 @@ def file_encoding
PARSER_EVENT_TABLE.each do |event, arity|
node_class = AstNode.node_class_for(event)
- if arity == 0 && /_new\z/ =~ event.to_s
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ if arity == 0 && event.to_s.end_with?('_new')
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
def on_#{event}(*args)
#{node_class}.new(:list, args, :listchar => charno...charno, :listline => lineno..lineno)
end
- eof
+ EOF
elsif /_add(_.+)?\z/ =~ event.to_s
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(list, item)
list.push(item)
list
end
- eof
+ EOF
elsif MAPPINGS.key?(event)
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(*args)
visit_event #{node_class}.new(:#{event}, args)
end
- eof
+ EOF
else
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(*args)
#{node_class}.new(:#{event}, args, :listline => lineno..lineno, :listchar => charno...charno)
end
- eof
+ EOF
end
end
SCANNER_EVENTS.each do |event|
ast_token = AST_TOKENS.include?(event)
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(tok)
visit_ns_token(:#{event}, tok, #{ast_token.inspect})
end
- eof
+ EOF
end
REV_MAPPINGS.select {|k, _v| k.is_a?(Symbol) }.each do |pair|
event = pair.first
ast_token = AST_TOKENS.include?(event)
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(tok)
(@map[:#{event}] ||= []) << [lineno, charno]
visit_ns_token(:#{event}, tok, #{ast_token.inspect})
end
- eof
+ EOF
end
- [:kw, :op].each do |event|
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ %i(kw op).each do |event|
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(tok)
unless @last_ns_token == [:kw, "def"] ||
@@ -213,18 +212,18 @@ def on_#{event}(tok)
end
visit_ns_token(:#{event}, tok, true)
end
- eof
+ EOF
end
- [:nl, :ignored_nl].each do |event|
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ %i(nl ignored_nl).each do |event|
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(tok)
add_token(:#{event}, tok)
@newline = true
@charno += tok ? tok.length : 0
end
- eof
+ EOF
end
undef on_sp
@@ -262,29 +261,17 @@ def visit_ns_token(token, data, ast_token = false)
@last_ns_token = [token, data]
@charno += data.length
@ns_charno = charno
- @newline = [:semicolon, :comment, :kw, :op, :lparen, :lbrace].include?(token)
- if ast_token
- AstNode.new(token, [data], :line => lineno..lineno, :char => ch..charno - 1, :token => true)
- end
+ @newline = %i(semicolon comment kw op lparen lbrace).include?(token)
+ AstNode.new(token, [data], :line => lineno..lineno, :char => ch..charno - 1, :token => true) if ast_token
end
def add_token(token, data)
- if @percent_ary
- if token == :words_sep && data !~ /\s\z/
- rng = @percent_ary.source_range
- rng = Range.new(rng.begin, rng.end.to_i + data.length)
- @percent_ary.source_range = rng
- @tokens << [token, data, [lineno, charno]]
- @percent_ary = nil
- return
- elsif token == :tstring_end && data =~ /\A\s/
- rng = @percent_ary.source_range
- rng = Range.new(rng.begin, rng.end.to_i + data.length)
- @percent_ary.source_range = rng
- @tokens << [token, data, [lineno, charno]]
- @percent_ary = nil
- return
- end
+ if @percent_ary && ((token == :words_sep && data !~ /\s\z/) || (token == :tstring_end && data =~ /\A\s/))
+ rng = @percent_ary.source_range
+ rng = Range.new(rng.begin, rng.end.to_i + data.length)
+ @percent_ary.source_range = rng
+ @tokens << [token, data, [lineno, charno]]
+ @percent_ary = nil
end
if @tokens.last && (@tokens.last[0] == :symbeg ||
@@ -298,7 +285,7 @@ def add_token(token, data)
data.force_encoding(file_encoding) if file_encoding
@heredoc_state = :ended if token == :heredoc_end
- elsif (token == :nl || token == :comment) && @heredoc_state == :ended
+ elsif %i(nl comment).include?(token) && @heredoc_state == :ended
@heredoc_tokens.unshift([token, data, [lineno, charno]])
@tokens += @heredoc_tokens
@heredoc_tokens = nil
@@ -442,9 +429,9 @@ def on_const_path_ref(*args)
ReferenceNode.new(:const_path_ref, args, :listline => lineno..lineno, :listchar => charno..charno)
end
- [:if_mod, :unless_mod, :while_mod, :until_mod].each do |kw|
+ %i(if_mod unless_mod while_mod until_mod).each do |kw|
node_class = AstNode.node_class_for(kw)
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{kw}; rescue NameError; end
def on_#{kw}(*args)
mapping = @map[#{kw.to_s.sub(/_mod$/, '').inspect}]
@@ -453,11 +440,11 @@ def on_#{kw}(*args)
lr = args.last.line_range.begin..args.first.line_range.end
#{node_class}.new(:#{kw}, args, :line => lr, :char => sr)
end
- eof
+ EOF
end
%w(symbols qsymbols words qwords).each do |kw|
- module_eval(<<-eof, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef on_#{kw}_new; rescue NameError; end
def on_#{kw}_new(*args)
node = LiteralNode.new(:#{kw}_literal, args)
@@ -478,7 +465,7 @@ def on_#{kw}_add(list, item)
list.push(item)
list
end
- eof
+ EOF
end
def on_string_literal(*args)
@@ -514,11 +501,11 @@ def on_void_stmt
def on_params(*args)
args.map! do |arg|
- next arg unless arg.class == Array
+ next arg unless arg.instance_of?(Array)
- if arg.first.class == Array
+ if arg.first.instance_of?(Array)
arg.map! do |sub_arg|
- next sub_arg unless sub_arg.class == Array
+ next sub_arg unless sub_arg.instance_of?(Array)
type = sub_arg[0].type == :label ?
:named_arg : :unnamed_optional_arg
AstNode.new(type, sub_arg, :listline => lineno..lineno, :listchar => charno..charno)
@@ -565,7 +552,7 @@ def on_comment(comment)
comment = comment.gsub(/^(\#+)\s{0,1}/, '').chomp
append_comment = @comments[lineno - 1]
- hash_flag = $1 == '##' ? true : false
+ hash_flag = $1 == '##'
if append_comment && @comments_last_column &&
@comments_last_column == column && comment_starts_line?(ch)
@@ -574,7 +561,7 @@ def on_comment(comment)
@comments_flags.delete(lineno - 1)
range = @comments_range.delete(lineno - 1)
source_range = range.begin..source_range.end
- comment = append_comment + "\n" + comment
+ comment = "#{append_comment}\n#{comment}"
end
@comments[lineno] = comment
@@ -622,9 +609,7 @@ def insert_comments
next if COMMENT_SKIP_NODE_TYPES.include?(node.type) || node.parent.type != :list
# never attach comments to if/unless mod nodes
- if node.type == :if_mod || node.type == :unless_mod
- node = node.then_block
- end
+ node = node.then_block if %i(if_mod unless_mod).include?(node.type)
# check upwards from line before node; check node's line at the end
if (n_l = node.line)
@@ -693,7 +678,7 @@ def add_comment(line, node = nil, before_node = nil, into = false)
end
def freeze_tree(node = nil)
- @tokens = @tokens.sort_by {|t| t.last }
+ @tokens = @tokens.sort_by(&:last)
nodes = [node || root]
until nodes.empty?
p_node = nodes.shift
diff --git a/lib/yard/parser/ruby/token_resolver.rb b/lib/yard/parser/ruby/token_resolver.rb
index 56421acf5..359ffb4bc 100644
--- a/lib/yard/parser/ruby/token_resolver.rb
+++ b/lib/yard/parser/ruby/token_resolver.rb
@@ -46,10 +46,11 @@ def initialize(source, namespace = Registry.root)
def each
@states = []
push_state
+ skip_types = %i(const ident op period)
@tokens.each do |token|
yield_obj = false
- if skip_group && [:const, :ident, :op, :period].include?(token[0])
+ if skip_group && skip_types.include?(token[0])
yield token, nil
next
else
@@ -57,11 +58,7 @@ def each
end
case token[0]
- when :const
- lookup(token[0], token[1])
- yield_obj = true
- self.last_sep = nil
- when :ident
+ when :const, :ident
lookup(token[0], token[1])
yield_obj = true
self.last_sep = nil
diff --git a/lib/yard/parser/source_parser.rb b/lib/yard/parser/source_parser.rb
index 82dd90f69..1b5203bfe 100644
--- a/lib/yard/parser/source_parser.rb
+++ b/lib/yard/parser/source_parser.rb
@@ -72,7 +72,7 @@ class SourceParser
# Byte order marks for various encodings
# @since 0.7.0
ENCODING_BYTE_ORDER_MARKS = {
- 'utf-8' => String.new("\xEF\xBB\xBF"),
+ 'utf-8' => String.new("\xEF\xBB\xBF")
# Not yet supported
# 'utf-16be' => "\xFE\xFF",
# 'utf-16le' => "\xFF\xFE",
@@ -144,7 +144,7 @@ def tokenize(content, ptype = parser_type)
# @return [void]
# @see Parser::Base
def register_parser_type(type, parser_klass, extensions = nil)
- unless Base > parser_klass
+ unless parser_klass < Base
raise ArgumentError, "expecting parser_klass to be a subclass of YARD::Parser::Base"
end
parser_type_extensions[type.to_sym] = extensions if extensions
@@ -423,9 +423,7 @@ def parse(content = __FILE__)
checksum = Registry.checksum_for(content)
return if Registry.checksums[file] == checksum
- if Registry.checksums.key?(file)
- log.info "File '#{file}' was modified, re-processing..."
- end
+ log.info "File '#{file}' was modified, re-processing..." if Registry.checksums.key?(file)
Registry.checksums[@file] = checksum
self.parser_type = parser_type_for_filename(file)
else
@@ -476,9 +474,7 @@ def convert_encoding(content)
content.force_encoding('binary')
ENCODING_BYTE_ORDER_MARKS.each do |encoding, bom|
bom.force_encoding('binary')
- if content.start_with?(bom)
- return content.sub(bom, '').force_encoding(encoding)
- end
+ return content.sub(bom, '').force_encoding(encoding) if content.start_with?(bom)
end
content.force_encoding('utf-8') # UTF-8 is default encoding
content
@@ -514,9 +510,7 @@ def parser_type_for_filename(filename)
# @since 0.5.6
def parser_class
klass = self.class.parser_types[parser_type]
- unless klass
- raise ArgumentError, "invalid parser type '#{parser_type}' or unrecognized file", caller[1..-1]
- end
+ raise ArgumentError, "invalid parser type '#{parser_type}' or unrecognized file", caller[1..-1] unless klass
klass
end
diff --git a/lib/yard/registry.rb b/lib/yard/registry.rb
index d70a442ea..d8307c99e 100644
--- a/lib/yard/registry.rb
+++ b/lib/yard/registry.rb
@@ -55,22 +55,22 @@ def yardoc_file_for_gem(gem, ver_require = ">= 0", for_writing = false)
return if specs.empty?
result = nil
- specs.reverse.each do |spec|
+ specs.reverse_each do |spec|
if gem =~ /^yard-doc-/
path = File.join(spec.full_gem_path, DEFAULT_YARDOC_FILE)
result = File.exist?(path) && !for_writing ? path : nil
result ? break : next
end
- if for_writing
- result = global_yardoc_file(spec, for_writing) ||
- old_global_yardoc_file(spec, for_writing) ||
- local_yardoc_file(spec, for_writing)
- else
- result = local_yardoc_file(spec, for_writing) ||
+ result = if for_writing
global_yardoc_file(spec, for_writing) ||
- old_global_yardoc_file(spec, for_writing)
- end
+ old_global_yardoc_file(spec, for_writing) ||
+ local_yardoc_file(spec, for_writing)
+ else
+ local_yardoc_file(spec, for_writing) ||
+ global_yardoc_file(spec, for_writing) ||
+ old_global_yardoc_file(spec, for_writing)
+ end
break if result
end
@@ -236,7 +236,7 @@ def each(&block)
# @see CodeObjects::Base#type
def all(*types)
if types.empty?
- thread_local_store.values.select {|obj| obj != root }
+ thread_local_store.values.reject {|obj| obj == root }
else
list = []
types.each do |type|
@@ -302,8 +302,8 @@ def locale(name)
# @see P
def resolve(namespace, name, inheritance = false, proxy_fallback = false, type = nil)
thread_local_resolver.lookup_by_path name,
- :namespace => namespace, :inheritance => inheritance,
- :proxy_fallback => proxy_fallback, :type => type
+ :namespace => namespace, :inheritance => inheritance,
+ :proxy_fallback => proxy_fallback, :type => type
end
# @group Managing Source File Checksums
@@ -373,7 +373,7 @@ def instance; self end
# @param [Symbol, nil] type the {CodeObjects::Base#type} that the resolved
# object must be equal to
def partial_resolve(namespace, name, type = nil)
- obj = at(name) || at('#' + name) if namespace.root?
+ obj = at(name) || at("##{name}") if namespace.root?
return obj if obj && (type.nil? || obj.type == type)
[CodeObjects::NSEP, CodeObjects::CSEP, ''].each do |s|
next if s.empty? && name =~ /^\w/
@@ -393,10 +393,10 @@ def global_yardoc_file(spec, for_writing = false)
if for_writing
if File.writable?(path) ||
(!File.directory?(path) && File.writable?(File.dirname(path)))
- return yfile
+ yfile
end
elsif !for_writing && File.exist?(yfile)
- return yfile
+ yfile
end
end
@@ -404,7 +404,7 @@ def old_global_yardoc_file(spec, for_writing = false)
path = spec.full_gem_path
yfile = File.join(path, DEFAULT_YARDOC_FILE)
return yfile if for_writing && File.writable?(path)
- return yfile if !for_writing && File.exist?(yfile)
+ yfile if !for_writing && File.exist?(yfile)
end
def local_yardoc_file(spec, for_writing = false)
diff --git a/lib/yard/registry_resolver.rb b/lib/yard/registry_resolver.rb
index bcf2bdff0..b66224ad6 100644
--- a/lib/yard/registry_resolver.rb
+++ b/lib/yard/registry_resolver.rb
@@ -82,13 +82,9 @@ def lookup_by_path(path, opts = {})
end
# method objects cannot be resolved through lexical lookup by more than 1 ns
- if lexical_lookup > 1 && resolved.is_a?(CodeObjects::MethodObject)
- resolved = nil
- end
+ resolved = nil if lexical_lookup > 1 && resolved.is_a?(CodeObjects::MethodObject)
- if proxy_fallback
- resolved ||= CodeObjects::Proxy.new(orignamespace, path, type)
- end
+ resolved ||= CodeObjects::Proxy.new(orignamespace, path, type) if proxy_fallback
resolved
end
@@ -105,9 +101,7 @@ def lookup_path_direct(namespace, path, type)
result = namespace.root? && validate(@registry.at(path), type)
return result if result
- if path =~ starts_with_separator_match
- return validate(@registry.at(namespace.path + path), type)
- end
+ return validate(@registry.at(namespace.path + path), type) if path =~ starts_with_separator_match
separators.each do |sep|
result = validate(@registry.at("#{namespace.path}#{sep}#{path}"), type)
diff --git a/lib/yard/registry_store.rb b/lib/yard/registry_store.rb
index dff048599..4c3acafa7 100644
--- a/lib/yard/registry_store.rb
+++ b/lib/yard/registry_store.rb
@@ -59,9 +59,7 @@ def put(key, value)
else
@notfound.delete(key.to_sym)
(@object_types[value.type] ||= []) << key.to_s
- if @store[key.to_sym]
- @object_types[@store[key.to_sym].type].delete(key.to_s)
- end
+ @object_types[@store[key.to_sym].type].delete(key.to_s) if @store[key.to_sym]
@store[key.to_sym] = value
end
end
@@ -291,9 +289,9 @@ def load_object_types
def load_checksums
return unless File.file?(checksums_path)
lines = File.readlines(checksums_path).map do |line|
- line.strip.rpartition(' ').tap { |p| p.delete_at(1) }
+ line.strip.rpartition(' ').tap {|p| p.delete_at(1) }
end
- @checksums = Hash[lines]
+ @checksums = lines.to_h
end
def load_root
@@ -336,7 +334,7 @@ def write_checksums
end
def write_complete_lock
- File.open!(@serializer.complete_lock_path, 'w') {}
+ FileUtils.touch(@serializer.complete_lock_path)
end
end
end
diff --git a/lib/yard/rubygems/backports.rb b/lib/yard/rubygems/backports.rb
index 8d915e2da..f9431393a 100644
--- a/lib/yard/rubygems/backports.rb
+++ b/lib/yard/rubygems/backports.rb
@@ -2,8 +2,8 @@
begin
require 'rubygems'
if defined?(Gem::VERSION) && Gem::VERSION >= '1.8.0'
- require File.dirname(__FILE__) + '/backports/gem'
- require File.dirname(__FILE__) + '/backports/source_index'
+ require "#{File.dirname(__FILE__)}/backports/gem"
+ require "#{File.dirname(__FILE__)}/backports/source_index"
end
rescue LoadError
nil # noop
diff --git a/lib/yard/rubygems/backports/source_index.rb b/lib/yard/rubygems/backports/source_index.rb
index c3159503c..76d748cbb 100644
--- a/lib/yard/rubygems/backports/source_index.rb
+++ b/lib/yard/rubygems/backports/source_index.rb
@@ -111,7 +111,7 @@ def all_gems
end
def prerelease_gems
- @gems.reject {|_name, gem| !gem.version.prerelease? }
+ @gems.select {|_name, gem| gem.version.prerelease? }
end
def released_gems
@@ -273,13 +273,14 @@ def search(gem_pattern, platform_only = false)
# TODO: Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
- warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
+ warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} " \
+ "patterns is deprecated, use #find_name"
end
case gem_pattern
- when Regexp then
+ when Regexp
requirement = platform_only || Gem::Requirement.default
- when Gem::Dependency then
+ when Gem::Dependency
only_platform = platform_only
requirement = gem_pattern.requirement
@@ -295,9 +296,7 @@ def search(gem_pattern, platform_only = false)
gem_pattern = /#{gem_pattern}/i
end
- unless Gem::Requirement === requirement
- requirement = Gem::Requirement.create requirement
- end
+ requirement = Gem::Requirement.create requirement unless Gem::Requirement === requirement
specs = all_gems.values.select do |spec|
spec.name =~ gem_pattern &&
@@ -337,7 +336,7 @@ def outdated
remotes = fetcher.find_matching dependency
remotes = remotes.map {|(_, version, _), _| version }
- latest = remotes.sort.last
+ latest = remotes.max
outdateds << local.name if latest && local.version < latest
end
diff --git a/lib/yard/rubygems/doc_manager.rb b/lib/yard/rubygems/doc_manager.rb
index e33f442ab..efc727837 100644
--- a/lib/yard/rubygems/doc_manager.rb
+++ b/lib/yard/rubygems/doc_manager.rb
@@ -1,4 +1,6 @@
# frozen_string_literal: true
+require 'fileutils'
+
begin
require 'rubygems/user_interaction'
require 'rubygems/doc_manager'
@@ -29,11 +31,11 @@ def run_yardoc(*args)
rescue Errno::EACCES => e
dirname = File.dirname e.message.split("-")[1].strip
raise Gem::FilePermissionError, dirname
- rescue => ex
+ rescue StandardError => e
alert_error "While generating documentation for #{@spec.full_name}"
- ui.errs.puts "... MESSAGE: #{ex}"
+ ui.errs.puts "... MESSAGE: #{e}"
ui.errs.puts "... YARDOC args: #{args.join(' ')}"
- ui.errs.puts "\t#{ex.backtrace.join("\n\t")}" if Gem.configuration.backtrace
+ ui.errs.puts "\t#{e.backtrace.join("\n\t")}" if Gem.configuration.backtrace
ui.errs.puts "(continuing with the rest of the installation)"
ensure
Dir.chdir(old_pwd)
@@ -41,11 +43,9 @@ def run_yardoc(*args)
begin undef setup_rdoc; rescue NameError; nil end
def setup_rdoc
- if File.exist?(@doc_dir) && !File.writable?(@doc_dir)
- raise Gem::FilePermissionError, @doc_dir
- end
+ raise Gem::FilePermissionError, @doc_dir if File.exist?(@doc_dir) && !File.writable?(@doc_dir)
- FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
+ FileUtils.mkdir_p @doc_dir
self.class.load_rdoc if @spec.has_rdoc?
self.class.load_yardoc if @spec.has_yardoc?
diff --git a/lib/yard/rubygems/hook.rb b/lib/yard/rubygems/hook.rb
index 4f1e0162f..60d9df56e 100644
--- a/lib/yard/rubygems/hook.rb
+++ b/lib/yard/rubygems/hook.rb
@@ -19,18 +19,14 @@ class RubygemsHook
##
# Force installation of documentation?
- attr_accessor :force
+ attr_accessor :force, :generate_yard, :generate_yri
##
# Generate yard?
- attr_accessor :generate_yard
-
##
# Generate yri data?
- attr_accessor :generate_yri
-
class << self
##
# Loaded version of YARD. Set by ::load_yard
@@ -120,11 +116,11 @@ def run_yardoc(*args)
rescue Errno::EACCES => e
dirname = File.dirname e.message.split("-")[1].strip
raise Gem::FilePermissionError, dirname
- rescue => ex
+ rescue StandardError => e
alert_error "While generating documentation for #{@spec.full_name}"
- ui.errs.puts "... MESSAGE: #{ex}"
+ ui.errs.puts "... MESSAGE: #{e}"
ui.errs.puts "... YARDOC args: #{args.join(' ')}"
- ui.errs.puts "\t#{ex.backtrace.join("\n\t")}" if Gem.configuration.backtrace
+ ui.errs.puts "\t#{e.backtrace.join("\n\t")}" if Gem.configuration.backtrace
ui.errs.puts "(continuing with the rest of the installation)"
end
@@ -193,5 +189,5 @@ def remove
end
end
-Gem.done_installing(&YARD::RubygemsHook.method(:generation_hook))
-Gem.pre_uninstall(&YARD::RubygemsHook.method(:removal_hook))
+Gem.done_installing { YARD::RubygemsHook.generation_hook }
+Gem.pre_uninstall { YARD::RubygemsHook.removal_hook }
diff --git a/lib/yard/serializers/file_system_serializer.rb b/lib/yard/serializers/file_system_serializer.rb
index c95f585f1..0bbfbc131 100644
--- a/lib/yard/serializers/file_system_serializer.rb
+++ b/lib/yard/serializers/file_system_serializer.rb
@@ -51,10 +51,10 @@ def serialized_path(object)
return object if object.is_a?(String)
if object.is_a?(CodeObjects::ExtraFileObject)
- fspath = ['file.' + object.name + (extension.empty? ? '' : ".#{extension}")]
+ fspath = ["file.#{object.name}#{extension.empty? ? '' : ".#{extension}"}"]
else
- objname = object != YARD::Registry.root ? mapped_name(object) : "top-level-namespace"
- objname += '_' + object.scope.to_s[0, 1] if object.is_a?(CodeObjects::MethodObject)
+ objname = object == YARD::Registry.root ? "top-level-namespace" : mapped_name(object)
+ objname += "_#{object.scope.to_s[0, 1]}" if object.is_a?(CodeObjects::MethodObject)
fspath = [objname + (extension.empty? ? '' : ".#{extension}")]
if object.namespace && object.namespace.path != ""
fspath.unshift(*object.namespace.path.split(CodeObjects::NSEP))
@@ -84,12 +84,11 @@ def exists?(object)
def build_filename_map
@name_map = {}
YARD::Registry.all.each do |object|
- lpath = nil
- if object.parent && object.parent.type != :root
- lpath = object.parent.path + "::" + object.name.to_s.downcase
- else
- lpath = object.path.downcase
- end
+ lpath = if object.parent && object.parent.type != :root
+ "#{object.parent.path}::#{object.name.to_s.downcase}"
+ else
+ object.path.downcase
+ end
@name_map[lpath] ||= {}
size = @name_map[lpath].size
diff --git a/lib/yard/serializers/stdout_serializer.rb b/lib/yard/serializers/stdout_serializer.rb
index 343b6ef7d..9a38651a9 100644
--- a/lib/yard/serializers/stdout_serializer.rb
+++ b/lib/yard/serializers/stdout_serializer.rb
@@ -25,7 +25,7 @@ def serialize(_object, data)
# @return [String] the wrapped text
def word_wrap(text, _length = 80)
# See ruby-talk/10655 / Ernest Ellingson
- text.gsub(/\t/, " ").gsub(/.{1,50}(?:\s|\Z)/) do
+ text.gsub("\t", " ").gsub(/.{1,50}(?:\s|\Z)/) do
($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n")
end
end
diff --git a/lib/yard/serializers/yardoc_serializer.rb b/lib/yard/serializers/yardoc_serializer.rb
index 875d73b83..2e4867ffc 100644
--- a/lib/yard/serializers/yardoc_serializer.rb
+++ b/lib/yard/serializers/yardoc_serializer.rb
@@ -1,4 +1,6 @@
# frozen_string_literal: true
+require 'fileutils'
+
module YARD
# Stubs marshal dumps and acts a delegate class for an object by path
#
@@ -52,10 +54,10 @@ def complete?
#
# @see #locked_for_writing?
def lock_for_writing
- File.open!(processing_path, 'w') {}
+ FileUtils.touch(processing_path)
yield
ensure
- File.unlink(processing_path) if File.exist?(processing_path)
+ FileUtils.rm_f(processing_path)
end
# @return [Boolean] whether the database is currently locked for writing
@@ -68,12 +70,12 @@ def serialized_path(object)
case object
when String, Symbol
object = object.to_s
- if object =~ /#/
+ if object.include?('#')
object += '_i'
- elsif object =~ /\./
+ elsif object.include?('.')
object += '_c'
end
- object.split(/::|\.|#/).map do |p|
+ object.split(/::|\.|#/).map do |p| # rubocop:disable Style/StringConcatenation
p.gsub(/[^\w\.-]/) do |x|
encoded = '_'
@@ -84,7 +86,7 @@ def serialized_path(object)
when YARD::CodeObjects::RootObject
'root.dat'
else
- super(object)
+ super
end
File.join('objects', path)
@@ -139,7 +141,7 @@ def internal_dump(object, first_object = false)
list = object.map do |k, v|
[k, v].map {|item| internal_dump(item) }
end
- object.replace(Hash[list])
+ object.replace(list.to_h)
when Array
list = object.map {|item| internal_dump(item) }
object.replace(list)
diff --git a/lib/yard/server/adapter.rb b/lib/yard/server/adapter.rb
index 0dced5f80..2a3828d64 100644
--- a/lib/yard/server/adapter.rb
+++ b/lib/yard/server/adapter.rb
@@ -47,7 +47,7 @@ class Adapter
# @return [void]
def self.setup
Templates::Template.extra_includes |= [YARD::Server::DocServerHelper]
- Templates::Engine.template_paths |= [File.dirname(__FILE__) + '/templates']
+ Templates::Engine.template_paths |= ["#{File.dirname(__FILE__)}/templates"]
end
# Performs any global shutdown procedures for the adapter.
@@ -55,7 +55,7 @@ def self.setup
# @return [void]
def self.shutdown
Templates::Template.extra_includes -= [YARD::Server::DocServerHelper]
- Templates::Engine.template_paths -= [File.dirname(__FILE__) + '/templates']
+ Templates::Engine.template_paths -= ["#{File.dirname(__FILE__)}/templates"]
end
# Creates a new adapter object
diff --git a/lib/yard/server/commands/base.rb b/lib/yard/server/commands/base.rb
index ef9d83f3a..9791cdd80 100644
--- a/lib/yard/server/commands/base.rb
+++ b/lib/yard/server/commands/base.rb
@@ -164,7 +164,7 @@ def render(object = nil)
# @see StaticCaching
def cache(data)
if caching && adapter.document_root
- path = File.join(adapter.document_root, request.path_info.sub(/\.html$/, '') + '.html')
+ path = File.join(adapter.document_root, "#{request.path_info.sub(/\.html$/, '')}.html")
path = path.sub(%r{/\.html$}, '.html')
FileUtils.mkdir_p(File.dirname(path))
log.debug "Caching data to #{path}"
diff --git a/lib/yard/server/commands/display_object_command.rb b/lib/yard/server/commands/display_object_command.rb
index 3f2e7e246..eb5cae11e 100644
--- a/lib/yard/server/commands/display_object_command.rb
+++ b/lib/yard/server/commands/display_object_command.rb
@@ -12,7 +12,7 @@ def run
filename = options.readme.filename
opts = adapter.options.merge(
:index => true, :library => library,
- :path => filename.sub(%r{^#{library.source_path.to_s}/}, '')
+ :path => filename.sub(%r{^#{library.source_path}/}, '')
)
self.status, self.headers, self.body =
*DisplayFileCommand.new(opts).call(request)
@@ -53,11 +53,11 @@ def not_found
def object_path
return @object_path if @object_path
- if path == "toplevel"
- @object_path = :root
- else
- @object_path = path.sub(':', '#').gsub('/', '::').sub(/^toplevel\b/, '').sub(/\.html$/, '')
- end
+ @object_path = if path == "toplevel"
+ :root
+ else
+ path.sub(':', '#').gsub('/', '::').sub(/^toplevel\b/, '').sub(/\.html$/, '')
+ end
end
end
end
diff --git a/lib/yard/server/commands/library_command.rb b/lib/yard/server/commands/library_command.rb
index c63db8d42..0464ca118 100644
--- a/lib/yard/server/commands/library_command.rb
+++ b/lib/yard/server/commands/library_command.rb
@@ -11,11 +11,10 @@ def single_library; @command.single_library end
def serializer; @command.serializer end
def serialize; false end
- attr_accessor :command
- attr_accessor :frames
+ attr_accessor :command, :frames
def each(&block)
- super(&block)
+ super
yield(:adapter, adapter)
yield(:library, library)
yield(:single_library, single_library)
@@ -31,7 +30,7 @@ def each(&block)
# @abstract
class LibraryCommand < Base
begin
- Process.fork { }
+ Process.fork {} # rubocop:disable Lint/EmptyBlock
CAN_FORK = true
rescue Exception # rubocop:disable Lint/RescueException
CAN_FORK = false
@@ -87,7 +86,7 @@ def call_without_fork(request)
options.command = self
setup_library
options.title = "Documentation for #{library.name} " +
- (library.version ? '(' + library.version + ')' : '')
+ (library.version ? "(#{library.version})" : '')
yield
rescue LibraryNotPreparedError
not_prepared
@@ -172,7 +171,7 @@ def fulldoc_template
tplopts = [options.template, :fulldoc, options.format]
tplclass = Templates::Engine.template(*tplopts)
obj = Object.new.extend(tplclass)
- class << obj; define_method(:init) {} end
+ class << obj; define_method(:init) {} end # rubocop:disable Lint/EmptyBlock
obj.class = tplclass
obj.send(:initialize, options)
class << obj
diff --git a/lib/yard/server/commands/search_command.rb b/lib/yard/server/commands/search_command.rb
index 433514b47..0dcfe0d3e 100644
--- a/lib/yard/server/commands/search_command.rb
+++ b/lib/yard/server/commands/search_command.rb
@@ -14,7 +14,8 @@ class SearchCommand < LibraryCommand
def run
Registry.load_all
self.query = request.query['q']
- redirect(abs_url(adapter.router.docs_prefix, single_library ? library : '')) if query.nil? || query =~ /\A\s*\Z/
+ redirect(abs_url(adapter.router.docs_prefix,
+ single_library ? library : '')) if query.nil? || query =~ /\A\s*\Z/
found = Registry.at(query)
redirect(url_for(found)) if found
@@ -31,17 +32,17 @@ def visible_results
def url_for(object)
abs_url(base_path(router.docs_prefix),
- serializer.serialized_path(object))
+ serializer.serialized_path(object))
end
def serve_xhr
headers['Content-Type'] = 'text/plain'
- self.body = visible_results.map {|o|
+ self.body = visible_results.map do |o|
[(o.type == :method ? o.name(true) : o.name).to_s,
o.path,
o.namespace.root? ? '' : o.namespace.path,
url_for(o)].join(",")
- }.join("\n")
+ end.join("\n")
end
def serve_normal
@@ -64,14 +65,15 @@ def search_for_object
!name.include?(query.downcase) ||
case o.type
when :method
- !(query =~ /[#.]/) && query.include?("::")
+ query !~ /[#.]/ && query.include?("::")
when :class, :module, :constant, :class_variable
query =~ /[#.]/
end
end.sort_by do |o|
name = (o.type == :method ? o.name(true) : o.name).to_s
- name.length.to_f / query.length.to_f
+ name.length.to_f / query.length
end
+ # rubocop:enable Style/MultilineBlockChain
end
end
end
diff --git a/lib/yard/server/commands/static_file_helpers.rb b/lib/yard/server/commands/static_file_helpers.rb
index e79c8588f..fb8220ed3 100644
--- a/lib/yard/server/commands/static_file_helpers.rb
+++ b/lib/yard/server/commands/static_file_helpers.rb
@@ -12,7 +12,7 @@ module StaticFileHelpers
# @raise [FinishRequest] finalizes an empty body if the path matches
# /favicon.ico so browsers don't complain.
def favicon?
- return unless request.path == '/favicon.ico'
+ return false unless request.path == '/favicon.ico'
headers['Content-Type'] = 'image/png'
self.status = 200
self.body = ''
@@ -30,7 +30,7 @@ def static_template_file?
file = find_file(adapter, path)
if file
- ext = "." + (path[/\.(\w+)$/, 1] || "html")
+ ext = ".#{path[/\.(\w+)$/, 1] || "html"}"
headers['Content-Type'] = mime_type(ext, default_mime_types)
self.body = File.read(file)
raise FinishRequest
diff --git a/lib/yard/server/doc_server_helper.rb b/lib/yard/server/doc_server_helper.rb
index 9256afcaf..649bf6419 100644
--- a/lib/yard/server/doc_server_helper.rb
+++ b/lib/yard/server/doc_server_helper.rb
@@ -22,10 +22,8 @@ def url_for(obj, anchor = nil, relative = false) # rubocop:disable Lint/UnusedMe
# @param (see Templates::Helpers::HtmlHelper#url_for_file)
# @return (see Templates::Helpers::HtmlHelper#url_for_file)
def url_for_file(filename, anchor = nil)
- if filename.is_a?(CodeObjects::ExtraFileObject)
- filename = filename.filename
- end
- fname = filename.sub(%r{^#{@library.source_path.to_s}/}, '')
+ filename = filename.filename if filename.is_a?(CodeObjects::ExtraFileObject)
+ fname = filename.sub(%r{^#{@library.source_path}/}, '')
fname += "##{anchor}" if anchor && !anchor.empty?
abs_url(base_path(router.docs_prefix), 'file', fname)
end
diff --git a/lib/yard/server/doc_server_serializer.rb b/lib/yard/server/doc_server_serializer.rb
index 131cda807..7b39a99f4 100644
--- a/lib/yard/server/doc_server_serializer.rb
+++ b/lib/yard/server/doc_server_serializer.rb
@@ -13,25 +13,23 @@ def serialized_path(object)
when CodeObjects::RootObject
"toplevel"
when CodeObjects::ExtendedMethodObject
- serialized_path(object.namespace) + ':' + urlencode(object.name.to_s)
+ "#{serialized_path(object.namespace)}:#{urlencode(object.name.to_s)}"
when CodeObjects::MethodObject
serialized_path(object.namespace) +
(object.scope == :instance ? ":" : ".") + urlencode(object.name.to_s)
when CodeObjects::ConstantObject, CodeObjects::ClassVariableObject
serialized_path(object.namespace) + "##{object.name}-#{object.type}"
when CodeObjects::ExtraFileObject
- super(object).gsub(/^file\./, 'file/')
+ super.gsub(/^file\./, 'file/')
else
- super(object)
+ super
end
end
private
def urlencode(name)
- if name.respond_to?(:force_encoding)
- name = name.dup.force_encoding('binary')
- end
+ name = name.dup.force_encoding('binary') if name.respond_to?(:force_encoding)
Templates::Helpers::HtmlHelper.urlencode(name)
end
end
diff --git a/lib/yard/server/http_utils.rb b/lib/yard/server/http_utils.rb
index ff2706d08..f1a27db79 100644
--- a/lib/yard/server/http_utils.rb
+++ b/lib/yard/server/http_utils.rb
@@ -23,18 +23,17 @@ module YARD::Server
# This module is generally used internally by WEBrick
module HTTPUtils
-
##
# Normalizes a request path. Raises an exception if the path cannot be
# normalized.
def normalize_path(path)
- raise "abnormal path `#{path}'" if path[0] != ?/
+ raise "abnormal path `#{path}'" if path[0] != '/'
ret = path.dup
ret.gsub!(%r{/+}o, '/') # // => /
- while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
- while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
+ while ret.sub!(%r{/\.(?:/|\Z)}, '/'); end # /. => /
+ while ret.sub!(%r{/(?!\.\./)[^/]+/\.\.(?:/|\Z)}, '/'); end # /foo/.. => /foo
raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
ret
@@ -54,7 +53,7 @@ def normalize_path(path)
"cer" => "application/pkix-cert",
"crl" => "application/pkix-crl",
"crt" => "application/x-x509-ca-cert",
- #"crl" => "application/x-pkcs7-crl",
+ # "crl" => "application/x-pkcs7-crl",
"css" => "text/css",
"dms" => "application/octet-stream",
"doc" => "application/msword",
@@ -103,27 +102,27 @@ def normalize_path(path)
"xml" => "text/xml",
"xpm" => "image/x-xpixmap",
"xwd" => "image/x-xwindowdump",
- "zip" => "application/zip",
+ "zip" => "application/zip"
}
##
# Loads Apache-compatible mime.types in +file+.
def load_mime_types(file)
- # note: +file+ may be a "| command" for now; some people may
+ # NOTE: +file+ may be a "| command" for now; some people may
# rely on this, but currently we do not use this method by default.
- open(file){ |io|
- hash = Hash.new
- io.each{ |line|
+ open(file) do |io|
+ hash = {}
+ io.each do |line|
next if /^#/ =~ line
line.chomp!
mimetype, ext0 = line.split(/\s+/, 2)
next unless ext0
next if ext0.empty?
- ext0.split(/\s+/).each{ |ext| hash[ext] = mimetype }
- }
+ ext0.split(/\s+/).each {|ext| hash[ext] = mimetype }
+ end
hash
- }
+ end
end
module_function :load_mime_types
@@ -132,8 +131,8 @@ def load_mime_types(file)
# mime type was found application/octet-stream is returned.
def mime_type(filename, mime_tab)
- suffix1 = (/\.(\w+)$/ =~ filename && $1.downcase)
- suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ filename && $1.downcase)
+ suffix1 = /\.(\w+)$/ =~ filename && $1.downcase
+ suffix2 = /\.(\w+)\.[\w\-]+$/ =~ filename && $1.downcase
mime_tab[suffix1] || mime_tab[suffix2] || "application/octet-stream"
end
module_function :mime_type
@@ -145,26 +144,25 @@ def mime_type(filename, mime_tab)
def parse_header(raw)
header = Hash.new([].freeze)
field = nil
- raw.each_line{|line|
+ raw.each_line do |line|
case line
when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):\s*(.*?)\s*\z/om
- field, value = $1, $2
+ field = $1
+ value = $2
field.downcase!
- header[field] = [] unless header.has_key?(field)
+ header[field] = [] unless header.key?(field)
header[field] << value
when /^\s+(.*?)\s*\z/om
value = $1
- unless field
- raise HTTPStatus::BadRequest, "bad header '#{line}'."
- end
+ raise HTTPStatus::BadRequest, "bad header '#{line}'." unless field
header[field][-1] << " " << value
else
raise HTTPStatus::BadRequest, "bad header '#{line}'."
end
- }
- header.each{|key, values|
+ end
+ header.each do |_key, values|
values.each(&:strip!)
- }
+ end
header
end
module_function :parse_header
@@ -173,8 +171,8 @@ def parse_header(raw)
# Splits a header value +str+ according to HTTP specification.
def split_header_value(str)
- str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
- (?:,\s*|\Z)'xn).flatten
+ str.scan(/\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
+ (?:,\s*|\Z)/xn).flatten
end
module_function :split_header_value
@@ -184,14 +182,14 @@ def split_header_value(str)
def parse_range_header(ranges_specifier)
if /^bytes=(.*)/ =~ ranges_specifier
byte_range_set = split_header_value($1)
- byte_range_set.collect{|range_spec|
+ byte_range_set.collect do |range_spec|
case range_spec
- when /^(\d+)-(\d+)/ then $1.to_i .. $2.to_i
- when /^(\d+)-/ then $1.to_i .. -1
- when /^-(\d+)/ then -($1.to_i) .. -1
+ when /^(\d+)-(\d+)/ then $1.to_i..$2.to_i
+ when /^(\d+)-/ then $1.to_i..-1
+ when /^-(\d+)/ then -$1.to_i..-1
else return nil
end
- }
+ end
end
end
module_function :parse_range_header
@@ -203,17 +201,16 @@ def parse_qvalues(value)
tmp = []
if value
parts = value.split(/,\s*/)
- parts.each {|part|
- if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
- val = m[1]
- q = (m[2] or 1).to_f
- tmp.push([val, q])
- end
- }
- tmp = tmp.sort_by{|val, q| -q}
- tmp.collect!{|val, q| val}
+ parts.each do |part|
+ next unless (m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part))
+ val = m[1]
+ q = (m[2] or 1).to_f
+ tmp.push([val, q])
+ end
+ tmp = tmp.sort_by {|_val, q| -q }
+ tmp.collect! {|val, _q| val }
end
- return tmp
+ tmp
end
module_function :parse_qvalues
@@ -221,7 +218,7 @@ def parse_qvalues(value)
# Removes quotes and escapes from +str+
def dequote(str)
- ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup
+ ret = /\A"(.*)"\Z/ =~ str ? $1 : str.dup
ret.gsub!(/\\(.)/, "\\1")
ret
end
@@ -246,14 +243,10 @@ class FormData < String
##
# The name of the form data part
- attr_accessor :name
+ attr_accessor :name, :filename, :next_data
##
- # The filename of the form data part
-
- attr_accessor :filename
-
- attr_accessor :next_data # :nodoc:
+ # The filename of the form data part # :nodoc:
protected :next_data
##
@@ -274,9 +267,7 @@ def initialize(*args)
@raw_header = EmptyRawHeader
@header = EmptyHeader
super(args.shift)
- unless args.empty?
- @next_data = self.class.new(*args)
- end
+ @next_data = self.class.new(*args) unless args.empty?
end
end
@@ -284,11 +275,9 @@ def initialize(*args)
# Retrieves the header at the first entry in +key+
def [](*key)
- begin
- @header[key[0].downcase].join(", ")
- rescue StandardError, NameError
- super
- end
+ @header[key[0].downcase].join(", ")
+ rescue StandardError, NameError
+ super
end
##
@@ -301,8 +290,8 @@ def <<(str)
if @header
super
elsif str == CRLF
- @header = HTTPUtils::parse_header(@raw_header.join)
- if cd = self['content-disposition']
+ @header = HTTPUtils.parse_header(@raw_header.join)
+ if (cd = self['content-disposition'])
if /\s+name="(.*?)"/ =~ cd then @name = $1 end
if /\s+filename="(.*?)"/ =~ cd then @filename = $1 end
end
@@ -346,16 +335,16 @@ def each_data
def list
ret = []
- each_data{|data|
+ each_data do |data|
ret << data.to_s
- }
+ end
ret
end
##
# A FormData will behave like an Array
- alias :to_ary :list
+ alias to_ary list
##
# This FormData's body
@@ -369,21 +358,21 @@ def to_s
# Parses the query component of a URI in +str+
def parse_query(str)
- query = Hash.new
+ query = {}
if str
- str.split(/[&;]/).each{|x|
+ str.split(/[&;]/).each do |x|
next if x.empty?
- key, val = x.split(/=/,2)
+ key, val = x.split('=', 2)
key = unescape_form(key)
val = unescape_form(val.to_s)
val = FormData.new(val)
val.name = key
- if query.has_key?(key)
+ if query.key?(key)
query[key].append_data(val)
next
end
query[key] = val
- }
+ end
end
query
end
@@ -394,15 +383,15 @@ def parse_query(str)
def parse_form_data(io, boundary)
boundary_regexp = /\A--#{Regexp.quote(boundary)}(--)?#{CRLF}\z/
- form_data = Hash.new
+ form_data = {}
return form_data unless io
data = nil
- io.each_line{|line|
+ io.each_line do |line|
if boundary_regexp =~ line
if data
data.chop!
key = data.name
- if form_data.has_key?(key)
+ if form_data.key?(key)
form_data[key].append_data(data)
else
form_data[key] = data
@@ -410,13 +399,11 @@ def parse_form_data(io, boundary)
end
data = FormData.new
next
- else
- if data
- data << line
- end
+ elsif data
+ data << line
end
- }
- return form_data
+ end
+ form_data
end
module_function :parse_form_data
@@ -428,11 +415,11 @@ def parse_form_data(io, boundary)
upalpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mark = '-_.!~*\'()'
unreserved = num + lowalpha + upalpha + mark
- control = (0x0..0x1f).collect{|c| c.chr }.join + "\x7f"
+ control = "#{(0x0..0x1f).collect(&:chr).join}\u007F"
space = " "
delims = '<>#%"'
unwise = '{}|\\^[]`'
- nonascii = (0x80..0xff).collect{|c| c.chr }.join
+ nonascii = (0x80..0xff).collect(&:chr).join
module_function
@@ -440,24 +427,26 @@ def parse_form_data(io, boundary)
def _make_regex(str) /([#{Regexp.escape(str)}])/n end
def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end
+
def _escape(str, regex)
str = str.b
- str.gsub!(regex) {"%%%02X" % $1.ord}
+ str.gsub!(regex) { "%%%02X" % $1.ord }
# %-escaped string should contain US-ASCII only
str.force_encoding(Encoding::US_ASCII)
end
+
def _unescape(str, regex)
str = str.b
- str.gsub!(regex) {$1.hex.chr}
+ str.gsub!(regex) { $1.hex.chr }
# encoding of %-unescaped string is unknown
str
end
- UNESCAPED = _make_regex(control+space+delims+unwise+nonascii)
- UNESCAPED_FORM = _make_regex(reserved+control+delims+unwise+nonascii)
+ UNESCAPED = _make_regex(control + space + delims + unwise + nonascii)
+ UNESCAPED_FORM = _make_regex(reserved + control + delims + unwise + nonascii)
NONASCII = _make_regex(nonascii)
ESCAPED = /%([0-9a-fA-F]{2})/
- UNESCAPED_PCHAR = _make_regex!(unreserved+":@&=+$,")
+ UNESCAPED_PCHAR = _make_regex!("#{unreserved}:@&=+$,")
# :startdoc:
@@ -480,7 +469,7 @@ def unescape(str)
def escape_form(str)
ret = _escape(str, UNESCAPED_FORM)
- ret.gsub!(/ /, "+")
+ ret.tr!(' ', "+")
ret
end
@@ -488,7 +477,7 @@ def escape_form(str)
# Unescapes form reserved characters in +str+
def unescape_form(str)
- _unescape(str.gsub(/\+/, " "), ESCAPED)
+ _unescape(str.tr('+', " "), ESCAPED)
end
##
@@ -496,10 +485,10 @@ def unescape_form(str)
def escape_path(str)
result = ""
- str.scan(%r{/([^/]*)}).each{|i|
+ str.scan(%r{/([^/]*)}).each do |i|
result << "/" << _escape(i[0], UNESCAPED_PCHAR)
- }
- return result
+ end
+ result
end
##
diff --git a/lib/yard/server/library_version.rb b/lib/yard/server/library_version.rb
index a3ab31b4d..53c6ec55d 100644
--- a/lib/yard/server/library_version.rb
+++ b/lib/yard/server/library_version.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-require 'fileutils'
require 'thread'
module YARD
@@ -106,7 +105,7 @@ class LibraryVersion
def yardoc_file
@yardoc_file ||= load_yardoc_file
end
- attr_writer :yardoc_file
+ attr_writer :yardoc_file, :source_path
# @return [Symbol] the source type representing where the yardoc should be
# loaded from. Defaults are +:disk+ and +:gem+, though custom sources
@@ -122,7 +121,6 @@ def yardoc_file
def source_path
@source_path ||= load_source_path
end
- attr_writer :source_path
# @param [String] name the name of the library
# @param [String] version the specific (usually, but not always, numeric) library
diff --git a/lib/yard/server/rack_adapter.rb b/lib/yard/server/rack_adapter.rb
index 453381f63..ed53f6fa5 100644
--- a/lib/yard/server/rack_adapter.rb
+++ b/lib/yard/server/rack_adapter.rb
@@ -58,10 +58,10 @@ def call(env)
request = Rack::Request.new(env)
request.path_info = unescape(request.path_info) # unescape things like %3F
router.call(request)
- rescue StandardError => ex
- log.backtrace(ex)
+ rescue StandardError => e
+ log.backtrace(e)
[500, {'Content-Type' => 'text/plain'},
- [ex.message + "\n" + ex.backtrace.join("\n")]]
+ ["#{e.message}\n#{e.backtrace.join("\n")}"]]
end
# Starts the Rack server. This method will pass control to the server and
@@ -69,7 +69,7 @@ def call(env)
# @return [void]
def start
server = RackServer.new(server_options)
- server.instance_variable_set("@app", self)
+ server.instance_variable_set(:@app, self)
print_start_message(server)
server.start
end
diff --git a/lib/yard/server/router.rb b/lib/yard/server/router.rb
index c12753ceb..2cc9bf377 100644
--- a/lib/yard/server/router.rb
+++ b/lib/yard/server/router.rb
@@ -54,7 +54,7 @@ def initialize(adapter)
def call(request)
self.request = request
result = check_static_cache || route
- result ? result : RootRequestCommand.new(adapter.options).call(request)
+ result || RootRequestCommand.new(adapter.options).call(request)
end
# @group Route Prefixes
diff --git a/lib/yard/server/static_caching.rb b/lib/yard/server/static_caching.rb
index ca43b15ac..63b5a830c 100644
--- a/lib/yard/server/static_caching.rb
+++ b/lib/yard/server/static_caching.rb
@@ -33,7 +33,7 @@ module StaticCaching
# @see Commands::Base#cache
def check_static_cache
return nil unless adapter.document_root
- cache_path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html')
+ cache_path = File.join(adapter.document_root, "#{request.path.sub(/\.html$/, '')}.html")
cache_path = cache_path.sub(%r{/\.html$}, '.html')
if File.file?(cache_path)
log.debug "Loading cache from disk: #{cache_path}"
diff --git a/lib/yard/server/templates/doc_server/library_list/html/setup.rb b/lib/yard/server/templates/doc_server/library_list/html/setup.rb
index a13cdeac6..0955e8755 100644
--- a/lib/yard/server/templates/doc_server/library_list/html/setup.rb
+++ b/lib/yard/server/templates/doc_server/library_list/html/setup.rb
@@ -2,5 +2,5 @@
include T('default/layout/html')
def init
- sections :library_list, [:title, :listing, :footer]
+ sections :library_list, %i(title listing footer)
end
diff --git a/lib/yard/server/webrick_adapter.rb b/lib/yard/server/webrick_adapter.rb
index 568e22fd8..bed95d5d7 100644
--- a/lib/yard/server/webrick_adapter.rb
+++ b/lib/yard/server/webrick_adapter.rb
@@ -26,7 +26,7 @@ def initialize(server, adapter)
end
# @private
- def do_GET(request, response) # rubocop:disable Style/MethodName
+ def do_GET(request, response) # rubocop:disable Naming/MethodName
status, headers, body = *adapter.router.call(request)
response.status = status
response.body = body.is_a?(Array) ? body[0] : body
diff --git a/lib/yard/tags/default_factory.rb b/lib/yard/tags/default_factory.rb
index aee61a949..6d04f043f 100644
--- a/lib/yard/tags/default_factory.rb
+++ b/lib/yard/tags/default_factory.rb
@@ -126,7 +126,8 @@ def extract_title_and_desc_from_text(text)
# @return [Array(String, Array, String)] the text before the type
# list (or nil), followed by the type list parsed into an array of
# strings, followed by the text following the type list.
- def extract_types_and_name_from_text(text, opening_types = TYPELIST_OPENING_CHARS, closing_types = TYPELIST_CLOSING_CHARS)
+ def extract_types_and_name_from_text(text, opening_types = TYPELIST_OPENING_CHARS,
+closing_types = TYPELIST_CLOSING_CHARS)
before, list, text = *extract_types_and_name_from_text_unstripped(text, opening_types, closing_types)
if list.nil?
[nil, nil, text.strip]
@@ -135,7 +136,8 @@ def extract_types_and_name_from_text(text, opening_types = TYPELIST_OPENING_CHAR
end
end
- def extract_types_and_name_from_text_unstripped(text, opening_types = TYPELIST_OPENING_CHARS, closing_types = TYPELIST_CLOSING_CHARS)
+ def extract_types_and_name_from_text_unstripped(text, opening_types = TYPELIST_OPENING_CHARS,
+closing_types = TYPELIST_CLOSING_CHARS)
e = 0
before = String.new("")
list = [String.new("")]
@@ -144,17 +146,18 @@ def extract_types_and_name_from_text_unstripped(text, opening_types = TYPELIST_O
i = 0
last_seen = ''
text ||= ''
+ quotes = ['"', "'"]
while i < text.length
c = text[i, 1]
- if (c == '"' || c == "'") && text[i..-1] =~ /#{c}.+?#{c}/
+ if quotes.include?(c) && text[i..-1] =~ /#{c}.+?#{c}/
list.last << $&
i += $&.length
next
end
if level > 0 && c == '#' && text[i + 1..-1] =~ CodeObjects::METHODNAMEMATCH
- list.last << c + $&
+ list.last << (c + $&)
i += $&.length + 1
next
elsif opening_types.include?(c)
@@ -180,7 +183,7 @@ def extract_types_and_name_from_text_unstripped(text, opening_types = TYPELIST_O
i += 1
end
- before = before.empty? ? nil : before
+ before = nil if before.empty?
if list.size == 1 && list.first == ''
[nil, nil, text]
else
diff --git a/lib/yard/tags/directives.rb b/lib/yard/tags/directives.rb
index c24ab4b36..1cf21452e 100644
--- a/lib/yard/tags/directives.rb
+++ b/lib/yard/tags/directives.rb
@@ -78,7 +78,7 @@ def after_parse; end
def inside_directive?
return true if parser.state.inside_directive
- parser.directives.any? { |d| d.is_a?(MethodDirective) && d.tag.text.empty? }
+ parser.directives.any? {|d| d.is_a?(MethodDirective) && d.tag.text.empty? }
end
end
@@ -274,8 +274,8 @@ def new?
end
def attach?
- new? && # must have data or there is nothing to attach
- class_method? || # always attach to class methods
+ (new? && # must have data or there is nothing to attach
+ class_method?) || # always attach to class methods
(tag.types && tag.types.include?('attach'))
end
@@ -312,8 +312,8 @@ def find_or_create
"#{object.path} (#{handler.parser.file}:#{handler.statement.line})"
obj = nil
else
- obj = object ? object :
- P("#{handler.namespace}.#{handler.caller_method}")
+ obj = object ||
+ P("#{handler.namespace}.#{handler.caller_method}")
end
else
obj = nil
@@ -379,7 +379,7 @@ def after_parse
def method_name
sig = sanitized_tag_signature
- if sig && sig =~ /^#{CodeObjects::METHODNAMEMATCH}(\s|\(|$)/
+ if sig && sig =~ /^#{CodeObjects::METHODNAMEMATCH}(\s|\(|$)/o
sig[/\A\s*([^\(; \t]+)/, 1]
else
handler.call_params.first
@@ -422,7 +422,7 @@ def create_object
obj.signature = method_signature
obj.parameters = OverloadTag.new(:overload, method_signature).parameters
obj.docstring = Docstring.new!(parser.text, parser.tags, obj,
- parser.raw_text, parser.reference)
+ parser.raw_text, parser.reference)
handler.register_module_function(obj)
old_obj = parser.object
parser.object = obj
@@ -494,7 +494,7 @@ def create_attribute_data(object)
writer.parameters = [['value', nil]]
else
writer = CodeObjects::MethodObject.new(object.namespace,
- object.name.to_s + '=', object.scope)
+ "#{object.name}=", object.scope)
writer.signature = "def #{object.name}=(value)"
writer.visibility = object.visibility
writer.dynamic = object.dynamic
diff --git a/lib/yard/tags/library.rb b/lib/yard/tags/library.rb
index 807962608..14cb292ed 100644
--- a/lib/yard/tags/library.rb
+++ b/lib/yard/tags/library.rb
@@ -156,19 +156,19 @@ def sorted_labels
# creating the tag or the name of the class to directly create a tag for
def define_tag(label, tag, meth = nil)
tag_meth = tag_method_name(tag)
- if meth.is_a?(Class) && Tag > meth
- class_eval(<<-eof, __FILE__, __LINE__ + 1)
+ if meth.is_a?(Class) && meth < Tag
+ class_eval(<<-EOF, __FILE__, __LINE__ + 1)
def #{tag_meth}(text)
#{meth}.new(#{tag.inspect}, text)
end
- eof
+ EOF
else
- class_eval(<<-eof, __FILE__, __LINE__ + 1)
+ class_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef #{tag_meth}; rescue NameError; end
def #{tag_meth}(text)
send_to_factory(#{tag.inspect}, #{meth.inspect}, text)
end
- eof
+ EOF
end
@labels ||= SymbolHash.new(false)
@@ -199,11 +199,11 @@ def define_directive(tag, tag_meth = nil, directive_class = nil)
directive_class = tag_meth
tag_meth = nil
end
- class_eval <<-eof, __FILE__, __LINE__
+ class_eval <<-EOF, __FILE__, __LINE__
def #{directive_meth}(tag, parser)
directive_call(tag, parser)
end
- eof
+ EOF
@factory_methods ||= SymbolHash.new(false)
@factory_methods.update(tag => tag_meth)
@@ -232,7 +232,7 @@ def tag_or_directive_method_name(tag_name, type = 'tag')
def send_to_factory(tag_name, meth, text)
meth = meth.to_s
- send_name = "parse_tag" + (meth.empty? ? "" : "_" + meth)
+ send_name = "parse_tag#{meth.empty? ? "" : "_#{meth}"}"
if @factory.respond_to?(send_name)
@factory.send(send_name, tag_name, text)
else
@@ -623,11 +623,11 @@ def directive_create(tag_name, tag_buf, parser)
# @yard.signature public | protected | private
define_directive :visibility, VisibilityDirective
- self.visible_tags = [:abstract, :deprecated, :note, :todo, :example, :overload,
- :param, :option, :yield, :yieldparam, :yieldreturn, :return, :raise,
- :see, :author, :since, :version]
+ self.visible_tags = %i(abstract deprecated note todo example overload
+ param option yield yieldparam yieldreturn return raise
+ see author since version)
- self.transitive_tags = [:since, :api]
+ self.transitive_tags = %i(since api)
end
end
end
diff --git a/lib/yard/tags/overload_tag.rb b/lib/yard/tags/overload_tag.rb
index 739495ab1..15f58b7fa 100644
--- a/lib/yard/tags/overload_tag.rb
+++ b/lib/yard/tags/overload_tag.rb
@@ -15,7 +15,7 @@ def tags(name = nil) docstring.tags(name) end
def has_tag?(name) docstring.has_tag?(name) end
def object=(value)
- super(value)
+ super
docstring.object = value
docstring.tags.each {|tag| tag.object = value }
end
@@ -51,7 +51,7 @@ def parse_tag(text)
end
def parse_signature
- if signature =~ /^(?:def\s)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m
+ if signature =~ /^(?:def\s)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/mo
meth = $1
args = $2
meth.gsub!(/\s+/, '')
diff --git a/lib/yard/tags/types_explainer.rb b/lib/yard/tags/types_explainer.rb
index d87657665..33a94737d 100644
--- a/lib/yard/tags/types_explainer.rb
+++ b/lib/yard/tags/types_explainer.rb
@@ -34,7 +34,8 @@ def to_s(singular = true)
if name[0, 1] == "#"
singular ? "an object that responds to #{name}" : "objects that respond to #{name}"
elsif name[0, 1] =~ /[A-Z]/
- singular ? "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} " + name : "#{name}#{name[-1, 1] =~ /[A-Z]/ ? "'" : ''}s"
+ singular ? "a#{name[0,
+ 1] =~ /[aeiou]/i ? 'n' : ''} " + name : "#{name}#{name[-1, 1] =~ /[A-Z]/ ? "'" : ''}s"
else
name
end
@@ -64,14 +65,14 @@ def initialize(name, types)
end
def to_s(_singular = true)
- "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} of (" + list_join(types.map {|t| t.to_s(false) }) + ")"
+ "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} of (#{list_join(types.map {|t| t.to_s(false) })})"
end
end
# @private
class FixedCollectionType < CollectionType
def to_s(_singular = true)
- "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} containing (" + types.map(&:to_s).join(" followed by ") + ")"
+ "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} containing (#{types.map(&:to_s).join(" followed by ")})"
end
end
@@ -86,9 +87,9 @@ def initialize(name, key_types, value_types)
end
def to_s(_singular = true)
- "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} with keys made of (" +
- list_join(key_types.map {|t| t.to_s(false) }) +
- ") and values of (" + list_join(value_types.map {|t| t.to_s(false) }) + ")"
+ "a#{name[0, 1] =~ /[aeiou]/i ? 'n' : ''} #{name} with keys made of " \
+ "(#{list_join(key_types.map {|t| t.to_s(false) })}) " \
+ "and values of (#{list_join(value_types.map {|t| t.to_s(false) })})"
end
end
@@ -135,7 +136,7 @@ def parse
name = token
when :type_next
raise SyntaxError, "expecting name, got '#{token}' at #{@scanner.pos}" if name.nil?
- type = Type.new(name) unless type
+ type ||= Type.new(name)
types << type
type = nil
name = nil
@@ -148,10 +149,11 @@ def parse
type = HashCollectionType.new(name, parse, parse)
when :hash_collection_next, :hash_collection_end, :fixed_collection_end, :collection_end, :parse_end
raise SyntaxError, "expecting name, got '#{token}'" if name.nil?
- type = Type.new(name) unless type
+ type ||= Type.new(name)
types << type
return types
end
+ # rubocop:enable Lint/AssignmentInCondition
end
raise SyntaxError, "invalid character at #{@scanner.peek(1)}" unless found
end
diff --git a/lib/yard/templates/engine.rb b/lib/yard/templates/engine.rb
index 4c7f57fa4..f9f94ae5c 100644
--- a/lib/yard/templates/engine.rb
+++ b/lib/yard/templates/engine.rb
@@ -39,9 +39,7 @@ def template(*path)
path = File.cleanpath(path).gsub('../', '')
raise ArgumentError, "No such template for #{path}" if full_paths.empty?
- mod = template!(path, full_paths)
-
- mod
+ template!(path, full_paths)
end
# Forces creation of a template at +path+ within a +full_path+.
@@ -114,9 +112,7 @@ def generate(objects, options = {})
def with_serializer(object, serializer)
output = nil
filename = serializer.serialized_path(object)
- if serializer.respond_to?(:basepath)
- filename = File.join(serializer.basepath, filename)
- end
+ filename = File.join(serializer.basepath, filename) if serializer.respond_to?(:basepath)
log.capture("Generating #{filename}", nil) do
serializer.before_serialize if serializer
output = yield
@@ -173,7 +169,7 @@ def find_template_paths(from_template, path)
# @param [String] path the path to generate a module name for
# @return [String] the module name
def template_module_name(path)
- 'Template_' + path.to_s.gsub(/[^a-z0-9]/i, '_')
+ "Template_#{path.to_s.gsub(/[^a-z0-9]/i, '_')}"
end
end
diff --git a/lib/yard/templates/helpers/base_helper.rb b/lib/yard/templates/helpers/base_helper.rb
index 537497cba..bb0abf62f 100644
--- a/lib/yard/templates/helpers/base_helper.rb
+++ b/lib/yard/templates/helpers/base_helper.rb
@@ -89,7 +89,7 @@ def linkify(*args)
''
end
when /^file:(\S+?)(?:#(\S+))?$/
- link_file($1, args[1] ? args[1] : nil, $2)
+ link_file($1, args[1] || nil, $2)
else
link_object(*args)
end
@@ -198,7 +198,7 @@ def format_object_title(object)
when YARD::CodeObjects::RootObject
"Top Level Namespace"
else
- format_object_type(object) + ": " + object.title
+ "#{format_object_type(object)}: #{object.title}"
end
end
diff --git a/lib/yard/templates/helpers/html_helper.rb b/lib/yard/templates/helpers/html_helper.rb
index 850d842c0..b620ce807 100644
--- a/lib/yard/templates/helpers/html_helper.rb
+++ b/lib/yard/templates/helpers/html_helper.rb
@@ -40,8 +40,8 @@ def urlencode(text)
text = text.force_encoding('binary')
end
- text = text.gsub(/%[a-z0-9]{2}|#{URLMATCH}/i) do
- $&.size > 1 ? $& : "%" + $&.ord.to_s(16).upcase
+ text = text.gsub(/%[a-z0-9]{2}|#{URLMATCH}/io) do
+ $&.size > 1 ? $& : "%#{$&.ord.to_s(16).upcase}"
end.tr(' ', '+')
text = text.force_encoding(enc) if enc
@@ -69,9 +69,7 @@ def htmlify(text, markup = options.markup)
html = html.encode(:invalid => :replace, :replace => '?')
end
html = resolve_links(html)
- unless [:text, :none, :pre, :ruby].include?(markup)
- html = parse_codeblocks(html)
- end
+ html = parse_codeblocks(html) unless %i(text none pre ruby).include?(markup)
html
end
@@ -83,18 +81,18 @@ def html_markup_markdown(text)
# TODO: other libraries might be more complex
provider = markup_class(:markdown)
case provider.to_s
- when 'RDiscount'
+ when 'RDiscount'
provider.new(text, :autolink).to_html
when 'RedcarpetCompat'
provider.new(text, :autolink,
- :fenced_code,
- :gh_blockcode,
- :lax_spacing,
- :tables,
- :with_toc_data,
- :no_intraemphasis).to_html
+ :fenced_code,
+ :gh_blockcode,
+ :lax_spacing,
+ :tables,
+ :with_toc_data,
+ :no_intraemphasis).to_html
when 'CommonMarker'
- CommonMarker.render_html(text, %i[DEFAULT GITHUB_PRE_LANG], %i[autolink table])
+ CommonMarker.render_html(text, %i(DEFAULT GITHUB_PRE_LANG), %i(autolink table))
else
provider.new(text).to_html
end
@@ -148,7 +146,7 @@ def html_markup_rdoc(text)
# @return [String] the output HTML
# @since 0.6.0
def html_markup_pre(text)
- "" + h(text) + "
"
+ "#{h(text)}"
end
# Converts plaintext to regular HTML
@@ -181,12 +179,12 @@ def html_markup_html(text)
# @return [String] the highlighted HTML
# @since 0.7.0
def html_markup_ruby(source)
- '' + html_syntax_highlight(source, :ruby) + '
'
+ "#{html_syntax_highlight(source, :ruby)}"
end
# @return [String] HTMLified text as a single line (paragraphs removed)
def htmlify_line(*args)
- "" + htmlify(*args) + "
"
+ "#{htmlify(*args)}
"
end
# @group Syntax Highlighting Source Code
@@ -257,12 +255,15 @@ def resolve_links(text)
object
else
link = linkify(name, title)
- if (link == name || link == title) && (name + ' ' + link !~ /\A/)
+ if (link == name || link == title) && ("#{name} #{link}" !~ /\A/)
match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
file = (defined?(@file) && @file ? @file.filename : object.file) || '(unknown)'
- line = (defined?(@file) && @file ? 1 : (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
- log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".") +
- "\n\t" + (match[1] ? '...' : '') + match[2].delete("\n") + (match[3] ? '...' : '') if match
+ line = (defined?(@file) && @file ? 1 :
+ (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
+ if match
+ log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text#{match ? ":" : "."}\n\t" \
+ "#{match[1] ? '...' : ''}#{match[2].delete("\n")}#{match[3] ? '...' : ''}"
+ end
end
link
@@ -284,9 +285,7 @@ def link_file(filename, title = nil, anchor = nil)
# (see BaseHelper#link_include_file)
def link_include_file(file)
- unless file.is_a?(CodeObjects::ExtraFileObject)
- file = CodeObjects::ExtraFileObject.new(file)
- end
+ file = CodeObjects::ExtraFileObject.new(file) unless file.is_a?(CodeObjects::ExtraFileObject)
file.attributes[:markup] ||= markup_for_file('', file.filename)
insert_include(file.contents, file.attributes[:markup] || options.markup)
end
@@ -305,28 +304,28 @@ def insert_include(text, markup = options.markup)
def link_object(obj, title = nil, anchor = nil, relative = true)
return title if obj.nil?
obj = Registry.resolve(object, obj, true, true) if obj.is_a?(String)
- if title
- title = title.to_s
- elsif object.is_a?(CodeObjects::Base)
- # Check if we're linking to a class method in the current
- # object. If we are, create a title in the format of
- # "CurrentClass.method_name"
- if obj.is_a?(CodeObjects::MethodObject) && obj.scope == :class && obj.parent == object
- title = h([object.name, obj.sep, obj.name].join)
- elsif obj.title != obj.path
- title = h(obj.title)
- else
- title = h(object.relative_path(obj))
- end
- else
- title = h(obj.title)
- end
+ title = if title
+ title.to_s
+ elsif object.is_a?(CodeObjects::Base)
+ # Check if we're linking to a class method in the current
+ # object. If we are, create a title in the format of
+ # "CurrentClass.method_name"
+ if obj.is_a?(CodeObjects::MethodObject) && obj.scope == :class && obj.parent == object
+ h([object.name, obj.sep, obj.name].join)
+ elsif obj.title != obj.path
+ h(obj.title)
+ else
+ h(object.relative_path(obj))
+ end
+ else
+ h(obj.title)
+ end
return title unless serializer
return title if obj.is_a?(CodeObjects::Proxy)
link = url_for(obj, anchor, relative)
link = link ? link_url(link, title, :title => h("#{obj.title} (#{obj.type})")) : title
- "" + link + ""
+ "#{link}"
rescue Parser::UndocumentableError
log.warn "The namespace of link #{obj.inspect} is a constant or invalid."
title || obj.to_s
@@ -397,7 +396,7 @@ def url_for(obj, anchor = nil, relative = true)
link = objpath
end
- link + (anchor ? '#' + urlencode(anchor_for(anchor)) : '')
+ link + (anchor ? "##{urlencode(anchor_for(anchor))}" : '')
end
alias mtime_url url_for
@@ -411,14 +410,12 @@ def mtime(_file) nil end
def url_for_file(filename, anchor = nil)
return '' unless serializer
fromobj = object
- if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
- fromobj = fromobj.namespace
- end
+ fromobj = fromobj.namespace if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
from = serializer.serialized_path(fromobj)
path = filename == options.readme ?
'index.html' : serializer.serialized_path(filename)
link = File.relative_path(from, path)
- link += (anchor ? '#' + urlencode(anchor) : '')
+ link += (anchor ? "##{urlencode(anchor)}" : '')
link
end
@@ -461,7 +458,7 @@ def url_for_index
# @return [String] a formatted list of objects
def format_object_name_list(objects)
objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
- "" + linkify(o, o.name) + ""
+ "#{linkify(o, o.name)}"
end.join(", ")
end
@@ -482,7 +479,7 @@ def format_types(typelist, brackets = true)
list = typelist.map do |type|
type = type.gsub(/([<>])/) { h($1) }
type = type.gsub(/([\w:]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
- "" + type + ""
+ "#{type}"
end
list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
end
@@ -495,25 +492,23 @@ def format_types(typelist, brackets = true)
# @since 0.5.3
def signature_types(meth, link = true)
meth = convert_method_to_overload(meth)
- if meth.respond_to?(:object) && !meth.has_tag?(:return)
- meth = meth.object
- end
+ meth = meth.object if meth.respond_to?(:object) && !meth.has_tag?(:return)
type = options.default_return || ""
if meth.tag(:return) && meth.tag(:return).types
- types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten.uniq
+ types = meth.tags(:return).map {|t| t.types || [] }.flatten.uniq
first = link ? h(types.first) : format_types([types.first], false)
- if types.size == 2 && types.last == 'nil'
- type = first + '?'
- elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
- type = first + '+'
- elsif types.size > 2
- type = [first, '...'].join(', ')
- elsif types == ['void'] && options.hide_void_return
- type = ""
- else
- type = link ? h(types.join(", ")) : format_types(types, false)
- end
+ type = if types.size == 2 && types.last == 'nil'
+ "#{first}?"
+ elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
+ "#{first}+"
+ elsif types.size > 2
+ [first, '...'].join(', ')
+ elsif types == ['void'] && options.hide_void_return
+ ""
+ else
+ link ? h(types.join(", ")) : format_types(types, false)
+ end
elsif !type.empty?
type = link ? h(type) : format_types([type], false)
end
@@ -545,19 +540,19 @@ def signature(meth, link = true, show_extras = true, full_attr_name = true)
rw = meth.attr_info
if rw
attname = [rw[:read] ? 'read' : nil, rw[:write] ? 'write' : nil].compact
- attname = attname.size == 1 ? attname.join('') + 'only' : nil
+ attname = attname.size == 1 ? "#{attname.join}only" : nil
extras << attname if attname
end
extras << meth.visibility if meth.visibility != :public
- extras_text = ' ' unless extras.empty?
+ extras_text = " " unless extras.empty?
end
title = "%s%s%s %s %s" % [scope, h(name), args, blk, type]
if link
- if meth.is_a?(YARD::CodeObjects::MethodObject)
- link_title = "#{h meth.name(true)} (#{meth.scope} #{meth.type})"
- else
- link_title = "#{h name} (#{meth.type})"
- end
+ link_title = if meth.is_a?(YARD::CodeObjects::MethodObject)
+ "#{h meth.name(true)} (#{meth.scope} #{meth.type})"
+ else
+ "#{h name} (#{meth.type})"
+ end
obj = meth.respond_to?(:object) ? meth.object : meth
url = url_for(object, obj)
link_url(url, title, :title => link_title) + extras_text
@@ -635,6 +630,10 @@ def parse_lang_for_codeblock(source)
[type, source]
end
+ # @!private
+ CODEBLOCKS_MATCH =
+ %r{(?:\s*)?(.+?)(?:\s*)?
}m
+
# Parses code blocks out of html and performs syntax highlighting
# on code inside of the blocks.
#
@@ -642,7 +641,7 @@ def parse_lang_for_codeblock(source)
# @return [String] highlighted html
# @see #html_syntax_highlight
def parse_codeblocks(html)
- html.gsub(%r{(?:\s*)?(.+?)(?:\s*)?
}m) do
+ html.gsub(CODEBLOCKS_MATCH) do
string = $3
# handle !!!LANG prefix to send to html_syntax_highlight_LANG
@@ -650,9 +649,7 @@ def parse_codeblocks(html)
language ||= detect_lang_in_codeblock_attributes($1, $2)
language ||= object.source_type
- if options.highlight
- string = html_syntax_highlight(CGI.unescapeHTML(string), language)
- end
+ string = html_syntax_highlight(CGI.unescapeHTML(string), language) if options.highlight
classes = ['code', language].compact.join(' ')
%(#{string}
)
end
@@ -667,9 +664,9 @@ def parse_codeblocks(html)
# @return [String, nil] detected programming language
def detect_lang_in_codeblock_attributes(pre_html_attrs, code_html_attrs)
detected = nil
- detected ||= (/\bdata-lang="(.+?)"/ =~ code_html_attrs && $1)
- detected ||= (/\blang="(.+?)"/ =~ pre_html_attrs && $1)
- detected ||= (/\bclass="(.+?)"/ =~ code_html_attrs && $1)
+ detected ||= /\bdata-lang="(.+?)"/ =~ code_html_attrs && $1
+ detected ||= /\blang="(.+?)"/ =~ pre_html_attrs && $1
+ detected ||= /\bclass="(.+?)"/ =~ code_html_attrs && $1
detected
end
end
diff --git a/lib/yard/templates/helpers/html_syntax_highlight_helper.rb b/lib/yard/templates/helpers/html_syntax_highlight_helper.rb
index 07ab9be79..882fa8475 100644
--- a/lib/yard/templates/helpers/html_syntax_highlight_helper.rb
+++ b/lib/yard/templates/helpers/html_syntax_highlight_helper.rb
@@ -19,12 +19,15 @@ def html_syntax_highlight_ruby(source)
private
+ RIPPER_STRING_START_TOKENS = %i(tstring_beg regexp_beg).freeze
+ RIPPER_STRING_END_TOKENS = %i(tstring_end regexp_end).freeze
+
def html_syntax_highlight_ruby_ripper(source)
resolver = Parser::Ruby::TokenResolver.new(source, object)
output = String.new("")
resolver.each do |s, token_obj|
token_obj = clean_token_object(token_obj)
- output << "" if [:tstring_beg, :regexp_beg].include?(s[0])
+ output << "" if RIPPER_STRING_START_TOKENS.include?(s[0])
case s.first
when :nl, :ignored_nl, :sp
output << h(s[1])
@@ -35,7 +38,7 @@ def html_syntax_highlight_ruby_ripper(source)
else
output << "#{h(s[1])}"
end
- output << "" if [:tstring_end, :regexp_end].include?(s[0])
+ output << "" if RIPPER_STRING_END_TOKENS.include?(s[0])
end
output
rescue Parser::ParserSyntaxError
@@ -63,14 +66,12 @@ def html_syntax_highlight_ruby_legacy(source)
def clean_token_object(token_obj)
return unless token_obj
if token_obj == object
- token_obj = nil
+ nil
elsif token_obj.is_a?(CodeObjects::MethodObject)
- token_obj = prune_method_listing([token_obj], false).first
+ prune_method_listing([token_obj], false).first
else
- token_obj = run_verifier([token_obj]).first
+ run_verifier([token_obj]).first
end
-
- token_obj
end
end
end
diff --git a/lib/yard/templates/helpers/markup/rdoc_markdown.rb b/lib/yard/templates/helpers/markup/rdoc_markdown.rb
index 03f9645fb..f7d8b77eb 100644
--- a/lib/yard/templates/helpers/markup/rdoc_markdown.rb
+++ b/lib/yard/templates/helpers/markup/rdoc_markdown.rb
@@ -12,7 +12,7 @@ module Markup
class RDocMarkdown < RDocMarkup
def initialize(text)
- super RDoc::Markdown.new.parse(text)
+ super(RDoc::Markdown.new.parse(text))
end
def fix_typewriter(html) html end
diff --git a/lib/yard/templates/helpers/markup/rdoc_markup.rb b/lib/yard/templates/helpers/markup/rdoc_markup.rb
index b65bf2fd5..1192a777e 100644
--- a/lib/yard/templates/helpers/markup/rdoc_markup.rb
+++ b/lib/yard/templates/helpers/markup/rdoc_markup.rb
@@ -10,6 +10,7 @@ module Markup
require 'rdoc/markup'
require 'rdoc/markup/to_html'
class RDocMarkup; MARKUP = RDoc::Markup end
+
class RDocMarkupToHtml < RDoc::Markup::ToHtml
if defined?(RDoc::VERSION) && RDoc::VERSION >= '4.0.0' &&
defined?(RDoc::Options)
@@ -24,7 +25,7 @@ def initialize
begin
require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
- class RDocMarkup; MARKUP = SM::SimpleMarkup end
+ class RDocMarkup; MARKUP = SM::SimpleMarkup end # rubocop:disable Lint/ConstantReassignment
class RDocMarkupToHtml < SM::ToHtml; end
rescue LoadError
raise NameError, "could not load RDocMarkup (rdoc is not installed)"
@@ -56,8 +57,7 @@ def to_html
html = @@markup.convert(@text, @@formatter)
end
html = fix_dash_dash(html)
- html = fix_typewriter(html)
- html
+ fix_typewriter(html)
end
private
@@ -78,7 +78,7 @@ def fix_typewriter(text)
next str
end
next str unless code_tags == 0
- first_text + '' + type_text + ''
+ "#{first_text}#{type_text}"
end
end
@@ -95,7 +95,7 @@ class RDocMarkupToHtml
attr_accessor :from_path
# Disable auto-link of URLs
- def handle_special_HYPERLINK(special) # rubocop:disable Style/MethodName
+ def handle_special_HYPERLINK(special) # rubocop:disable Naming/MethodName
@hyperlink ? special.text : super
end
diff --git a/lib/yard/templates/helpers/markup_helper.rb b/lib/yard/templates/helpers/markup_helper.rb
index 9d7a6dcd1..64a2756a7 100644
--- a/lib/yard/templates/helpers/markup_helper.rb
+++ b/lib/yard/templates/helpers/markup_helper.rb
@@ -90,9 +90,7 @@ def load_markup_provider(type = options.markup)
providers = MARKUP_PROVIDERS[type.to_sym]
return true if providers && providers.empty?
- if providers && options.markup_provider
- providers = providers.select {|p| p[:lib] == options.markup_provider }
- end
+ providers = providers.select {|p| p[:lib] == options.markup_provider } if providers && options.markup_provider
if providers.nil? || providers.empty?
log.error "Invalid markup type '#{type}' or markup provider " \
@@ -103,7 +101,7 @@ def load_markup_provider(type = options.markup)
# Search for provider, return the library class name as const if found
providers.each do |provider|
begin require provider[:lib].to_s; rescue LoadError; next end if provider[:lib]
- begin klass = eval("::" + provider[:const]); rescue NameError; next end # rubocop:disable Lint/Eval
+ begin klass = eval("::#{provider[:const]}"); rescue NameError; next end # rubocop:disable Security/Eval
MarkupHelper.markup_cache[type][:provider] = provider[:lib] # Cache the provider
MarkupHelper.markup_cache[type][:class] = klass
return true
diff --git a/lib/yard/templates/helpers/method_helper.rb b/lib/yard/templates/helpers/method_helper.rb
index 5e61bd180..ef5585780 100644
--- a/lib/yard/templates/helpers/method_helper.rb
+++ b/lib/yard/templates/helpers/method_helper.rb
@@ -10,7 +10,7 @@ def format_args(object)
if object.has_tag?(:yield) || object.has_tag?(:yieldparam)
params.reject! do |param|
param[0].to_s[0, 1] == "&" &&
- !object.tags(:param).any? {|t| t.name == param[0][1..-1] }
+ object.tags(:param).none? {|t| t.name == param[0][1..-1] }
end
end
@@ -43,24 +43,24 @@ def format_block(object)
params = nil
end
- params ? h("{|" + params.join(", ") + "| ... }") : ""
+ params ? h("{|#{params.join(", ")}| ... }") : ""
end
# @return [String] formats line numbers for source code of an object
def format_lines(object)
return "" if object.source.nil? || object.line.nil?
i = -1
- object.source.split(/\n/).map { object.line + (i += 1) }.join("\n")
+ object.source.split("\n").map { object.line + (i += 1) }.join("\n")
end
# @return [String] formats source of an object
def format_code(object, _show_lines = false)
i = -1
- lines = object.source.split(/\n/)
+ lines = object.source.split("\n")
longestline = (object.line + lines.size).to_s.length
lines.map do |line|
lineno = object.line + (i += 1)
- (" " * (longestline - lineno.to_s.length)) + lineno.to_s + " " + line
+ "#{" " * (longestline - lineno.to_s.length)}#{lineno} #{line}"
end.join("\n")
end
diff --git a/lib/yard/templates/helpers/text_helper.rb b/lib/yard/templates/helpers/text_helper.rb
index 7d829afda..9bf5fb2d8 100644
--- a/lib/yard/templates/helpers/text_helper.rb
+++ b/lib/yard/templates/helpers/text_helper.rb
@@ -8,12 +8,12 @@ module TextHelper
def h(text)
out = String.new("")
text = resolve_links(text)
- text = text.split(/\n/)
+ text = text.split("\n")
text.each_with_index do |line, i|
out <<
case line
when /^\s*$/; "\n\n"
- when /^\s+\S/, /^=/; line + "\n"
+ when /^\s+\S/, /^=/; "#{line}\n"
else; line + (text[i + 1] =~ /^\s+\S/ ? "\n" : " ")
end
end
@@ -37,8 +37,8 @@ def title_align_right(text, col = 72)
# @return [String] aligns text to the right
def align_right(text, spacer = ' ', col = 72)
- text = text[0, col - 4] + '...' if (col - 1 - text.length) < 0
- spacer * (col - 1 - text.length) + " " + text
+ text = "#{text[0, col - 4]}..." if (col - 1 - text.length) < 0
+ "#{spacer * (col - 1 - text.length)} #{text}"
end
# @return [String] returns a horizontal rule for output
@@ -49,29 +49,25 @@ def hr(col = 72, sep = "-")
# @return [String] the formatted signature for a method
def signature(meth)
# use first overload tag if it has a return type and method itself does not
- if !meth.tag(:return) && meth.tag(:overload) && meth.tag(:overload).tag(:return)
- meth = meth.tag(:overload)
- end
+ meth = meth.tag(:overload) if !meth.tag(:return) && meth.tag(:overload) && meth.tag(:overload).tag(:return)
type = options.default_return || ""
rmeth = meth
- if !rmeth.has_tag?(:return) && rmeth.respond_to?(:object)
- rmeth = meth.object
- end
+ rmeth = meth.object if !rmeth.has_tag?(:return) && rmeth.respond_to?(:object)
if rmeth.tag(:return) && rmeth.tag(:return).types
- types = rmeth.tags(:return).map {|t| t.types ? t.types : [] }.flatten.uniq
+ types = rmeth.tags(:return).map {|t| t.types || [] }.flatten.uniq
first = types.first
- if types.size == 2 && types.last == 'nil'
- type = first + '?'
- elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
- type = first + '+'
- elsif types.size > 2
- type = [first, '...'].join(', ')
- elsif types == ['void'] && options.hide_void_return
- type = ""
- else
- type = types.join(", ")
- end
+ type = if types.size == 2 && types.last == 'nil'
+ "#{first}?"
+ elsif types.size == 2 && types.last =~ /^(Array)?<#{Regexp.quote types.first}>$/
+ "#{first}+"
+ elsif types.size > 2
+ [first, '...'].join(', ')
+ elsif types == ['void'] && options.hide_void_return
+ ""
+ else
+ types.join(", ")
+ end
end
type = "(#{type})" if type.include?(',')
type = " -> #{type} " unless type.empty?
@@ -84,11 +80,11 @@ def signature(meth)
rw = meth.namespace.attributes[meth.scope][meth.name]
if rw
attname = [rw[:read] ? 'read' : nil, rw[:write] ? 'write' : nil].compact
- attname = attname.size == 1 ? attname.join('') + 'only' : nil
+ attname = attname.size == 1 ? "#{attname.join}only" : nil
extras << attname if attname
end
extras << meth.visibility if meth.visibility != :public
- extras_text = '(' + extras.join(", ") + ')' unless extras.empty?
+ extras_text = "(#{extras.join(", ")})" unless extras.empty?
title = "%s%s%s %s%s%s" % [scope, name, args, blk, type, extras_text]
title.gsub(/\s+/, ' ')
end
diff --git a/lib/yard/templates/helpers/uml_helper.rb b/lib/yard/templates/helpers/uml_helper.rb
index a295ace17..1fc792387 100644
--- a/lib/yard/templates/helpers/uml_helper.rb
+++ b/lib/yard/templates/helpers/uml_helper.rb
@@ -3,15 +3,13 @@ module YARD
module Templates::Helpers
# Helpers for UML template format
module UMLHelper
+ VISIBILITIES = {:public => '+', :protected => '#', :private => '-'}
+
# Official UML visibility prefix syntax for an object given its visibility
# @param [CodeObjects::Base] object the object to retrieve visibility for
# @return [String] the UML visibility prefix
def uml_visibility(object)
- case object.visibility
- when :public; '+'
- when :protected; '#'
- when :private; '-'
- end
+ VISIBILITIES[object.visibility]
end
# Formats the path of an object for Graphviz syntax
@@ -33,7 +31,7 @@ def h(text)
# @return [String] tidied text.
def tidy(data)
indent = 0
- data.split(/\n/).map do |line|
+ data.split("\n").map do |line| # rubocop:disable Style/StringConcatenation
line.gsub!(/^\s*/, '')
next if line.empty?
indent -= 1 if line =~ /^\s*\}\s*$/
diff --git a/lib/yard/templates/section.rb b/lib/yard/templates/section.rb
index ca42adddc..ec828056e 100644
--- a/lib/yard/templates/section.rb
+++ b/lib/yard/templates/section.rb
@@ -20,15 +20,15 @@ def dup
def [](*args)
if args.first.is_a?(Range) || args.size > 1
- return self.class.new(name, *super(*args))
+ return self.class.new(name, *super)
elsif args.first.is_a?(Integer)
- return super(*args)
+ return super
end
find {|o| o.name == args.first }
end
def eql?(other)
- super(other) && name == other.name
+ super && name == other.name
end
def ==(other)
@@ -82,9 +82,7 @@ def any(item)
private
def parse_sections(args)
- if args.size == 1 && args.first.is_a?(Array) && !args.first.is_a?(Section)
- args = args.first
- end
+ args = args.first if args.size == 1 && args.first.is_a?(Array) && !args.first.is_a?(Section)
sections = []
args.each_with_index do |name, index|
case name
diff --git a/lib/yard/templates/template.rb b/lib/yard/templates/template.rb
index 6450bcb50..3a48cfc7a 100644
--- a/lib/yard/templates/template.rb
+++ b/lib/yard/templates/template.rb
@@ -121,7 +121,7 @@ def find_nth_file(basename, index = 1)
def is_a?(klass)
return true if klass == Template
- super(klass)
+ super
end
# Creates a new template object to be rendered with {Template#run}
@@ -136,7 +136,7 @@ def run(*args)
new(*args).run
end
- # rubocop:disable Style/MethodName
+ # rubocop:disable Naming/MethodName
# Alias for creating {Engine.template}.
def T(*path)
@@ -150,7 +150,7 @@ def S(*args)
Section.new(*args)
end
- # rubocop:enable Style/MethodName
+ # rubocop:enable Naming/MethodName
private
@@ -168,7 +168,7 @@ def include_parent
end
def include_inherited(full_paths)
- full_paths.reverse.each do |full_path|
+ full_paths.reverse_each do |full_path|
include Engine.template!(path, full_path)
end
end
@@ -201,7 +201,7 @@ def initialize(opts = TemplateOptions.new)
#
# @param [Array] path the path of the template
# @return [Template] the loaded template module
- def T(*path) # rubocop:disable Style/MethodName
+ def T(*path) # rubocop:disable Naming/MethodName
path.unshift(options.template) if options.template
path.push(options.format) if options.format
self.class.T(*path)
@@ -236,8 +236,7 @@ def sections(*args)
# sections :section1, :section2, [:subsection1, :etc]
# end
# @see #sections
- def init
- end
+ def init; end
# Runs a template on +sects+ using extra options. This method should
# not be called directly. Instead, call the class method {ClassMethods#run}
@@ -313,10 +312,10 @@ def file(basename, allow_inherited = false)
file = self.class.find_file(basename)
raise ArgumentError, "no file for '#{basename}' in #{self.class.path}" unless file
- data = IO.read(file)
+ data = File.read(file)
if allow_inherited
superfile = self.class.find_nth_file(basename, 2)
- data.gsub!('{{{__super__}}}', superfile ? IO.read(superfile) : "")
+ data.gsub!('{{{__super__}}}', superfile ? File.read(superfile) : "")
end
data
@@ -330,7 +329,7 @@ def file(basename, allow_inherited = false)
def superb(sect = section, &block)
filename = self.class.find_nth_file(erb_file_for(sect), 2)
return "" unless filename
- method_name = ErbCache.method_for(filename) { erb_with(IO.read(filename), filename) }
+ method_name = ErbCache.method_for(filename) { erb_with(File.read(filename), filename) }
send(method_name, &block)
end
@@ -382,7 +381,7 @@ def cache(section)
file = cache_filename(section)
@cache_filename[section.to_sym] = file
raise ArgumentError, "no template for section '#{section}' in #{self.class.path}" unless file
- @cache[section.to_sym] = IO.read(file)
+ @cache[section.to_sym] = File.read(file)
end
def cache_filename(section)
diff --git a/lib/yard/templates/template_options.rb b/lib/yard/templates/template_options.rb
index 11a270e7d..b5d4e0c21 100644
--- a/lib/yard/templates/template_options.rb
+++ b/lib/yard/templates/template_options.rb
@@ -76,7 +76,7 @@ def no_highlight=(value) self.highlight = !value end
# @return [nil] if the mixin is not a module object
def embed_mixins_match?(mixin)
return true if mixin == object # the method is not inherited
- return nil unless mixin.is_a?(CodeObjects::ModuleObject)
+ return false unless mixin.is_a?(CodeObjects::ModuleObject)
embed_mixins.any? do |embed_mixin|
re = /\A#{Regexp.quote(embed_mixin).gsub('\*', '.*')}\Z/
matchstr = embed_mixin.include?("::") ? mixin.path : mixin.name
diff --git a/lib/yard/verifier.rb b/lib/yard/verifier.rb
index 37d45129f..dff42dfd8 100644
--- a/lib/yard/verifier.rb
+++ b/lib/yard/verifier.rb
@@ -101,7 +101,7 @@ def run(list)
private
# @private
- NILCLASS_METHODS = [:type, :method_missing]
+ NILCLASS_METHODS = %i(type method_missing)
# Modifies nil to not throw NoMethodErrors. This allows
# syntax like object.tag(:return).text to work if the #tag
@@ -111,7 +111,7 @@ def run(list)
# @return [void]
def modify_nilclass
NILCLASS_METHODS.each do |meth|
- NilClass.send(:define_method, meth) {|*args| }
+ NilClass.send(:define_method, meth) {|*args| } # rubocop:disable Lint/EmptyBlock
end
end
@@ -130,10 +130,10 @@ def unmodify_nilclass
def create_method_from_expressions
expr = expressions.map {|e| "(#{parse_expression(e)})" }.join(" && ")
- instance_eval(<<-eof, __FILE__, __LINE__ + 1)
+ instance_eval(<<-EOF, __FILE__, __LINE__ + 1)
begin; undef __execute; rescue NameError; end
def __execute; #{expr}; end
- eof
+ EOF
end
# Parses a single expression, handling some of the DSL syntax.
@@ -144,8 +144,7 @@ def __execute; #{expr}; end
# @return [String] the parsed expression
def parse_expression(expr)
expr = expr.gsub(/@@(?:(\w+)|\{([\w\.]+)\})/, 'object.tags("\1\2")')
- expr = expr.gsub(/@(?:(\w+)|\{([\w\.]+)\})/, 'object.tag("\1\2")')
- expr
+ expr.gsub(/@(?:(\w+)|\{([\w\.]+)\})/, 'object.tag("\1\2")')
end
end
end
diff --git a/lib/yard/version.rb b/lib/yard/version.rb
index d7609cf38..4d2ab9c64 100644
--- a/lib/yard/version.rb
+++ b/lib/yard/version.rb
@@ -1,4 +1,3 @@
-
# frozen_string_literal: true
module YARD
diff --git a/spec/cli/diff_spec.rb b/spec/cli/diff_spec.rb
index 245e5d044..d167172a3 100644
--- a/spec/cli/diff_spec.rb
+++ b/spec/cli/diff_spec.rb
@@ -31,7 +31,7 @@ def run(*args)
@objects = [@objects1, @objects2]
expect(@diff).to receive(:load_gem_data).ordered.with('gem1') do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class C
def fooey; end
def baz; FOO end
@@ -39,11 +39,11 @@ def baz; FOO end
class D
def self.bar; end
end
- eof
+ EOF
end
expect(@diff).to receive(:load_gem_data).ordered.with('gem2') do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A
module B
class C; end
@@ -56,7 +56,7 @@ def self.foo; end
def self.bar; end
def baz; BAR end
end
- eof
+ EOF
end
allow(log).to receive(:print) {|data| @data << data }
allow(log).to receive(:puts) {|*pargs| @data << pargs.join("\n"); @data << "\n" }
@@ -65,7 +65,7 @@ def baz; BAR end
it "shows differences between objects" do
run
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
Added objects:
A ((stdin):1) (...)
@@ -82,12 +82,12 @@ def baz; BAR end
C#fooey ((stdin):2)
D ((stdin):5) (...)
-eof
+ EOF
end
it "accepts --compact" do
run('--compact')
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
A A ((stdin):1) (...)
A A::B::C ((stdin):3)
A C.bar ((stdin):10)
@@ -95,13 +95,13 @@ def baz; BAR end
M C#baz ((stdin):3)
D C#fooey ((stdin):2)
D D ((stdin):5) (...)
-eof
+ EOF
end
it "accepts -a/--all" do
['-a', '--all'].each do |opt|
run(opt)
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
Added objects:
A ((stdin):1)
@@ -122,13 +122,13 @@ def baz; BAR end
D ((stdin):5)
D.bar ((stdin):6)
-eof
+ EOF
end
end
it "accepts --compact and --all" do
run('--compact', '--all')
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
A A ((stdin):1)
A A#foo ((stdin):6)
A A.foo ((stdin):5)
@@ -140,24 +140,24 @@ def baz; BAR end
D C#fooey ((stdin):2)
D D ((stdin):5)
D D.bar ((stdin):6)
-eof
+ EOF
end
it "accepts --no-modified" do
run('--compact', '--no-modified')
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
A A ((stdin):1) (...)
A A::B::C ((stdin):3)
A C.bar ((stdin):10)
A C.foo ((stdin):9)
D C#fooey ((stdin):2)
D D ((stdin):5) (...)
-eof
+ EOF
end
it "accepts --query" do
run('--compact', '--query', 'o.type == :method')
- expect(@data.string).to eq <<-eof
+ expect(@data.string).to eq <<-EOF
A A#foo ((stdin):6)
A A.foo ((stdin):5)
A C.bar ((stdin):10)
@@ -165,7 +165,7 @@ def baz; BAR end
M C#baz ((stdin):3)
D C#fooey ((stdin):2)
D D.bar ((stdin):6)
-eof
+ EOF
end
end
diff --git a/spec/cli/server_spec.rb b/spec/cli/server_spec.rb
index 89337bf74..846b1663c 100644
--- a/spec/cli/server_spec.rb
+++ b/spec/cli/server_spec.rb
@@ -70,7 +70,7 @@ def assert_libraries(expected_libs, actual_libs)
expected_libs.each do |name, libs|
libs.each_with_index do |expected, i|
actual = actual_libs[name][i]
- [:source, :source_path, :yardoc_file].each do |m|
+ %i(source source_path yardoc_file).each do |m|
expect(actual.send(m)).to eq expected.send(m)
end
end
@@ -210,7 +210,7 @@ def mock_file(filename, content = nil)
end
it "accepts --docroot" do
- @server_options[:DocumentRoot] = Dir.pwd + '/__foo/bar'
+ @server_options[:DocumentRoot] = "#{Dir.pwd}/__foo/bar"
run '--docroot', '__foo/bar'
end
@@ -308,7 +308,7 @@ def mock_file(filename, content = nil)
it "loads ruby code (-e) after adapter" do
unstub_adapter
@cli.adapter = Server::WebrickAdapter
- path = File.dirname(__FILE__) + '/tmp.adapterscript.rb'
+ path = "#{File.dirname(__FILE__)}/tmp.adapterscript.rb"
begin
File.open(path, 'w') do |f|
f.puts "YARD::Templates::Engine.register_template_path 'foo'"
diff --git a/spec/cli/stats_spec.rb b/spec/cli/stats_spec.rb
index 42299bfb0..fb9cc2138 100644
--- a/spec/cli/stats_spec.rb
+++ b/spec/cli/stats_spec.rb
@@ -4,7 +4,7 @@
RSpec.describe YARD::CLI::Stats do
before do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class A
CONST = 1
@@ -16,7 +16,7 @@ def foo; end
def bar; end
end
module B; end
- eof
+ EOF
@main_stats =
"Files: 1\n" \
@@ -24,8 +24,8 @@ module B; end
"Classes: 1 ( 1 undocumented)\n" \
"Constants: 1 ( 1 undocumented)\n" \
"Attributes: 1 ( 0 undocumented)\n" \
- "Methods: 2 ( 1 undocumented)\n" \
- " 33.33% documented\n"
+ "Methods: 2 ( 1 undocumented)\n " \
+ "33.33% documented\n"
@output = StringIO.new
@stats = CLI::Stats.new(false)
@@ -36,7 +36,7 @@ module B; end
it "lists undocumented objects with --list-undoc when there are undocumented objects" do
@stats.run('--list-undoc')
- expect(@output.string).to eq <<-eof
+ expect(@output.string).to eq <<-EOF
#{@main_stats}
Undocumented Objects:
@@ -45,35 +45,35 @@ module B; end
A#foo
A::CONST
B
-eof
+ EOF
end
it "lists no undocumented objects with --list-undoc when there is nothing undocumented" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# documentation
def foo; end
- eof
+ EOF
@stats.run('--list-undoc')
expect(@output.string).to eq "Files: 1\n" \
"Modules: 0 ( 0 undocumented)\n" \
"Classes: 0 ( 0 undocumented)\n" \
"Constants: 0 ( 0 undocumented)\n" \
"Attributes: 0 ( 0 undocumented)\n" \
- "Methods: 1 ( 0 undocumented)\n" \
- " 100.00% documented\n"
+ "Methods: 1 ( 0 undocumented)\n " \
+ "100.00% documented\n"
end
it "lists undocumented objects in compact mode with --list-undoc --compact" do
@stats.run('--list-undoc', '--compact')
- expect(@output.string).to eq <<-eof
+ expect(@output.string).to eq <<-EOF
#{@main_stats}
Undocumented Objects:
A ((stdin):1)
A#foo ((stdin):4)
A::CONST ((stdin):2)
B ((stdin):11)
-eof
+ EOF
end
it "still lists stats with --quiet" do
@@ -89,8 +89,8 @@ def foo; end
"Classes: 0 ( 0 undocumented)\n" \
"Constants: 0 ( 0 undocumented)\n" \
"Attributes: 0 ( 0 undocumented)\n" \
- "Methods: 0 ( 0 undocumented)\n" \
- " 100.00% documented\n"
+ "Methods: 0 ( 0 undocumented)\n " \
+ "100.00% documented\n"
)
end
end
diff --git a/spec/cli/yard_on_yard_spec.rb b/spec/cli/yard_on_yard_spec.rb
index 9eda07eef..9de962be3 100644
--- a/spec/cli/yard_on_yard_spec.rb
+++ b/spec/cli/yard_on_yard_spec.rb
@@ -12,7 +12,7 @@
rm_rf File.join($TOPDIR, 'doc')
rm_rf File.join($TOPDIR, '.yardoc')
- # Note: as this is very time consuming, we do it only once
+ # NOTE: as this is very time consuming, we do it only once
Dir.chdir($TOPDIR) do
@res = YARD::CLI::Yardoc.new.run('--title', 'YARD-On-YARD')
end
diff --git a/spec/cli/yardoc_spec.rb b/spec/cli/yardoc_spec.rb
index 1d93b2d16..dddad0400 100644
--- a/spec/cli/yardoc_spec.rb
+++ b/spec/cli/yardoc_spec.rb
@@ -198,7 +198,7 @@ def self.should_accept(*args, &block)
expect(YARD).to receive(:parse)
begin
@yardoc.run(arg)
- rescue SystemExit # rubocop:disable Lint/HandleExceptions
+ rescue SystemExit
end
end
end
@@ -312,7 +312,7 @@ def self.should_accept(*args, &block)
end
it "allows from:to syntax" do
- expect(FileUtils).to receive(:cp_r).with(%r{foo(\/\.)?}, 'doc/bar')
+ expect(FileUtils).to receive(:cp_r).with(%r{foo(/\.)?}, 'doc/bar')
@yardoc.run(*%w(--asset foo:bar))
expect(@yardoc.assets).to eq('foo' => 'bar')
end
@@ -366,38 +366,38 @@ def self.should_accept(*args, &block)
before { Registry.clear }
it "allows --api name" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
# @api public
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--api', 'private')
expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Foo')]
end
it "allows multiple --api's to all be shown" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
# @api public
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--api', 'private', '--api', 'public')
expect(@yardoc.options.verifier.run(Registry.all).
sort_by(&:path)).to eq [P('Bar'), P('Foo')]
end
it "allows --no-api to specify objects with no @api tag" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
# @api public
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--api', '')
expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Baz')]
@yardoc.options.verifier = Verifier.new
@@ -406,13 +406,13 @@ class Baz; end
end
it "allows --no-api to work with other --api switches" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
# @api public
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--no-api', '--api', 'public')
expect(@yardoc.options.verifier.run(Registry.all).
sort_by(&:path)).to eq [P('Bar'), P('Baz')]
@@ -429,25 +429,25 @@ class Baz; end
describe "--hide-api option" do
it "allows --hide-api to hide objects with api tags" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--hide-api', 'private')
expect(@yardoc.options.verifier.run(Registry.all).
sort_by(&:path)).to eq [P('Bar'), P('Baz')]
end
it "allows --hide-api to work with --api" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @api private
class Foo; end
# @api public
class Bar; end
class Baz; end
- eof
+ EOF
@yardoc.run('--api', 'public', '--hide-api', 'private')
expect(@yardoc.options.verifier.run(Registry.all).
sort_by(&:path)).to eq [P('Bar')]
@@ -498,12 +498,12 @@ class Baz; end
it "hides methods inside a 'private' class/module with --no-private" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @private
class ABC
def foo; end
end
- eof
+ EOF
@yardoc.parse_arguments(*%w(--no-private))
expect(@yardoc.options.verifier.call(Registry.at('ABC'))).to be false
expect(@yardoc.options.verifier.call(Registry.at('ABC#foo'))).to be false
@@ -680,8 +680,8 @@ def expect_extra_files_valid(obj, validity_hash = {})
it "selects readme with no suffix over readme with hyphenated suffix" do
expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README-fr.md', 'README.long-extension', 'README-de.md']
- expect_extra_files_valid(@yardoc, 'README-fr.md' => true, 'README.long-extension'=> true, 'README-de.md' => true)
- expect_extra_files_valid(@yardoc, 'README.long-extension'=> true)
+ expect_extra_files_valid(@yardoc, 'README-fr.md' => true, 'README.long-extension' => true, 'README-de.md' => true)
+ expect_extra_files_valid(@yardoc, 'README.long-extension' => true)
expect(File).to receive(:read).with('README.long-extension').and_return('')
@yardoc.parse_arguments
expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.long-extension', '')
@@ -696,7 +696,7 @@ def expect_extra_files_valid(obj, validity_hash = {})
it "selects first readme from lexically sorted list" do
expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README-fr.md', 'README-de.md']
- expect_extra_files_valid(@yardoc, 'README-fr.md'=> true, 'README-de.md' => true)
+ expect_extra_files_valid(@yardoc, 'README-fr.md' => true, 'README-de.md' => true)
expect_extra_files_valid(@yardoc, 'README-de.md' => true)
expect(File).to receive(:read).with('README-de.md').and_return('')
@yardoc.parse_arguments
@@ -705,8 +705,8 @@ def expect_extra_files_valid(obj, validity_hash = {})
it "selects readme that exists over a readme that does not" do
expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README.fr.md', 'README.md', 'README.de.md']
- expect_extra_files_valid(@yardoc, 'README.fr.md'=> true, 'README.md' => false, 'README.de.md' => false)
- expect_extra_files_valid(@yardoc, 'README.fr.md'=> true)
+ expect_extra_files_valid(@yardoc, 'README.fr.md' => true, 'README.md' => false, 'README.de.md' => false)
+ expect_extra_files_valid(@yardoc, 'README.fr.md' => true)
expect(File).to receive(:read).with('README.fr.md').and_return('')
@yardoc.parse_arguments
expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.fr.md', '')
@@ -721,7 +721,7 @@ def expect_extra_files_valid(obj, validity_hash = {})
expect(Encoding.default_external.name).to eq 'ASCII-8BIT'
Encoding.default_internal = ienc
Encoding.default_external = eenc
- end if defined?(::Encoding)
+ end if defined?(Encoding)
end
describe "Source file arguments" do
diff --git a/spec/cli/yri_spec.rb b/spec/cli/yri_spec.rb
index d151bc5bd..07ce22277 100644
--- a/spec/cli/yri_spec.rb
+++ b/spec/cli/yri_spec.rb
@@ -20,7 +20,7 @@ def print_object(*args) test_stub; super end
expect(Registry).to receive(:load).with('bar.yardoc')
expect(Registry).to receive(:at).ordered.with('Foo').and_return(nil)
expect(Registry).to receive(:at).ordered.with('Foo').and_return('OBJ')
- @yri.instance_variable_set("@cache", 'Foo' => 'bar.yardoc')
+ @yri.instance_variable_set(:@cache, 'Foo' => 'bar.yardoc')
expect(@yri.find_object('Foo')).to eq 'OBJ'
end
@@ -30,9 +30,9 @@ def print_object(*args) test_stub; super end
expect(Registry).to receive(:load).with('.yardoc')
expect(Registry).to receive(:at).ordered.with('Foo').and_return(nil)
expect(Registry).to receive(:at).ordered.with('Foo').and_return('OBJ')
- @yri.instance_variable_set("@cache", 'Foo' => 'bar.yardoc')
+ @yri.instance_variable_set(:@cache, 'Foo' => 'bar.yardoc')
expect(@yri.find_object('Foo')).to eq 'OBJ'
- expect(@yri.instance_variable_get("@search_paths")[0]).to eq '.yardoc'
+ expect(@yri.instance_variable_get(:@search_paths)[0]).to eq '.yardoc'
end
end
@@ -51,7 +51,7 @@ def print_object(*args) test_stub; super end
allow(File).to receive(:file?).with(path).and_return(true)
allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2))
@yri = YARD::CLI::YRI.new
- spaths = @yri.instance_variable_get("@search_paths")
+ spaths = @yri.instance_variable_get(:@search_paths)
expect(spaths).to include('line1')
expect(spaths).to include('line2')
end
@@ -64,7 +64,7 @@ def print_object(*args) test_stub; super end
allow(File).to receive(:file?).with(path).and_return(true)
allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2))
@yri = YARD::CLI::YRI.new
- spaths = @yri.instance_variable_get("@search_paths")
+ spaths = @yri.instance_variable_get(:@search_paths)
expect(spaths[0, 4]).to eq %w(foo bar line1 line2)
YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.replace([])
end
@@ -85,7 +85,7 @@ def print_object(*args) test_stub; super end
end
it "prints 'no documentation exists for object' if object is not found" do
- expect(STDERR).to receive(:puts).with("No documentation for `Foo'")
+ expect($stderr).to receive(:puts).with("No documentation for `Foo'")
expect(@yri).to receive(:exit).with(1)
@yri.run('Foo')
end
diff --git a/spec/code_objects/base_spec.rb b/spec/code_objects/base_spec.rb
index 4e766c440..02ae46939 100644
--- a/spec/code_objects/base_spec.rb
+++ b/spec/code_objects/base_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::Base do
before { Registry.clear }
@@ -88,7 +88,7 @@
a = ConstantObject.new(:root, :A)
a.value = "B::C"
b = ClassObject.new(:root, :B)
- c = ClassObject.new(b, :C)
+ ClassObject.new(b, :C)
klass = ClassObject.new(a, "MyClass")
expect(klass.path).to eq "B::C::MyClass"
end
@@ -104,7 +104,7 @@
expect(Registry.at(:Me)).to eq obj
obj2 = ModuleObject.new(obj, :Too)
- expect(Registry.at(:"Me::Too")).to eq obj2
+ expect(Registry.at(:'Me::Too')).to eq obj2
end
describe "#[]=" do
@@ -148,7 +148,7 @@
it "properly re-indents source starting from 0 indentation" do
obj = CodeObjects::Base.new(nil, :test)
- obj.source = <<-eof
+ obj.source = <<-EOF
def mymethod
if x == 2 &&
5 == 5
@@ -157,19 +157,19 @@ def mymethod
1
end
end
- eof
+ EOF
expect(obj.source).to eq "def mymethod\n if x == 2 &&\n 5 == 5\n 3\n else\n 1\n end\nend"
Registry.clear
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
def key?(key)
super(key)
end
- eof
+ EOF
expect(Registry.at('#key?').source).to eq "def key?(key)\n super(key)\nend"
Registry.clear
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
def key?(key)
if x == 2
puts key
@@ -177,12 +177,12 @@ def key?(key)
exit
end
end
- eof
+ EOF
expect(Registry.at('#key?').source).to eq "def key?(key)\n if x == 2\n puts key\n else\n exit\n end\nend"
end
it "does not add newlines to source when parsing sub blocks" do
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
module XYZ
module ZYX
class ABC
@@ -192,7 +192,7 @@ def msg
end
end
end
- eof
+ EOF
expect(Registry.at('XYZ::ZYX::ABC#msg').source).to eq "def msg\n hello_world\nend"
end
@@ -203,19 +203,19 @@ def msg
end
it "sets file and line information" do
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
class X; end
- eof
+ EOF
expect(Registry.at(:X).file).to eq '(stdin)'
expect(Registry.at(:X).line).to eq 1
end
it "maintains all file associations when objects are defined multiple times in one file" do
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
class X; end
class X; end
class X; end
- eof
+ EOF
expect(Registry.at(:X).file).to eq '(stdin)'
expect(Registry.at(:X).line).to eq 1
@@ -234,12 +234,12 @@ class X; end
end
it "prioritizes the definition with a docstring when returning #file" do
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
class X; end
class X; end
# docstring
class X; end
- eof
+ EOF
expect(Registry.at(:X).file).to eq '(stdin)'
expect(Registry.at(:X).line).to eq 4
@@ -427,14 +427,14 @@ class X; end
describe "#copy_to" do
it "copies all data to new object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
private
# A docstring
# @return [String] a tag
def foo(a, b, c)
source_code_here
end
- eof
+ EOF
foo_c = MethodObject.new(:root, :foo, :class)
Registry.at('#foo').copy_to(foo_c)
expect(foo_c.scope).to eq :class
@@ -458,10 +458,10 @@ def foo(a, b, c)
end
it "copies docstring and rewrite tags to new object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @return [String] a tag
def foo; end
- eof
+ EOF
foo_c = MethodObject.new(:root, :foo, :class)
foo_i = Registry.at('#foo')
foo_i.copy_to(foo_c)
diff --git a/spec/code_objects/class_object_spec.rb b/spec/code_objects/class_object_spec.rb
index 15c433f00..3f669dd4f 100644
--- a/spec/code_objects/class_object_spec.rb
+++ b/spec/code_objects/class_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::ClassObject do
describe "#inheritance_tree" do
@@ -49,7 +49,7 @@
before(:all) do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class SuperYard < String
def foo; end
def foo2; end
@@ -76,7 +76,7 @@ def foo; end
class FinalYard < SuperYard
include IncludedYard
end
- eof
+ EOF
end
it "shows inherited methods by default" do
@@ -125,7 +125,7 @@ class FinalYard < SuperYard
before(:all) do
Registry.clear
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
class YARD
CONST1 = 1
CONST2 = "hello"
@@ -140,7 +140,7 @@ class SubYard < SUPERYARD
CONST2 = "hi"
CONST3 = "foo"
end
- eof
+ EOF
end
it "lists inherited constants by default" do
diff --git a/spec/code_objects/code_object_list_spec.rb b/spec/code_objects/code_object_list_spec.rb
index dd4d3a408..c05607bbf 100644
--- a/spec/code_objects/code_object_list_spec.rb
+++ b/spec/code_objects/code_object_list_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::CodeObjectList do
before { Registry.clear }
diff --git a/spec/code_objects/constants_spec.rb b/spec/code_objects/constants_spec.rb
index 3c6b9180d..4df14d192 100644
--- a/spec/code_objects/constants_spec.rb
+++ b/spec/code_objects/constants_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects do
def silence_warnings
@@ -107,7 +107,7 @@ def silence_warnings
it "includes all base modules" do
silence_warnings do
YARD::CodeObjects::BUILTIN_MODULES.each do |name|
- next if YARD.ruby19? && ["Precision"].include?(name)
+ next if YARD.ruby19? && name == "Precision"
expect(eval(name)).to be_instance_of(Module)
end
end
diff --git a/spec/code_objects/extra_file_object_spec.rb b/spec/code_objects/extra_file_object_spec.rb
index c4957bf6b..055be651f 100644
--- a/spec/code_objects/extra_file_object_spec.rb
+++ b/spec/code_objects/extra_file_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::ExtraFileObject do
describe "#initialize" do
diff --git a/spec/code_objects/macro_object_spec.rb b/spec/code_objects/macro_object_spec.rb
index 843d58332..7561a3c82 100644
--- a/spec/code_objects/macro_object_spec.rb
+++ b/spec/code_objects/macro_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::MacroObject do
before do
diff --git a/spec/code_objects/method_object_spec.rb b/spec/code_objects/method_object_spec.rb
index 917524a11..adc11e2cc 100644
--- a/spec/code_objects/method_object_spec.rb
+++ b/spec/code_objects/method_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::MethodObject do
before do
@@ -152,27 +152,27 @@
before { Registry.clear }
it "returns overridden method from mixin first" do
- YARD.parse_string(<<-eof)
+ YARD.parse_string(<<-EOF)
module C; def foo; end end
class A; def foo; end end
class B < A; include C; def foo; end end
- eof
+ EOF
expect(Registry.at('B#foo').overridden_method).to eq Registry.at('C#foo')
end
it "returns overridden method from superclass" do
- YARD.parse_string(<<-eof)
+ YARD.parse_string(<<-EOF)
class A; def foo; end end
class B < A; def foo; end end
- eof
+ EOF
expect(Registry.at('B#foo').overridden_method).to eq Registry.at('A#foo')
end
it "returns nil if none is found" do
- YARD.parse_string(<<-eof)
+ YARD.parse_string(<<-EOF)
class A; end
class B < A; def foo; end end
- eof
+ EOF
expect(Registry.at('B#foo').overridden_method).to be nil
end
diff --git a/spec/code_objects/module_object_spec.rb b/spec/code_objects/module_object_spec.rb
index bfbb09898..d13056023 100644
--- a/spec/code_objects/module_object_spec.rb
+++ b/spec/code_objects/module_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::ModuleObject do
describe "#meths" do
@@ -50,7 +50,7 @@
it "allows :visibility to be set" do
meths = @yard.meths(:visibility => :public)
expect(meths).not_to include(P("YARD.bar"))
- meths = @yard.meths(:visibility => [:public, :private])
+ meths = @yard.meths(:visibility => %i(public private))
expect(meths).to include(P("YARD#foo"))
expect(meths).to include(P("YARD.bar"))
expect(meths).not_to include(P("YARD#foo2"))
diff --git a/spec/code_objects/namespace_mapper_spec.rb b/spec/code_objects/namespace_mapper_spec.rb
index 49a3c59c9..8e838be43 100644
--- a/spec/code_objects/namespace_mapper_spec.rb
+++ b/spec/code_objects/namespace_mapper_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::NamespaceMapper do
include YARD::CodeObjects::NamespaceMapper
diff --git a/spec/code_objects/namespace_object_spec.rb b/spec/code_objects/namespace_object_spec.rb
index 3cc33eb3d..4c46e883a 100644
--- a/spec/code_objects/namespace_object_spec.rb
+++ b/spec/code_objects/namespace_object_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::NamespaceObject do
before { Registry.clear }
@@ -112,7 +112,7 @@
before do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A
CONST1 = 1
CONST2 = 2
@@ -130,7 +130,7 @@ class C
include A
include B
end
- eof
+ EOF
end
it "lists all included constants by default" do
@@ -160,11 +160,11 @@ class C
describe "#included_meths" do
it "returns all included methods with :all = true" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module B; def foo; end end
module C; def bar; end end
class A; include B; include C; def foo; end; def bar; end end
- eof
+ EOF
expect(Registry.at('A').included_meths(:all => true)).to eq [P('C#bar'), P('B#foo')]
end
end
diff --git a/spec/code_objects/proxy_spec.rb b/spec/code_objects/proxy_spec.rb
index 15c0c1c6d..b4dac7da5 100644
--- a/spec/code_objects/proxy_spec.rb
+++ b/spec/code_objects/proxy_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::CodeObjects::Proxy do
before { Registry.clear }
@@ -91,12 +91,12 @@
end
it "uses type to ensure resolved object is of intended type" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
class Bar; end
def self.Bar; end
end
- eof
+ EOF
proxy = Proxy.new(P('Foo'), 'Bar')
proxy.type = :method
expect(proxy.path).to eq 'Foo.Bar'
@@ -138,10 +138,10 @@ def self.Bar; end
end
it "handles constant names in namespaces" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A; end; B = A
module B::C; def foo; end end
- eof
+ EOF
expect(Proxy.new(:root, 'B::C')).to eq Registry.at('A::C')
end
end
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index b592ce4da..eba6b0e3c 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -18,9 +18,9 @@
expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(true)
expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
if YAML.respond_to?(:safe_load_file)
- expect(YAML).to receive(:safe_load_file)
- .with(YARD::Config::CONFIG_FILE, permitted_classes: [SymbolHash, Symbol])
- .and_return('test' => true)
+ expect(YAML).to receive(:safe_load_file).
+ with(YARD::Config::CONFIG_FILE, :permitted_classes => [SymbolHash, Symbol]).
+ and_return('test' => true)
else
expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
end
diff --git a/spec/core_ext/hash_spec.rb b/spec/core_ext/hash_spec.rb
index e93a69140..4b1dfb4b5 100644
--- a/spec/core_ext/hash_spec.rb
+++ b/spec/core_ext/hash_spec.rb
@@ -4,11 +4,11 @@
describe ".[]" do
it "accepts an Array argument (Ruby 1.8.6 and older)" do
list = [['foo', 'bar'], ['foo2', 'bar2']]
- expect(Hash[list]).to eq('foo' => 'bar', 'foo2' => 'bar2')
+ expect(list.to_h).to eq('foo' => 'bar', 'foo2' => 'bar2')
end
it "accepts an array as a key" do
- expect(Hash[['a', 'b'], 1]).to eq(['a', 'b'] => 1)
+ expect({['a', 'b'] => 1}).to eq(['a', 'b'] => 1)
end
end
end
diff --git a/spec/core_ext/symbol_hash_spec.rb b/spec/core_ext/symbol_hash_spec.rb
index 35738f576..0e546e30d 100644
--- a/spec/core_ext/symbol_hash_spec.rb
+++ b/spec/core_ext/symbol_hash_spec.rb
@@ -62,7 +62,7 @@ class Substring < String; end
h = SymbolHash.new
h.update('test' => 'value')
expect(h[:test]).to eq :value
- h.merge!('test' => 'value2') # rubocop:disable Performance/RedundantMerge
+ h.merge!('test' => 'value2')
expect(h[:test]).to eq :value2
end
diff --git a/spec/docstring_parser_spec.rb b/spec/docstring_parser_spec.rb
index 1d6a9d33c..29e9dd88f 100644
--- a/spec/docstring_parser_spec.rb
+++ b/spec/docstring_parser_spec.rb
@@ -18,7 +18,7 @@ def docstring(content, object = nil, handler = nil)
describe "#parse" do
it "parses comments into tags" do
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
@param name Hello world
how are you?
@param name2
@@ -27,7 +27,7 @@ def docstring(content, object = nil, handler = nil)
is a new paragraph:
right here.
- eof
+ EOF
tags = doc.tags(:param)
expect(tags[0].name).to eq "name"
expect(tags[0].text).to eq "Hello world\nhow are you?"
@@ -38,17 +38,17 @@ def docstring(content, object = nil, handler = nil)
end
it "ends parsing a tag on de-dent" do
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
@note test
one two three
rest of docstring
- eof
+ EOF
expect(doc.tag(:note).text).to eq "test\none two three"
expect(doc).to eq "rest of docstring"
end
it "parses examples embedded in doc" do
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
test string here
@example code
@@ -58,18 +58,18 @@ def foo(x, y, z)
class A; end
more stuff
-eof
+ EOF
expect(doc).to eq "test string here\nmore stuff"
expect(doc.tag(:example).text).to eq "\ndef foo(x, y, z)\nend\n\nclass A; end"
end
it "removes only original indentation from beginning of line in tags" do
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
@param name
some value
foo bar
baz
-eof
+ EOF
expect(doc.tag(:param).text).to eq "some value\nfoo bar\n baz"
end
@@ -77,21 +77,21 @@ class A; end
Tags::Library.define_tag(nil, :foo1)
Tags::Library.define_tag(nil, :foo2)
Tags::Library.define_tag(nil, :foo3)
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
@foo1 bar1
@foo2 bar2
@foo3 bar3
-eof
+ EOF
expect(doc.tag(:foo1).text).to eq "bar1"
expect(doc.tag(:foo2).text).to eq "bar2"
end
it "ends tag on newline if next line is not indented" do
- doc = docstring(<<-eof)
+ doc = docstring(<<-EOF)
@author bar1
@api bar2
Hello world
-eof
+ EOF
expect(doc.tag(:author).text).to eq "bar1"
expect(doc.tag(:api).text).to eq "bar2"
end
@@ -116,7 +116,7 @@ class TestLibrary < Tags::Library; end
valid = %w(testing valid is_a is_A __)
valid.each do |tag|
TestLibrary.define_tag("Tag", tag)
- doc = docstring('@' + tag + ' foo bar')
+ doc = docstring("@#{tag} foo bar")
expect(doc.tag(tag).text).to eq 'foo bar'
end
end
@@ -124,7 +124,7 @@ class TestLibrary < Tags::Library; end
it "does not parse invalid tag names" do
invalid = %w(@ @return@ @p,aram @x-y @.x.y.z)
invalid.each do |tag|
- expect(docstring(tag + ' foo bar')).to eq tag + ' foo bar'
+ expect(docstring("#{tag} foo bar")).to eq "#{tag} foo bar"
end
end
@@ -209,55 +209,55 @@ class TestLibrary < Tags::Library; end
it "warns about invalid named parameters" do
expect(log).to receive(:warn).with(/@param tag has unknown parameter name: notaparam/)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @param notaparam foo
def foo(a) end
- eof
+ EOF
end
it "warns about invalid named parameters on @!method directives" do
expect(log).to receive(:warn).with(/@param tag has unknown parameter name: notaparam/)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!method foo(a)
# @param notaparam foo
test
- eof
+ EOF
end
it "warns about duplicate named parameters" do
expect(log).to receive(:warn).with(/@param tag has duplicate parameter name: a/)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @param a foo
# @param a foo
def foo(a) end
- eof
+ EOF
end
it "does not warn on aliases" do
expect(log).to_not receive(:warn)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @param a foo
def foo(a) end
alias bar foo
- eof
+ EOF
end
it "does not warn on matching param with inline method modifier" do
expect(log).to_not receive(:warn)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @param [Numeric] a
# @return [Numeric]
private_class_method def self.foo(a); a + 1; end
- eof
+ EOF
end
it "warns on mismatching param with inline method modifier" do
expect(log).to receive(:warn).with(/@param tag has unknown parameter name: notaparam/)
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @param [Numeric] notaparam
# @return [Numeric]
private_class_method def self.foo(a); a + 1; end
- eof
+ EOF
end
end
diff --git a/spec/docstring_spec.rb b/spec/docstring_spec.rb
index 999afd414..1b77e7c9d 100644
--- a/spec/docstring_spec.rb
+++ b/spec/docstring_spec.rb
@@ -24,7 +24,7 @@
end
it "adds a String" do
- d = Docstring.new("FOO") + "BAR"
+ d = "#{Docstring.new("FOO")}BAR"
expect(d).to eq "FOOBAR"
end
end
@@ -78,13 +78,13 @@
o = Docstring.new("Returns a list of tags specified by +name+ or all tags if +name+ is not specified.\n\nTest")
expect(o.summary).to eq "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
- doc = Docstring.new(<<-eof)
+ doc = Docstring.new(<<-EOF)
Returns a list of tags specified by +name+ or all tags if +name+ is not specified.
@param name the tag name to return data for, or nil for all tags
@return [Array] the list of tags by the specified tag name
- eof
+ EOF
expect(doc.summary).to eq "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
end
@@ -183,14 +183,14 @@
end
it "returns an empty list (and warning) if circular reftags are found" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @param (see #b)
def a; end
# @param (see #a)
def b; end
end
- eof
+ EOF
expect(log.io.string).to match(/error.*circular reference tag in `Foo#b'/)
expect(Registry.at('Foo#a').tags).to be_empty
@@ -198,12 +198,12 @@ def b; end
end
it "returns an empty list (and warning) if self-circular reftags are found" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @param (see #bar)
def bar; end
end
- eof
+ EOF
expect(log.io.string).to match(/error.*circular reference tag in `Foo#bar'/)
expect(Registry.at('Foo#bar').tags).to be_empty
@@ -353,7 +353,7 @@ def bar; end
describe "reference docstrings" do
it "allows for construction of docstring with ref object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class A
# Docstring
# @return [Boolean]
@@ -361,7 +361,7 @@ def a; end
# (see #a)
def b; end
end
- eof
+ EOF
object = YARD::Registry.at('A#b')
expect(object.docstring).to eq 'Docstring'
diff --git a/spec/handlers/alias_handler_spec.rb b/spec/handlers/alias_handler_spec.rb
index 381c8503f..4eb177929 100644
--- a/spec/handlers/alias_handler_spec.rb
+++ b/spec/handlers/alias_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}AliasHandler" do
before(:all) { parse_file :alias_handler_001, __FILE__ }
@@ -10,8 +10,8 @@
['c', 'd?', '[]', '[]=', '-@', '%', '*', 'cstrkey', 'cstrmeth'].each do |a|
it "handles the Ruby 'alias' keyword syntax for method ##{a}" do
- expect(P('A#' + a)).to be_instance_of(CodeObjects::MethodObject)
- expect(P('A#' + a).is_alias?).to be true
+ expect(P("A##{a}")).to be_instance_of(CodeObjects::MethodObject)
+ expect(P("A##{a}").is_alias?).to be true
end
end
diff --git a/spec/handlers/attribute_handler_spec.rb b/spec/handlers/attribute_handler_spec.rb
index 572a12ac8..e97473144 100644
--- a/spec/handlers/attribute_handler_spec.rb
+++ b/spec/handlers/attribute_handler_spec.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}AttributeHandler" do
before(:all) { parse_file :attribute_handler_001, __FILE__ }
def read_write(namespace, name, read, write, scope = :instance)
- rname = namespace.to_s + "#" + name.to_s
- wname = namespace.to_s + "#" + name.to_s + "="
+ rname = "#{namespace}##{name}"
+ wname = "#{namespace}##{name}="
if read
expect(Registry.at(rname)).to be_instance_of(CodeObjects::MethodObject)
else
diff --git a/spec/handlers/base_spec.rb b/spec/handlers/base_spec.rb
index 0bfbdfc28..d98c556c8 100644
--- a/spec/handlers/base_spec.rb
+++ b/spec/handlers/base_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
include Parser
@@ -26,7 +26,7 @@ class TestNotImplementedHandler < Handlers::Base
class TestHandler1 < Handlers::Base
handles :a, :b, :c
end
- expect(TestHandler1.handlers).to eq [:a, :b, :c]
+ expect(TestHandler1.handlers).to eq %i(a b c)
end
it "allows multiple handles calls" do
@@ -36,7 +36,7 @@ class TestHandler2 < Handlers::Base
handles :b
handles :c
end
- expect(TestHandler2.handlers).to eq [:a, :b, :c]
+ expect(TestHandler2.handlers).to eq %i(a b c)
end
end
@@ -52,7 +52,7 @@ class AbortHandler1 < Handlers::Ruby::Base
describe "transitive tags" do
it "adds transitive tags to children" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @since 1.0
# @author Foo
class A
@@ -60,7 +60,7 @@ def foo; end
# @since 1.1
def bar; end
end
- eof
+ EOF
expect(Registry.at('A').tag(:since).text).to eq "1.0"
expect(Registry.at('A#foo').tag(:since).text).to eq "1.0"
expect(Registry.at('A#bar').tag(:since).text).to eq "1.1"
@@ -153,20 +153,20 @@ def process
describe ".in_file" do
def parse(filename, parser_type, src = "class A; end")
parser = Parser::SourceParser.new(parser_type)
- parser.instance_variable_set("@file", filename)
+ parser.instance_variable_set(:@file, filename)
parser.parse(StringIO.new(src))
end
def create_handler(stmts, parser_type)
$handler_counter ||= 0
sklass = parser_type == :ruby ? "Base" : "Legacy::Base"
- instance_eval(<<-eof, __FILE__, __LINE__ + 1)
+ instance_eval(<<-EOF, __FILE__, __LINE__ + 1)
class ::InFileHandler#{$handler_counter += 1} < Handlers::Ruby::#{sklass}
handles(/^class/)
#{stmts}
def process; MethodObject.new(:root, :FOO) end
end
- eof
+ EOF
end
def test_handler(file, stmts, creates = true, parser_type = :ruby)
@@ -178,7 +178,7 @@ def test_handler(file, stmts, creates = true, parser_type = :ruby)
Handlers::Base.subclasses.delete_if {|k, _v| k.to_s =~ /^InFileHandler/ }
end
- [:ruby, :ruby18].each do |parser_type|
+ %i(ruby ruby18).each do |parser_type|
next if parser_type == :ruby && LEGACY_PARSER
describe "Parser type = #{parser_type.inspect}" do
it "allows handler to be specific to a file" do
diff --git a/spec/handlers/c/alias_handler_spec.rb b/spec/handlers/c/alias_handler_spec.rb
index 10d57e22f..fb3e6c6a7 100644
--- a/spec/handlers/c/alias_handler_spec.rb
+++ b/spec/handlers/c/alias_handler_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::AliasHandler do
it "allows defining of aliases (rb_define_alias)" do
- parse <<-eof
+ parse <<-EOF
/* FOO */
VALUE foo(VALUE x) { int value = x; }
void Init_Foo() {
@@ -11,14 +11,14 @@
rb_define_method(rb_cFoo, "foo", foo, 1);
rb_define_alias(rb_cFoo, "bar", "foo");
}
- eof
+ EOF
expect(Registry.at('Foo#bar')).to be_is_alias
expect(Registry.at('Foo#bar').docstring).to eq 'FOO'
end
it "allows defining of aliases (rb_define_alias) of attributes" do
- parse <<-eof
+ parse <<-EOF
/* FOO */
VALUE foo(VALUE x) { int value = x; }
void Init_Foo() {
@@ -26,7 +26,7 @@
rb_define_attr(rb_cFoo, "foo", 1, 0);
rb_define_alias(rb_cFoo, "foo?", "foo");
}
- eof
+ EOF
expect(Registry.at('Foo#foo')).to be_reader
expect(Registry.at('Foo#foo?')).to be_is_alias
diff --git a/spec/handlers/c/attribute_handler_spec.rb b/spec/handlers/c/attribute_handler_spec.rb
index f631b5362..62649a5b3 100644
--- a/spec/handlers/c/attribute_handler_spec.rb
+++ b/spec/handlers/c/attribute_handler_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::AttributeHandler do
def run(read, write, commented = nil)
- parse <<-eof
+ parse <<-EOF
/* FOO */
VALUE foo(VALUE x) { int value = x; }
void Init_Foo() {
@@ -12,7 +12,7 @@ def run(read, write, commented = nil)
rb_define_attr(rb_cFoo, "foo", #{read}, #{write});
#{commented ? '*/' : ''}
}
- eof
+ EOF
end
it "handles readonly attribute (rb_define_attr)" do
diff --git a/spec/handlers/c/class_handler_spec.rb b/spec/handlers/c/class_handler_spec.rb
index f79625982..ac983c37a 100644
--- a/spec/handlers/c/class_handler_spec.rb
+++ b/spec/handlers/c/class_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::ClassHandler do
it "registers classes" do
@@ -17,51 +17,51 @@
end
it "remembers symbol defined with class" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
cXYZ = rb_define_class("Foo", rb_cObject);
rb_define_method(cXYZ, "bar", bar, 0);
- eof
+ EOF
expect(Registry.at('Foo').type).to eq :class
expect(Registry.at('Foo#bar')).not_to be nil
end
it "looks up superclass symbol name" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
cXYZ = rb_define_class("Foo", rb_cObject);
cBar = rb_define_class("Bar", cXYZ);
- eof
+ EOF
expect(Registry.at('Bar').superclass).to eq Registry.at('Foo')
end
it "uses superclass symbol name as proxy if not found" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
// cXYZ = rb_define_class("Foo", rb_cObject);
cBar = rb_define_class("Bar", cXYZ);
- eof
+ EOF
expect(Registry.at('Bar').superclass).to eq P('XYZ')
end
it "does not associate declaration comments as class docstring" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
/* Docstring! */
cFoo = rb_define_class("Foo", cObject);
- eof
+ EOF
expect(Registry.at('Foo').docstring).to be_blank
end
it "associates a file with the declaration" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
cFoo = rb_define_class("Foo", cObject);
- eof
+ EOF
expect(Registry.at('Foo').file).to eq '(stdin)'
expect(Registry.at('Foo').line).to eq 2
end
it "properly handles Proxy superclasses" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
cBar = rb_define_class_under(mFoo, "Bar", rb_cBar);
- eof
+ EOF
expect(Registry.at('Foo::Bar').type).to eq :class
expect(Registry.at('Foo::Bar').superclass).to eq P('Bar')
expect(Registry.at('Foo::Bar').superclass.type).to eq :class
diff --git a/spec/handlers/c/constant_handler_spec.rb b/spec/handlers/c/constant_handler_spec.rb
index a311c0919..edbd19187 100644
--- a/spec/handlers/c/constant_handler_spec.rb
+++ b/spec/handlers/c/constant_handler_spec.rb
@@ -1,19 +1,19 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::ConstantHandler do
it "registers constants" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_const(mFoo, "FOO", ID2SYM(100));
rb_define_global_const("BAR", ID2SYM(100));
- eof
+ EOF
expect(Registry.at('Foo::FOO').type).to eq :constant
expect(Registry.at('BAR').type).to eq :constant
end
it "looks for override comments" do
- parse <<-eof
+ parse <<-EOF
/* Document-const: FOO
* Document-const: Foo::BAR
* Foo bar!
@@ -24,7 +24,7 @@
rb_define_const(mFoo, "FOO", ID2SYM(100));
rb_define_const(mFoo, "BAR", ID2SYM(101));
}
- eof
+ EOF
foo = Registry.at('Foo::FOO')
expect(foo.type).to eq :constant
expect(foo.docstring).to eq 'Foo bar!'
@@ -40,30 +40,30 @@
end
it "uses comment attached to declaration as fallback" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_const(mFoo, "FOO", ID2SYM(100)); // foobar!
- eof
+ EOF
foo = Registry.at('Foo::FOO')
expect(foo.value).to eq 'ID2SYM(100)'
expect(foo.docstring).to eq 'foobar!'
end
it "allows the form VALUE: DOCSTRING to document value" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_const(mFoo, "FOO", ID2SYM(100)); // 100: foobar!
- eof
+ EOF
foo = Registry.at('Foo::FOO')
expect(foo.value).to eq '100'
expect(foo.docstring).to eq 'foobar!'
end
it "allows escaping of backslashes in VALUE: DOCSTRING syntax" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_const(mFoo, "FOO", ID2SYM(100)); // 100\\:x\\:y: foobar:x!
- eof
+ EOF
foo = Registry.at('Foo::FOO')
expect(foo.value).to eq '100:x:y'
expect(foo.docstring).to eq 'foobar:x!'
diff --git a/spec/handlers/c/init_handler_spec.rb b/spec/handlers/c/init_handler_spec.rb
index 2f0a408f3..6f8b71345 100644
--- a/spec/handlers/c/init_handler_spec.rb
+++ b/spec/handlers/c/init_handler_spec.rb
@@ -1,28 +1,28 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::InitHandler do
it "adds documentation in Init_ClassName() to ClassName" do
- parse(<<-eof)
+ parse(<<-EOF)
// Bar!
void Init_A() {
rb_cA = rb_define_class("A", rb_cObject);
}
- eof
+ EOF
expect(Registry.at('A').docstring).to eq 'Bar!'
end
it "does not add documentation if ClassName is not created in Init" do
- parse(<<-eof)
+ parse(<<-EOF)
// Bar!
void Init_A() {
}
- eof
+ EOF
expect(Registry.at('A')).to be nil
end
it "does not overwrite override comment" do
- parse(<<-eof)
+ parse(<<-EOF)
/* Document-class: A
* Foo!
*/
@@ -31,17 +31,17 @@
static SWIGEXPORT void Init_A() {
rb_cA = rb_define_class("A", rb_cObject);
}
- eof
+ EOF
expect(Registry.at('A').docstring).to eq 'Foo!'
end
it "checks non-Init methods for declarations too" do
- parse(<<-eof)
+ parse(<<-EOF)
void foo(int x, int y, char *name) {
rb_cB = rb_define_class("B", rb_cObject);
rb_define_method(rb_cB, "foo", foo_impl, 0);
}
- eof
+ EOF
expect(Registry.at('B')).to be_a(CodeObjects::ClassObject)
expect(Registry.at('B#foo')).to be_a(CodeObjects::MethodObject)
end
diff --git a/spec/handlers/c/method_handler_spec.rb b/spec/handlers/c/method_handler_spec.rb
index 51fee3128..582f96272 100644
--- a/spec/handlers/c/method_handler_spec.rb
+++ b/spec/handlers/c/method_handler_spec.rb
@@ -1,36 +1,36 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::MethodHandler do
it "registers methods" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "bar", bar, 0);
- eof
+ EOF
expect(Registry.at('Foo#bar')).not_to be nil
expect(Registry.at('Foo#bar').visibility).to eq :public
end
it "registers private methods" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_private_method(mFoo, "bar", bar, 0);
- eof
+ EOF
expect(Registry.at('Foo#bar')).not_to be nil
expect(Registry.at('Foo#bar').visibility).to eq :private
end
it "registers singleton methods" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_singleton_method(mFoo, "bar", bar, 0);
- eof
+ EOF
expect(Registry.at('Foo.bar')).not_to be nil
expect(Registry.at('Foo.bar').visibility).to eq :public
end
it "registers module functions" do
- parse <<-eof
+ parse <<-EOF
/* DOCSTRING
* @return [String] foo!
*/
@@ -40,7 +40,7 @@
mFoo = rb_define_module("Foo");
rb_define_module_function(mFoo, "bar", bar, 0);
}
- eof
+ EOF
bar_c = Registry.at('Foo.bar')
bar_i = Registry.at('Foo#bar')
expect(bar_c).to be_module_function
@@ -61,7 +61,7 @@
end
it "looks for symbol containing method source" do
- parse <<-eof
+ parse <<-EOF
static VALUE foo(VALUE self) { x(); y(); z(); }
VALUE bar() { a(); b(); c(); }
void Init_Foo() {
@@ -69,7 +69,7 @@
rb_define_method(mFoo, "foo", foo, 0);
rb_define_method(mFoo, "bar", bar, 0);
}
- eof
+ EOF
foo = Registry.at('Foo#foo')
bar = Registry.at('Foo#bar')
expect(foo.source).to eq "static VALUE foo(VALUE self) { x(); y(); z(); }"
@@ -81,20 +81,20 @@
end
it "finds docstrings attached to method symbols" do
- parse <<-eof
+ parse <<-EOF
/* DOCSTRING */
static VALUE foo(VALUE self) { x(); y(); z(); }
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo", foo, 0);
}
- eof
+ EOF
foo = Registry.at('Foo#foo')
expect(foo.docstring).to eq 'DOCSTRING'
end
it "uses declaration comments as docstring if there are no others" do
- parse <<-eof
+ parse <<-EOF
static VALUE foo(VALUE self) { x(); y(); z(); }
void Init_Foo() {
mFoo = rb_define_module("Foo");
@@ -103,7 +103,7 @@
// DOCSTRING!
rb_define_method(mFoo, "bar", bar, 0);
}
- eof
+ EOF
foo = Registry.at('Foo#foo')
expect(foo.docstring).to eq 'DOCSTRING'
bar = Registry.at('Foo#bar')
@@ -111,17 +111,17 @@
end
it "looks for symbols in other file" do
- other = <<-eof
+ other = <<-EOF
/* DOCSTRING! */
static VALUE foo() { x(); }
- eof
+ EOF
expect(File).to receive(:read).with('other.c').and_return(other)
- parse <<-eof
+ parse <<-EOF
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo", foo, 0); // in other.c
}
- eof
+ EOF
foo = Registry.at('Foo#foo')
expect(foo.docstring).to eq 'DOCSTRING!'
expect(foo.file).to eq 'other.c'
@@ -130,33 +130,33 @@
end
it "allows extra file to include /'s and other filename characters" do
- expect(File).to receive(:read).at_least(1).times.with('ext/a-file.c').and_return(<<-eof)
+ expect(File).to receive(:read).at_least(1).times.with('ext/a-file.c').and_return(<<-EOF)
/* FOO */
VALUE foo(VALUE x) { int value = x; }
/* BAR */
VALUE bar(VALUE x) { int value = x; }
- eof
- parse_init <<-eof
+ EOF
+ parse_init <<-EOF
rb_define_method(rb_cFoo, "foo", foo, 1); /* in ext/a-file.c */
rb_define_global_function("bar", bar, 1); /* in ext/a-file.c */
- eof
+ EOF
expect(Registry.at('Foo#foo').docstring).to eq 'FOO'
expect(Registry.at('Kernel#bar').docstring).to eq 'BAR'
end
it "warns if other file can't be found" do
expect(log).to receive(:warn).with(/Missing source file `other.c' when parsing Foo#foo/)
- parse <<-eof
+ parse <<-EOF
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo", foo, 0); // in other.c
}
- eof
+ EOF
end
it "looks at override comments for docstring" do
- parse <<-eof
+ parse <<-EOF
/* Document-method: Foo::foo
* Document-method: new
* Document-method: Foo::Bar#baz
@@ -171,22 +171,22 @@
mBar = rb_define_module_under(mFoo, "Bar");
rb_define_method(mBar, "baz", foo, 0);
}
- eof
+ EOF
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
end
it "looks at overrides in other files" do
- other = <<-eof
+ other = <<-EOF
/* Document-method: Foo::foo
* Document-method: new
* Document-method: Foo::Bar#baz
* Foo bar!
*/
- eof
+ EOF
expect(File).to receive(:read).with('foo/bar/other.c').and_return(other)
- src = <<-eof
+ src = <<-EOF
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo", foo, 0); // in foo/bar/other.c
@@ -194,7 +194,7 @@
mBar = rb_define_module_under(mFoo, "Bar"); // in foo/bar/other.c
rb_define_method(mBar, "baz", foo, 0); // in foo/bar/other.c
}
- eof
+ EOF
parse(src, 'foo/bar/baz/init.c')
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
@@ -202,14 +202,14 @@
end
it "adds return tag on methods ending in '?'" do
- parse <<-eof
+ parse <<-EOF
/* DOCSTRING */
static VALUE foo(VALUE self) { x(); y(); z(); }
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo?", foo, 0);
}
- eof
+ EOF
foo = Registry.at('Foo#foo?')
expect(foo.docstring).to eq 'DOCSTRING'
expect(foo.tag(:return).types).to eq ['Boolean']
@@ -217,31 +217,31 @@
end
it "does not add return tag if return tags exist" do
- parse <<-eof
+ parse <<-EOF
// @return [String] foo
static VALUE foo(VALUE self) { x(); y(); z(); }
void Init_Foo() {
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "foo?", foo, 0);
}
- eof
+ EOF
foo = Registry.at('Foo#foo?')
expect(foo.tag(:return).types).to eq ['String']
expect(foo.tags(:return).size).to eq 1
end
it "handles casted method names" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_define_method(mFoo, "bar", (METHOD)bar, 0);
rb_define_global_function("baz", (METHOD)baz, 0);
- eof
+ EOF
expect(Registry.at('Foo#bar')).not_to be nil
expect(Registry.at('Kernel#baz')).not_to be nil
end
it "extracts at regular method parameters from C function signatures" do
- parse <<-eof
+ parse <<-EOF
static VALUE noargs_func(VALUE self) { return Qnil; }
static VALUE twoargs_func(VALUE self, VALUE a, VALUE b) { return a; }
void Init_Foo() {
@@ -249,13 +249,13 @@
rb_define_method(mFoo, "noargs", noargs_func, 0);
rb_define_method(mFoo, "twoargs", twoargs_func, 2);
}
- eof
+ EOF
expect(Registry.at('Foo#noargs').parameters).to be_empty
expect(Registry.at('Foo#twoargs').parameters).to eq [['a', nil], ['b', nil]]
end
it "extracts at varargs method parameters from C function signatures" do
- parse <<-eof
+ parse <<-EOF
static VALUE varargs_func(int argc, VALUE *argv, VALUE self) { return self; }
/* let's see if parser is robust in the face of strange spacing */
static VALUE varargs_func2( int argc , VALUE
@@ -267,13 +267,13 @@
rb_define_method(mFoo, "varargs", varargs_func, -1);
rb_define_method( mFoo ,"varargs2",varargs_func2 ,-1);
}
- eof
+ EOF
expect(Registry.at('Foo#varargs').parameters).to eq [['*args', nil]]
expect(Registry.at('Foo#varargs2').parameters).to eq [['*args', nil]]
end
it "is not too strict or too loose about matching override comments to methods" do
- parse <<-eof
+ parse <<-EOF
/* Document-method: Foo::foo
* Document-method: new
* Document-method: Foo::Bar#baz
@@ -297,7 +297,7 @@
rb_define_method(mBar, "baz", foo, 0);
rb_define_singleton_method(mBar, "baz", foo, 0);
}
- eof
+ EOF
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
expect(Registry.at('Foo.foo').docstring).to eq 'Foo bar!'
expect(Registry.at('Foo::Bar#foo').docstring).to be_empty
@@ -311,11 +311,11 @@
end
it "recognizes core Ruby classes and modules provided by ruby.h" do
- parse_init <<-eof
+ parse_init <<-EOF
rb_define_method(rb_cFixnum, "popcount", fix_popcount, 0);
rb_define_private_method(rb_mKernel, "pp", obj_pp, 0);
rb_define_method(rb_mEnumerable, "to_hash", enum_to_hash, 0);
- eof
+ EOF
expect(Registry.at('Fixnum').type).to eq :class
expect(Registry.at('Fixnum#popcount').type).to eq :method
expect(Registry.at('Object').type).to eq :class
diff --git a/spec/handlers/c/mixin_handler_spec.rb b/spec/handlers/c/mixin_handler_spec.rb
index 0049875fe..cd19fa669 100644
--- a/spec/handlers/c/mixin_handler_spec.rb
+++ b/spec/handlers/c/mixin_handler_spec.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::MixinHandler do
it "adds includes to modules or classes" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
cBar = rb_define_class("Bar", rb_cObject);
mBaz = rb_define_module("Baz");
rb_include_module(cBar, mFoo);
rb_include_module(mBaz, mFoo);
- eof
+ EOF
foo = Registry.at('Foo')
bar = Registry.at('Bar')
baz = Registry.at('Baz')
@@ -18,17 +18,17 @@
end
it "adds include as proxy if symbol lookup fails" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
rb_include_module(mFoo, mXYZ);
- eof
+ EOF
foo = Registry.at('Foo')
expect(foo.mixins(:instance)).to eq [P('XYZ')]
end
it "fails if mixin variable cannot be detected" do
with_parser(:c) do
- undoc_error <<-eof
+ undoc_error <<-EOF
void Init_Foo() {
VALUE noprefix;
@@ -38,7 +38,7 @@
rb_include_module(mFoo, noprefix);
}
- eof
+ EOF
end
end
end
diff --git a/spec/handlers/c/module_handler_spec.rb b/spec/handlers/c/module_handler_spec.rb
index 9df55b4ba..a3635e560 100644
--- a/spec/handlers/c/module_handler_spec.rb
+++ b/spec/handlers/c/module_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::ClassHandler do
it "registers modules" do
@@ -16,26 +16,26 @@
end
it "remembers symbol defined with class" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
cXYZ = rb_define_module("Foo");
rb_define_method(cXYZ, "bar", bar, 0);
- eof
+ EOF
expect(Registry.at('Foo').type).to eq :module
expect(Registry.at('Foo#bar')).not_to be nil
end
it "does not associate declaration comments as module docstring" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
/* Docstring! */
mFoo = rb_define_module("Foo");
- eof
+ EOF
expect(Registry.at('Foo').docstring).to be_blank
end
it "associates a file with the declaration" do
- parse_init(<<-eof)
+ parse_init(<<-EOF)
mFoo = rb_define_module("Foo");
- eof
+ EOF
expect(Registry.at('Foo').file).to eq '(stdin)'
expect(Registry.at('Foo').line).to eq 2
end
@@ -51,21 +51,21 @@
it "raises undoc error if a class is defined under a namespace that cannot be resolved" do
with_parser(:c) do
- undoc_error <<-eof
+ undoc_error <<-EOF
void Init_Foo() {
mFoo = rb_define_class_under(invalid, "Foo", rb_cObject);
}
- eof
+ EOF
end
end unless ENV['LEGACY']
it "raises undoc error if a module is defined under a namespace that cannot be resolved" do
with_parser(:c) do
- undoc_error <<-eof
+ undoc_error <<-EOF
void Init_Foo() {
mFoo = rb_define_module_under(invalid, "Foo");
}
- eof
+ EOF
end
end unless ENV['LEGACY']
end
diff --git a/spec/handlers/c/override_comment_handler_spec.rb b/spec/handlers/c/override_comment_handler_spec.rb
index fddf5f70d..140d266fa 100644
--- a/spec/handlers/c/override_comment_handler_spec.rb
+++ b/spec/handlers/c/override_comment_handler_spec.rb
@@ -1,16 +1,16 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::OverrideCommentHandler do
- [:class, :module].each do |type|
+ %i(class module).each do |type|
it "handles Document-#{type}" do
- parse(<<-eof)
+ parse(<<-EOF)
void something;
/* Document-#{type}: A
* Foo bar baz
*/
void
- eof
+ EOF
expect(Registry.at('A').type).to eq type
expect(Registry.at('A').docstring).to eq 'Foo bar baz'
expect(Registry.at('A').file).to eq '(stdin)'
@@ -19,13 +19,13 @@
end
it "handles multiple class/module combinations" do
- parse(<<-eof)
+ parse(<<-EOF)
/* Document-class: A
* Document-class: B
* Document-module: C
* Foo bar baz
*/
- eof
+ EOF
expect(Registry.at('A').docstring).to eq 'Foo bar baz'
expect(Registry.at('B').docstring).to eq 'Foo bar baz'
expect(Registry.at('C').docstring).to eq 'Foo bar baz'
@@ -33,12 +33,12 @@
end
it "handles Document-class with inheritance" do
- parse(<<-eof)
+ parse(<<-EOF)
/* Document-class: A < B
* Foo bar baz
*/
void
- eof
+ EOF
obj = Registry.at('A')
expect(obj.type).to eq :class
expect(obj.docstring).to eq 'Foo bar baz'
diff --git a/spec/handlers/c/path_handler_spec.rb b/spec/handlers/c/path_handler_spec.rb
index 5b475c350..179b08084 100644
--- a/spec/handlers/c/path_handler_spec.rb
+++ b/spec/handlers/c/path_handler_spec.rb
@@ -1,36 +1,36 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::PathHandler do
it "tracks variable names defined under namespaces" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
rb_define_method(cBar, "foo", foo, 1);
- eof
+ EOF
expect(Registry.at('Foo::Bar')).not_to be nil
expect(Registry.at('Foo::Bar#foo')).not_to be nil
end
it "tracks variable names defined under namespaces" do
- parse_init <<-eof
+ parse_init <<-EOF
mFoo = rb_define_module("Foo");
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
mBaz = rb_define_module_under(cBar, "Baz");
rb_define_method(mBaz, "foo", foo, 1);
- eof
+ EOF
expect(Registry.at('Foo::Bar::Baz')).not_to be nil
expect(Registry.at('Foo::Bar::Baz#foo')).not_to be nil
end
it "handles rb_path2class() calls" do
- parse_init <<-eof
+ parse_init <<-EOF
somePath = rb_path2class("Foo::Bar::Baz")
mFoo = rb_define_module("Foo");
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
mBaz = rb_define_module_under(cBar, "Baz");
rb_define_method(somePath, "foo", foo, 1);
- eof
+ EOF
expect(Registry.at('Foo::Bar::Baz#foo')).not_to be nil
end
end
diff --git a/spec/handlers/c/struct_handler_spec.rb b/spec/handlers/c/struct_handler_spec.rb
index 72f5914f6..bc17f99de 100644
--- a/spec/handlers/c/struct_handler_spec.rb
+++ b/spec/handlers/c/struct_handler_spec.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::C::StructHandler do
after { Registry.clear }
it "handles Struct class definitions" do
- parse_init <<-eof
+ parse_init <<-EOF
rb_cRange = rb_struct_define_without_accessor(
"Range", rb_cFoo, range_alloc,
"begin", "end", "excl", NULL);
- eof
+ EOF
expect(Registry.at('Range').type).to eq :class
expect(Registry.at('Range').superclass).to eq P(:Foo)
end
diff --git a/spec/handlers/class_condition_handler_spec.rb b/spec/handlers/class_condition_handler_spec.rb
index 51cfb738f..445965863 100644
--- a/spec/handlers/class_condition_handler_spec.rb
+++ b/spec/handlers/class_condition_handler_spec.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ClassConditionHandler" do
before(:all) { parse_file :class_condition_handler_001, __FILE__ }
def verify_method(*names)
- names.each {|name| expect(Registry.at("A##{name}")).not_to be nil }
- names.each {|name| expect(Registry.at("A##{name}not")).to be nil }
+ names.each do |name|
+ expect(Registry.at("A##{name}")).not_to be nil
+ expect(Registry.at("A##{name}not")).to be nil
+ end
end
def no_undoc_error(code)
@@ -58,11 +60,11 @@ def no_undoc_error(code)
expect(log).not_to receive(:warn)
expect(log).not_to receive(:error)
no_undoc_error "if defined?(A) && defined?(B); puts 'hi' end"
- no_undoc_error(<<-eof)
+ no_undoc_error(<<-EOF)
(<<-TEST) unless defined?(ABCD_MODEL_TEST)
'String'
TEST
- eof
+ EOF
no_undoc_error "if caller.none? { |l| l =~ %r{lib/rails/generators\\.rb:(\\d+):in `lookup!'$} }; end"
end
@@ -73,13 +75,13 @@ def self.b(value) @@value = value end
def self.value; @@value end
end
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
if defined? A.b(42).to_i
class Foo; end
else
class Bar; end
end
- eof
+ EOF
expect(A.value).to be_nil
expect(YARD::Registry.at('Foo')).not_to be_nil
expect(YARD::Registry.at('Bar')).not_to be_nil
diff --git a/spec/handlers/class_handler_spec.rb b/spec/handlers/class_handler_spec.rb
index 2a413dbaf..b2bd78bdc 100644
--- a/spec/handlers/class_handler_spec.rb
+++ b/spec/handlers/class_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ClassHandler" do
before(:all) { parse_file :class_handler_001, __FILE__ }
@@ -78,10 +78,10 @@
['not.aclass', 'self', 'AnotherClass.new'].each do |klass|
it "raises an UndocumentableError if the constant class reference 'class << SomeConstant' does not point to a valid class name" do
with_parser(:ruby18) do
- undoc_error <<-eof
+ undoc_error <<-EOF
CONST = #{klass}
class << CONST; end
- eof
+ EOF
end
expect(Registry.at(klass)).to be nil
end
@@ -96,10 +96,10 @@ class << CONST; end
end
it "documents 'class Exception' without running into superclass issues" do
- Parser::SourceParser.parse_string <<-eof
+ Parser::SourceParser.parse_string <<-EOF
class Exception
end
- eof
+ EOF
expect(Registry.at(:Exception)).not_to be nil
end
@@ -116,7 +116,7 @@ class Exception
obj = Registry.at("Point")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
attrs = obj.attributes[:instance]
- [:x, :y, :z].each do |key|
+ %i(x y z).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -127,7 +127,7 @@ class Exception
obj = Registry.at("AnotherPoint")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
attrs = obj.attributes[:instance]
- [:a, :b, :c].each do |key|
+ %i(a b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -144,7 +144,7 @@ class Exception
it "attaches attribtues to the generated Struct::Name class when Struct.new('Name') is used" do
obj = Registry.at("Struct::XPoint")
attrs = obj.attributes[:instance]
- [:a, :b, :c].each do |key|
+ %i(a b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -177,7 +177,7 @@ class Exception
end
["SemiDoccedStruct", "NotAStruct"].each do |struct|
- describe("Attributes on a " + (struct == "NotAStruct" ? "class" : "struct")) do
+ describe("Attributes on a #{struct == "NotAStruct" ? "class" : "struct"}") do
it "defines both readers and writers when @attr is used on Structs" do
obj = Registry.at(struct)
attrs = obj.attributes[:instance]
diff --git a/spec/handlers/class_method_handler_shared_examples.rb b/spec/handlers/class_method_handler_shared_examples.rb
index bf0ffdec7..cbe1b2d67 100644
--- a/spec/handlers/class_method_handler_shared_examples.rb
+++ b/spec/handlers/class_method_handler_shared_examples.rb
@@ -27,7 +27,7 @@ def self.e; end
# Issue #760
# https://github.com/lsegal/yard/issues/760
it "handles singleton classes" do
- # Note: It's important to def a method within the singleton class or
+ # NOTE: It's important to def a method within the singleton class or
# the bug may not trigger.
code = <<-CODE
class SingletonClass
@@ -87,7 +87,7 @@ def self.bat
expect(Registry.at('SingletonClass.baz').visibility).to eq visibility
expect(Registry.at('SingletonClass.bat').visibility).not_to eq visibility
end
- end unless LEGACY_PARSER # reopened class
+ end unless LEGACY_PARSER
describe "as method definition decorator" do
subject { Registry.at('SingletonClass.foo') }
diff --git a/spec/handlers/class_variable_handler_spec.rb b/spec/handlers/class_variable_handler_spec.rb
index 64cd34011..fbfb6e900 100644
--- a/spec/handlers/class_variable_handler_spec.rb
+++ b/spec/handlers/class_variable_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ClassVariableHandler" do
before(:all) { parse_file :class_variable_handler_001, __FILE__ }
diff --git a/spec/handlers/constant_handler_spec.rb b/spec/handlers/constant_handler_spec.rb
index 3547a7680..fd27050ab 100644
--- a/spec/handlers/constant_handler_spec.rb
+++ b/spec/handlers/constant_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ConstantHandler" do
before(:all) { parse_file :constant_handler_001, __FILE__ }
@@ -20,7 +20,7 @@
obj = Registry.at("MyClass")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
attrs = obj.attributes[:instance]
- [:a, :b, :c].each do |key|
+ %i(a b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -42,7 +42,7 @@
obj = Registry.at("NotMyClass")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
attrs = obj.attributes[:instance]
- [:b, :c].each do |key|
+ %i(b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -62,7 +62,7 @@
expect(obj).to be_kind_of(CodeObjects::ClassObject)
expect(obj.superclass).to eq P(:Struct)
attrs = obj.attributes[:instance]
- [:b, :c].each do |key|
+ %i(b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).not_to be nil
@@ -90,7 +90,7 @@
expect(obj).to be_kind_of(CodeObjects::ClassObject)
expect(obj.superclass).to eq P(:Data)
attrs = obj.attributes[:instance]
- [:a, :b, :c].each do |key|
+ %i(a b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).to be nil
@@ -109,7 +109,7 @@
expect(obj).to be_kind_of(CodeObjects::ClassObject)
expect(obj.superclass).to eq P(:Data)
attrs = obj.attributes[:instance]
- [:b, :c].each do |key|
+ %i(b c).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).to be nil
@@ -121,7 +121,7 @@
expect(obj).to be_kind_of(CodeObjects::ClassObject)
expect(obj.superclass).to eq P(:Data)
attrs = obj.attributes[:instance]
- [:c, :d].each do |key|
+ %i(c d).each do |key|
expect(attrs).to have_key(key)
expect(attrs[key][:read]).not_to be nil
expect(attrs[key][:write]).to be nil
@@ -135,32 +135,32 @@
%w(module class).each do |type|
it "does not allow #{type} to be redefined as constant" do
- undoc_error <<-eof
+ undoc_error <<-EOF
#{type} Foo; end
Foo = "value"
- eof
+ EOF
end
end unless LEGACY_PARSER
it "allows constant to have same name as constant in parent namespace" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A
class C; end
module B; C = 1 end
end
- eof
+ EOF
expect(log.io.string).to eq ""
expect(Registry.at('A::B::C').type).to eq :constant
end
it "detects compound constant names" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A
class AA; end
AA::B = true
end
A::AA::C = true
- eof
+ EOF
expect(Registry.at('A::AA::B').type).to eq :constant
expect(Registry.at('A::AA::C').type).to eq :constant
diff --git a/spec/handlers/decorator_handler_methods_spec.rb b/spec/handlers/decorator_handler_methods_spec.rb
index 43d0360b3..8058a7b5b 100644
--- a/spec/handlers/decorator_handler_methods_spec.rb
+++ b/spec/handlers/decorator_handler_methods_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::DecoratorHandlerMethods" do
describe "#process_decorator" do
@@ -48,7 +48,7 @@ def make_ast(code)
subject { data[:mock] }
- let(:data) { Hash.new }
+ let(:data) { {} }
let(:nodes) { [] }
let(:mock_handler_opts) { {:scope => :instance} }
let(:class_name) { 'DecoratorTest' }
@@ -57,13 +57,13 @@ def make_ast(code)
let(:method_defs) { [] }
let(:method_string) { "#{class_name}#foo" }
let(:code) do
- <<-eof
+ <<-EOF
class #{class_name}
#{make_defs(*method_defs)}
# #{docstring}
mock_decorator #{param_string}
end
- eof
+ EOF
end
before do
@@ -125,7 +125,7 @@ class #{class_name}
subject { data[:mock][:return].map {|h| h[:method].to_s } }
describe "assumes all params refer to methods by default" do
- let(:method_defs) { [:foo, :bar] }
+ let(:method_defs) { %i(foo bar) }
let(:param_string) { method_defs.map(&:inspect).join(',') }
let(:nodes) { [] }
@@ -135,9 +135,9 @@ class #{class_name}
end
describe "can specify which params to capture as methods" do
- let(:method_defs) { [:foo, :bar, :baz, :bat] }
+ let(:method_defs) { %i(foo bar baz bat) }
let(:parameters) do
- [:option_1, :baz, :bat, :option_2, :foo, :bar].map do |s|
+ %i(option_1 baz bat option_2 foo bar).map do |s|
make_ast s.inspect
end
end
@@ -206,7 +206,7 @@ class #{class_name}
let(:param_string) { decorator_params.map(&:inspect).join(',') }
describe "for symbols" do
- let(:decorator_params) { [:foo, :bar] }
+ let(:decorator_params) { %i(foo bar) }
specify do
expect(subject.count).to eq decorator_params.count
@@ -248,16 +248,16 @@ class #{class_name}
expect(subject[i].to_s).to eq \
class_name +
(mock_handler_opts[:scope] == :class ? '.' : '#') +
- decorator_params[i].split(' ')[1][/\w+$/]
+ decorator_params[i].split[1][/\w+$/]
end
end
end
- end # decorator helper scope shared examples
+ end
subject { data[:mock][:return].map {|h| h[:method] } }
let(:docstring) { 'the foo method' }
- let(:method_defs) { [:foo, :bar] }
+ let(:method_defs) { %i(foo bar) }
describe "for :instance" do
let(:mock_handler_opts) { {:scope => :instance} }
@@ -283,12 +283,12 @@ class #{class_name}
describe "does not attach" do
describe "to undefined methods" do
let(:code) do
- <<-eof
+ <<-EOF
class #{class_name}
# #{docstring}
mock_decorator :foo
end
- eof
+ EOF
end
specify do
@@ -298,7 +298,7 @@ class #{class_name}
describe "to methods with existing docstring" do
let(:code) do
- <<-eof
+ <<-EOF
class #{class_name}
# original docstring
@@ -307,7 +307,7 @@ def foo; end
# #{docstring}
mock_decorator :foo
end
- eof
+ EOF
end
specify do
@@ -322,13 +322,13 @@ def foo; end
let(:param_string) { 'def foo param1, param2; end' }
let(:code) do
- <<-eof
+ <<-EOF
class #{class_name}
#{make_defs(*method_defs)}
# #{docstring}
first_decorator second_decorator third_decorator #{param_string}
end
- eof
+ EOF
end
specify "register nested method defs" do
@@ -389,5 +389,5 @@ class #{class_name}
end
end
end
- end # process_decorator
+ end
end unless LEGACY_PARSER
diff --git a/spec/handlers/dsl_handler_spec.rb b/spec/handlers/dsl_handler_spec.rb
index faf2a48b6..73808f46f 100644
--- a/spec/handlers/dsl_handler_spec.rb
+++ b/spec/handlers/dsl_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}DSLHandler" do
before(:all) { parse_file :dsl_handler_001, __FILE__ }
@@ -201,12 +201,12 @@
end
it "does not detect implicit macros with invalid method names" do
- undoc_error <<-eof
+ undoc_error <<-EOF
##
# IMPLICIT METHOD THAT SHOULD
# NOT BE DETECTED
dsl_method '/foo/bar'
- eof
+ EOF
end
it "warns on unparsable DSL statements" do
diff --git a/spec/handlers/exception_handler_spec.rb b/spec/handlers/exception_handler_spec.rb
index cd0f83d80..0f73a5369 100644
--- a/spec/handlers/exception_handler_spec.rb
+++ b/spec/handlers/exception_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ExceptionHandler" do
before(:all) { parse_file :exception_handler_001, __FILE__ }
diff --git a/spec/handlers/extend_handler_spec.rb b/spec/handlers/extend_handler_spec.rb
index 48a913671..506eb8fa6 100644
--- a/spec/handlers/extend_handler_spec.rb
+++ b/spec/handlers/extend_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ExtendHandler" do
before(:all) { parse_file :extend_handler_001, __FILE__ }
diff --git a/spec/handlers/legacy_base_spec.rb b/spec/handlers/legacy_base_spec.rb
index 8b936bba8..343b64e30 100644
--- a/spec/handlers/legacy_base_spec.rb
+++ b/spec/handlers/legacy_base_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
include Parser::Ruby::Legacy
@@ -15,7 +15,7 @@ def tokval(code, *types)
end
it "does not allow interpolated strings with TkSTRING" do
- expect(tokval('"#{c}"', RubyToken::TkSTRING)).to be nil
+ expect(tokval(%("\#{c}"), RubyToken::TkSTRING)).to be nil
end
it "returns a Symbol's value as a String (as if it was done via :name.to_sym)" do
@@ -45,11 +45,11 @@ def tokval(code, *types)
it "allows :string for any string type" do
expect(tokval('"hello"', :string)).to eq "hello"
- expect(tokval('"#{c}"', :string)).to eq '#{c}'
+ expect(tokval(%("\#{c}"), :string)).to eq %(\#{c})
end
it "does not include interpolated strings when using :attr" do
- expect(tokval('"#{c}"', :attr)).to be nil
+ expect(tokval(%("\#{c}"), :attr)).to be nil
end
it "allows any number type with :number" do
@@ -74,18 +74,18 @@ def tokval_list(code, *types)
it "returns the list of tokvalues" do
expect(tokval_list(":a, :b, \"\#{c}\", 'd'", :attr)).to eq [:a, :b, 'd']
expect(tokval_list(":a, :b, File.read(\"\#{c}\", ['w']), :d",
- RubyToken::Token)).to eq [:a, :b, 'File.read("#{c}", [\'w\'])', :d]
+ RubyToken::Token)).to eq [:a, :b, %{File.read("\#{c}", ['w'])}, :d]
end
it "tries to skip any invalid tokens" do
- expect(tokval_list(":a, :b, \"\#{c}\", :d", :attr)).to eq [:a, :b, :d]
- expect(tokval_list(":a, :b, File.read(\"\#{c}\", 'w', File.open { }), :d", :attr)).to eq [:a, :b, :d]
+ expect(tokval_list(":a, :b, \"\#{c}\", :d", :attr)).to eq %i(a b d)
+ expect(tokval_list(":a, :b, File.read(\"\#{c}\", 'w', File.open { }), :d", :attr)).to eq %i(a b d)
expect(tokval_list("CONST1, identifier, File.read(\"\#{c}\", 'w', File.open { }), CONST2",
- RubyToken::TkId)).to eq ['CONST1', 'identifier', 'CONST2']
+ RubyToken::TkId)).to eq ['CONST1', 'identifier', 'CONST2']
end
it "ignores a token if another invalid token is read before a comma" do
- expect(tokval_list(":a, :b XYZ, :c", RubyToken::TkSYMBOL)).to eq [:a, :c]
+ expect(tokval_list(":a, :b XYZ, :c", RubyToken::TkSYMBOL)).to eq %i(a c)
end
it "stops on most keywords" do
@@ -93,26 +93,26 @@ def tokval_list(code, *types)
end
it "handles ignore parentheses that begin the token list" do
- expect(tokval_list('(:a, :b, :c)', :attr)).to eq [:a, :b, :c]
+ expect(tokval_list('(:a, :b, :c)', :attr)).to eq %i(a b c)
end
it "ends when a closing parenthesis was found" do
- expect(tokval_list(':a, :b, :c), :d', :attr)).to eq [:a, :b, :c]
+ expect(tokval_list(':a, :b, :c), :d', :attr)).to eq %i(a b c)
end
it "ignores parentheses around items in a list" do
- expect(tokval_list(':a, (:b), :c, (:d TEST), :e, [:f], :g', :attr)).to eq [:a, :b, :c, :e, :g]
- expect(tokval_list(':a, (((:f)))', :attr)).to eq [:a, :f]
+ expect(tokval_list(':a, (:b), :c, (:d TEST), :e, [:f], :g', :attr)).to eq %i(a b c e g)
+ expect(tokval_list(':a, (((:f)))', :attr)).to eq %i(a f)
expect(tokval_list(':a, ([:f]), :c)', RubyToken::Token)).to eq [:a, '[:f]', :c]
end
it "does not stop on a true/false/self keyword (cannot handle nil)" do
expect(tokval_list(':a, true, :b, self, false, :c, nil, File, super, if, XYZ',
- RubyToken::Token)).to eq [:a, true, :b, 'self', false, :c, 'File', 'super']
+ RubyToken::Token)).to eq [:a, true, :b, 'self', false, :c, 'File', 'super']
end
it "ignores invalid commas" do
- expect(tokval_list(":a, :b, , :d")).to eq [:a, :b, :d]
+ expect(tokval_list(":a, :b, , :d")).to eq %i(a b d)
end
it "returns an empty list if no matches were found" do
diff --git a/spec/handlers/method_condition_handler_spec.rb b/spec/handlers/method_condition_handler_spec.rb
index 3dd02ac44..2dad22f8c 100644
--- a/spec/handlers/method_condition_handler_spec.rb
+++ b/spec/handlers/method_condition_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodConditionHandler" do
before(:all) { parse_file :method_condition_handler_001, __FILE__ }
diff --git a/spec/handlers/method_handler_spec.rb b/spec/handlers/method_handler_spec.rb
index b399570d1..f5c3e9926 100644
--- a/spec/handlers/method_handler_spec.rb
+++ b/spec/handlers/method_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodHandler" do
before(:all) do
@@ -20,7 +20,7 @@
expect(P("String.hello")).to be_instance_of(CodeObjects::MethodObject)
end
- [:[], :[]=, :allowed?, :/, :=~, :==, :`, :|, :*, :&, :%, :'^', :-@, :+@, :'~@'].each do |name|
+ %i([] []= allowed? / =~ == ` | * & % ^ -@ +@ ~@).each do |name|
it "allows valid method #{name}" do
expect(Registry.at("Foo##{name}")).not_to be nil
end
@@ -82,7 +82,7 @@ def method_with_forwarding(...)
EOF
expect(P('Bar#method_with_forwarding').signature).to eq "def method_with_forwarding(...)"
- end if YARD.ruby3? # this is 2.7+ but we can just test on 3+
+ end if YARD.ruby3?
it "handles method with anonymous block" do
YARD.parse_string <<-EOF
@@ -154,7 +154,7 @@ def endless_with_arg(arg = true) = true
%w(inherited included method_added method_removed method_undefined).each do |meth|
it "sets @private tag on #{meth} callback method if no docstring is set" do
- expect(P('Foo.' + meth)).to have_tag(:private)
+ expect(P("Foo.#{meth}")).to have_tag(:private)
end
end
diff --git a/spec/handlers/mixin_handler_spec.rb b/spec/handlers/mixin_handler_spec.rb
index e98e74c46..c80c8d424 100644
--- a/spec/handlers/mixin_handler_spec.rb
+++ b/spec/handlers/mixin_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MixinHandler" do
before(:all) { parse_file :mixin_handler_001, __FILE__ }
@@ -60,11 +60,11 @@
end
it "can mixin a const by complex path" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class A1; class B1; class C1; end end end
class D1; class E1; module F1; end end end
A1::B1::C1.include D1::E1::F1
- eof
+ EOF
expect(YARD::Registry.root.instance_mixins).not_to eq [P('D1::E1::F1')]
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
@@ -76,7 +76,7 @@ class D1; class E1; module F1; end end end
it "ensures the recipient is loaded from another file" do
# 002 includes a module into a module defined in 003
- parse_file [:mixin_handler_002, :mixin_handler_003], __FILE__
+ parse_file %i(mixin_handler_002 mixin_handler_003), __FILE__
expect(P('A1').instance_mixins).to eq [P('B1')]
end
diff --git a/spec/handlers/module_function_handler_spec.rb b/spec/handlers/module_function_handler_spec.rb
index 806b2c908..f55c795e8 100644
--- a/spec/handlers/module_function_handler_spec.rb
+++ b/spec/handlers/module_function_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}VisibilityHandler" do
after { Registry.clear }
@@ -16,20 +16,20 @@ def assert_module_function(namespace, name)
end
it "is able to create a module function with parameters" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
def bar; end
def baz; end
module_function :bar, :baz
end
- eof
+ EOF
assert_module_function('Foo', 'bar')
assert_module_function('Foo', 'baz')
end
it "is able to set scope for duration of block without params" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
def qux; end
@@ -38,14 +38,14 @@ def qux; end
def bar; end
def baz; end
end
- eof
+ EOF
expect(Registry.at('Foo.qux')).to be nil
assert_module_function('Foo', 'bar')
assert_module_function('Foo', 'baz')
end
it "can decorate a method definition" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
def qux; end
@@ -53,7 +53,7 @@ def qux; end
def baz; end
end
- eof
+ EOF
expect(Registry.at('Foo.qux')).to be nil
assert_module_function('Foo', 'bar')
expect(Registry.at('Foo.baz')).to be nil
@@ -61,7 +61,7 @@ def baz; end
# @bug gh-563
it "copies tags to module function properly" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
# @param [String] foo bar
# @option foo [String] bar (nil) baz
@@ -69,7 +69,7 @@ module Foo
def bar(foo); end
module_function :bar
end
- eof
+ EOF
assert_module_function('Foo', 'bar')
o = Registry.at('Foo.bar')
expect(o.tag(:param).types).to eq ['String']
@@ -83,39 +83,39 @@ def bar(foo); end
end
it "handles all method names in parameters" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
def -(t); end
def ==(other); end
def a?; end
module_function :-, '==', :a?
end
- eof
+ EOF
assert_module_function('Foo', '-')
assert_module_function('Foo', '==')
assert_module_function('Foo', 'a?')
end
it "only accepts strings and symbols" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
module_function name
module_function *argument
module_function *(method_call)
end
- eof
+ EOF
expect(Registry.at('Foo#name')).to be nil
expect(Registry.at('Foo#argument')).to be nil
expect(Registry.at('Foo#method_call')).to be nil
end
it "handles constants passed in as symbols" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
def Foo; end
module_function :Foo
end
- eof
+ EOF
assert_module_function('Foo', 'Foo')
end
end
diff --git a/spec/handlers/module_handler_spec.rb b/spec/handlers/module_handler_spec.rb
index cb55a3ab9..e640455e7 100644
--- a/spec/handlers/module_handler_spec.rb
+++ b/spec/handlers/module_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ModuleHandler" do
before(:all) { parse_file :module_handler_001, __FILE__ }
diff --git a/spec/handlers/private_class_method_handler_spec.rb b/spec/handlers/private_class_method_handler_spec.rb
index 83ebf242f..406301b9a 100644
--- a/spec/handlers/private_class_method_handler_spec.rb
+++ b/spec/handlers/private_class_method_handler_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/class_method_handler_shared_examples'
+require "#{File.dirname(__FILE__)}/spec_helper"
+require "#{File.dirname(__FILE__)}/class_method_handler_shared_examples"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}PrivateClassMethodHandler" do
before { Registry.clear }
diff --git a/spec/handlers/private_constant_handler_spec.rb b/spec/handlers/private_constant_handler_spec.rb
index 26dd51afa..7ccce50af 100644
--- a/spec/handlers/private_constant_handler_spec.rb
+++ b/spec/handlers/private_constant_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}PrivateConstantHandler" do
before(:all) { parse_file :private_constant_handler_001, __FILE__ }
diff --git a/spec/handlers/processor_spec.rb b/spec/handlers/processor_spec.rb
index 46c47ead7..5f6a4a63c 100644
--- a/spec/handlers/processor_spec.rb
+++ b/spec/handlers/processor_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Handlers::Processor do
before do
diff --git a/spec/handlers/public_class_method_handler_spec.rb b/spec/handlers/public_class_method_handler_spec.rb
index 7bccad4c1..c24d44d3c 100644
--- a/spec/handlers/public_class_method_handler_spec.rb
+++ b/spec/handlers/public_class_method_handler_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
-require File.dirname(__FILE__) + '/class_method_handler_shared_examples'
+require "#{File.dirname(__FILE__)}/spec_helper"
+require "#{File.dirname(__FILE__)}/class_method_handler_shared_examples"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}PublicClassMethodHandler" do
before { Registry.clear }
diff --git a/spec/handlers/ruby/base_spec.rb b/spec/handlers/ruby/base_spec.rb
index 3121bf801..16a731ef0 100644
--- a/spec/handlers/ruby/base_spec.rb
+++ b/spec/handlers/ruby/base_spec.rb
@@ -25,6 +25,7 @@ def invalid(handler, stmt)
class IgnoredHandler < Handlers::Base
handles :list
end
+
class NotIgnoredHandler < Handlers::Ruby::Base
handles :list
end
@@ -75,7 +76,7 @@ class MethCallHandler < Handlers::Ruby::Base
handles method_call(:meth)
end
allow(Handlers::Base).to receive(:subclasses).and_return [MethCallHandler]
- ast = Parser::Ruby::RubyParser.parse(<<-"eof").ast
+ ast = Parser::Ruby::RubyParser.parse(<<-EOF).ast
meth # 0
meth() # 1
meth(1,2,3) # 2
@@ -86,7 +87,7 @@ class MethCallHandler < Handlers::Ruby::Base
NotMeth.meth 1, 2, 3 # 7
NotMeth.meth(1, 2, 3) # 8
NotMeth # 9
- eof
+ EOF
(0..8).each do |i|
valid MethCallHandler, ast[i]
end
diff --git a/spec/handlers/ruby/legacy/base_spec.rb b/spec/handlers/ruby/legacy/base_spec.rb
index f8db761ab..09f3b08aa 100644
--- a/spec/handlers/ruby/legacy/base_spec.rb
+++ b/spec/handlers/ruby/legacy/base_spec.rb
@@ -23,6 +23,7 @@ def stmt(string)
class IgnoredHandler < Handlers::Base
handles "hello"
end
+
class NotIgnoredHandlerLegacy < Handlers::Ruby::Legacy::Base
handles "hello"
end
diff --git a/spec/handlers/visibility_handler_spec.rb b/spec/handlers/visibility_handler_spec.rb
index ae202bea0..bb532b7b3 100644
--- a/spec/handlers/visibility_handler_spec.rb
+++ b/spec/handlers/visibility_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}VisibilityHandler" do
before(:all) { parse_file :visibility_handler_001, __FILE__ }
diff --git a/spec/handlers/yield_handler_spec.rb b/spec/handlers/yield_handler_spec.rb
index 12c232954..f6893c6d0 100644
--- a/spec/handlers/yield_handler_spec.rb
+++ b/spec/handlers/yield_handler_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}YieldHandler" do
before(:all) { parse_file :yield_handler_001, __FILE__ }
diff --git a/spec/i18n/locale_spec.rb b/spec/i18n/locale_spec.rb
index c13c267d2..590c93b2d 100644
--- a/spec/i18n/locale_spec.rb
+++ b/spec/i18n/locale_spec.rb
@@ -41,7 +41,7 @@ def locale(name)
end
it "returns true for existent PO", :if => have_gettext_gem do
- data = <<-eop
+ data = <<-EOP
msgid ""
msgstr ""
"Language: fr\n"
@@ -51,7 +51,7 @@ def locale(name)
msgid "Hello"
msgstr "Bonjour"
-eop
+ EOP
parser = GetText::POParser.new
expect(File).to receive(:exist?).with('foo/fr.po').and_return(true)
expect(GetText::POParser).to receive(:new).and_return(parser)
diff --git a/spec/i18n/messages_spec.rb b/spec/i18n/messages_spec.rb
index 5cb34c323..47b88265a 100644
--- a/spec/i18n/messages_spec.rb
+++ b/spec/i18n/messages_spec.rb
@@ -17,18 +17,16 @@ def messages
it "enumerates messages" do
@messages.register("Hello World!")
@messages.register("Title")
- enumerated_messages = []
- @messages.each do |message|
- enumerated_messages << message
+ enumerated_messages = @messages.map do |message|
+ message
end
enumerated_messages = enumerated_messages.sort_by(&:id)
expect(enumerated_messages).to eq [message("Hello World!"), message("Title")]
end
it "does not yield any message if there are none" do
- enumerated_messages = []
- @messages.each do |message|
- enumerated_messages << message
+ enumerated_messages = @messages.map do |message|
+ message
end
expect(enumerated_messages).to eq []
end
diff --git a/spec/i18n/pot_generator_spec.rb b/spec/i18n/pot_generator_spec.rb
index a762417a5..478e6f82b 100644
--- a/spec/i18n/pot_generator_spec.rb
+++ b/spec/i18n/pot_generator_spec.rb
@@ -28,7 +28,7 @@ def add_messages(yard_messages, messages)
current_time = Time.parse("2011-11-20 22:17+0900")
allow(@generator).to receive(:current_time).and_return(current_time)
pot_creation_date = current_time.strftime("%Y-%m-%d %H:%M%z")
- expect(@generator.generate).to eq <<-eoh
+ expect(@generator.generate).to eq <<-EOH
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
@@ -48,7 +48,7 @@ def add_messages(yard_messages, messages)
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
-eoh
+ EOH
end
it "generates messages in location order" do
@@ -64,7 +64,7 @@ def add_messages(yard_messages, messages)
}
}
add_messages(@generator.messages, messages)
- expect(@generator.generate).to eq <<-'eoh'
+ expect(@generator.generate).to eq <<-EOH
HEADER
# YARD.parse
@@ -79,7 +79,7 @@ def add_messages(yard_messages, messages)
msgid "tag|see|Parser::SourceParser.parse"
msgstr ""
-eoh
+ EOH
end
end
@@ -92,28 +92,28 @@ def generate_message_pot(message_id)
end
it "escapes <\\>" do
- expect(generate_message_pot("hello \\ world")).to eq <<-'eop'
+ expect(generate_message_pot("hello \\ world")).to eq <<-'EOP'
msgid "hello \\ world"
msgstr ""
-eop
+ EOP
end
it "escapes <\">" do
- expect(generate_message_pot("hello \" world")).to eq <<-'eop'
+ expect(generate_message_pot("hello \" world")).to eq <<-'EOP'
msgid "hello \" world"
msgstr ""
-eop
+ EOP
end
it "escapes <\\n>" do
- expect(generate_message_pot("hello \n world")).to eq <<-'eop'
+ expect(generate_message_pot("hello \n world")).to eq <<-'EOP'
msgid "hello \n"
" world"
msgstr ""
-eop
+ EOP
end
end
@@ -166,10 +166,10 @@ def generate_message_pot(message_id)
it "extracts at tag text" do
object = YARD::CodeObjects::MethodObject.new(@yard, :parse, :module) do |o|
- o.docstring = <<-eod
+ o.docstring = <<-EOD
@example Parse a glob of files
YARD.parse('lib/**/*.rb')
-eod
+ EOD
o.files = [["yard.rb", 12]]
end
@generator.parse_objects([object])
@@ -187,10 +187,10 @@ def generate_message_pot(message_id)
it "extracts at tag types" do
object = YARD::CodeObjects::MethodObject.new(@yard, :parse, :module) do |o|
- o.docstring = <<-eod
+ o.docstring = <<-EOD
@param [String, Array] paths a path, glob, or list of paths to
parse
-eod
+ EOD
o.files = [["yard.rb", 12]]
end
@generator.parse_objects([object])
@@ -208,11 +208,11 @@ def generate_message_pot(message_id)
it "extracts at overload tag recursively" do
object = YARD::CodeObjects::MethodObject.new(@yard, :parse, :module) do |o|
- o.docstring = <<-eod
+ o.docstring = <<-EOD
@overload foo(i)
docstring foo(i)
@param [Integer] i integer parameter
-eod
+ EOD
end
@generator.parse_objects([object])
@@ -240,11 +240,11 @@ def generate_message_pot(message_id)
describe "File" do
it "extracts at attribute" do
path = "GettingStarted.md"
- text = <<-eor
+ text = <<-EOR
# @title Getting Started Guide
# Getting Started with YARD
-eor
+ EOR
allow(File).to receive(:open).with(path).and_yield(StringIO.new(text))
allow(File).to receive(:read).with(path).and_return(text)
file = YARD::CodeObjects::ExtraFileObject.new(path)
@@ -263,19 +263,19 @@ def generate_message_pot(message_id)
it "extracts at paragraphs" do
path = "README.md"
- paragraph1 = <<-eop.strip
+ paragraph1 = <<-EOP.strip
Note that class methods must not be referred to with the "::" namespace
separator. Only modules, classes and constants should use "::".
-eop
- paragraph2 = <<-eop.strip
+ EOP
+ paragraph2 = <<-EOP.strip
You can also do lookups on any installed gems. Just make sure to build the
.yardoc databases for installed gems with:
-eop
- text = <<-eot
+ EOP
+ text = <<-EOT
#{paragraph1}
#{paragraph2}
-eot
+ EOT
allow(File).to receive(:open).with(path).and_yield(StringIO.new(text))
allow(File).to receive(:read).with(path).and_return(text)
file = YARD::CodeObjects::ExtraFileObject.new(path)
diff --git a/spec/i18n/text_spec.rb b/spec/i18n/text_spec.rb
index 593174862..679bb7609 100644
--- a/spec/i18n/text_spec.rb
+++ b/spec/i18n/text_spec.rb
@@ -13,11 +13,11 @@ def extract_messages(input, options = {})
describe "Header" do
it "extracts at attribute" do
- text = <<-eot
+ text = <<-EOT
# @title Getting Started Guide
# Getting Started with YARD
-eot
+ EOT
expect(extract_messages(text, :have_header => true)).to eq(
[[:attribute, "title", "Getting Started Guide", 1],
[:paragraph, "# Getting Started with YARD", 3]]
@@ -25,12 +25,12 @@ def extract_messages(input, options = {})
end
it "ignores markup line" do
- text = <<-eot
+ text = <<-EOT
#!markdown
# @title Getting Started Guide
# Getting Started with YARD
-eot
+ EOT
expect(extract_messages(text, :have_header => true)).to eq(
[[:attribute, "title", "Getting Started Guide", 2],
[:paragraph, "# Getting Started with YARD", 4]]
@@ -38,12 +38,12 @@ def extract_messages(input, options = {})
end
it "terminates header block by markup line not at the first line" do
- text = <<-eot
+ text = <<-EOT
# @title Getting Started Guide
#!markdown
# Getting Started with YARD
-eot
+ EOT
expect(extract_messages(text, :have_header => true)).to eq(
[[:attribute, "title", "Getting Started Guide", 1],
[:paragraph, "#!markdown", 2],
@@ -54,19 +54,19 @@ def extract_messages(input, options = {})
describe "Body" do
it "splits to paragraphs" do
- paragraph1 = <<-eop.strip
+ paragraph1 = <<-EOP.strip
Note that class methods must not be referred to with the "::" namespace
separator. Only modules, classes and constants should use "::".
-eop
- paragraph2 = <<-eop.strip
+ EOP
+ paragraph2 = <<-EOP.strip
You can also do lookups on any installed gems. Just make sure to build the
.yardoc databases for installed gems with:
-eop
- text = <<-eot
+ EOP
+ text = <<-EOT
#{paragraph1}
#{paragraph2}
-eot
+ EOT
expect(extract_messages(text)).to eq(
[[:paragraph, paragraph1, 1],
[:paragraph, paragraph2, 4]]
@@ -93,91 +93,91 @@ def translate(input, options = {})
describe "Header" do
it "extracts at attribute" do
- text = <<-eot
+ text = <<-EOT
# @title Hello
# Getting Started with YARD
Paragraph.
-eot
- expect(translate(text, :have_header => true)).to eq <<-eot
+ EOT
+ expect(translate(text, :have_header => true)).to eq <<-EOT
# @title Bonjour (Hello in fr)
# Getting Started with YARD
Paragraph.
-eot
+ EOT
end
it "ignores markup line" do
- text = <<-eot
+ text = <<-EOT
#!markdown
# @title Hello
# Getting Started with YARD
Paragraph.
-eot
- expect(translate(text, :have_header => true)).to eq <<-eot
+ EOT
+ expect(translate(text, :have_header => true)).to eq <<-EOT
#!markdown
# @title Bonjour (Hello in fr)
# Getting Started with YARD
Paragraph.
-eot
+ EOT
end
end
describe "Body" do
it "splits to paragraphs" do
- paragraph1 = <<-eop.strip
+ paragraph1 = <<-EOP.strip
Paragraph 1.
-eop
- paragraph2 = <<-eop.strip
+ EOP
+ paragraph2 = <<-EOP.strip
Paragraph 2.
-eop
- text = <<-eot
+ EOP
+ text = <<-EOT
#{paragraph1}
#{paragraph2}
-eot
- expect(translate(text)).to eq <<-eot
+ EOT
+ expect(translate(text)).to eq <<-EOT
Paragraphe 1.
Paragraphe 2.
-eot
+ EOT
end
it "does not modify non-translated message" do
- nonexistent_paragraph = <<-eop.strip
+ nonexistent_paragraph = <<-EOP.strip
Nonexsitent paragraph.
-eop
- text = <<-eot
+ EOP
+ text = <<-EOT
#{nonexistent_paragraph}
-eot
- expect(translate(text)).to eq <<-eot
+ EOT
+ expect(translate(text)).to eq <<-EOT
#{nonexistent_paragraph}
-eot
+ EOT
end
it "keeps empty lines" do
- text = <<-eot
+ text = <<-EOT
Paragraph 1.
Paragraph 2.
-eot
- expect(translate(text)).to eq <<-eot
+ EOT
+ expect(translate(text)).to eq <<-EOT
Paragraphe 1.
Paragraphe 2.
-eot
+ EOT
end
end
end
diff --git a/spec/options_spec.rb b/spec/options_spec.rb
index 25fdb9127..fca14cfaf 100644
--- a/spec/options_spec.rb
+++ b/spec/options_spec.rb
@@ -41,6 +41,7 @@ class ResetDefaultOptions1 < YARD::Options
class ResetDefaultOptions2 < YARD::Options
default_attr :foo, 'FOO'
end
+
class ResetDefaultOptions3 < ResetDefaultOptions2
end
o = ResetDefaultOptions3.new
diff --git a/spec/parser/base_spec.rb b/spec/parser/base_spec.rb
index f4d93dba6..277a49097 100644
--- a/spec/parser/base_spec.rb
+++ b/spec/parser/base_spec.rb
@@ -6,7 +6,7 @@ class MyParser < Parser::Base; def initialize(a, b) end end
it "takes 2 arguments" do
expect { YARD::Parser::Base.new }.to raise_error(ArgumentError,
- /wrong (number|#) of arguments|given 0, expected 2/)
+ /wrong (number|#) of arguments|given 0, expected 2/)
end
it "raises NotImplementedError on #initialize" do
diff --git a/spec/parser/c_parser_spec.rb b/spec/parser/c_parser_spec.rb
index 26a14115c..b9279a54c 100644
--- a/spec/parser/c_parser_spec.rb
+++ b/spec/parser/c_parser_spec.rb
@@ -88,7 +88,7 @@ def parse(contents)
describe "Foo class" do
it "does not include comments in docstring source" do
- parse <<-eof
+ parse <<-EOF
/*
* Hello world
*/
@@ -99,7 +99,7 @@ def parse(contents)
void Init_Foo() {
rb_define_method(rb_cFoo, "foo", foo, 1);
}
- eof
+ EOF
expect(Registry.at('Foo#foo').source.gsub(/\s\s+/, ' ')).to eq(
"VALUE foo(VALUE x) { int value = x;\n}"
)
@@ -108,14 +108,14 @@ def parse(contents)
describe "Class inherited from core error class" do
it "resolves correct name" do
- parse <<-eof
+ parse <<-EOF
void
Init_Mask(void)
{
rb_cFoo = rb_define_class("Foo", rb_cObject);
rb_cMyError = rb_define_class("MyError", rb_eArgError);
}
- eof
+ EOF
klass = Registry.at('MyError')
expect(klass.name).to eq :MyError
expect(klass.title).to eq 'MyError'
@@ -126,7 +126,7 @@ def parse(contents)
describe "Constant" do
it "does not truncate docstring" do
- parse <<-eof
+ parse <<-EOF
#define MSK_DEADBEEF 0xdeadbeef
void
Init_Mask(void)
@@ -136,7 +136,7 @@ def parse(contents)
* software crash or deadlock in embedded systems. */
rb_define_const(rb_cMask, "DEADBEEF", INT2FIX(MSK_DEADBEEF));
}
- eof
+ EOF
constant = Registry.at('Mask::DEADBEEF')
expect(constant.value).to eq '0xdeadbeef'
expect(constant.docstring).to eq "This constant is frequently used to indicate a\nsoftware crash or deadlock in embedded systems."
@@ -146,7 +146,7 @@ def parse(contents)
describe "Macros" do
it "handles param## inside of macros" do
thr = Thread.new do
- parse <<-eof
+ parse <<-EOF
void
Init_gobject_gparamspecs(void)
{
@@ -169,7 +169,7 @@ def parse(contents)
c = G_DEF_CLASS(G_TYPE_PARAM_CHAR, "Char", cParamSpec);
DEF_NUMERIC_PSPEC_METHODS(c, char);
- eof
+ EOF
end
thr.join(5)
if thr.alive?
@@ -182,7 +182,7 @@ def parse(contents)
describe "C macros in declaration" do
it "handles C macros in method declaration" do
Registry.clear
- parse <<-eof
+ parse <<-EOF
// docstring
FOOBAR VALUE func() { }
@@ -191,7 +191,7 @@ def parse(contents)
{
rb_define_method(rb_cFoo, "func", func, 0); \
}
- eof
+ EOF
expect(Registry.at('Foo#func').docstring).to eq "docstring"
end
diff --git a/spec/parser/ruby/ast_node_spec.rb b/spec/parser/ruby/ast_node_spec.rb
index d7149e7ac..4ca00f2ea 100644
--- a/spec/parser/ruby/ast_node_spec.rb
+++ b/spec/parser/ruby/ast_node_spec.rb
@@ -23,11 +23,11 @@
out = StringIO.new
PP.pp(obj, out)
vcall = RUBY_VERSION >= '1.9.3' ? 'vcall' : 'var_ref'
- expect(out.string).to eq "s(s(:#{vcall},\n" \
- " s(:ident, \"bye\", line: 2..2, source: 4..6),\n" \
- " docstring: \"x\",\n" \
- " line: 2..2,\n" \
- " source: 4..6))\n"
+ expect(out.string).to eq "s(s(:#{vcall},\n " \
+ "s(:ident, \"bye\", line: 2..2, source: 4..6),\n " \
+ "docstring: \"x\",\n " \
+ "line: 2..2,\n " \
+ "source: 4..6))\n"
end
end unless YARD.ruby31?
diff --git a/spec/parser/ruby/legacy/statement_list_spec.rb b/spec/parser/ruby/legacy/statement_list_spec.rb
index 525b5bdc3..e3ca621e1 100644
--- a/spec/parser/ruby/legacy/statement_list_spec.rb
+++ b/spec/parser/ruby/legacy/statement_list_spec.rb
@@ -5,23 +5,23 @@ def stmts(code) YARD::Parser::Ruby::Legacy::StatementList.new(code) end
def stmt(code) stmts(code).first end
it "parses dangling block expressions" do
- s = stmt <<-eof
+ s = stmt <<-EOF
if
foo
puts 'hi'
end
-eof
+ EOF
expect(s.tokens.to_s(true)).to eq "if\n foo\n ...\n end"
expect(s.tokens.to_s).to eq "if\n foo"
expect(s.block.to_s).to eq "puts 'hi'"
- s = stmt <<-eof
+ s = stmt <<-EOF
if foo ||
bar
puts 'hi'
end
-eof
+ EOF
expect(s.tokens.to_s(true)).to eq "if foo ||\n bar\n ...\n end"
expect(s.tokens.to_s).to eq "if foo ||\n bar"
@@ -92,11 +92,11 @@ def stmt(code) stmts(code).first end
end
it "parses blocks with do/end" do
- s = stmt <<-eof
+ s = stmt <<-EOF
foo do
puts 'hi'
end
- eof
+ EOF
expect(s.tokens.to_s(true)).to eq "foo do\n ...\n end"
expect(s.block.to_s).to eq "puts 'hi'"
@@ -154,92 +154,92 @@ def stmt(code) stmts(code).first end
end
it "handles multiple methods" do
- s = stmt <<-eof
+ s = stmt <<-EOF
def %; end
def b; end
- eof
+ EOF
expect(s.to_s).to eq "def %; end"
end
it "handles nested methods" do
- s = stmt <<-eof
+ s = stmt <<-EOF
def *(o) def +@; end
def ~@
end end
- eof
+ EOF
expect(s.tokens.to_s(true)).to eq "def *(o) ... end"
expect(s.block.to_s).to eq "def +@; end\n def ~@\n end"
- s = stmts(<<-eof)
+ s = stmts(<<-EOF)
def /(other) 'hi' end
def method1
def dynamic; end
end
- eof
+ EOF
expect(s[1].to_s).to eq "def method1\n def dynamic; end\n end"
end
it "gets comment line numbers" do
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq ["comment", "comment", "comment"]
expect(s.comments_range).to eq(1..3)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq ["comment", "comment"]
expect(s.comments_range).to eq(2..3)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq ["comment", "comment"]
expect(s.comments_range).to eq(1..2)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq ["comment"]
expect(s.comments_range).to eq(1..1)
- s = stmt <<-eof
+ s = stmt <<-EOF
def method; end # comment
- eof
+ EOF
expect(s.comments).to eq ["comment"]
expect(s.comments_range).to eq(1..1)
end
it "only looks up to two lines back for comments" do
- s = stmt <<-eof
+ s = stmt <<-EOF
# comments
# comments
def method; end
- eof
+ EOF
expect(s.comments).to eq ["comments"]
- s = stmt <<-eof
+ s = stmt <<-EOF
# comments
def method; end
- eof
+ EOF
expect(s.comments).to eq nil
- ss = stmts <<-eof
+ ss = stmts <<-EOF
# comments
@@ -247,7 +247,7 @@ def method; end
# hello
def method2; end
- eof
+ EOF
expect(ss[0].comments).to eq nil
expect(ss[1].comments).to eq ['hello']
end
@@ -283,10 +283,10 @@ def method2; end
end
it "does not open a block on an aliased keyword block opener" do
- s = stmts(<<-eof)
+ s = stmts(<<-EOF)
class A; alias x do end
class B; end
- eof
+ EOF
expect(s[0].block.to_s).to eq 'alias x do'
expect(s.size).to be > 1
end
diff --git a/spec/parser/ruby/legacy/token_list_spec.rb b/spec/parser/ruby/legacy/token_list_spec.rb
index ee03ad701..b97507eb7 100644
--- a/spec/parser/ruby/legacy/token_list_spec.rb
+++ b/spec/parser/ruby/legacy/token_list_spec.rb
@@ -33,7 +33,7 @@
x = TokenList.new('x = "hello #{world}"')
expect(x.size).to eq 6
expect(x[4].class).to eq LT::TkDSTRING
- expect(x.to_s).to eq 'x = "hello #{world}"' + "\n"
+ expect(x.to_s.strip).to eq %(x = "hello \#{world}")
end
it "handles label syntax" do
diff --git a/spec/parser/ruby/ruby_parser_spec.rb b/spec/parser/ruby/ruby_parser_spec.rb
index c66dc1527..aa4d01639 100644
--- a/spec/parser/ruby/ruby_parser_spec.rb
+++ b/spec/parser/ruby/ruby_parser_spec.rb
@@ -15,66 +15,66 @@ def tokenize(stmt)
describe "#parse" do
it "gets comment line numbers" do
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq "comment\ncomment\ncomment"
expect(s.comments_range).to eq(1..3)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq "comment\ncomment"
expect(s.comments_range).to eq(2..3)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq "comment\ncomment"
expect(s.comments_range).to eq(1..2)
- s = stmt <<-eof
+ s = stmt <<-EOF
# comment
def method; end
- eof
+ EOF
expect(s.comments).to eq "comment"
expect(s.comments_range).to eq(1..1)
- s = stmt <<-eof
+ s = stmt <<-EOF
def method; end # comment
- eof
+ EOF
expect(s.comments).to eq "comment"
expect(s.comments_range).to eq(1..1)
end
it "only looks up to two lines back for comments" do
- s = stmts <<-eof
+ s = stmts <<-EOF
# comments
# comments
def method; end
- eof
+ EOF
expect(s[1].comments).to eq "comments"
- s = stmts <<-eof
+ s = stmts <<-EOF
# comments
def method; end
- eof
+ EOF
expect(s[1].comments).to eq nil
- ss = stmts <<-eof
+ ss = stmts <<-EOF
# comments
@@ -82,13 +82,13 @@ def method; end
# hello
def method2; end
- eof
+ EOF
expect(ss[1].comments).to eq nil
expect(ss[2].comments).to eq 'hello'
end
it "handles block comment followed by line comment" do
- ss = stmts <<-eof
+ ss = stmts <<-EOF
# comments1
=begin
@@ -96,12 +96,12 @@ def method2; end
=end
# comments3
def hello; end
-eof
+ EOF
expect(ss.last.comments).to eq "comments3"
end
it "handles block comment followed by block comment" do
- ss = stmts <<-eof
+ ss = stmts <<-EOF
=begin
comments1
=end
@@ -109,7 +109,7 @@ def hello; end
comments2
=end
def hello; end
-eof
+ EOF
expect(ss.last.comments.strip).to eq "comments2"
end
@@ -301,7 +301,7 @@ def hello; end
"TEST = %#{id}(\n A\n B\n C\n )"
].each do |str|
node = stmt(str).jump(sym)
- expect(node.source).to eq(str[/(\%#{id}\(.+\))/m, 1])
+ expect(node.source).to eq(str[/(%#{id}\(.+\))/m, 1])
end
end
@@ -311,10 +311,10 @@ def hello; end
"TEST = %#{id}{ A B C }",
"TEST = %#{id}{ \nA \nB \nC \n}",
"TEST = %#{id}{\n\nAD\n\nB\n\nC\n\n}",
- "TEST = %#{id}{\n A\n B\n C\n }",
+ "TEST = %#{id}{\n A\n B\n C\n }"
].each do |str|
node = stmt(str).jump(sym)
- expect(node.source).to eq(str[/(\%#{id}\{.+\})/m, 1])
+ expect(node.source).to eq(str[/(%#{id}\{.+\})/m, 1])
end
end
@@ -325,10 +325,10 @@ def hello; end
"TEST = %#{id}[ \nA \nB \nC \n]",
"TEST = %#{id}[\n\nAD\n\nB\n\nC\n\n]",
"TEST = %#{id}[\n A\n B\n C\n ]",
- "TEST = %#{id}[\n A]",
+ "TEST = %#{id}[\n A]"
].each do |str|
node = stmt(str).jump(sym)
- expect(node.source).to eq(str[/(\%#{id}\[.+\])/m, 1])
+ expect(node.source).to eq(str[/(%#{id}\[.+\])/m, 1])
end
end
@@ -339,7 +339,7 @@ def hello; end
end
it "properly tokenizes symbols" do
- tokens = tokenize(<<-eof)
+ tokens = tokenize(<<-EOF)
class X
Foo = :''
Fuu = :bar
@@ -347,30 +347,30 @@ class X
Baz = :"B+z"
Qux = :if
end
- eof
+ EOF
symbols = tokens.select {|t| t[0] == :symbol }.map {|t| t[1] }
expect(symbols).to eq %w(:'' :bar :BAR :"B+z" :if)
end
# @bug gh-1313
it "tokenizes comments in-order" do
- src = <<-eof
+ src = <<-EOF
def method
# Method comment not docstring
end
- eof
+ EOF
tokens = tokenize(src.gsub(/^ +/, ''))
- expect(tokens).to eq(tokens.sort_by {|t| t.last })
- expect(tokens.map {|t| t.first }).to eq %i(kw sp ident nl comment kw nl)
+ expect(tokens).to eq(tokens.sort_by(&:last))
+ expect(tokens.map(&:first)).to eq %i(kw sp ident nl comment kw nl)
end
it "parses %w() array in constant declaration" do
- s = stmt(<<-eof)
+ s = stmt(<<-EOF)
class Foo
FOO = %w( foo bar )
end
- eof
+ EOF
expect(s.jump(:qwords_literal).source).to eq '%w( foo bar )'
if RUBY_VERSION >= '1.9.3' # ripper fix: array node encapsulates qwords
expect(s.jump(:array).source).to eq '%w( foo bar )'
@@ -378,43 +378,43 @@ class Foo
end
it "parses %w() array source in object[] parsed context" do
- s = stmts(<<-eof)
+ s = stmts(<<-EOF)
{}[:key]
FOO = %w( foo bar )
- eof
+ EOF
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
end
it "parses %w() array source in object[]= parsed context" do
- s = stmts(<<-eof)
+ s = stmts(<<-EOF)
{}[:key] = :value
FOO = %w( foo bar )
- eof
+ EOF
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
end
it "parses [] as array" do
- s = stmt(<<-eof)
+ s = stmt(<<-EOF)
class Foo
FOO = ['foo', 'bar']
end
- eof
+ EOF
expect(s.jump(:array).source).to eq "['foo', 'bar']"
end
it "parses [[]] as array of arrays" do
- s = stmt(<<-eof)
+ s = stmt(<<-EOF)
class Foo
FOO = [['foo', 'bar']]
end
- eof
+ EOF
expect(s.jump(:array).source).to eq "[['foo', 'bar']]"
end
it "parses %w() array inside another empty array" do
- s = stmts(<<-eof)
+ s = stmts(<<-EOF)
FOO = [%w( foo bar )]
- eof
+ EOF
expect(s[0].jump(:array).source).to eq '[%w( foo bar )]'
end
@@ -432,7 +432,7 @@ class Foo
end
it "has the correct line range for class/modules" do
- s = stmt(<<-eof)
+ s = stmt(<<-EOF)
class Foo
def foo; end
@@ -440,23 +440,23 @@ def foo; end
# Ending comment
end
- eof
+ EOF
expect(s.jump(:class).line_range).to eq(1..7)
end
it "has the correct line range for blocks" do
Registry.clear
- ast = YARD.parse_string(<<-eof).enumerator
+ ast = YARD.parse_string(<<-EOF).enumerator
module A
some_method
end
- eof
+ EOF
expect(ast.first.block.source.strip).to eq "some_method"
end
it "finds lone comments" do
Registry.clear
- ast = YARD.parse_string(<<-eof).enumerator
+ ast = YARD.parse_string(<<-EOF).enumerator
class Foo
##
# comment here
@@ -466,7 +466,7 @@ def foo; end
# end comment
end
- eof
+ EOF
comment = ast.first.last.jump(:comment)
expect(comment.type).to eq :comment
expect(comment.docstring_hash_flag).to be true
@@ -478,25 +478,25 @@ def foo; end
it "does not group comments if they don't begin the line" do
Registry.clear
- YARD.parse_string(<<-eof).enumerator
+ YARD.parse_string(<<-EOF).enumerator
class Foo
CONST1 = 1 # Comment here
CONST2 = 2 # Another comment here
end
- eof
+ EOF
expect(Registry.at("Foo::CONST1").docstring).to eq "Comment here"
expect(Registry.at("Foo::CONST2").docstring).to eq "Another comment here"
end
it "handles comments in the middle of a multi-line statement" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
foo # BREAK
.bar
# Documentation
class Baz; end
- eof
+ EOF
expect(Registry.at('Baz')).not_to be_nil
expect(Registry.at('Baz').docstring).to eq 'Documentation'
end
@@ -504,7 +504,7 @@ class Baz; end
%w(if unless).each do |type|
it "does not get confused by modifier '#{type}' statements" do
Registry.clear
- YARD.parse_string(<<-eof).enumerator
+ YARD.parse_string(<<-EOF).enumerator
module Foo
#{type} test?
# Docstring
@@ -516,7 +516,7 @@ def foo
end
end
end
- eof
+ EOF
expect(Registry.at("Foo::Bar").docstring).to eq "Docstring"
expect(Registry.at("Foo::Bar#foo").docstring).to eq "Docstring2"
@@ -524,11 +524,11 @@ def foo
it "supports #{type} statements at start of source" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
#{type} condition?
class Foo; def bar; #{type} true; end end end
end
- eof
+ EOF
expect(log.io.string).to eq ""
expect(Registry.at('Foo#bar')).not_to eq nil
@@ -536,14 +536,14 @@ class Foo; def bar; #{type} true; end end end
it "can handle complex non-modifier '#{type}' statements" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
def initialize(data, options = Hash.new)
#{type} true; raise "error" end
@x = ( #{type} 1; true end ) # This line should not blow up
end
end
- eof
+ EOF
expect(log.io.string).to eq ""
expect(Registry.at('Foo#initialize')).not_to eq nil
@@ -551,12 +551,12 @@ def initialize(data, options = Hash.new)
it "does not add comment blocks to #{type}_mod nodes" do
Registry.clear
- YARD.parse_string(<<-eof).enumerator
+ YARD.parse_string(<<-EOF).enumerator
class Foo
# Docstring
def bar; end if true
end
- eof
+ EOF
expect(Registry.at("Foo#bar").docstring).to eq "Docstring"
end
@@ -575,20 +575,20 @@ def bar; end if true
end
it "handles cls/mod comments without line spacing" do
- ast = stmt <<-eof
+ ast = stmt <<-EOF
module A
# comment 1
# comment 2
class B
end
end
- eof
+ EOF
expect(ast.jump(:class).docstring).to eq "comment 1\ncomment 2"
end
%w(if unless).each do |type|
let(:condition_type) { type }
- let(:ast) { stmt '"#{' + type + ' condition?; 42; end}" ' + type + ' verbose?' }
+ let(:ast) { stmt "\"\#{#{type} condition?; 42; end}\" #{type} verbose?" }
let(:subject) { ast.jump(:string_embexpr)[0][0].source }
it "returns correct source for interpolated non-ternary '#{type}' conditionals" do
@@ -597,12 +597,12 @@ class B
end
it "handles single-line method declaration syntax" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class A
# Adds two numbers
def add(x) = x + 1
end
- eof
+ EOF
expect(Registry.at('A#add').docstring).to eq('Adds two numbers')
end if RUBY_VERSION >= '3.'
diff --git a/spec/parser/ruby/token_resolver_spec.rb b/spec/parser/ruby/token_resolver_spec.rb
index 1d577283d..4656094f3 100644
--- a/spec/parser/ruby/token_resolver_spec.rb
+++ b/spec/parser/ruby/token_resolver_spec.rb
@@ -2,7 +2,7 @@
RSpec.describe YARD::Parser::Ruby::TokenResolver do
before(:all) do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module A
def nomatch; end
@@ -47,7 +47,7 @@ def method; end
# @return [Q]
def self.q; end
end
- eof
+ EOF
end
def tokens_match
@@ -55,7 +55,7 @@ def tokens_match
end
def objs_match(*objects)
- other_objs = @resolved.reject {|_, o| !o }.map {|_, o| o.path }
+ other_objs = @resolved.select {|_, o| o }.map {|_, o| o.path }
expect(other_objs).to eq objects.flatten
tokens_match
end
diff --git a/spec/parser/source_parser_spec.rb b/spec/parser/source_parser_spec.rb
index e88a554e9..fba2e3a74 100644
--- a/spec/parser/source_parser_spec.rb
+++ b/spec/parser/source_parser_spec.rb
@@ -60,7 +60,7 @@ def after_file(&block)
before_list { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two]
+ expect(checks).to eq %i(one two)
end
it "cancels parsing if it returns false" do
@@ -80,7 +80,7 @@ def after_file(&block)
before_list { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two]
+ expect(checks).to eq %i(one two)
end
it "passes in globals" do
@@ -115,7 +115,7 @@ def after_file(&block)
after_list { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two]
+ expect(checks).to eq %i(one two)
end
it "does not cancel parsing if it returns false" do
@@ -125,7 +125,7 @@ def after_file(&block)
after_list { checks << :three }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :three]
+ expect(checks).to eq %i(one three)
end
end
@@ -150,7 +150,7 @@ def after_file(&block)
before_file { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two, :one, :two, :one, :two]
+ expect(checks).to eq %i(one two one two one two)
end
it "cancels parsing if it returns false" do
@@ -160,7 +160,7 @@ def after_file(&block)
before_file { checks << :three }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).to be nil
- expect(checks).to eq [:one, :one, :one]
+ expect(checks).to eq %i(one one one)
end
it "does not cancel on nil" do
@@ -170,7 +170,7 @@ def after_file(&block)
before_file { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two, :one, :two, :one, :two]
+ expect(checks).to eq %i(one two one two one two)
end
end
@@ -195,7 +195,7 @@ def after_file(&block)
after_file { checks << :two }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :two, :one, :two, :one, :two]
+ expect(checks).to eq %i(one two one two one two)
end
it "does not cancel parsing if it returns false" do
@@ -205,7 +205,7 @@ def after_file(&block)
after_file { checks << :three }
parse_list ['file.rb', ''], ['file2.rb', ''], ['file3.rb', 'class Foo; end']
expect(Registry.at('Foo')).not_to be nil
- expect(checks).to eq [:one, :three, :one, :three, :one, :three]
+ expect(checks).to eq %i(one three one three one three)
end
end
@@ -258,7 +258,7 @@ def after_file(&block)
describe "#parse_string" do
it "parses basic Ruby code" do
- YARD.parse_string(<<-eof)
+ YARD.parse_string(<<-EOF)
module Hello
class Hi
# Docstring
@@ -266,7 +266,7 @@ class Hi
def me; "VALUE" end
end
end
- eof
+ EOF
expect(Registry.at(:Hello)).not_to eq nil
expect(Registry.at("Hello::Hi#me")).not_to eq nil
expect(Registry.at("Hello::Hi#me").docstring).to eq "Docstring\nDocstring2"
@@ -274,7 +274,7 @@ def me; "VALUE" end
end
it "parses Ruby code with metaclasses" do
- YARD.parse_string(<<-eof)
+ YARD.parse_string(<<-EOF)
module Hello
class Hi
class < e
+ rescue StandardError => e
e.set_backtrace(["#{path}:#{obj.line}:in @it tag specification"])
raise e
end
@@ -91,11 +91,11 @@ def docspec(objname = self.class.description, klass = self.class.described_type)
# Run examples
obj.tags(:example).each do |exs|
- exs.text.split(/\n/).each do |ex|
+ exs.text.split("\n").each do |ex|
begin
hash = eval("{ #{ex} }")
expect(hash.keys.first).to eq hash.values.first
- rescue => e
+ rescue StandardError => e
raise e, "#{e.message}\nInvalid spec example in #{objname}:\n\n\t#{ex}\n"
end
end
@@ -115,7 +115,7 @@ def p(*args)
end
def puts(str = '')
- STDOUT.puts str + "
\n"
+ $stdout.puts "#{str}
\n"
str
end
end if ENV['TM_APP_PATH']
@@ -219,6 +219,4 @@ def puts(str = '')
begin
require 'asciidoctor'
rescue LoadError; end
-
-YARD::Logger
include YARD
diff --git a/spec/tags/directives_spec.rb b/spec/tags/directives_spec.rb
index 147a8e53d..3e4d8af88 100644
--- a/spec/tags/directives_spec.rb
+++ b/spec/tags/directives_spec.rb
@@ -29,13 +29,13 @@ def foo; end
end
it "parses code in context of current handler" do
- src = <<-eof
+ src = <<-EOF
class A
# @!parse
# def foo; end
eval "def foo; end"
end
- eof
+ EOF
parser = YARD::Parser::SourceParser.new
parser.file = "myfile.rb"
parser.parse(StringIO.new(src))
@@ -166,25 +166,25 @@ def handler
after { Registry.clear }
it "uses entire docstring if no indented data is found" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!method foo
# @!method bar
# @!scope class
end
- eof
+ EOF
expect(Registry.at('Foo.foo')).to be_a(CodeObjects::MethodObject)
expect(Registry.at('Foo.bar')).to be_a(CodeObjects::MethodObject)
end
it "handles indented block text in @!method" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!method foo(a)
# Docstring here
# @return [String] the foo
# Ignore this
# @param [String] a
- eof
+ EOF
foo = Registry.at('#foo')
expect(foo.docstring).to eq "Docstring here"
expect(foo.docstring.tag(:return)).not_to be nil
@@ -192,7 +192,7 @@ class Foo
end
it "executes directives on object in indented block" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!method foo(a)
# @!scope class
@@ -201,7 +201,7 @@ class Foo
# Hello
# Ignore this
end
- eof
+ EOF
foo = Registry.at('Foo.foo')
expect(foo.visibility).to eq :private
bar = Registry.at('Foo#bar')
@@ -209,7 +209,7 @@ class Foo
end
it "is able to define multiple @methods in docstring" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!method foo1
# Docstring1
@@ -219,7 +219,7 @@ class Foo
# @!scope class
# Docstring3
end
- eof
+ EOF
foo1 = Registry.at('Foo#foo1')
foo2 = Registry.at('Foo#foo2')
foo3 = Registry.at('Foo.foo3')
@@ -229,7 +229,7 @@ class Foo
end
it "defines the method inside namespace if attached to namespace object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
# @!method foo
# Docstring1
@@ -238,40 +238,40 @@ module Foo
class Bar
end
end
- eof
+ EOF
expect(Registry.at('Foo::Bar#foo').docstring).to eq 'Docstring1'
expect(Registry.at('Foo::Bar#bar').docstring).to eq 'Docstring2'
end
it "sets scope to class if signature has 'self.' prefix" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!method self.foo
# @!method self. bar
# @!method self.baz()
class Foo
end
- eof
+ EOF
%w(foo bar baz).each do |name|
expect(Registry.at("Foo.#{name}")).to be_a(CodeObjects::MethodObject)
end
end
it "defines parameters from signature" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!method foo(a, b, c = nil)
- eof
+ EOF
expect(Registry.at('#foo').parameters).to eq [['a', nil], ['b', nil], ['c', 'nil']]
end
it "is able to define method with module scope (module function)" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!method foo
# @!scope module
# This is a docstring
# @return [Boolean] whether this is true
class Foo
end
- eof
+ EOF
foo_c = Registry.at('Foo.foo')
foo_i = Registry.at('Foo#foo')
expect(foo_c).not_to be nil
@@ -288,25 +288,25 @@ class Foo
after { Registry.clear }
it "uses entire docstring if no indented data is found" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!attribute foo
# @!attribute bar
# @!scope class
end
- eof
+ EOF
expect(Registry.at('Foo.foo')).to be_reader
expect(Registry.at('Foo.bar')).to be_reader
end
it "handles indented block in @!attribute" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!attribute foo
# Docstring here
# @return [String] the foo
# Ignore this
# @param [String] a
- eof
+ EOF
foo = Registry.at('#foo')
expect(foo.is_attribute?).to be true
expect(foo.docstring).to eq "Docstring here"
@@ -315,7 +315,7 @@ class Foo
end
it "is able to define multiple @attributes in docstring" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!attribute [r] foo1
# Docstring1
@@ -325,7 +325,7 @@ class Foo
# @!scope class
# Docstring3
end
- eof
+ EOF
foo1 = Registry.at('Foo#foo1')
foo2 = Registry.at('Foo#foo2=')
foo3 = Registry.at('Foo.foo3')
@@ -342,27 +342,27 @@ class Foo
end
it "defines the attr inside namespace if attached to namespace object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
module Foo
# @!attribute [r] foo
# @!attribute [r] bar
class Bar
end
end
- eof
+ EOF
expect(Registry.at('Foo::Bar#foo')).to be_reader
expect(Registry.at('Foo::Bar#bar')).to be_reader
end
end
it "sets scope to class if signature has 'self.' prefix" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @!attribute self.foo
# @!attribute self. bar
# @!attribute self.baz
class Foo
end
- eof
+ EOF
%w(foo bar baz).each do |name|
expect(Registry.at("Foo.#{name}")).to be_reader
end
@@ -445,7 +445,7 @@ class Foo
it "updates visibility on future methods" do
Registry.clear
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @!visibility private
@@ -454,7 +454,7 @@ def foo; end
def bar; end
def baz; end
end
- eof
+ EOF
%w(foo bar baz).each do |name|
expect(Registry.at("Foo##{name}").visibility).to eq :private
end
diff --git a/spec/tags/overload_tag_spec.rb b/spec/tags/overload_tag_spec.rb
index 1bc296853..a418644ca 100644
--- a/spec/tags/overload_tag_spec.rb
+++ b/spec/tags/overload_tag_spec.rb
@@ -2,12 +2,12 @@
RSpec.describe YARD::Tags::OverloadTag do
before do
- @tag = Tags::OverloadTag.new(:overload, <<-'eof')
+ @tag = Tags::OverloadTag.new(:overload, <<-EOF)
def bar(a, b = 1, &block)
Hello world
@param a [String]
@return [String]
- eof
+ EOF
end
it "parses the first line as a method signature" do
@@ -62,7 +62,7 @@ def bar(a, b = 1, &block)
['f:', "2"],
['g:', nil],
['**rest', nil],
- ['&block', nil],
+ ['&block', nil]
]
end
end
diff --git a/spec/templates/class_spec.rb b/spec/templates/class_spec.rb
index b44e4dcdf..9113fa4b7 100644
--- a/spec/templates/class_spec.rb
+++ b/spec/templates/class_spec.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Engine.template(:default, :docstring) do
before do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
private
# Comments
# @abstract override this class
@@ -28,7 +28,7 @@ class D
# @private
def initialize; end
end
- eof
+ EOF
end
it "renders html format correctly" do
diff --git a/spec/templates/constant_spec.rb b/spec/templates/constant_spec.rb
index b6cc38fec..4a12fa2bd 100644
--- a/spec/templates/constant_spec.rb
+++ b/spec/templates/constant_spec.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/spec_helper"
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Engine.template(:default, :constant) do
describe "fully dressed constant" do
it "renders text format correctly" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
class YARD::CLI::YRI
# Default search paths that should be loaded dynamically into YRI. These paths
# take precedence over all other paths ({SEARCH_PATHS_FILE} and RubyGems
@@ -16,7 +16,7 @@ class YARD::CLI::YRI
# @since 0.6.0
DEFAULT_SEARCH_PATHS = []
end
- eof
+ EOF
text_equals(Registry.at('YARD::CLI::YRI::DEFAULT_SEARCH_PATHS').format(text_options), :constant001)
end
end
@@ -24,17 +24,17 @@ class YARD::CLI::YRI
describe "simple constant with no documentation" do
it "renders text format correctly" do
# Short constant should show on single line
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
MYCONST = 'foo'
- eof
+ EOF
text_equals(Registry.at('MYCONST').format(text_options), :constant002)
# Long constant should show on multiple lines, indented
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
MYCONST = [A, B, C, D, E, F, G, H, I, J, K, L,
M, N, O, P, Q, R, S, T, U, V, W,
X, Y, Z]
- eof
+ EOF
text_equals(Registry.at('MYCONST').format(text_options), :constant003)
end
end
diff --git a/spec/templates/engine_spec.rb b/spec/templates/engine_spec.rb
index 16f70046c..89d0eb6a9 100644
--- a/spec/templates/engine_spec.rb
+++ b/spec/templates/engine_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Engine do
before { @paths = Engine.template_paths }
@@ -49,8 +49,8 @@
expect(Engine).to receive(:template_paths).and_return([])
expect(File).to receive(:directory?).with("/full/path/template/notname").and_return(true)
start_template = double(:start_template,
- :full_path => '/full/path/template/name',
- :full_paths => ['/full/path/template/name'])
+ :full_path => '/full/path/template/name',
+ :full_paths => ['/full/path/template/name'])
expect(start_template).to receive(:is_a?).with(Template).and_return(true)
mod = Engine.template(start_template, '..', 'notname')
expect(mod).to include(Template)
@@ -79,11 +79,11 @@
mod = double(:template)
options = TemplateOptions.new
options.reset_defaults
- options.objects = [:a, :b, :c]
+ options.objects = %i(a b c)
options.object = Registry.root
expect(mod).to receive(:run).with(options)
expect(Engine).to receive(:template).with(:default, :fulldoc, :text).and_return(mod)
- Engine.generate([:a, :b, :c])
+ Engine.generate(%i(a b c))
end
end
diff --git a/spec/templates/helpers/base_helper_spec.rb b/spec/templates/helpers/base_helper_spec.rb
index fc2cd3863..505bfcc74 100644
--- a/spec/templates/helpers/base_helper_spec.rb
+++ b/spec/templates/helpers/base_helper_spec.rb
@@ -49,7 +49,7 @@
it "returns path of Proxified object if argument is a String or Symbol" do
expect(link_object("Array")).to eq "Array"
- expect(link_object(:"A::B")).to eq "A::B"
+ expect(link_object(:'A::B')).to eq "A::B"
end
it "returns the argument if not an object, proxy, String or Symbol" do
diff --git a/spec/templates/helpers/html_helper_spec.rb b/spec/templates/helpers/html_helper_spec.rb
index cbc43f11d..c8b5eca3a 100644
--- a/spec/templates/helpers/html_helper_spec.rb
+++ b/spec/templates/helpers/html_helper_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/shared_signature_examples"
+require "#{File.dirname(__FILE__)}/shared_signature_examples"
RSpec.describe YARD::Templates::Helpers::HtmlHelper do
include YARD::Templates::Helpers::BaseHelper
@@ -85,14 +85,10 @@ def options
"Array<String, Symbol>"],
"Array<{String => Array}>" => [["Array", "String", "Array", "Symbol"],
"Array<{String => " \
- "Array<Symbol>}>"]}.each do |text, values|
+ "Array<Symbol>}>"]}.each do |text, values|
it "links all classes in #{text}" do
- if text.count('<') > 0
- expect(self).to receive(:h).with('<').at_least(text.count('<')).times.and_return("<")
- end
- if text.count('>') > 0
- expect(self).to receive(:h).with('>').at_least(text.count('>')).times.and_return(">")
- end
+ expect(self).to receive(:h).with('<').at_least(text.count('<')).times.and_return("<") if text.count('<') > 0
+ expect(self).to receive(:h).with('>').at_least(text.count('>')).times.and_return(">") if text.count('>') > 0
values[0].each {|v| expect(self).to receive(:linkify).with(v, v).and_return("#{v}") }
expect(format_types([text], false)).to eq values[1]
end
@@ -178,9 +174,7 @@ def options
it "handles fenced code blocks (Redcarpet specific)" do
log.enter_level(Logger::FATAL) do
- unless markup_class(:markdown).to_s == 'RedcarpetCompat'
- pending 'This test is Redcarpet specific'
- end
+ pending 'This test is Redcarpet specific' unless markup_class(:markdown).to_s == 'RedcarpetCompat'
end
markdown = "Introduction:\n```ruby\nputs\n\nputs\n```"
@@ -237,7 +231,7 @@ def options
end
it "links objects from overload tag" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module Foo
class Bar; def a; end end
class Baz
@@ -245,7 +239,7 @@ class Baz
def a; end
end
end
- eof
+ EOF
obj = Registry.at('Foo::Baz#a').tag(:overload)
allow(self).to receive(:serializer).and_return(Serializers::FileSystemSerializer.new)
allow(self).to receive(:object).and_return(obj)
@@ -286,12 +280,12 @@ def a; end
end
it "escapes method name in title" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
class Array
def &(other)
end
end
- eof
+ EOF
obj = Registry.at('Array#&')
allow(self).to receive(:serializer).and_return(Serializers::FileSystemSerializer.new)
allow(self).to receive(:object).and_return(obj)
@@ -468,11 +462,11 @@ def parse_link(link)
end
it "warns about missing reference at right file location for object" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# Comments here
# And a reference to {InvalidObject}
class MyObject; end
- eof
+ EOF
logger = double(:log)
expect(logger).to receive(:warn).ordered.with(
"In file `(stdin)':2: Cannot resolve link to InvalidObject from text:\n\t...{InvalidObject}"
@@ -483,13 +477,13 @@ class MyObject; end
end
it "shows ellipsis on either side if there is more on the line in a reference warning" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# {InvalidObject1} beginning of line
# end of line {InvalidObject2}
# Middle of {InvalidObject3} line
# {InvalidObject4}
class MyObject; end
- eof
+ EOF
logger = double(:log)
expect(logger).to receive(:warn).ordered.with("In file `(stdin)':1: Cannot resolve link to InvalidObject1 from text:\n\t{InvalidObject1}...")
expect(logger).to receive(:warn).ordered.with("In file `(stdin)':2: Cannot resolve link to InvalidObject2 from text:\n\t...{InvalidObject2}")
@@ -506,12 +500,12 @@ class MyObject; end
expect(logger).to receive(:warn).ordered.with("In file `myfile.txt':3: Cannot resolve link to InvalidObject from text:\n\t...{InvalidObject Some Title}")
allow(self).to receive(:log).and_return(logger)
allow(self).to receive(:object).and_return(Registry.root)
- resolve_links(<<-eof)
+ resolve_links(<<-EOF)
Hello world
This is a line
And {InvalidObject Some Title}
And more.
- eof
+ EOF
end
it "warns if you link a constant namespace as if it were a class/module" do
@@ -548,17 +542,17 @@ class MyObject; end
end
def format_types(types, _brackets = false) types.join(", ") end
- def signature(obj, link = false) super(obj, link).strip end
+ def signature(obj, link = false) super.strip end
it_should_behave_like "signature"
it "links to regular method if overload name does not have the same method name" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class Foo
# @overload bar(a, b, c)
def foo; end
end
- eof
+ EOF
serializer = double(:serializer)
allow(serializer).to receive(:serialized_path).with(Registry.at('Foo')).and_return('')
allow(self).to receive(:serializer).and_return(serializer)
@@ -608,10 +602,10 @@ def foo; end
it "calls html_syntax_highlight_NAME if source starts with !!!NAME" do
expect(subject).to receive(:html_syntax_highlight_NAME).and_return("foobar")
- expect(subject.html_syntax_highlight(<<-eof
+ expect(subject.html_syntax_highlight(<<-EOF
!!!NAME
def x; end
- eof
+ EOF
)).to eq "foobar"
end
diff --git a/spec/templates/helpers/markup/rdoc_markup_spec.rb b/spec/templates/helpers/markup/rdoc_markup_spec.rb
index 44a7315da..ee9b1bf7a 100644
--- a/spec/templates/helpers/markup/rdoc_markup_spec.rb
+++ b/spec/templates/helpers/markup/rdoc_markup_spec.rb
@@ -12,12 +12,12 @@ def require(lib)
def load_markup
require 'rdoc/markup'
require 'rdoc/markup/to_html'
- return :RDoc2
+ :RDoc2
rescue LoadError
begin
require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
- return :RDoc1
+ :RDoc1
rescue LoadError
raise NameError, "could not load RDocMarkup (rdoc is not installed)"
end
diff --git a/spec/templates/helpers/markup_helper_spec.rb b/spec/templates/helpers/markup_helper_spec.rb
index 9b914a04e..eb4e03de6 100644
--- a/spec/templates/helpers/markup_helper_spec.rb
+++ b/spec/templates/helpers/markup_helper_spec.rb
@@ -73,7 +73,7 @@ def initialize(options = Templates::TemplateOptions.new)
# loading any libraries but our implementation tries to return the library
# name as a constant
@gen.load_markup_provider
- expect(@gen.markup_provider).to eq :"rpeg-markdown"
+ expect(@gen.markup_provider).to eq :'rpeg-markdown'
end
it "overrides the search if `:markup_provider` is set in options" do
diff --git a/spec/templates/helpers/method_helper_spec.rb b/spec/templates/helpers/method_helper_spec.rb
index 108a8609f..c517e68c2 100644
--- a/spec/templates/helpers/method_helper_spec.rb
+++ b/spec/templates/helpers/method_helper_spec.rb
@@ -13,28 +13,28 @@
end
it "does not show &blockarg if no @param tag and has @yield" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yield blah
def foo(&block); end
- eof
+ EOF
expect(format_args(Registry.at('#foo'))).to eq ''
end
it "does not show &blockarg if no @param tag and has @yieldparam" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yieldparam blah test
def foo(&block); end
- eof
+ EOF
expect(format_args(Registry.at('#foo'))).to eq ''
end
it "shows &blockarg if @param block is documented (even with @yield)" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yield [a,b]
# @yieldparam a test
# @param block test
def foo(&block) end
- eof
+ EOF
expect(format_args(Registry.at('#foo'))).to eq '(&block)'
end
end
@@ -43,39 +43,39 @@ def foo(&block) end
before { YARD::Registry.clear }
it "shows block for method with yield" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
def foo; yield(a, b, c) end
- eof
+ EOF
expect(format_block(Registry.at('#foo'))).to eq "{|a, b, c| ... }"
end
it "shows block for method with @yieldparam tags" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yieldparam _self me!
def foo; end
- eof
+ EOF
expect(format_block(Registry.at('#foo'))).to eq "{|_self| ... }"
end
it "shows block for method with @yield but no types" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yield blah
# @yieldparam a
def foo; end
# @yield blah
def foo2; end
- eof
+ EOF
expect(format_block(Registry.at('#foo'))).to eq "{|a| ... }"
expect(format_block(Registry.at('#foo2'))).to eq "{ ... }"
end
it "shows block for method with @yield and types" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @yield [a, b, c] blah
# @yieldparam a
def foo; end
- eof
+ EOF
expect(format_block(Registry.at('#foo'))).to eq "{|a, b, c| ... }"
end
end
diff --git a/spec/templates/helpers/module_helper_spec.rb b/spec/templates/helpers/module_helper_spec.rb
index a2532daf0..b489f6b49 100644
--- a/spec/templates/helpers/module_helper_spec.rb
+++ b/spec/templates/helpers/module_helper_spec.rb
@@ -21,12 +21,12 @@
end
it "ignores methods if namespace object is filtered" do
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
# @author test
class Foo
def bar; end
end
- eof
+ EOF
options.verifier = YARD::Verifier.new('@author.text != "test"')
expect(prune_method_listing(objects)).to eq []
diff --git a/spec/templates/helpers/shared_signature_examples.rb b/spec/templates/helpers/shared_signature_examples.rb
index d2238e5df..630b00878 100644
--- a/spec/templates/helpers/shared_signature_examples.rb
+++ b/spec/templates/helpers/shared_signature_examples.rb
@@ -32,95 +32,95 @@ def trim(sig) sig.gsub(/\s+/, ' ') end
end
it "shows return type for single type" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [String]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:single]
end
it "shows return type for 2 types" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [String, Symbol]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:two_types]
end
it "shows return type for 2 types over multiple tags" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [String]
# @return [Symbol]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:two_types_multitag]
end
it "shows 'Type?' if return types are [Type, nil]" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [Type, nil]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:type_nil]
end
it "shows 'Type?' if return types are [Type, nil, nil] (extra nil)" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [Type, nil]
# @return [nil]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:type_nil]
end
it "shows 'Type+' if return types are [Type, Array]" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [Type, ]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:type_array]
end
it "shows (Type, ...) for more than 2 return types" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [Type, ]
# @return [AnotherType]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:multitype]
end
it "shows (void) for @return [void] by default" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [void]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:void]
end
it "does not show return for @return [void] if :hide_void_return is true" do
@options.hide_void_return = true
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [void]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:hide_void]
end
it "shows block for method with yield" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
def foo; yield(a, b, c) end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo')))).to eq @results[:block]
end
it "uses regular return tag if the @overload is empty" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @overload foobar
# Hello world
# @return [String]
def foo; end
- eof
+ EOF
expect(trim(signature(Registry.at('#foo').tag(:overload)))).to eq @results[:empty_overload]
end
end
diff --git a/spec/templates/helpers/text_helper_spec.rb b/spec/templates/helpers/text_helper_spec.rb
index 51bfe2924..85fdd6267 100644
--- a/spec/templates/helpers/text_helper_spec.rb
+++ b/spec/templates/helpers/text_helper_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + "/shared_signature_examples"
+require "#{File.dirname(__FILE__)}/shared_signature_examples"
RSpec.describe YARD::Templates::Helpers::TextHelper do
include YARD::Templates::Helpers::BaseHelper
@@ -26,7 +26,7 @@
}
end
- def signature(obj) super(obj).strip end
+ def signature(obj) super.strip end
it_should_behave_like "signature"
end
@@ -34,12 +34,12 @@ def signature(obj) super(obj).strip end
describe "#align_right" do
it "aligns text right" do
text = "Method: #some_method (SomeClass)"
- expect(align_right(text)).to eq ' ' * 40 + text
+ expect(align_right(text)).to eq (' ' * 40) + text
end
it "truncates text that is longer than allowed width" do
text = "(Defined in: /home/user/.rip/.packages/some_gem-2460672e333ac07b9190ade88ec9a91c/long/path.rb)"
- expect(align_right(text)).to eq ' ' + text[0, 68] + '...'
+ expect(align_right(text)).to eq " #{text[0, 68]}..."
end
end
diff --git a/spec/templates/markup_processor_integrations/asciidoctor_spec.rb b/spec/templates/markup_processor_integrations/asciidoctor_spec.rb
index 74bd98ee2..580519836 100644
--- a/spec/templates/markup_processor_integrations/asciidoctor_spec.rb
+++ b/spec/templates/markup_processor_integrations/asciidoctor_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/integration_spec_helper'
+require "#{File.dirname(__FILE__)}/integration_spec_helper"
RSpec.describe 'Asciidoctor integration' do
include_context 'shared helpers for markup processor integration specs'
@@ -35,7 +35,7 @@
x = 4
-----
-ASCIIDOC
+ ASCIIDOC
end
it 'renders level 2 header' do
diff --git a/spec/templates/markup_processor_integrations/integration_spec_helper.rb b/spec/templates/markup_processor_integrations/integration_spec_helper.rb
index de9843897..392f7f089 100644
--- a/spec/templates/markup_processor_integrations/integration_spec_helper.rb
+++ b/spec/templates/markup_processor_integrations/integration_spec_helper.rb
@@ -25,9 +25,7 @@
end
before(:each) do
- if html_renderer.markup_class(markup).nil?
- skip "Missing markup renderer #{markup}"
- end
+ skip "Missing markup renderer #{markup}" if html_renderer.markup_class(markup).nil?
end
# Works only with one-liners.
diff --git a/spec/templates/markup_processor_integrations/markdown_spec.rb b/spec/templates/markup_processor_integrations/markdown_spec.rb
index 8581f7dd8..ec14e87f2 100644
--- a/spec/templates/markup_processor_integrations/markdown_spec.rb
+++ b/spec/templates/markup_processor_integrations/markdown_spec.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/integration_spec_helper'
+require "#{File.dirname(__FILE__)}/integration_spec_helper"
RSpec.describe 'Markdown processors integration' do
include_context 'shared helpers for markup processor integration specs'
shared_examples 'shared examples for markdown processors' do
let(:document) do
- <<-MARKDOWN
+ <<-MARKDOWN
## Example code listings
Indented block of Ruby code:
@@ -36,7 +36,7 @@
commonmark line break with\\
a backslash
-MARKDOWN
+ MARKDOWN
end
it 'renders level 2 header' do
@@ -72,7 +72,6 @@
include_examples 'shared examples for markdown processors'
-
it 'generates anchor tags for level 2 header' do
expect(rendered_document).to include('Example code listings
')
end
@@ -82,7 +81,7 @@
end
end
- describe 'CommonMarker', if: RUBY_VERSION >= '2.3' do
+ describe 'CommonMarker', :if => RUBY_VERSION >= '2.3' do
let(:markup) { :markdown }
let(:markup_provider) { :commonmarker }
diff --git a/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb b/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb
index 1e1a24d13..eca4b9e2b 100644
--- a/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb
+++ b/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/integration_spec_helper'
+require "#{File.dirname(__FILE__)}/integration_spec_helper"
RSpec.describe 'Markdown via RDoc integration' do
include_context 'shared helpers for markup processor integration specs'
@@ -27,7 +27,7 @@
x = 3
```
-MARKDOWN
+ MARKDOWN
end
it 'renders level 2 header' do
diff --git a/spec/templates/markup_processor_integrations/rdoc_spec.rb b/spec/templates/markup_processor_integrations/rdoc_spec.rb
index 3ad18a365..e21334fe3 100644
--- a/spec/templates/markup_processor_integrations/rdoc_spec.rb
+++ b/spec/templates/markup_processor_integrations/rdoc_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/integration_spec_helper'
+require "#{File.dirname(__FILE__)}/integration_spec_helper"
RSpec.describe 'RDoc integration' do
include_context 'shared helpers for markup processor integration specs'
@@ -21,7 +21,7 @@
This has nothing to do with Ruby.
-RDOC
+ RDOC
end
it 'renders level 2 header' do
@@ -33,7 +33,7 @@
end
it 'renders indented block of text which is not a piece of Ruby code, ' \
- 'and does not apply syntax highlight' do
+ 'and does not apply syntax highlight' do
expect(rendered_document).to match('This has nothing to do with Ruby.')
end
end
diff --git a/spec/templates/markup_processor_integrations/redcloth_spec.rb b/spec/templates/markup_processor_integrations/redcloth_spec.rb
index d006eb04c..3c85f1da0 100644
--- a/spec/templates/markup_processor_integrations/redcloth_spec.rb
+++ b/spec/templates/markup_processor_integrations/redcloth_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/integration_spec_helper'
+require "#{File.dirname(__FILE__)}/integration_spec_helper"
# Hack to fix RedCloth compat issues with MinGW compilation hosts
begin
@@ -30,7 +30,7 @@
p. Block of Ruby code using 'pre' tag:
pre. x = 2
-TEXTILE
+ TEXTILE
end
it 'renders level 2 header' do
diff --git a/spec/templates/method_spec.rb b/spec/templates/method_spec.rb
index 1ba86eb39..ce34805ec 100644
--- a/spec/templates/method_spec.rb
+++ b/spec/templates/method_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
# $COPY = :method001
# $COPYT = :html
@@ -20,7 +20,7 @@
describe "regular (deprecated) method" do
before do
@template = :method001
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
private
# Comments
# @param [Hash] x the x argument
@@ -31,7 +31,7 @@
# @deprecated for great justice
def m(x) end
alias x m
- eof
+ EOF
end
it_should_behave_like "all formats"
@@ -40,14 +40,14 @@ def m(x) end
describe "method with 1 overload" do
before do
@template = :method002
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
private
# Comments
# @overload m(x, y)
# @param [String] x parameter x
# @param [Boolean] y parameter y
def m(x) end
- eof
+ EOF
end
it_should_behave_like "all formats"
@@ -56,7 +56,7 @@ def m(x) end
describe "method with 2 overloads" do
before do
@template = :method003
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
private
# Method comments
# @overload m(x, y)
@@ -68,7 +68,7 @@ def m(x) end
# @param [Boolean] y parameter y
# @param [Boolean] z parameter z
def m(*args) end
- eof
+ EOF
end
it_should_behave_like "all formats"
@@ -77,10 +77,10 @@ def m(*args) end
describe "method void return" do
before do
@template = :method004
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @return [void]
def m(*args) end
- eof
+ EOF
end
it_should_behave_like "all formats"
@@ -89,13 +89,13 @@ def m(*args) end
describe "method void return in an overload" do
before do
@template = :method005
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @overload m(a)
# @return [void]
# @overload m(b)
# @param [String] b hi
def m(*args) end
- eof
+ EOF
end
it_should_behave_like "all formats"
@@ -104,13 +104,13 @@ def m(*args) end
describe "method with keyword arguments" do
before do
@template = :method006
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @param [String] x the x argument
# @param [Boolean] y the y argument
# @param [kword1] keyword 1
# @param [kword2] keyword 2
def m(x, y, *args, kword1: 123, kword2:, **) end
- eof
+ EOF
end
it_should_behave_like "all formats"
diff --git a/spec/templates/module_spec.rb b/spec/templates/module_spec.rb
index 416008249..0f414aa49 100644
--- a/spec/templates/module_spec.rb
+++ b/spec/templates/module_spec.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Engine.template(:default, :module) do
before do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module B
def c; end
def d; end
@@ -63,21 +63,21 @@ module Z; end
module TMP; include A end
class TMP2; extend A end
- eof
+ EOF
end
it "renders html format correctly" do
html_equals(Registry.at('A').format(html_options(:hide_void_return => true,
- :verifier => Verifier.new('object.type != :method || object.visibility == :public'))),
- :module001)
+ :verifier => Verifier.new('object.type != :method || object.visibility == :public'))),
+ :module001)
end
it "renders text format correctly" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module A
include D, E, F, A::B::C
end
- eof
+ EOF
text_equals(Registry.at('A').format(text_options), :module001)
end
@@ -88,7 +88,7 @@ module A
it "renders groups correctly in html" do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module A
# @group Foo
attr_accessor :foo_attr
@@ -102,14 +102,14 @@ def baz; end
def self.baz; end
end
- eof
+ EOF
html_equals(Registry.at('A').format(html_options), :module002)
end
it "ignores overwritten/private attributes/constants from inherited list" do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module B
attr_reader :foo
attr_accessor :bar
@@ -123,7 +123,7 @@ def foo; end
attr_reader :bar
FOO = 2
end
- eof
+ EOF
html_equals(Registry.at('A').
format(html_options(:verifier => Verifier.new('!@private'))), :module003)
@@ -131,7 +131,7 @@ def foo; end
it "embeds mixins with :embed_mixins = ['Foo', 'Bar', 'Baz::A*']" do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
class A
# This method is in A
def foo; end
@@ -175,14 +175,14 @@ module ABC
def baz_abc; end
end
end
- eof
+ EOF
html_equals(Registry.at('A').format(html_options(:embed_mixins => ['Foo', 'Bar', 'Baz::A*'])), :module004)
end
it "renders constant groups correctly in html" do
Registry.clear
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
module A
# @group Foo
FOO = 1
@@ -197,7 +197,7 @@ module A
WORLD = 4
end
- eof
+ EOF
html_equals(Registry.at('A').format(html_options), :module005)
end
end
diff --git a/spec/templates/onefile_spec.rb b/spec/templates/onefile_spec.rb
index b969a69a7..d241ae7a4 100644
--- a/spec/templates/onefile_spec.rb
+++ b/spec/templates/onefile_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
class StringSerializer < YARD::Serializers::Base
attr_accessor :files, :string
@@ -17,7 +17,7 @@ def serialize(object, data)
RSpec.describe YARD::Templates::Engine.template(:default, :onefile) do
before do
Registry.clear
- if defined?(::Encoding)
+ if defined?(Encoding)
@eenc = Encoding.default_external
Encoding.default_external = 'ascii-8bit'
@ienc = Encoding.default_internal
@@ -26,7 +26,7 @@ def serialize(object, data)
end
after do
- if defined?(::Encoding)
+ if defined?(Encoding)
Encoding.default_internal = @ienc
Encoding.default_external = @eenc
end
@@ -35,7 +35,7 @@ def serialize(object, data)
def render
@files = []
@output = String.new("")
- YARD.parse_string <<-eof
+ YARD.parse_string <<-EOF
class A
# Foo method
# @return [String]
@@ -45,13 +45,13 @@ def foo; end
# @return [Numeric]
def bar; end
end
- eof
+ EOF
readme = CodeObjects::ExtraFileObject.new('README',
- "# This is a code comment\n\n# Top of file\n\n\nclass C; end")
+ "# This is a code comment\n\n# Top of file\n\n\nclass C; end")
Templates::Engine.generate Registry.all(:class),
- :serializer => StringSerializer.new(@files, @output),
- :onefile => true, :format => :html, :readme => readme, :files => [readme,
- CodeObjects::ExtraFileObject.new('LICENSE', 'This is a license!')]
+ :serializer => StringSerializer.new(@files, @output),
+ :onefile => true, :format => :html, :readme => readme, :files => [readme,
+ CodeObjects::ExtraFileObject.new('LICENSE', 'This is a license!')]
end
it "renders html" do
diff --git a/spec/templates/section_spec.rb b/spec/templates/section_spec.rb
index 262188e05..cbbac1e15 100644
--- a/spec/templates/section_spec.rb
+++ b/spec/templates/section_spec.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Section do
include YARD::Templates
describe "#initialize" do
it "converts first argument to splat if it is array" do
- s = Section.new(:name, [:foo, :bar])
+ s = Section.new(:name, %i(foo bar))
expect(s.name).to eq :name
expect(s[0].name).to eq :foo
expect(s[1].name).to eq :bar
@@ -27,7 +27,7 @@
describe "#[]" do
it "uses Array#[] if argument is integer" do
- expect(Section.new(:name, [:foo, :bar])[0].name).to eq :foo
+ expect(Section.new(:name, %i(foo bar))[0].name).to eq :foo
end
it "returns new Section object if more than one argument" do
@@ -45,13 +45,13 @@
describe "#eql?" do
it "checks for equality of two equal sections" do
- expect(Section.new(:foo, [:a, :b])).to eql(Section.new(:foo, :a, :b))
- expect(Section.new(:foo, [:a, :b])).to eq Section.new(:foo, :a, :b)
+ expect(Section.new(:foo, %i(a b))).to eql(Section.new(:foo, :a, :b))
+ expect(Section.new(:foo, %i(a b))).to eq Section.new(:foo, :a, :b)
end
it "is not equal if section names are different" do
- expect(Section.new(:foo, [:a, :b])).not_to eql(Section.new(:bar, :a, :b))
- expect(Section.new(:foo, [:a, :b])).not_to eq Section.new(:bar, :a, :b)
+ expect(Section.new(:foo, %i(a b))).not_to eql(Section.new(:bar, :a, :b))
+ expect(Section.new(:foo, %i(a b))).not_to eq Section.new(:bar, :a, :b)
end
end
@@ -132,7 +132,7 @@
it "finds item inside sections" do
s = Section.new(:foo, Section.new(:bar, Section.new(:bar)))
s.any(:bar).push(:baz)
- expect(s.to_a).to eq [:foo, [:bar, [:bar, :baz]]]
+ expect(s.to_a).to eq [:foo, [:bar, %i(bar baz)]]
end
it "finds item in any deeply nested set of sections" do
diff --git a/spec/templates/spec_helper.rb b/spec/templates/spec_helper.rb
index cecdb7c0e..c9adc04aa 100644
--- a/spec/templates/spec_helper.rb
+++ b/spec/templates/spec_helper.rb
@@ -5,9 +5,7 @@
def only_copy?(result, example, type)
return false unless defined?($COPY)
- if $COPY == :all || $COPY == example
- puts(result) unless $COPYT && $COPYT != type
- end
+ puts(result) if ($COPY == :all || $COPY == example) && !($COPYT && $COPYT != type)
$COPY ? true : false
end
@@ -30,7 +28,7 @@ def html_equals_string(result, expected)
expected = String.new(expected)
[expected, result].each do |value|
value.gsub!(/(>)\s+|\s+(<)/, '\1\2')
- value.gsub!(/'/, "'")
+ value.gsub!(''', "'")
value.strip!
end
text_equals_string(result, expected)
diff --git a/spec/templates/tag_spec.rb b/spec/templates/tag_spec.rb
index 5e5b641ab..67ed8c20d 100644
--- a/spec/templates/tag_spec.rb
+++ b/spec/templates/tag_spec.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Engine.template(:default, :tags) do
before { Registry.clear }
describe "all known tags" do
before do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# Comments
# @abstract override me
# @param [Hash] opts the options
@@ -30,7 +30,7 @@
# a = String.new
# flip(a.reverse)
def m(opts = {}) end
- eof
+ EOF
end
it "renders text format correctly" do
@@ -40,25 +40,25 @@ def m(opts = {}) end
describe "param tags on non-methods" do
it "does not display @param tags on non-method objects" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @param [#to_s] name the name
module Foo; end
- eof
+ EOF
- expect { Registry.at('Foo').format(html_options) }
- .not_to raise_error
+ expect { Registry.at('Foo').format(html_options) }.
+ not_to raise_error
end
end
describe "option tags on non-methods" do
it "does not display @option tags on non-method objects" do
- YARD.parse_string <<-'eof'
+ YARD.parse_string <<-EOF
# @option opts name [#to_s] ('bar') the name
module Foo; end
- eof
+ EOF
- expect { Registry.at('Foo').format(html_options) }
- .not_to raise_error
+ expect { Registry.at('Foo').format(html_options) }.
+ not_to raise_error
end
end
end
diff --git a/spec/templates/template_spec.rb b/spec/templates/template_spec.rb
index 21808cc24..9ec48816b 100644
--- a/spec/templates/template_spec.rb
+++ b/spec/templates/template_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require File.dirname(__FILE__) + '/spec_helper'
+require "#{File.dirname(__FILE__)}/spec_helper"
RSpec.describe YARD::Templates::Template do
def template(path)
- YARD::Templates::Engine.template!(path, '/full/path/' + path.to_s)
+ YARD::Templates::Engine.template!(path, "/full/path/#{path}")
end
before :each do
@@ -49,7 +49,7 @@ def template(path)
mod = template(:c)
mod.send(:include, template(:d))
mod.send(:include, template(:a))
- expect(mod.full_paths).to eq ['c', 'a', 'b', 'd'].map {|o| '/full/path/' + o }
+ expect(mod.full_paths).to eq(['c', 'a', 'b', 'd'].map {|o| "/full/path/#{o}" })
end
it "only lists full paths of modules that respond to full_paths" do
@@ -134,7 +134,7 @@ module MyModule2; end
describe "#init" do
it "is called during initialization" do
- module YARD::Templates::Engine::Template__full_path_e # rubocop:disable Style/ClassAndModuleCamelCase
+ module YARD::Templates::Engine::Template__full_path_e # rubocop:disable Naming/ClassAndModuleCamelCase
def init; sections 1, 2, 3 end
end
expect(template(:e).new.sections).to eq Section.new(nil, 1, 2, 3)
@@ -216,10 +216,10 @@ def init; sections 1, 2, 3 end
it "runs section list if provided" do
mod = template(:e).new
expect(mod).to receive(:render_section).exactly(2).times do |section|
- expect([:q, :x]).to include(section.name)
+ expect(%i(q x)).to include(section.name)
section.name.to_s
end
- mod.run({}, [:q, :x])
+ mod.run({}, %i(q x))
end
it "accepts a nil section as empty string" do
@@ -235,8 +235,8 @@ def init; sections 1, 2, 3 end
mod = template(:f).new
mod.send(:add_options, :a => 1, :b => 2)
expect(mod.options).to eq(:a => 1, :b => 2)
- expect(mod.instance_variable_get("@a")).to eq 1
- expect(mod.instance_variable_get("@b")).to eq 2
+ expect(mod.instance_variable_get(:@a)).to eq 1
+ expect(mod.instance_variable_get(:@b)).to eq 2
end
it "sets instance variables and options only for the block" do
@@ -287,9 +287,9 @@ def init; sections 1, 2, 3 end
describe "#yield" do
it "yields a subsection" do
mod = template(:e).new
- mod.sections :a, [:b, :c]
+ mod.sections :a, %i(b c)
class << mod
- def a; "(" + yield + ")" end
+ def a; "(#{yield})" end
def b; "b" end
def c; "c" end
end
@@ -301,7 +301,7 @@ def c; "c" end
mod = template(:e).new
mod.sections :a, [:b, [:c]]
class << mod
- def a; "(" + yield + ")" end
+ def a; "(#{yield})" end
def b; yield end
def c; "c" end
end
@@ -313,7 +313,7 @@ def c; "c" end
mod = template(:e).new
mod.sections :a, [:b, [:c, [:d, [:e]]]]
class << mod
- def a; "(" + yield + ")" end
+ def a; "(#{yield})" end
def b; yield end
def c; yield end
def d; yield end
@@ -325,9 +325,9 @@ def e; "e" end
it "yields first two elements if yield is called twice" do
mod = template(:e).new
- mod.sections :a, [:b, :c, :d]
+ mod.sections :a, %i(b c d)
class << mod
- def a; "(" + yield + yield + ")" end
+ def a; "(#{yield}#{yield})" end
def b; 'b' end
def c; "c" end
end
@@ -339,7 +339,7 @@ def c; "c" end
mod = template(:e).new
mod.sections :a, [:b, [:c], :d]
class << mod
- def a; "(" + yield + yield + ")" end
+ def a; "(#{yield}#{yield})" end
def b; 'b' end
def d; "d" end
end
@@ -351,7 +351,7 @@ def d; "d" end
mod = template(:e).new
mod.sections :a, [:b]
class << mod
- def a; "(" + yield(:x => "a") + ")" end
+ def a; "(#{yield(:x => "a")})" end
def b; options.x + @x end
end
@@ -364,10 +364,10 @@ def b; options.x + @x end
mod = template(:e).new
mod.sections :a, [:b, [:d, [:e]], :c]
class << mod
- def a; "(" + yieldall + ")" end
- def b; "b" + yieldall end
+ def a; "(#{yieldall})" end
+ def b; "b#{yieldall}" end
def c; "c" end
- def d; 'd' + yieldall end
+ def d; "d#{yieldall}" end
def e; 'e' end
end
@@ -376,9 +376,9 @@ def e; 'e' end
it "yields options to all subsections" do
mod = template(:e).new
- mod.sections :a, [:b, :c]
+ mod.sections :a, %i(b c)
class << mod
- def a; "(" + yieldall(:x => "2") + ")" end
+ def a; "(#{yieldall(:x => "2")})" end
def b; @x end
def c; @x end
end
@@ -389,7 +389,7 @@ def c; @x end
mod = template(:e).new
mod.sections :a, [:b]
class << mod
- def a; "(" + yieldall + yieldall + ")" end
+ def a; "(#{yieldall}#{yieldall})" end
def b; "b" end
end
diff --git a/tasks/prepare_tag.rake b/tasks/prepare_tag.rake
index 3f44ab7d6..29194b88b 100644
--- a/tasks/prepare_tag.rake
+++ b/tasks/prepare_tag.rake
@@ -1,3 +1,4 @@
+require 'English'
require 'json'
require 'tempfile'
@@ -8,7 +9,7 @@ namespace :release do
restore_file.close
at_exit { restore_file.unlink }
- version = ENV['VERSION']
+ version = ENV.fetch('VERSION', nil)
build_path = File.expand_path(File.join(`gem which samus`.strip, '..', '..', 'commands', 'build'))
samus_contents = File.read(File.join(__dir__, '..', 'samus.json'))
samus_json = JSON.parse(samus_contents.gsub('$version', version))
@@ -17,21 +18,20 @@ namespace :release do
env = {
'_VERSION' => version,
'__ORIG_BRANCH' => `git rev-parse --abbrev-ref HEAD`.strip,
- '__RESTORE_FILE' => restore_file.path,
+ '__RESTORE_FILE' => restore_file.path
}
(action['arguments'] || {}).each {|k, v| env["_#{k.upcase}"] = v }
file = File.join(build_path, action['action'])
- shebang = File.readlines(file).first[%r{\A#!(?:\S+)/(.+)}, 1].strip.split(' ')
+ shebang = File.readlines(file).first[%r{\A#!(?:\S+)/(.+)}, 1].strip.split
cmd = [*shebang, file, *action['files']]
puts "[C] #{action['action']} #{(action['files'] || []).join(' ')}"
output = ""
IO.popen(env, cmd) {|io| output = io.read }
- status = $?
- unless status.success?
- puts "[F] Last command failed with: #{status.to_i}"
- puts output
- exit(status.to_i)
- end
+ status = $CHILD_STATUS
+ next if status.success?
+ puts "[F] Last command failed with: #{status.to_i}"
+ puts output
+ exit(status.to_i)
end
puts ""
@@ -42,6 +42,6 @@ namespace :release do
desc 'Pushes the main branch and tag for VERSION=X.Y.Z'
task :push do
- sh "git push origin main v#{ENV['VERSION']}"
+ sh "git push origin main v#{ENV.fetch('VERSION', nil)}"
end
end
diff --git a/tasks/update_error_map.rake b/tasks/update_error_map.rake
index 547d19584..961eeeef3 100644
--- a/tasks/update_error_map.rake
+++ b/tasks/update_error_map.rake
@@ -8,18 +8,17 @@ require 'stringio'
desc 'Update the error class names map'
task :update_error_map do
+ error_c_url = 'https://raw.githubusercontent.com/ruby/ruby/master/error.c'
- ERROR_C_URL = 'https://raw.githubusercontent.com/ruby/ruby/master/error.c'
+ init_match = /void\s+Init_Exception\(void\)\s*\{(.+?)^\}/m
+ name_match = /(\w+)\s*=\s*rb_define_class\("([^"]+)"/
- INIT_MATCH = /void\s+Init_Exception\(void\)\s*\{(.+?)^\}/m
- NAME_MATCH = /(\w+)\s*=\s*rb_define_class\("([^"]+)"/
-
- $stderr.puts "Downloading #{ERROR_C_URL} ..."
- content = open(ERROR_C_URL) { |io| io.read }
+ $stderr.puts "Downloading #{error_c_url} ..."
+ content = open(error_c_url, &:read) # rubocop:disable Security/Open
$stderr.puts "Extracting class names ..."
- init_source = content.match(INIT_MATCH).captures.first
- map = init_source.scan(NAME_MATCH).sort_by { |key, value| key }
+ init_source = content.match(init_match).captures.first
+ map = init_source.scan(name_match).sort_by {|key, _value| key }
$stderr.puts "Generating new lookup table ..."
indent = ' ' * 4
@@ -33,21 +32,20 @@ task :update_error_map do
$stderr.puts source.string
$stderr.puts "Patching 'lib/yard/handlers/c/base.rb' ..."
- CLASS_NAME_MAP_MATCH = /^\s+ERROR_CLASS_NAMES = {[^}]+}/
+ class_name_map_match = /^\s+ERROR_CLASS_NAMES = {[^}]+}/
- PROJECT_PATH = File.expand_path('..', __dir__)
- C_BASE_HANDLER = File.join(PROJECT_PATH, 'lib/yard/handlers/c/base.rb')
+ project_path = File.expand_path('..', __dir__)
+ c_base_handler = File.join(project_path, 'lib/yard/handlers/c/base.rb')
- File.open(C_BASE_HANDLER, 'r+') { |file|
+ File.open(c_base_handler, 'r+') do |file|
content = file.read
# .rstrip is added to avoid adding new empty lines due to the new lines
# added by `.puts` when building the string.
- content.gsub!(CLASS_NAME_MAP_MATCH, source.string.rstrip)
+ content.gsub!(class_name_map_match, source.string.rstrip)
file.rewind
file.truncate(0)
file.write(content)
- }
+ end
$stderr.puts "Done!"
-
end
diff --git a/templates/default/docstring/setup.rb b/templates/default/docstring/setup.rb
index 5ff09f866..0aa0211bf 100644
--- a/templates/default/docstring/setup.rb
+++ b/templates/default/docstring/setup.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
def init
return if object.docstring.blank? && !object.has_tag?(:api)
- sections :index, [:private, :deprecated, :abstract, :todo, :note, :returns_void, :text], T('tags')
+ sections :index, %i(private deprecated abstract todo note returns_void text), T('tags')
end
def private
@@ -38,9 +38,7 @@ def returns_void
def docstring_text
text = ""
- unless object.tags(:overload).size == 1 && object.docstring.empty?
- text = object.docstring
- end
+ text = object.docstring unless object.tags(:overload).size == 1 && object.docstring.empty?
if text.strip.empty? && object.tags(:return).size == 1 && object.tag(:return).text
text = object.tag(:return).text.gsub(/\A([a-z])/, &:downcase)
diff --git a/templates/default/fulldoc/html/setup.rb b/templates/default/fulldoc/html/setup.rb
index 923bc31fb..3cce0bde4 100644
--- a/templates/default/fulldoc/html/setup.rb
+++ b/templates/default/fulldoc/html/setup.rb
@@ -17,7 +17,7 @@ def init
objects.each do |object|
begin
serialize(object)
- rescue => e
+ rescue StandardError => e
path = options.serializer.serialized_path(object)
log.error "Exception occurred while generating '#{path}'"
log.backtrace(e)
@@ -63,7 +63,7 @@ def serialize_index(options)
def serialize_file(file, title = nil) # rubocop:disable Lint/UnusedMethodArgument
options.object = Registry.root
options.file = file
- outfile = 'file.' + file.name + '.html'
+ outfile = "file.#{file.name}.html"
serialize_index(options) if file == options.readme
Templates::Engine.with_serializer(outfile, options.serializer) do
@@ -222,9 +222,7 @@ def next
def class_list(root = Registry.root, tree = TreeContext.new)
out = String.new("")
children = run_verifier(root.children)
- if root == Registry.root
- children += @items.select {|o| o.namespace.is_a?(CodeObjects::Proxy) }
- end
+ children += @items.select {|o| o.namespace.is_a?(CodeObjects::Proxy) } if root == Registry.root
children.compact.sort_by(&:path).each do |child|
next unless child.is_a?(CodeObjects::NamespaceObject)
name = child.namespace.is_a?(CodeObjects::Proxy) ? child.path : child.name
diff --git a/templates/default/layout/html/setup.rb b/templates/default/layout/html/setup.rb
index ab97c5f1e..6aa220376 100644
--- a/templates/default/layout/html/setup.rb
+++ b/templates/default/layout/html/setup.rb
@@ -9,7 +9,7 @@ def init
if @file.attributes[:namespace]
@object = options.object = Registry.at(@file.attributes[:namespace]) || Registry.root
end
- @breadcrumb_title = "File: " + @file.title
+ @breadcrumb_title = "File: #{@file.title}"
@page_title = @breadcrumb_title
sections :layout, [:diskfile]
elsif @contents
@@ -18,7 +18,7 @@ def init
case object
when '_index.html'
@page_title = options.title
- sections :layout, [:index, [:listing, [:files, :objects]]]
+ sections :layout, [:index, [:listing, %i(files objects)]]
when CodeObjects::Base
unless object.root?
cur = object.namespace
@@ -65,7 +65,7 @@ def layout
def diskfile
@file.attributes[:markup] ||= markup_for_file('', @file.filename)
data = htmlify(@file.contents, @file.attributes[:markup])
- "" + data + "
"
+ "#{data}
"
end
# @return [Array] core javascript files for layout
diff --git a/templates/default/module/setup.rb b/templates/default/module/setup.rb
index 95bf3a4bb..92e12ccb3 100644
--- a/templates/default/module/setup.rb
+++ b/templates/default/module/setup.rb
@@ -3,12 +3,12 @@
def init
sections :header, :box_info, :pre_docstring, T('docstring'), :children,
- :constant_summary, [T('docstring')], :inherited_constants,
- :attribute_summary, [:item_summary], :inherited_attributes,
- :method_summary, [:item_summary], :inherited_methods,
- :methodmissing, [T('method_details')],
- :attribute_details, [T('method_details')],
- :method_details_list, [T('method_details')]
+ :constant_summary, [T('docstring')], :inherited_constants,
+ :attribute_summary, [:item_summary], :inherited_attributes,
+ :method_summary, [:item_summary], :inherited_methods,
+ :methodmissing, [T('method_details')],
+ :attribute_details, [T('method_details')],
+ :method_details_list, [T('method_details')]
end
def pre_docstring
@@ -37,9 +37,7 @@ def method_listing(include_specials = true)
return @smeths ||= method_listing.reject {|o| special_method?(o) } unless include_specials
return @meths if defined?(@meths) && @meths
@meths = object.meths(:inherited => false, :included => !options.embed_mixins.empty?)
- unless options.embed_mixins.empty?
- @meths = @meths.reject {|m| options.embed_mixins_match?(m.namespace) == false }
- end
+ @meths = @meths.reject {|m| options.embed_mixins_match?(m.namespace) == false } unless options.embed_mixins.empty?
@meths = sort_listing(prune_method_listing(@meths))
@meths
end
@@ -53,11 +51,12 @@ def special_method?(meth)
def attr_listing
return @attrs if defined?(@attrs) && @attrs
@attrs = []
+ types = %i(class instance)
object.inheritance_tree(true).each do |superclass|
next if superclass.is_a?(CodeObjects::Proxy)
next if !options.embed_mixins.empty? &&
!options.embed_mixins_match?(superclass)
- [:class, :instance].each do |scope|
+ types.each do |scope|
superclass.attributes[scope].each do |_name, rw|
attr = prune_method_listing([rw[:read], rw[:write]].compact, false).first
@attrs << attr if attr
@@ -150,7 +149,7 @@ def groups(list, type = "Method")
end
def scopes(list)
- [:class, :instance].each do |scope|
+ %i(class instance).each do |scope|
items = list.select {|m| m.scope == scope }
yield(items, scope) unless items.empty?
end
diff --git a/templates/default/module/text/setup.rb b/templates/default/module/text/setup.rb
index 4f4dbf24e..189aea134 100644
--- a/templates/default/module/text/setup.rb
+++ b/templates/default/module/text/setup.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
def init
sections :header, [T('docstring')], :children, :includes, :extends,
- :class_meths_list, :instance_meths_list
+ :class_meths_list, :instance_meths_list
end
def class_meths
- @classmeths ||= method_listing.select {|o| o.scope == :class }
+ @class_meths ||= method_listing.select {|o| o.scope == :class }
end
def instance_meths
- @instmeths ||= method_listing.select {|o| o.scope == :instance }
+ @instance_meths ||= method_listing.select {|o| o.scope == :instance }
end
diff --git a/templates/default/onefile/html/setup.rb b/templates/default/onefile/html/setup.rb
index cd82aea14..727d6ae6c 100644
--- a/templates/default/onefile/html/setup.rb
+++ b/templates/default/onefile/html/setup.rb
@@ -8,7 +8,7 @@ def init
@files.shift
@objects.delete(YARD::Registry.root)
@objects.unshift(YARD::Registry.root)
- sections :layout, [:readme, :files, :all_objects]
+ sections :layout, %i(readme files all_objects)
end
def all_objects
@@ -18,7 +18,7 @@ def all_objects
def layout
layout = Object.new.extend(T('layout'))
@css_data = layout.stylesheets.map {|sheet| read_asset(sheet) }.join("\n")
- @js_data = layout.javascripts.map {|script| read_asset(script) }.join("")
+ @js_data = layout.javascripts.map {|script| read_asset(script) }.join
erb(:layout)
end
@@ -28,7 +28,7 @@ def read_asset(file)
return unless file
data = File.read(file)
superfile = self.class.find_nth_file('fulldoc', 2)
- data.gsub!('{{{__super__}}}', superfile ? IO.read(superfile) : "")
+ data.gsub!('{{{__super__}}}', superfile ? File.read(superfile) : "")
data
end
@@ -41,7 +41,7 @@ def parse_top_comments_from_file
tokens = TokenList.new(@readme.contents)
tokens.each do |token|
break unless token.is_a?(RubyToken::TkCOMMENT) || token.is_a?(RubyToken::TkNL)
- data += (token.text[/\A#\s{0,1}(.*)/, 1] || "\n")
+ data += token.text[/\A#\s{0,1}(.*)/, 1] || "\n"
end
YARD::Docstring.new(data)
end
diff --git a/templates/default/tags/setup.rb b/templates/default/tags/setup.rb
index 6344ab43f..b99ad8ba4 100644
--- a/templates/default/tags/setup.rb
+++ b/templates/default/tags/setup.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
def init
- tags = Tags::Library.visible_tags - [:abstract, :deprecated, :note, :todo]
- create_tag_methods(tags - [:example, :option, :overload, :see])
- sections :index, tags.map {|t| t.to_s.tr('.', '_').to_sym }
+ tags = Tags::Library.visible_tags - %i(abstract deprecated note todo)
+ create_tag_methods(tags - %i(example option overload see))
+ sections(:index, tags.map {|t| t.to_s.tr('.', '_').to_sym })
sections.any(:overload).push(T('docstring'))
end
@@ -36,9 +36,9 @@ def create_tag_methods(tags)
tags.each do |tag|
tag_meth = tag.to_s.tr('.', '_')
next if respond_to?(tag_meth)
- instance_eval(<<-eof, __FILE__, __LINE__ + 1)
+ instance_eval(<<-EOF, __FILE__, __LINE__ + 1)
def #{tag_meth}; tag(#{tag.inspect}) end
- eof
+ EOF
end
end
diff --git a/templates/guide/fulldoc/html/setup.rb b/templates/guide/fulldoc/html/setup.rb
index 87d4b121b..fcb24875a 100644
--- a/templates/guide/fulldoc/html/setup.rb
+++ b/templates/guide/fulldoc/html/setup.rb
@@ -46,11 +46,9 @@ def generate_assets
def serialize_file(file)
index = options.files.index(file)
- outfile = file.name.downcase + '.html'
+ outfile = "#{file.name.downcase}.html"
options.file = file
- if file.attributes[:namespace]
- options.object = Registry.at(file.attributes[:namespace])
- end
+ options.object = Registry.at(file.attributes[:namespace]) if file.attributes[:namespace]
options.object ||= Registry.root
if file == options.readme
@@ -67,7 +65,7 @@ def serialize_file(file)
def serialize_onefile
layout = Object.new.extend(T('layout'))
options.css_data = layout.stylesheets.map {|sheet| file(sheet, true) }.join("\n")
- options.js_data = layout.javascripts.map {|script| file(script, true) }.join("")
+ options.js_data = layout.javascripts.map {|script| file(script, true) }.join
Templates::Engine.with_serializer('onefile.html', options.serializer) do
T('onefile').run(options)
end
diff --git a/templates/guide/layout/html/setup.rb b/templates/guide/layout/html/setup.rb
index e6e236893..533cccf53 100644
--- a/templates/guide/layout/html/setup.rb
+++ b/templates/guide/layout/html/setup.rb
@@ -6,9 +6,7 @@ def init
@topfile = options.readme
if options.files
- if @topfile
- @toptitle = @topfile.attributes[:title] || "Documentation Overview"
- end
+ @toptitle = @topfile.attributes[:title] || "Documentation Overview" if @topfile
@page_title = @file == options.readme ? options.title : @file.title
index = options.files.index(@file)
diff --git a/templates/guide/method/html/setup.rb b/templates/guide/method/html/setup.rb
index e2888fea0..facf7c088 100644
--- a/templates/guide/method/html/setup.rb
+++ b/templates/guide/method/html/setup.rb
@@ -9,14 +9,14 @@ def format_args(object)
if object.has_tag?(:yield) || object.has_tag?(:yieldparam)
params.reject! do |param|
param[0].to_s[0, 1] == "&" &&
- !object.tags(:param).any? {|t| t.name == param[0][1..-1] }
+ object.tags(:param).none? {|t| t.name == param[0][1..-1] }
end
end
if params.empty?
""
else
- args = params.map {|n, v| v ? "#{h n} = #{h v}" : "" + n.to_s + "" }.join(", ")
- args
+ params.map {|n, v| v ? "#{h n} = #{h v}" : "#{n}" }.join(", ")
+
end
end
diff --git a/templates/guide/onefile/html/setup.rb b/templates/guide/onefile/html/setup.rb
index 6c2efd108..5d9ce6028 100644
--- a/templates/guide/onefile/html/setup.rb
+++ b/templates/guide/onefile/html/setup.rb
@@ -2,5 +2,5 @@
include T('default/onefile/html')
def init
- sections :layout, [:toc, :files]
+ sections :layout, %i(toc files)
end
diff --git a/templates/guide/tags/html/setup.rb b/templates/guide/tags/html/setup.rb
index fe59cd75c..1502bec0c 100644
--- a/templates/guide/tags/html/setup.rb
+++ b/templates/guide/tags/html/setup.rb
@@ -3,7 +3,7 @@
def init
super
- [:since, :see, :return].each do |section|
+ %i(since see return).each do |section|
sections[:index].delete(section)
end
end
diff --git a/yard.gemspec b/yard.gemspec
index fa43eff9b..48dcc5197 100644
--- a/yard.gemspec
+++ b/yard.gemspec
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require File.expand_path('../lib/yard/version', __FILE__)
+require File.expand_path('lib/yard/version', __dir__)
Gem::Specification.new do |s|
s.name = "yard"
s.summary = "Documentation tool for consistent and usable documentation in Ruby."
- s.description = <<-eof
+ s.description = <<-EOF
YARD is a documentation generation tool for the Ruby programming language.
It enables the user to generate consistent, usable documentation that can be
exported to a number of formats very easily, and also supports extending for
custom Ruby constructs such as custom class level definitions.
- eof
+ EOF
s.version = YARD::VERSION
s.author = "Loren Segal"
s.email = "lsegal@soen.ca"
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.executables = ['yard', 'yardoc', 'yri']
s.license = 'MIT' if s.respond_to?(:license=)
s.metadata['yard.run'] = 'yri'
+ s.required_ruby_version = '>= 2.0.0' if s.respond_to?(:required_ruby_version=)
end