yard 0.9.20 → 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 (69) hide show
  1. checksums.yaml +4 -4
  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_guide +19 -0
  10. data/.yardopts_i18n +23 -0
  11. data/CHANGELOG.md +16 -0
  12. data/CODE_OF_CONDUCT.md +15 -0
  13. data/CONTRIBUTING.md +140 -0
  14. data/Dockerfile.samus +28 -0
  15. data/Gemfile +32 -0
  16. data/README.md +2 -0
  17. data/SECURITY.md +26 -0
  18. data/lib/yard/code_objects/base.rb +8 -1
  19. data/lib/yard/code_objects/proxy.rb +4 -0
  20. data/lib/yard/handlers/ruby/attribute_handler.rb +1 -1
  21. data/lib/yard/handlers/ruby/dsl_handler_methods.rb +3 -3
  22. data/lib/yard/handlers/ruby/method_handler.rb +0 -10
  23. data/lib/yard/handlers/ruby/mixin_handler.rb +13 -1
  24. data/lib/yard/parser/c/statement.rb +2 -0
  25. data/lib/yard/parser/ruby/ast_node.rb +11 -0
  26. data/lib/yard/parser/ruby/legacy/irb/slex.rb +276 -0
  27. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +3 -12
  28. data/lib/yard/parser/ruby/legacy/statement.rb +2 -0
  29. data/lib/yard/parser/ruby/ruby_parser.rb +1 -1
  30. data/lib/yard/registry_resolver.rb +47 -5
  31. data/lib/yard/registry_store.rb +6 -1
  32. data/lib/yard/templates/helpers/html_helper.rb +20 -3
  33. data/lib/yard/version.rb +1 -1
  34. data/po/ja.po +31108 -0
  35. data/samus.json +80 -0
  36. data/spec/code_objects/base_spec.rb +15 -0
  37. data/spec/code_objects/extra_file_object_spec.rb +4 -3
  38. data/spec/code_objects/proxy_spec.rb +6 -0
  39. data/spec/handlers/dsl_handler_spec.rb +7 -0
  40. data/spec/handlers/examples/dsl_handler_001.rb.txt +2 -0
  41. data/spec/handlers/examples/extend_handler_001.rb.txt +4 -1
  42. data/spec/handlers/examples/mixin_handler_001.rb.txt +3 -0
  43. data/spec/handlers/extend_handler_spec.rb +4 -0
  44. data/spec/handlers/method_handler_spec.rb +24 -0
  45. data/spec/handlers/mixin_handler_spec.rb +4 -0
  46. data/spec/registry_store_spec.rb +11 -0
  47. data/spec/templates/examples/module001.html +3 -3
  48. data/spec/templates/examples/module002.html +1 -1
  49. data/spec/templates/examples/module003.html +1 -1
  50. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +60 -0
  51. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +46 -0
  52. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +59 -0
  53. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +39 -0
  54. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +59 -0
  55. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +48 -0
  56. data/templates/default/docstring/setup.rb +1 -1
  57. data/templates/default/fulldoc/html/css/style.css +2 -2
  58. data/templates/default/fulldoc/html/frames.erb +1 -1
  59. data/templates/default/fulldoc/html/full_list.erb +1 -1
  60. data/templates/default/fulldoc/html/js/app.js +14 -3
  61. data/templates/default/fulldoc/html/js/jquery.js +2 -4
  62. data/templates/default/layout/html/headers.erb +1 -1
  63. data/templates/default/layout/html/script_setup.erb +1 -1
  64. data/templates/default/onefile/html/headers.erb +1 -1
  65. data/templates/default/tags/html/tag.erb +1 -1
  66. data/templates/guide/layout/html/layout.erb +1 -1
  67. data/yard.gemspec +1 -20
  68. metadata +27 -21
  69. data/spec/examples.txt +0 -1883
@@ -0,0 +1,80 @@
1
+ {
2
+ "actions": [
3
+ {
4
+ "action": "fs-sedfiles",
5
+ "files": ["lib/*/version.rb"],
6
+ "arguments": {
7
+ "search": "VERSION = ['\"](.+?)['\"]",
8
+ "replace": "VERSION = '$version'"
9
+ }
10
+ },
11
+ {
12
+ "action": "chmod-files",
13
+ "files": ["**/*,644", "bin/*,755"]
14
+ },
15
+ {
16
+ "action": "changelog-rotate",
17
+ "files": ["CHANGELOG.md"],
18
+ "arguments": {
19
+ "title_format": "$version - %B %-d$day_nth, %Y"
20
+ }
21
+ },
22
+ {
23
+ "action": "git-commit",
24
+ "files": ["CHANGELOG.md", "lib/*/version.rb"]
25
+ },
26
+ {
27
+ "action": "git-merge",
28
+ "arguments": {
29
+ "branch": "master"
30
+ }
31
+ },
32
+ {
33
+ "action": "ruby-bundle"
34
+ },
35
+ {
36
+ "action": "rake-task"
37
+ },
38
+ {
39
+ "action": "archive-git-full",
40
+ "files": ["git.tgz"],
41
+ "publish": [
42
+ {
43
+ "action": "git-push",
44
+ "credentials": "lsegal.github.ssh",
45
+ "arguments": {
46
+ "remotes": "origin",
47
+ "refs": "master v$version"
48
+ }
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "action": "gem-build",
54
+ "files": ["*.gemspec"],
55
+ "publish": [
56
+ {
57
+ "action": "gem-push",
58
+ "files": ["*.gem"],
59
+ "credentials": "lsegal.rubygems"
60
+ }
61
+ ]
62
+ },
63
+ {
64
+ "action": "changelog-parse",
65
+ "files": ["CHANGELOG.md"],
66
+ "publish": [
67
+ {
68
+ "action": "github-release",
69
+ "credentials": "lsegal.github",
70
+ "files": [],
71
+ "arguments": {
72
+ "repository": "lsegal/yard",
73
+ "tag": "v$version",
74
+ "changelog": "CHANGELOG.md"
75
+ }
76
+ }
77
+ ]
78
+ }
79
+ ]
80
+ }
@@ -84,6 +84,21 @@ RSpec.describe YARD::CodeObjects::Base do
84
84
  expect { CodeObjects::Base.new("ROOT!", :Me) }.to raise_error(ArgumentError)
85
85
  end
86
86
 
87
+ it "allows constants to be used as a namespace" do
88
+ a = ConstantObject.new(:root, :A)
89
+ a.value = "B::C"
90
+ b = ClassObject.new(:root, :B)
91
+ c = ClassObject.new(b, :C)
92
+ klass = ClassObject.new(a, "MyClass")
93
+ expect(klass.path).to eq "B::C::MyClass"
94
+ end
95
+
96
+ it "does not allow constants to be used as a namespace if they do not resolve to a valid namespace" do
97
+ a = ConstantObject.new(:root, :A)
98
+ a.value = "$$INVALID$$"
99
+ expect { ClassObject.new(a, "MyClass") }.to raise_error(Parser::UndocumentableError)
100
+ end
101
+
87
102
  it "registers itself in the registry if namespace is supplied" do
88
103
  obj = ModuleObject.new(:root, :Me)
89
104
  expect(Registry.at(:Me)).to eq obj
@@ -103,10 +103,11 @@ RSpec.describe YARD::CodeObjects::ExtraFileObject do
103
103
  it "attempts to re-parse data as 8-bit ascii if parsing fails" do
104
104
  expect(log).not_to receive(:warn)
105
105
  str, out = *([String.new("\xB0")] * 2)
106
- if str.respond_to?(:force_encoding)
107
- str.force_encoding('utf-8')
108
- out.force_encoding('binary')
106
+ if str.respond_to?(:force_encoding!)
107
+ str.force_encoding!('utf-8')
108
+ out.force_encoding!('binary')
109
109
  end
110
+ expect(str.valid_encoding?).to be(false)
110
111
  file = ExtraFileObject.new('file.txt', str)
111
112
  expect(file.contents).to eq out
112
113
  end
@@ -4,6 +4,12 @@ require File.dirname(__FILE__) + '/spec_helper'
4
4
  RSpec.describe YARD::CodeObjects::Proxy do
5
5
  before { Registry.clear }
6
6
 
7
+ it "does not allow constants to be used as a namespace if they do not resolve to a valid namespace" do
8
+ a = ConstantObject.new(:root, :A)
9
+ a.value = "$$INVALID$$"
10
+ expect { P("A::MyClass") }.to raise_error(Parser::UndocumentableError)
11
+ end
12
+
7
13
  it "returns the object if it's in the Registry" do
8
14
  ModuleObject.new(:root, :YARD)
9
15
  proxyobj = P(:root, :YARD)
@@ -67,6 +67,13 @@ RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}DSLHandl
67
67
  expect(obj.docstring).to eq 'The foo method'
68
68
  end
69
69
 
70
+ it "recognizes methods with no attached source" do
71
+ obj = Registry.at('Foo#no_src')
72
+ expect(obj).not_to be nil
73
+ expect(obj.signature).to eq 'def no_src'
74
+ expect(obj.source).to eq ''
75
+ end
76
+
70
77
  it "allows setting of @!scope" do
71
78
  expect(Registry.at('Foo.xyz').scope).to eq :class
72
79
  end
@@ -79,6 +79,8 @@ class Foo
79
79
  # @!method qux2(a, b, c)
80
80
  something
81
81
 
82
+ # @!method no_src
83
+
82
84
  # @!macro
83
85
  # $1 $2 $3
84
86
  def regular_meth(a, b, c) end
@@ -13,4 +13,7 @@ module Q
13
13
  extend A
14
14
  end
15
15
  end
16
- end
16
+ end
17
+
18
+ module FromConstant; end
19
+ FromConstant.extend A
@@ -35,3 +35,6 @@ module ABC
35
35
  end
36
36
  end
37
37
  end
38
+
39
+ module FromConstant; end
40
+ FromConstant.include A
@@ -21,4 +21,8 @@ RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ExtendHa
21
21
  it "does not allow extending self if object is a class" do
22
22
  undoc_error "class Foo; extend self; end"
23
23
  end
24
+
25
+ it "adds mixins from extend calls to constants" do
26
+ expect(P('FromConstant').class_mixins).to eq [P('A')]
27
+ end
24
28
  end
@@ -43,6 +43,30 @@ RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodHa
43
43
  expect(P('Foo#/').parameters).to eq [['x', "File.new('x', 'w')"], ['y', '2']]
44
44
  end
45
45
 
46
+ it "handles multiline parameters" do
47
+ YARD.parse_string <<-EOF
48
+ class Bar
49
+ def multiline_params(x,
50
+ y, z, zz = 'zz',
51
+ *foo,
52
+ a: 'a', b: 'b',
53
+ c: 'c',
54
+ **bar,
55
+ &blk
56
+ )
57
+ end
58
+ end
59
+ EOF
60
+
61
+ sig = "def multiline_params(x, y, z, zz = 'zz', *foo, a: 'a', b: 'b', c: 'c', **bar, &blk)"
62
+ expect(P('Bar#multiline_params').signature).to eq sig
63
+ end if YARD.ruby2?
64
+
65
+ it "handles method signature with no parameters" do
66
+ YARD.parse_string "class Bar; def foo; end end"
67
+ expect(P('Bar#foo').signature).to eq 'def foo'
68
+ end
69
+
46
70
  it "handles opts = {} as parameter" do
47
71
  expect(P('Foo#optsmeth').parameters).to eq [['x', nil], ['opts', '{}']]
48
72
  end
@@ -53,4 +53,8 @@ RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MixinHan
53
53
  undoc_error "module X; include invalid, Y; end"
54
54
  expect(Registry.at('X').mixins).to eq [P('Y')]
55
55
  end
56
+
57
+ it "adds mixins from include calls to constants" do
58
+ expect(P('FromConstant').instance_mixins).to eq [P('A')]
59
+ end
56
60
  end
@@ -304,6 +304,17 @@ RSpec.describe YARD::RegistryStore do
304
304
  end
305
305
  end
306
306
 
307
+ describe "#delete" do
308
+ it "deletes the given object from store" do
309
+ @store.put(:YARD, @foo)
310
+ expect(@store.get(:YARD)).to be @foo
311
+ expect(@store.paths_for_type(:method)).to eq ["YARD"]
312
+ @store.delete(:YARD)
313
+ expect(@store.get(:YARD)).to be nil
314
+ expect(@store.paths_for_type(:method)).to eq []
315
+ end
316
+ end
317
+
307
318
  describe "#locale" do
308
319
  it "loads ./po/LOCALE_NAME.po" do
309
320
  fr_locale = I18n::Locale.new("fr")
@@ -381,7 +381,7 @@ and newlines.
381
381
 
382
382
  </h3><div class="docstring">
383
383
  <div class="discussion">
384
- Returns the value of attribute attr1
384
+ Returns the value of attribute attr1.
385
385
 
386
386
  </div>
387
387
  </div>
@@ -422,7 +422,7 @@ end</pre>
422
422
 
423
423
  </h3><div class="docstring">
424
424
  <div class="discussion">
425
- Returns the value of attribute attr2
425
+ Returns the value of attribute attr2.
426
426
 
427
427
  </div>
428
428
  </div>
@@ -481,7 +481,7 @@ end</pre>
481
481
  <span class="signature">#<strong>attr3</strong> &#x21d2; <tt>String</tt> </span>
482
482
  <div class="docstring">
483
483
  <div class="discussion">
484
- Returns a string
484
+ Returns a string.
485
485
 
486
486
  </div>
487
487
  </div>
@@ -193,7 +193,7 @@
193
193
 
194
194
  </h3><div class="docstring">
195
195
  <div class="discussion">
196
- Returns the value of attribute foo_attr
196
+ Returns the value of attribute foo_attr.
197
197
 
198
198
  </div>
199
199
  </div>
@@ -138,7 +138,7 @@
138
138
 
139
139
  </h3><div class="docstring">
140
140
  <div class="discussion">
141
- Returns the value of attribute bar
141
+ Returns the value of attribute bar.
142
142
 
143
143
  </div>
144
144
  </div>
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/integration_spec_helper'
4
+
5
+ RSpec.describe 'Asciidoctor integration' do
6
+ include_context 'shared helpers for markup processor integration specs'
7
+ let(:markup) { :asciidoc }
8
+ let(:markup_provider) { :asciidoctor }
9
+
10
+ let(:document) do
11
+ <<-ASCIIDOC
12
+ == Example code listings
13
+
14
+ Indented block of Ruby code:
15
+
16
+ x = 1
17
+
18
+ Fenced block of Ruby code:
19
+
20
+ -----
21
+ x = 2
22
+ -----
23
+
24
+ Fenced and annotated block of Ruby code:
25
+
26
+ [source,ruby]
27
+ -----
28
+ x = 3
29
+ -----
30
+
31
+ Fenced and annotated block of non-Ruby code:
32
+
33
+ [source,bash]
34
+ -----
35
+ x = 4
36
+ -----
37
+
38
+ ASCIIDOC
39
+ end
40
+
41
+ it 'renders level 2 header' do
42
+ expect(rendered_document).to match(header_regexp(2, 'Example code listings'))
43
+ end
44
+
45
+ it 'renders indented block of code, and applies Ruby syntax highlight' do
46
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '1'))
47
+ end
48
+
49
+ it 'renders fenced block of code, and applies Ruby syntax highlight' do
50
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '2'))
51
+ end
52
+
53
+ it 'renders fenced and annotated block of Ruby code, and applies syntax highlight' do
54
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '3'))
55
+ end
56
+
57
+ it 'renders fenced and annotated block of non-Ruby code, and does not apply syntax highlight' do
58
+ expect(rendered_document).to match('x = 4')
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context 'shared helpers for markup processor integration specs' do
4
+ let(:rendered_document) { html_renderer.htmlify document }
5
+
6
+ let(:template_options) do
7
+ Templates::TemplateOptions.new.tap do |o|
8
+ o.reset_defaults
9
+ o.default_return = nil
10
+ o.markup = markup
11
+ o.markup_provider = markup_provider
12
+ end
13
+ end
14
+
15
+ let(:html_renderer) do
16
+ obj = OpenStruct.new
17
+ obj.options = template_options
18
+ obj.object = Registry.root
19
+ obj.extend(Templates::Helpers::HtmlHelper)
20
+ obj
21
+ end
22
+
23
+ before(:each) do
24
+ if html_renderer.markup_class(markup).nil?
25
+ skip "Missing markup renderer #{markup}"
26
+ end
27
+ end
28
+
29
+ # Works only with one-liners.
30
+ def highlighted_ruby_regexp(*identifiers)
31
+ prefix = Regexp.escape '<pre class="code ruby"><code class="ruby">'
32
+ any_span_tag = '<span\b'
33
+ escaped_identifiers = identifiers.map {|a| Regexp.escape(a) }
34
+
35
+ regexp_parts = [prefix, any_span_tag, escaped_identifiers]
36
+ regexp_str = regexp_parts.flatten.join(".*")
37
+ Regexp.compile(regexp_str)
38
+ end
39
+
40
+ def header_regexp(level, text)
41
+ prefix = "<h#{level}[^>]*?>"
42
+ escaped_text = Regexp.escape text
43
+ regexp_str = [prefix, escaped_text].join(".*")
44
+ Regexp.compile(regexp_str)
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/integration_spec_helper'
4
+
5
+ RSpec.describe 'Markdown via RDoc integration' do
6
+ include_context 'shared helpers for markup processor integration specs'
7
+ let(:markup) { :markdown }
8
+ let(:markup_provider) { :rdoc }
9
+
10
+ let(:document) do
11
+ <<-MARKDOWN
12
+ ## Example code listings
13
+
14
+ Indented block of Ruby code:
15
+
16
+ x = 1
17
+
18
+ Fenced block of Ruby code:
19
+
20
+ ```
21
+ x = 2
22
+ ```
23
+
24
+ Fenced and annotated block of Ruby code:
25
+
26
+ ```ruby
27
+ x = 3
28
+ ```
29
+
30
+ Fenced and annotated block of non-Ruby code:
31
+
32
+ ```plain
33
+ x = 4
34
+ ```
35
+
36
+ MARKDOWN
37
+ end
38
+
39
+ it 'renders level 2 header' do
40
+ expect(rendered_document).to match(header_regexp(2, 'Example code listings'))
41
+ end
42
+
43
+ it 'renders indented block of code, and applies Ruby syntax highlight' do
44
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '1'))
45
+ end
46
+
47
+ it 'renders fenced block of code, and applies Ruby syntax highlight' do
48
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '2'))
49
+ end
50
+
51
+ it 'renders fenced and annotated block of Ruby code, and applies syntax highlight' do
52
+ expect(rendered_document).to match(highlighted_ruby_regexp('x', '=', '3'))
53
+ end
54
+
55
+ it 'renders fenced and annotated block of non-Ruby code, and does not apply syntax highlight' do
56
+ pending 'This is actually highlighted, but it is not a big deal'
57
+ expect(rendered_document).to match('x = 4')
58
+ end
59
+ end