yard 0.9.16 → 0.9.21

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.github/ISSUE_TEMPLATE.md +33 -0
  4. data/.github/PULL_REQUEST_TEMPLATE.md +12 -0
  5. data/.gitignore +14 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +99 -0
  8. data/.travis.yml +52 -0
  9. data/.yardopts +0 -0
  10. data/.yardopts_guide +19 -0
  11. data/.yardopts_i18n +23 -0
  12. data/CHANGELOG.md +41 -1
  13. data/CODE_OF_CONDUCT.md +15 -0
  14. data/CONTRIBUTING.md +140 -0
  15. data/Dockerfile.samus +28 -0
  16. data/Gemfile +32 -0
  17. data/README.md +3 -1
  18. data/Rakefile +7 -17
  19. data/SECURITY.md +26 -0
  20. data/bin/yard +0 -0
  21. data/bin/yardoc +0 -0
  22. data/bin/yri +0 -0
  23. data/docs/GettingStarted.md +1 -1
  24. data/lib/yard/autoload.rb +5 -0
  25. data/lib/yard/cli/i18n.rb +1 -1
  26. data/lib/yard/cli/stats.rb +1 -1
  27. data/lib/yard/cli/yardoc.rb +4 -3
  28. data/lib/yard/code_objects/base.rb +14 -2
  29. data/lib/yard/code_objects/extra_file_object.rb +7 -4
  30. data/lib/yard/code_objects/proxy.rb +4 -0
  31. data/lib/yard/core_ext/module.rb +0 -9
  32. data/lib/yard/docstring.rb +10 -2
  33. data/lib/yard/handlers/c/handler_methods.rb +2 -1
  34. data/lib/yard/handlers/c/method_handler.rb +9 -0
  35. data/lib/yard/handlers/common/method_handler.rb +19 -0
  36. data/lib/yard/handlers/ruby/alias_handler.rb +5 -4
  37. data/lib/yard/handlers/ruby/attribute_handler.rb +1 -1
  38. data/lib/yard/handlers/ruby/constant_handler.rb +1 -5
  39. data/lib/yard/handlers/ruby/dsl_handler_methods.rb +6 -5
  40. data/lib/yard/handlers/ruby/method_handler.rb +3 -17
  41. data/lib/yard/handlers/ruby/mixin_handler.rb +13 -1
  42. data/lib/yard/parser/c/statement.rb +2 -0
  43. data/lib/yard/parser/ruby/ast_node.rb +11 -0
  44. data/lib/yard/parser/ruby/legacy/irb/slex.rb +276 -0
  45. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +3 -12
  46. data/lib/yard/parser/ruby/legacy/statement.rb +2 -0
  47. data/lib/yard/parser/ruby/ruby_parser.rb +14 -2
  48. data/lib/yard/parser/source_parser.rb +1 -1
  49. data/lib/yard/registry_resolver.rb +47 -5
  50. data/lib/yard/registry_store.rb +6 -1
  51. data/lib/yard/server/commands/display_file_command.rb +1 -1
  52. data/lib/yard/server/commands/static_file_helpers.rb +0 -1
  53. data/lib/yard/templates/helpers/html_helper.rb +25 -4
  54. data/lib/yard/version.rb +6 -4
  55. data/po/ja.po +31108 -0
  56. data/samus.json +80 -0
  57. data/spec/cli/yardoc_spec.rb +48 -1
  58. data/spec/code_objects/base_spec.rb +25 -0
  59. data/spec/code_objects/extra_file_object_spec.rb +4 -3
  60. data/spec/code_objects/proxy_spec.rb +6 -0
  61. data/spec/core_ext/module_spec.rb +0 -6
  62. data/spec/docstring_parser_spec.rb +18 -0
  63. data/spec/docstring_spec.rb +9 -0
  64. data/spec/handlers/c/method_handler_spec.rb +2 -0
  65. data/spec/handlers/constant_handler_spec.rb +1 -1
  66. data/spec/handlers/dsl_handler_spec.rb +7 -0
  67. data/spec/handlers/examples/dsl_handler_001.rb.txt +2 -0
  68. data/spec/handlers/examples/extend_handler_001.rb.txt +4 -1
  69. data/spec/handlers/examples/mixin_handler_001.rb.txt +3 -0
  70. data/spec/handlers/extend_handler_spec.rb +4 -0
  71. data/spec/handlers/method_handler_spec.rb +24 -0
  72. data/spec/handlers/mixin_handler_spec.rb +4 -0
  73. data/spec/parser/c_parser_spec.rb +13 -0
  74. data/spec/parser/examples/file.c.txt +28 -0
  75. data/spec/registry_store_spec.rb +11 -0
  76. data/spec/templates/examples/module001.html +3 -3
  77. data/spec/templates/examples/module002.html +1 -1
  78. data/spec/templates/examples/module003.html +1 -1
  79. data/spec/templates/helpers/html_helper_spec.rb +34 -0
  80. data/spec/templates/helpers/method_helper_spec.rb +2 -2
  81. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +60 -0
  82. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +46 -0
  83. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +59 -0
  84. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +39 -0
  85. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +59 -0
  86. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +48 -0
  87. data/spec/templates/method_spec.rb +2 -2
  88. data/templates/default/docstring/setup.rb +1 -1
  89. data/templates/default/fulldoc/html/css/style.css +2 -2
  90. data/templates/default/fulldoc/html/frames.erb +1 -1
  91. data/templates/default/fulldoc/html/full_list.erb +1 -1
  92. data/templates/default/fulldoc/html/js/app.js +25 -3
  93. data/templates/default/fulldoc/html/js/jquery.js +2 -4
  94. data/templates/default/layout/html/headers.erb +1 -1
  95. data/templates/default/layout/html/script_setup.erb +1 -1
  96. data/templates/default/onefile/html/headers.erb +1 -1
  97. data/templates/default/onefile/html/setup.rb +1 -1
  98. data/templates/default/tags/html/tag.erb +1 -1
  99. data/templates/guide/layout/html/layout.erb +1 -1
  100. data/yard.gemspec +1 -20
  101. metadata +29 -22
  102. data/spec/examples.txt +0 -1874
@@ -7,8 +7,9 @@ module YARD
7
7
  include Parser
8
8
 
9
9
  IGNORE_METHODS = Hash[*%w(alias alias_method autoload attr attr_accessor
10
- attr_reader attr_writer extend include public private protected
11
- private_constant).map {|n| [n, true] }.flatten]
10
+ attr_reader attr_writer extend include module_function public private
11
+ protected private_constant private_class_method public_class_method).
12
+ map {|n| [n, true] }.flatten]
12
13
 
13
14
  def handle_comments
14
15
  return if IGNORE_METHODS[caller_method]
@@ -39,9 +40,9 @@ module YARD
39
40
  return register_docstring(nil)
40
41
  end
41
42
 
42
- object = MethodObject.new(namespace, method_name, scope)
43
- object.signature = method_signature
44
- register(object)
43
+ register MethodObject.new(namespace, method_name, scope) do |o|
44
+ o.signature = method_signature
45
+ end
45
46
  end
46
47
 
47
48
  def register_docstring(object, docstring = @docstring, stmt = statement)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  # Handles a method definition
3
3
  class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
4
+ include YARD::Handlers::Common::MethodHandler
5
+
4
6
  handles :def, :defs
5
7
 
6
8
  process do
@@ -19,7 +21,6 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
19
21
 
20
22
  nobj = P(namespace, nobj.value) while nobj.type == :constant
21
23
  obj = register MethodObject.new(nobj, meth, mscope) do |o|
22
- o.signature = method_signature
23
24
  o.explicit = true
24
25
  o.parameters = args
25
26
  end
@@ -39,13 +40,7 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
39
40
  extended method_added method_removed method_undefined).include?(meth)
40
41
  obj.add_tag(YARD::Tags::Tag.new(:private, nil))
41
42
  elsif meth.to_s =~ /\?$/
42
- if obj.tag(:return) && (obj.tag(:return).types || []).empty?
43
- obj.tag(:return).types = ['Boolean']
44
- elsif obj.tag(:return).nil?
45
- unless obj.tags(:overload).any? {|overload| overload.tag(:return) }
46
- obj.add_tag(YARD::Tags::Tag.new(:return, "", "Boolean"))
47
- end
48
- end
43
+ add_predicate_return_tag(obj)
49
44
  end
50
45
 
51
46
  if obj.has_tag?(:option)
@@ -106,13 +101,4 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
106
101
 
107
102
  params
108
103
  end
109
-
110
- def method_signature
111
- method_name = statement.method_name(true)
112
- if statement.parameters.any? {|e| e }
113
- "def #{method_name}(#{statement.parameters.source})"
114
- else
115
- "def #{method_name}"
116
- end
117
- end
118
104
  end
@@ -32,6 +32,18 @@ class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
32
32
  obj = Proxy.new(namespace, mixin.source, :module)
33
33
  end
34
34
 
35
- namespace.mixins(scope).unshift(obj) unless namespace.mixins(scope).include?(obj)
35
+ rec = recipient(mixin)
36
+ return if rec.nil? || rec.mixins(scope).include?(obj)
37
+ rec.mixins(scope).unshift(obj)
38
+ end
39
+
40
+ def recipient(mixin)
41
+ if statement[0].type == :var_ref && statement[0][0] != s(:kw, "self")
42
+ statement[0][0].type == :const ?
43
+ Proxy.new(namespace, statement.namespace.source) :
44
+ nil
45
+ else
46
+ namespace
47
+ end
36
48
  end
37
49
  end
@@ -31,6 +31,8 @@ module YARD
31
31
  source.split(/\n/).first
32
32
  end
33
33
 
34
+ alias signature first_line
35
+
34
36
  def show
35
37
  "\t#{line}: #{first_line}"
36
38
  end
@@ -485,6 +485,17 @@ module YARD
485
485
  include_block_param ? params : params[0...-1]
486
486
  end
487
487
 
488
+ def signature
489
+ params_src = ''
490
+ params = self[1 + index_adjust]
491
+ if params.first
492
+ params_src = params.type == :paren ? '' : ' '
493
+ params_src += params.source.gsub(/\s+(\s|\))/m, '\1')
494
+ end
495
+
496
+ "def #{method_name(true)}#{params_src}"
497
+ end
498
+
488
499
  alias block last
489
500
 
490
501
  private
@@ -0,0 +1,276 @@
1
+ # frozen_string_literal: false
2
+ #
3
+ # irb/slex.rb - simple lex analyzer
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ require "irb/notifier"
14
+
15
+ # :stopdoc:
16
+ module IRB
17
+ class SLex
18
+ DOUT = Notifier::def_notifier("SLex::")
19
+ D_WARN = DOUT::def_notifier(1, "Warn: ")
20
+ D_DEBUG = DOUT::def_notifier(2, "Debug: ")
21
+ D_DETAIL = DOUT::def_notifier(4, "Detail: ")
22
+
23
+ DOUT.level = Notifier::D_NOMSG
24
+
25
+ def initialize
26
+ @head = Node.new("")
27
+ end
28
+
29
+ def def_rule(token, preproc = nil, postproc = nil, &block)
30
+ D_DETAIL.pp token
31
+
32
+ postproc = block if block_given?
33
+ create(token, preproc, postproc)
34
+ end
35
+
36
+ def def_rules(*tokens, &block)
37
+ if block_given?
38
+ p = block
39
+ end
40
+ for token in tokens
41
+ def_rule(token, nil, p)
42
+ end
43
+ end
44
+
45
+ def preproc(token, proc)
46
+ node = search(token)
47
+ node.preproc=proc
48
+ end
49
+
50
+ # need a check?
51
+ def postproc(token)
52
+ node = search(token, proc)
53
+ node.postproc=proc
54
+ end
55
+
56
+ def search(token)
57
+ @head.search(token.split(//))
58
+ end
59
+
60
+ def create(token, preproc = nil, postproc = nil)
61
+ @head.create_subnode(token.split(//), preproc, postproc)
62
+ end
63
+
64
+ def match(token)
65
+ case token
66
+ when Array
67
+ when String
68
+ return match(token.split(//))
69
+ else
70
+ return @head.match_io(token)
71
+ end
72
+ ret = @head.match(token)
73
+ D_DETAIL.exec_if{D_DETAIL.printf "match end: %s:%s\n", ret, token.inspect}
74
+ ret
75
+ end
76
+
77
+ def inspect
78
+ format("<SLex: @head = %s>", @head.inspect)
79
+ end
80
+
81
+ #----------------------------------------------------------------------
82
+ #
83
+ # class Node -
84
+ #
85
+ #----------------------------------------------------------------------
86
+ class Node
87
+ # if postproc is nil, this node is an abstract node.
88
+ # if postproc is non-nil, this node is a real node.
89
+ def initialize(preproc = nil, postproc = nil)
90
+ @Tree = {}
91
+ @preproc = preproc
92
+ @postproc = postproc
93
+ end
94
+
95
+ attr_accessor :preproc
96
+ attr_accessor :postproc
97
+
98
+ def search(chrs, opt = nil)
99
+ return self if chrs.empty?
100
+ ch = chrs.shift
101
+ if node = @Tree[ch]
102
+ node.search(chrs, opt)
103
+ else
104
+ if opt
105
+ chrs.unshift ch
106
+ self.create_subnode(chrs)
107
+ else
108
+ raise "node nothing"
109
+ end
110
+ end
111
+ end
112
+
113
+ def create_subnode(chrs, preproc = nil, postproc = nil)
114
+ if chrs.empty?
115
+ if @postproc
116
+ D_DETAIL.pp node
117
+ raise "node already exists"
118
+ else
119
+ D_DEBUG.puts "change abstract node to real node."
120
+ @preproc = preproc
121
+ @postproc = postproc
122
+ end
123
+ return self
124
+ end
125
+
126
+ ch = chrs.shift
127
+ if node = @Tree[ch]
128
+ if chrs.empty?
129
+ if node.postproc
130
+ DebugLogger.pp node
131
+ DebugLogger.pp self
132
+ DebugLogger.pp ch
133
+ DebugLogger.pp chrs
134
+ raise "node already exists"
135
+ else
136
+ D_WARN.puts "change abstract node to real node"
137
+ node.preproc = preproc
138
+ node.postproc = postproc
139
+ end
140
+ else
141
+ node.create_subnode(chrs, preproc, postproc)
142
+ end
143
+ else
144
+ if chrs.empty?
145
+ node = Node.new(preproc, postproc)
146
+ else
147
+ node = Node.new
148
+ node.create_subnode(chrs, preproc, postproc)
149
+ end
150
+ @Tree[ch] = node
151
+ end
152
+ node
153
+ end
154
+
155
+ #
156
+ # chrs: String
157
+ # character array
158
+ # io must have getc()/ungetc(); and ungetc() must be
159
+ # able to be called arbitrary number of times.
160
+ #
161
+ def match(chrs, op = "")
162
+ D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
163
+ if chrs.empty?
164
+ if @preproc.nil? || @preproc.call(op, chrs)
165
+ DOUT.printf(D_DETAIL, "op1: %s\n", op)
166
+ @postproc.call(op, chrs)
167
+ else
168
+ nil
169
+ end
170
+ else
171
+ ch = chrs.shift
172
+ if node = @Tree[ch]
173
+ if ret = node.match(chrs, op+ch)
174
+ return ret
175
+ else
176
+ chrs.unshift ch
177
+ if @postproc and @preproc.nil? || @preproc.call(op, chrs)
178
+ DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
179
+ ret = @postproc.call(op, chrs)
180
+ return ret
181
+ else
182
+ return nil
183
+ end
184
+ end
185
+ else
186
+ chrs.unshift ch
187
+ if @postproc and @preproc.nil? || @preproc.call(op, chrs)
188
+ DOUT.printf(D_DETAIL, "op3: %s\n", op)
189
+ @postproc.call(op, chrs)
190
+ return ""
191
+ else
192
+ return nil
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ def match_io(io, op = "")
199
+ if op == ""
200
+ ch = io.getc
201
+ if ch == nil
202
+ return nil
203
+ end
204
+ else
205
+ ch = io.getc_of_rests
206
+ end
207
+ if ch.nil?
208
+ if @preproc.nil? || @preproc.call(op, io)
209
+ D_DETAIL.printf("op1: %s\n", op)
210
+ @postproc.call(op, io)
211
+ else
212
+ nil
213
+ end
214
+ else
215
+ if node = @Tree[ch]
216
+ if ret = node.match_io(io, op+ch)
217
+ ret
218
+ else
219
+ io.ungetc ch
220
+ if @postproc and @preproc.nil? || @preproc.call(op, io)
221
+ DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
222
+ @postproc.call(op, io)
223
+ else
224
+ nil
225
+ end
226
+ end
227
+ else
228
+ io.ungetc ch
229
+ if @postproc and @preproc.nil? || @preproc.call(op, io)
230
+ D_DETAIL.printf("op3: %s\n", op)
231
+ @postproc.call(op, io)
232
+ else
233
+ nil
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+ # :startdoc:
242
+
243
+ if $0 == __FILE__
244
+ case $1
245
+ when "1"
246
+ tr = SLex.new
247
+ print "0: ", tr.inspect, "\n"
248
+ tr.def_rule("=") {print "=\n"}
249
+ print "1: ", tr.inspect, "\n"
250
+ tr.def_rule("==") {print "==\n"}
251
+ print "2: ", tr.inspect, "\n"
252
+
253
+ print "case 1:\n"
254
+ print tr.match("="), "\n"
255
+ print "case 2:\n"
256
+ print tr.match("=="), "\n"
257
+ print "case 3:\n"
258
+ print tr.match("=>"), "\n"
259
+
260
+ when "2"
261
+ tr = SLex.new
262
+ print "0: ", tr.inspect, "\n"
263
+ tr.def_rule("=") {print "=\n"}
264
+ print "1: ", tr.inspect, "\n"
265
+ tr.def_rule("==", proc{false}) {print "==\n"}
266
+ print "2: ", tr.inspect, "\n"
267
+
268
+ print "case 1:\n"
269
+ print tr.match("="), "\n"
270
+ print "case 2:\n"
271
+ print tr.match("=="), "\n"
272
+ print "case 3:\n"
273
+ print tr.match("=>"), "\n"
274
+ end
275
+ exit
276
+ end
@@ -1,5 +1,4 @@
1
- require "e2mmap"
2
- require "irb/slex"
1
+ require_relative 'irb/slex'
3
2
 
4
3
  module YARD
5
4
  module Parser::Ruby::Legacy
@@ -129,7 +128,7 @@ module YARD
129
128
  when String, Symbol
130
129
  source = token.is_a?(String) ? TkReading2Token : TkSymbol2Token
131
130
  if (tk = source[token]).nil?
132
- IRB.fail TkReading2TokenNoKey, token
131
+ raise "no key #{token}"
133
132
  end
134
133
  tk = Token(tk[0], value)
135
134
  else
@@ -285,7 +284,7 @@ module YARD
285
284
 
286
285
  if reading
287
286
  if TkReading2Token[reading]
288
- IRB.fail TkReading2TokenDuplicateError, token_n, reading
287
+ raise "duplicate #{token_n} #{reading}"
289
288
  end
290
289
  if opts.empty?
291
290
  TkReading2Token[reading] = [token_c]
@@ -425,14 +424,6 @@ module YARD
425
424
 
426
425
  # end of nested class BufferedReader
427
426
 
428
- extend Exception2MessageMapper
429
- def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
430
- def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
431
- def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
432
- def_exception(:TkReading2TokenDuplicateError,
433
- "key duplicate(token_n='%s', key='%s')")
434
- def_exception(:SyntaxError, "%s")
435
-
436
427
  include RubyToken
437
428
  include IRB
438
429
 
@@ -22,6 +22,8 @@ module YARD
22
22
  to_s.split(/\n/)[0]
23
23
  end
24
24
 
25
+ alias signature first_line
26
+
25
27
  def to_s(include_block = true)
26
28
  tokens.map do |token|
27
29
  RubyToken::TkBlockContents === token ? (include_block ? block.to_s : '') : token.text
@@ -333,6 +333,7 @@ module YARD
333
333
  undef on_bodystmt
334
334
  undef on_top_const_ref
335
335
  undef on_const_path_ref
336
+ undef on_dyna_symbol
336
337
 
337
338
  def on_program(*args)
338
339
  args.first
@@ -410,6 +411,16 @@ module YARD
410
411
  visit_ns_token(:rbracket, tok, false)
411
412
  end
412
413
 
414
+ def on_dyna_symbol(sym)
415
+ rng = if sym.source_range.size == 0 # rubocop:disable Style/ZeroLengthPredicate
416
+ (sym.source_range.begin - 3)...sym.source_range.end
417
+ else
418
+ (sym.source_range.begin - 2)..(sym.source_range.end + 1)
419
+ end
420
+ AstNode.new(:dyna_symbol, [sym], :line => lineno..lineno,
421
+ :listline => lineno..lineno, :listchar => rng, :char => rng)
422
+ end
423
+
413
424
  def on_top_const_ref(*args)
414
425
  type = :top_const_ref
415
426
  node = AstNode.node_class_for(type).new(type, args)
@@ -481,7 +492,8 @@ module YARD
481
492
  end
482
493
 
483
494
  def on_string_content(*args)
484
- AstNode.new(:string_content, args, :listline => lineno..lineno, :listchar => charno..charno)
495
+ chr_rng = args.empty? ? charno...charno : charno..charno
496
+ AstNode.new(:string_content, args, :listline => lineno..lineno, :listchar => chr_rng)
485
497
  end
486
498
 
487
499
  def on_rescue(exc, *args)
@@ -600,7 +612,7 @@ module YARD
600
612
 
601
613
  def insert_comments
602
614
  root.traverse do |node|
603
- next if node.type == :comment || node.type == :list || node.parent.type != :list
615
+ next if %i{comment void_stmt list}.include?(node.type) || node.parent.type != :list
604
616
 
605
617
  # never attach comments to if/unless mod nodes
606
618
  if node.type == :if_mod || node.type == :unless_mod