inch 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +113 -0
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +5 -2
  6. data/README.md +2 -2
  7. data/Rakefile +2 -2
  8. data/bin/inch +3 -2
  9. data/config/defaults.rb +7 -0
  10. data/inch.gemspec +7 -7
  11. data/lib/inch.rb +9 -10
  12. data/lib/inch/api.rb +10 -10
  13. data/lib/inch/api/compare.rb +2 -2
  14. data/lib/inch/api/compare/code_objects.rb +2 -3
  15. data/lib/inch/api/compare/codebases.rb +1 -1
  16. data/lib/inch/api/diff.rb +6 -9
  17. data/lib/inch/api/options/base.rb +4 -4
  18. data/lib/inch/api/options/suggest.rb +1 -1
  19. data/lib/inch/api/stats.rb +0 -1
  20. data/lib/inch/api/suggest.rb +8 -9
  21. data/lib/inch/cli.rb +6 -6
  22. data/lib/inch/cli/command.rb +15 -15
  23. data/lib/inch/cli/command/base.rb +2 -2
  24. data/lib/inch/cli/command/console.rb +5 -5
  25. data/lib/inch/cli/command/diff.rb +7 -8
  26. data/lib/inch/cli/command/inspect.rb +5 -4
  27. data/lib/inch/cli/command/list.rb +4 -4
  28. data/lib/inch/cli/command/options/base.rb +8 -8
  29. data/lib/inch/cli/command/options/base_list.rb +9 -5
  30. data/lib/inch/cli/command/options/console.rb +4 -3
  31. data/lib/inch/cli/command/options/diff.rb +6 -4
  32. data/lib/inch/cli/command/options/inspect.rb +2 -2
  33. data/lib/inch/cli/command/options/list.rb +4 -3
  34. data/lib/inch/cli/command/options/show.rb +2 -2
  35. data/lib/inch/cli/command/options/stats.rb +2 -1
  36. data/lib/inch/cli/command/options/suggest.rb +6 -3
  37. data/lib/inch/cli/command/output/base.rb +2 -4
  38. data/lib/inch/cli/command/output/console.rb +4 -5
  39. data/lib/inch/cli/command/output/diff.rb +6 -6
  40. data/lib/inch/cli/command/output/inspect.rb +6 -8
  41. data/lib/inch/cli/command/output/list.rb +0 -1
  42. data/lib/inch/cli/command/output/show.rb +4 -5
  43. data/lib/inch/cli/command/output/stats.rb +21 -21
  44. data/lib/inch/cli/command/output/suggest.rb +28 -26
  45. data/lib/inch/cli/command/show.rb +4 -4
  46. data/lib/inch/cli/command/stats.rb +4 -4
  47. data/lib/inch/cli/command/suggest.rb +6 -6
  48. data/lib/inch/cli/command_parser.rb +6 -5
  49. data/lib/inch/cli/sparkline_helper.rb +2 -2
  50. data/lib/inch/cli/trace_helper.rb +1 -1
  51. data/lib/inch/cli/yardopts_helper.rb +4 -3
  52. data/lib/inch/code_object.rb +3 -3
  53. data/lib/inch/code_object/converter.rb +6 -8
  54. data/lib/inch/code_object/provider.rb +1 -1
  55. data/lib/inch/code_object/provider/yard.rb +10 -12
  56. data/lib/inch/code_object/provider/yard/docstring.rb +53 -21
  57. data/lib/inch/code_object/provider/yard/nodoc_helper.rb +3 -3
  58. data/lib/inch/code_object/provider/yard/object.rb +11 -9
  59. data/lib/inch/code_object/provider/yard/object/base.rb +33 -9
  60. data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +12 -0
  61. data/lib/inch/code_object/provider/yard/object/method_object.rb +36 -11
  62. data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +2 -2
  63. data/lib/inch/code_object/provider/yard/object/method_signature.rb +11 -8
  64. data/lib/inch/code_object/provider/yard/object/namespace_object.rb +1 -4
  65. data/lib/inch/code_object/provider/yard/parser.rb +2 -2
  66. data/lib/inch/code_object/proxy.rb +10 -9
  67. data/lib/inch/code_object/proxy/base.rb +8 -8
  68. data/lib/inch/code_object/proxy/class_variable_object.rb +8 -0
  69. data/lib/inch/code_object/proxy/method_object.rb +3 -2
  70. data/lib/inch/code_object/proxy/method_parameter_object.rb +1 -1
  71. data/lib/inch/codebase.rb +4 -5
  72. data/lib/inch/codebase/objects_filter.rb +2 -4
  73. data/lib/inch/codebase/serializer.rb +3 -3
  74. data/lib/inch/config.rb +2 -2
  75. data/lib/inch/config/base.rb +0 -1
  76. data/lib/inch/config/codebase.rb +3 -3
  77. data/lib/inch/core_ext.rb +1 -1
  78. data/lib/inch/core_ext/string.rb +1 -1
  79. data/lib/inch/evaluation.rb +16 -15
  80. data/lib/inch/evaluation/grade_list.rb +2 -2
  81. data/lib/inch/evaluation/object_schema.rb +1 -1
  82. data/lib/inch/evaluation/proxy.rb +8 -7
  83. data/lib/inch/evaluation/proxy/base.rb +12 -7
  84. data/lib/inch/evaluation/proxy/class_variable_object.rb +19 -0
  85. data/lib/inch/evaluation/proxy/constant_object.rb +1 -1
  86. data/lib/inch/evaluation/proxy/method_object.rb +12 -5
  87. data/lib/inch/evaluation/proxy/module_object.rb +1 -1
  88. data/lib/inch/evaluation/proxy/namespace_object.rb +1 -1
  89. data/lib/inch/evaluation/role/base.rb +1 -1
  90. data/lib/inch/evaluation/role/class_variable.rb +55 -0
  91. data/lib/inch/evaluation/role/method.rb +0 -1
  92. data/lib/inch/evaluation/role/method_parameter.rb +2 -1
  93. data/lib/inch/evaluation/role/object.rb +2 -2
  94. data/lib/inch/rake.rb +2 -2
  95. data/lib/inch/rake/suggest.rb +2 -2
  96. data/lib/inch/utils/shell_helper.rb +1 -1
  97. data/lib/inch/utils/ui.rb +5 -5
  98. data/lib/inch/utils/weighted_list.rb +2 -3
  99. data/lib/inch/version.rb +1 -1
  100. data/test/fixtures/simple/lib/broken.rb +35 -7
  101. data/test/fixtures/simple/lib/broken_ruby_2_0_features.rb +7 -0
  102. data/test/fixtures/simple/lib/directives.rb +8 -0
  103. data/test/fixtures/simple/lib/foo.rb +17 -0
  104. data/test/integration/api/compare/codebases.rb +1 -1
  105. data/test/integration/cli/command/console_test.rb +5 -5
  106. data/test/integration/cli/command/inspect_test.rb +4 -5
  107. data/test/integration/cli/command/list_test.rb +3 -4
  108. data/test/integration/cli/command/show_test.rb +4 -4
  109. data/test/integration/cli/command/stats_test.rb +2 -2
  110. data/test/integration/cli/command/suggest_test.rb +7 -7
  111. data/test/integration/stats_options_test.rb +3 -3
  112. data/test/integration/visibility_options_test.rb +13 -13
  113. data/test/shared/base_list.rb +4 -3
  114. data/test/test_helper.rb +16 -5
  115. data/test/unit/api/filter_test.rb +7 -7
  116. data/test/unit/api/get_test.rb +1 -1
  117. data/test/unit/api/list_test.rb +1 -1
  118. data/test/unit/api/options/base_test.rb +3 -3
  119. data/test/unit/api/stats_test.rb +1 -1
  120. data/test/unit/api/suggest_test.rb +3 -3
  121. data/test/unit/cli/arguments_test.rb +1 -1
  122. data/test/unit/cli/command/base_test.rb +1 -1
  123. data/test/unit/cli/command/options/base_list_test.rb +2 -2
  124. data/test/unit/cli/command/options/base_object_test.rb +1 -1
  125. data/test/unit/cli/command/options/base_test.rb +1 -1
  126. data/test/unit/cli/command_parser_test.rb +2 -2
  127. data/test/unit/cli/trace_helper_test.rb +1 -1
  128. data/test/unit/cli/yardopts_helper_test.rb +4 -3
  129. data/test/unit/code_object/converter_test.rb +1 -1
  130. data/test/unit/code_object/provider/yard/docstring_test.rb +105 -28
  131. data/test/unit/code_object/provider/yard/nodoc_helper_test.rb +5 -5
  132. data/test/unit/code_object/provider/yard/object/method_object_test.rb +20 -10
  133. data/test/unit/code_object/provider/yard_test.rb +4 -4
  134. data/test/unit/code_object/provider_test.rb +1 -1
  135. data/test/unit/code_object/proxy/method_object_test.rb +366 -262
  136. data/test/unit/code_object/proxy_test.rb +1 -1
  137. data/test/unit/codebase/objects_test.rb +2 -2
  138. data/test/unit/codebase/proxy_test.rb +1 -1
  139. data/test/unit/config/codebase_test.rb +1 -1
  140. data/test/unit/evaluation/role/base_test.rb +1 -1
  141. data/test/unit/utils/ui_test.rb +4 -4
  142. data/test/unit/utils/weighted_list_test.rb +7 -4
  143. metadata +12 -2
@@ -21,9 +21,9 @@ module Inch
21
21
 
22
22
  def __sparkline(list, grade_lists)
23
23
  sparkline = Sparkr::Sparkline.new(list)
24
- sparkline.format do |tick, count, index|
24
+ sparkline.format do |tick, _count, index|
25
25
  t = tick.color(grade_lists[index].color)
26
- index == 0 ? t + ' ' : t
26
+ index == 0 ? t + " " : t
27
27
  end
28
28
  end
29
29
  end
@@ -1,4 +1,4 @@
1
- require 'inch/utils/ui'
1
+ require "inch/utils/ui"
2
2
 
3
3
  module Inch
4
4
  module CLI
@@ -8,7 +8,8 @@ module Inch
8
8
  attr_accessor :excluded
9
9
 
10
10
  VALID_YARD_SWITCHES = %w(--private --no-private --protected --no-public
11
- --plugin --load --safe --yardopts --no-yardopts --document --no-document)
11
+ --plugin --load --safe --yardopts --no-yardopts
12
+ --document --no-document)
12
13
 
13
14
  # Parses the option and gracefully handles invalid switches
14
15
  #
@@ -17,7 +18,7 @@ module Inch
17
18
  # array will be modified.
18
19
  # @return [void]
19
20
  def parse_yardopts_options(opts, args)
20
- wrapper = YardoptsWrapper.new()
21
+ wrapper = YardoptsWrapper.new
21
22
 
22
23
  dupped_args = args.dup
23
24
  dupped_args.delete("--help")
@@ -35,7 +36,7 @@ module Inch
35
36
  end
36
37
 
37
38
  def yardopts_options(opts)
38
- wrapper = YardoptsWrapper.new()
39
+ wrapper = YardoptsWrapper.new
39
40
  wrapper.add_yardoc_options(opts)
40
41
  end
41
42
 
@@ -3,6 +3,6 @@ module Inch
3
3
  end
4
4
  end
5
5
 
6
- require 'inch/code_object/converter'
7
- require 'inch/code_object/provider'
8
- require 'inch/code_object/proxy'
6
+ require "inch/code_object/converter"
7
+ require "inch/code_object/provider"
8
+ require "inch/code_object/proxy"
@@ -52,7 +52,7 @@ module Inch
52
52
  unconsidered_tag_count
53
53
  undocumented?
54
54
  visibility
55
- ).map(&:to_sym)
55
+ ).map(&:to_sym)
56
56
 
57
57
  PARAMETER_ATTRIBUTES = %w(
58
58
  name
@@ -62,7 +62,7 @@ module Inch
62
62
  splat?
63
63
  typed?
64
64
  wrongly_mentioned?
65
- ).map(&:to_sym)
65
+ ).map(&:to_sym)
66
66
 
67
67
  # Returns an attributes Hash for a given code object
68
68
  #
@@ -71,16 +71,14 @@ module Inch
71
71
  def self.to_hash(o)
72
72
  attributes = {}
73
73
  OBJECT_ATTRIBUTES.each do |name|
74
- if o.respond_to?(name)
75
- attributes[name] = o.public_send(name)
76
- end
74
+ next unless o.respond_to?(name)
75
+ attributes[name] = o.public_send(name)
77
76
  end
78
77
  attributes[:parameters] = o.parameters.map do |parameter|
79
78
  hash = {}
80
79
  PARAMETER_ATTRIBUTES.each do |pname|
81
- if parameter.respond_to?(pname)
82
- hash[pname] = parameter.public_send(pname)
83
- end
80
+ next unless parameter.respond_to?(pname)
81
+ hash[pname] = parameter.public_send(pname)
84
82
  end
85
83
  hash
86
84
  end
@@ -33,4 +33,4 @@ module Inch
33
33
  end
34
34
  end
35
35
 
36
- require 'inch/code_object/provider/yard'
36
+ require "inch/code_object/provider/yard"
@@ -3,7 +3,6 @@ module Inch
3
3
  module Provider
4
4
  # Parses the source tree (using YARD)
5
5
  module YARD
6
-
7
6
  # Returns +true+ if the docstring was generated by YARD
8
7
  #
9
8
  # @param docstring [Docstring,String]
@@ -13,7 +12,7 @@ module Inch
13
12
  if method.getter?
14
13
  docstring.to_s == "Returns the value of attribute #{name}"
15
14
  elsif method.setter?
16
- basename = name.to_s.gsub(/(\=)$/, '')
15
+ basename = name.to_s.gsub(/(\=)$/, "")
17
16
  docstring.to_s == "Sets the attribute #{basename}"
18
17
  else
19
18
  false
@@ -27,11 +26,11 @@ module Inch
27
26
  def self.implicit_tag?(tag, method)
28
27
  name = method.name
29
28
  if method.getter?
30
- tag.tag_name == 'return' &&
29
+ tag.tag_name == "return" &&
31
30
  tag.text == "the current value of #{name}"
32
31
  elsif method.setter?
33
- tag.tag_name == 'return' &&
34
- tag.text == 'the newly set value'
32
+ tag.tag_name == "return" &&
33
+ tag.text == "the newly set value"
35
34
  else
36
35
  false
37
36
  end
@@ -40,18 +39,17 @@ module Inch
40
39
  def self.parse(dir, config = Inch::Config.codebase)
41
40
  Parser.parse(dir, config)
42
41
  end
43
-
44
42
  end
45
43
  end
46
44
  end
47
45
  end
48
46
 
49
- require 'logger'
50
- require 'yard'
47
+ require "logger"
48
+ require "yard"
51
49
 
52
50
  log.level = ::Logger::UNKNOWN # basically disable YARD's logging
53
51
 
54
- require 'inch/code_object/provider/yard/parser'
55
- require 'inch/code_object/provider/yard/docstring'
56
- require 'inch/code_object/provider/yard/nodoc_helper'
57
- require 'inch/code_object/provider/yard/object'
52
+ require "inch/code_object/provider/yard/parser"
53
+ require "inch/code_object/provider/yard/docstring"
54
+ require "inch/code_object/provider/yard/nodoc_helper"
55
+ require "inch/code_object/provider/yard/object"
@@ -42,11 +42,16 @@ module Inch
42
42
  end
43
43
 
44
44
  def mentions_return?
45
- last_line =~ /^Returns\ /
45
+ last_lines.any? do |line|
46
+ line =~ /^#{tomdoc_modifiers}Returns\ /
47
+ end
46
48
  end
47
49
 
48
50
  def describes_return?
49
- last_line =~ /^Returns\ (\w+\s){2,}/
51
+ last_lines.any? do |line|
52
+ line =~ /^#{tomdoc_modifiers}Returns\ (\w+\s){2,}/i ||
53
+ line =~ /^#{tomdoc_modifiers}Returns\ (nil|nothing)\.*/i
54
+ end
50
55
  end
51
56
 
52
57
  def to_s
@@ -59,18 +64,28 @@ module Inch
59
64
  @first_line ||= @text.lines.to_a.first
60
65
  end
61
66
 
62
- def last_line
63
- @last_line ||= @text.lines.to_a.last
67
+ # Returns the last lines of the docstring.
68
+ # @return [Array<String>] the last line and, if the last line(s) is indented,
69
+ # the last unindented line
70
+ def last_lines
71
+ @last_lines ||= begin
72
+ list = []
73
+ @text.lines.to_a.reverse.each do |line|
74
+ list << line
75
+ break if line =~ /^\S/
76
+ end
77
+ list.reverse
78
+ end
64
79
  end
65
80
 
66
81
  def parse_code_examples
67
82
  code_examples = []
68
83
  example = nil
69
- @text.lines.each_with_index do |line, index|
70
- if line =~/^\s*+$/
84
+ @text.lines.each do |line|
85
+ if line =~ /^\s*+$/
71
86
  code_examples << example if example
72
87
  example = []
73
- elsif line =~/^\ {2,}\S+/
88
+ elsif line =~ /^\ {2,}\S+/
74
89
  example << line if example
75
90
  else
76
91
  code_examples << example if example
@@ -81,22 +96,34 @@ module Inch
81
96
  code_examples.delete_if(&:empty?).map(&:join)
82
97
  end
83
98
 
84
- def mention_parameter_patterns(name)
85
- [
86
- "+#{name}+",
87
- "+#{name}+::",
88
- "<tt>#{name}</tt>",
89
- "<tt>#{name}</tt>::",
90
- "#{name}::",
91
- /^#{Regexp.escape(name)}\ \-\ /
92
- ]
99
+ # Returns patterns in which method parameters are mentioned
100
+ # in inline docs.
101
+ #
102
+ # @param _name [String] the name of the method parameter
103
+ # @return [Array<Regexp>]
104
+ def mention_parameter_patterns(_name)
105
+ name = Regexp.escape(_name)
106
+ type = /<[^>]+>/
107
+ arr = [
108
+ name,
109
+ /#{name}#{type}/ # matches "param1<String,nil>"
110
+ ].map do |expr|
111
+ [
112
+ /#{expr}\:\:/, # param1::
113
+ /\+#{expr}\+/, # +param1+
114
+ /\+#{expr}\+\:\:/, # +param1+::
115
+ /<tt>#{expr}<\/tt>/, # <tt>param1</tt>
116
+ /<tt>#{expr}<\/tt>\:\:/, # <tt>param1</tt>::
117
+ /^#{expr}\ \-\ / # param1 -
118
+ ]
119
+ end.flatten
93
120
  end
94
121
 
95
122
  def describe_parameter_extra_regexps(name)
96
123
  [
97
124
  "#{name}::",
98
125
  "+#{name}+::",
99
- "<tt>#{name}</tt>::",
126
+ "<tt>#{name}</tt>::"
100
127
  ].map do |pattern|
101
128
  r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
102
129
  /#{r}\n\ {2,}.+/m
@@ -104,10 +131,11 @@ module Inch
104
131
  end
105
132
 
106
133
  def describe_parameter_regexps(name)
107
- same_line_regexps = mention_parameter_patterns(name).map do |pattern|
108
- r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
109
- /^#{r}\s?\S+/
110
- end
134
+ same_line_regexps =
135
+ mention_parameter_patterns(name).map do |pattern|
136
+ r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
137
+ /^#{r}\s?\S+/
138
+ end
111
139
  same_line_regexps + describe_parameter_extra_regexps(name)
112
140
  end
113
141
 
@@ -121,6 +149,10 @@ module Inch
121
149
  end
122
150
  end
123
151
  end
152
+
153
+ def tomdoc_modifiers
154
+ /((Public|Private|Internal)\:\ )*/
155
+ end
124
156
  end
125
157
  end
126
158
  end
@@ -3,7 +3,6 @@ module Inch
3
3
  module Provider
4
4
  module YARD
5
5
  module NodocHelper
6
-
7
6
  # Returns true if the code object is somehow marked not to be
8
7
  # documented.
9
8
  #
@@ -81,10 +80,11 @@ module Inch
81
80
  # @return [String]
82
81
  def get_line_no(filename, line_number)
83
82
  f = File.open(filename)
84
- line_number.times{f.gets}
83
+ line_number.times { f.gets }
85
84
  result = $_
86
85
  f.close
87
- result
86
+ result.encode("UTF-8", "binary",
87
+ invalid: :replace, undef: :replace, replace: "")
88
88
  end
89
89
  end
90
90
  end
@@ -19,7 +19,8 @@ module Inch
19
19
  if proxy_object = @cache[cache_key(yard_object)]
20
20
  proxy_object
21
21
  else
22
- @cache[cache_key(yard_object)] = class_for(yard_object).new(yard_object)
22
+ @cache[cache_key(yard_object)] =
23
+ class_for(yard_object).new(yard_object)
23
24
  end
24
25
  end
25
26
 
@@ -30,7 +31,7 @@ module Inch
30
31
  # @param yard_object [YARD::CodeObject]
31
32
  # @return [Class]
32
33
  def class_for(yard_object)
33
- class_name = yard_object.class.to_s.split('::').last
34
+ class_name = yard_object.class.to_s.split("::").last
34
35
  const_get(class_name)
35
36
  rescue NameError
36
37
  Base
@@ -50,10 +51,11 @@ module Inch
50
51
  end
51
52
  end
52
53
 
53
- require 'inch/code_object/provider/yard/object/base'
54
- require 'inch/code_object/provider/yard/object/namespace_object'
55
- require 'inch/code_object/provider/yard/object/class_object'
56
- require 'inch/code_object/provider/yard/object/constant_object'
57
- require 'inch/code_object/provider/yard/object/method_object'
58
- require 'inch/code_object/provider/yard/object/method_parameter_object'
59
- require 'inch/code_object/provider/yard/object/module_object'
54
+ require "inch/code_object/provider/yard/object/base"
55
+ require "inch/code_object/provider/yard/object/namespace_object"
56
+ require "inch/code_object/provider/yard/object/class_object"
57
+ require "inch/code_object/provider/yard/object/class_variable_object"
58
+ require "inch/code_object/provider/yard/object/constant_object"
59
+ require "inch/code_object/provider/yard/object/method_object"
60
+ require "inch/code_object/provider/yard/object/method_parameter_object"
61
+ require "inch/code_object/provider/yard/object/module_object"
@@ -1,4 +1,4 @@
1
- require 'forwardable'
1
+ require "forwardable"
2
2
 
3
3
  module Inch
4
4
  module CodeObject
@@ -21,7 +21,9 @@ module Inch
21
21
  AUTO_GENERATED_TAG_NAMES = %w(raise yield)
22
22
 
23
23
  # convenient shortcuts to (YARD) code object
24
- def_delegators :object, :type, :namespace, :source, :source_type, :group, :dynamic, :visibility
24
+ def_delegators :object,
25
+ :type, :namespace, :source, :source_type, :group,
26
+ :dynamic, :visibility
25
27
 
26
28
  # @param object [YARD::CodeObjects::Base] the actual (YARD) code object
27
29
  def initialize(object)
@@ -67,8 +69,29 @@ module Inch
67
69
  []
68
70
  end
69
71
 
70
- RUBY_CORE = %w(Array Bignum BasicObject Object Module Class Complex NilClass Numeric String Float Fiber FiberError Continuation Dir File Encoding Enumerator StopIteration Enumerator::Generator Enumerator::Yielder Exception SystemExit SignalException Interrupt StandardError TypeError ArgumentError IndexError KeyError RangeError ScriptError SyntaxError LoadError NotImplementedError NameError NoMethodError RuntimeError SecurityError NoMemoryError EncodingError SystemCallError Encoding::CompatibilityError File::Stat IO Hash ENV IOError EOFError ARGF RubyVM RubyVM::InstructionSequence Math::DomainError ZeroDivisionError FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex Thread Proc LocalJumpError SystemStackError Method UnboundMethod Binding Process::Status Random Range Rational RegexpError Regexp MatchData Symbol Struct ThreadGroup ThreadError Time Encoding::UndefinedConversionError Encoding::InvalidByteSequenceError Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env) +
71
- %w(Comparable Kernel File::Constants Enumerable Errno FileTest GC ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal Math Process Process::UID Process::GID Process::Sys Signal)
72
+ RUBY_CORE = %w(
73
+ Array Bignum BasicObject Object Module Class Complex NilClass
74
+ Numeric String Float Fiber FiberError Continuation Dir File
75
+ Encoding Enumerator StopIteration Enumerator::Generator
76
+ Enumerator::Yielder Exception SystemExit SignalException Interrupt
77
+ StandardError TypeError ArgumentError IndexError KeyError
78
+ RangeError ScriptError SyntaxError LoadError NotImplementedError
79
+ NameError NoMethodError RuntimeError SecurityError NoMemoryError
80
+ EncodingError SystemCallError Encoding::CompatibilityError
81
+ File::Stat IO Hash ENV IOError EOFError ARGF RubyVM
82
+ RubyVM::InstructionSequence Math::DomainError ZeroDivisionError
83
+ FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex
84
+ Thread Proc LocalJumpError SystemStackError Method UnboundMethod
85
+ Binding Process::Status Random Range Rational RegexpError Regexp
86
+ MatchData Symbol Struct ThreadGroup ThreadError Time
87
+ Encoding::UndefinedConversionError
88
+ Encoding::InvalidByteSequenceError
89
+ Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env
90
+
91
+ Comparable Kernel File::Constants Enumerable Errno FileTest GC
92
+ ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal
93
+ Math Process Process::UID Process::GID Process::Sys Signal
94
+ )
72
95
  def core?
73
96
  RUBY_CORE.include?(name.to_s)
74
97
  end
@@ -92,7 +115,8 @@ module Inch
92
115
  []
93
116
  end
94
117
 
95
- # CodeLocation is a utility class to find declarations of objects in files
118
+ # CodeLocation is a utility class to find declarations of objects in
119
+ # files
96
120
  class CodeLocation < Struct.new(:base_dir, :relative_path, :line_no)
97
121
  def filename
98
122
  File.join(base_dir, relative_path)
@@ -228,7 +252,7 @@ module Inch
228
252
  end
229
253
 
230
254
  def inspect
231
- "#<#{self.class.to_s}: #{fullname}>"
255
+ "#<#{self.class}: #{fullname}>"
232
256
  end
233
257
 
234
258
  protected
@@ -248,7 +272,7 @@ module Inch
248
272
  end
249
273
 
250
274
  def private_api_tag?
251
- api_tag && api_tag.text == 'private'
275
+ api_tag && api_tag.text == "private"
252
276
  end
253
277
 
254
278
  def tag(name)
@@ -269,12 +293,12 @@ module Inch
269
293
  @unconsidered_tags ||= tags.reject do |tag|
270
294
  auto_generated_tag?(tag) ||
271
295
  CONSIDERED_YARD_TAGS.include?(tag.tag_name)
272
- end
296
+ end
273
297
  end
274
298
 
275
299
  def __depth(i = 0)
276
300
  if parent
277
- parent.__depth(i+1)
301
+ parent.__depth(i + 1)
278
302
  else
279
303
  i
280
304
  end
@@ -0,0 +1,12 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ class ClassVariableObject < Base
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
- require 'inch/code_object/provider/yard/object/method_signature'
1
+ require "inch/code_object/provider/yard/object/method_signature"
2
2
 
3
3
  module Inch
4
4
  module CodeObject
@@ -46,7 +46,7 @@ module Inch
46
46
  end
47
47
 
48
48
  def parameter(name)
49
- parameters.detect { |p| p.name == name.to_s }
49
+ parameters.find { |p| p.name == name.to_s }
50
50
  end
51
51
 
52
52
  def overridden?
@@ -66,14 +66,16 @@ module Inch
66
66
  # Returns +true+ if a return value is described by it's type or
67
67
  # mentioned in the docstring (e.g. "Returns a String").
68
68
  def return_mentioned?
69
- return_tags.any? { |t| !t.types.nil? && !t.types.empty? && !YARD.implicit_tag?(t, self) } ||
70
- docstring.mentions_return? && !implicit_docstring?
69
+ return_tags.any? do |t|
70
+ !t.types.nil? && !t.types.empty? && !YARD.implicit_tag?(t, self)
71
+ end || docstring.mentions_return? && !implicit_docstring?
71
72
  end
72
73
 
73
74
  # Returns +true+ if a return value is described by words.
74
75
  def return_described?
75
- return_tags.any? { |t| !t.text.empty? && !YARD.implicit_tag?(t, self) } ||
76
- docstring.describes_return? && !implicit_docstring?
76
+ return_tags.any? do |t|
77
+ !t.text.empty? && !YARD.implicit_tag?(t, self)
78
+ end || docstring.describes_return? && !implicit_docstring?
77
79
  end
78
80
 
79
81
  def return_typed?
@@ -102,24 +104,47 @@ module Inch
102
104
 
103
105
  private
104
106
 
105
- # Returns +true+ if the docstring was generated by YARD
107
+ # Returns @return tags that are assigned to the getter
108
+ # corresponding to this setter.
109
+ #
110
+ # @return [Array<::YARD::Tag>]
111
+ def attributed_return_tags
112
+ if setter? && object.tags(:return).empty?
113
+ method = corresponding_getter
114
+ return method.object.tags(:return) if method
115
+ end
116
+ []
117
+ end
118
+
119
+ # @return [MethodObject,nil]
120
+ def corresponding_getter
121
+ clean_name = name.to_s.gsub(/(\=)$/, "")
122
+ parent.child(clean_name.to_sym)
123
+ end
124
+
125
+ # Returns +true+ if the docstring was generated by YARD.
106
126
  def implicit_docstring?
107
127
  YARD.implicit_docstring?(docstring, self)
108
128
  end
109
129
 
130
+ # @return [Array<::YARD::Tag>]
110
131
  def overload_tags
111
132
  object.tags(:overload)
112
133
  end
113
134
 
114
- def return_tags
115
- object.tags(:return) + overloaded_return_tags
116
- end
117
-
135
+ # @return [Array<::YARD::Tag>]
118
136
  def overloaded_return_tags
119
137
  overload_tags.map do |overload_tag|
120
138
  overload_tag.tag(:return)
121
139
  end.compact
122
140
  end
141
+
142
+ # @return [Array<::YARD::Tag>]
143
+ def return_tags
144
+ object.tags(:return) +
145
+ overloaded_return_tags +
146
+ attributed_return_tags
147
+ end
123
148
  end
124
149
  end
125
150
  end