inch 0.5.0.rc3 → 0.5.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +94 -0
  4. data/CHANGELOG.md +26 -2
  5. data/Gemfile +5 -2
  6. data/README.md +3 -3
  7. data/Rakefile +6 -2
  8. data/bin/inch +3 -3
  9. data/config/{example.yml → .inch.yml.sample} +1 -0
  10. data/config/base.rb +53 -0
  11. data/config/elixir.rb +43 -0
  12. data/config/nodejs.rb +10 -0
  13. data/config/{defaults.rb → ruby.rb} +5 -54
  14. data/inch.gemspec +7 -7
  15. data/lib/inch.rb +14 -9
  16. data/lib/inch/api.rb +10 -10
  17. data/lib/inch/api/compare.rb +2 -2
  18. data/lib/inch/api/compare/code_objects.rb +2 -3
  19. data/lib/inch/api/compare/codebases.rb +1 -1
  20. data/lib/inch/api/diff.rb +13 -16
  21. data/lib/inch/api/filter.rb +1 -1
  22. data/lib/inch/api/get.rb +2 -2
  23. data/lib/inch/api/options/base.rb +4 -4
  24. data/lib/inch/api/options/filter.rb +0 -4
  25. data/lib/inch/api/options/suggest.rb +2 -6
  26. data/lib/inch/api/stats.rb +0 -1
  27. data/lib/inch/api/suggest.rb +9 -10
  28. data/lib/inch/cli.rb +6 -6
  29. data/lib/inch/cli/arguments.rb +2 -2
  30. data/lib/inch/cli/command.rb +15 -15
  31. data/lib/inch/cli/command/base.rb +30 -9
  32. data/lib/inch/cli/command/base_list.rb +2 -2
  33. data/lib/inch/cli/command/console.rb +5 -5
  34. data/lib/inch/cli/command/diff.rb +9 -9
  35. data/lib/inch/cli/command/inspect.rb +5 -4
  36. data/lib/inch/cli/command/list.rb +4 -4
  37. data/lib/inch/cli/command/options/base.rb +17 -16
  38. data/lib/inch/cli/command/options/base_list.rb +9 -5
  39. data/lib/inch/cli/command/options/console.rb +4 -3
  40. data/lib/inch/cli/command/options/diff.rb +8 -6
  41. data/lib/inch/cli/command/options/inspect.rb +2 -2
  42. data/lib/inch/cli/command/options/list.rb +3 -2
  43. data/lib/inch/cli/command/options/show.rb +2 -2
  44. data/lib/inch/cli/command/options/stats.rb +2 -1
  45. data/lib/inch/cli/command/options/suggest.rb +6 -3
  46. data/lib/inch/cli/command/output/base.rb +4 -6
  47. data/lib/inch/cli/command/output/console.rb +6 -7
  48. data/lib/inch/cli/command/output/diff.rb +6 -6
  49. data/lib/inch/cli/command/output/inspect.rb +6 -8
  50. data/lib/inch/cli/command/output/list.rb +0 -1
  51. data/lib/inch/cli/command/output/show.rb +4 -5
  52. data/lib/inch/cli/command/output/stats.rb +21 -21
  53. data/lib/inch/cli/command/output/suggest.rb +31 -28
  54. data/lib/inch/cli/command/show.rb +4 -4
  55. data/lib/inch/cli/command/stats.rb +4 -4
  56. data/lib/inch/cli/command/suggest.rb +6 -6
  57. data/lib/inch/cli/command_parser.rb +6 -5
  58. data/lib/inch/cli/sparkline_helper.rb +6 -6
  59. data/lib/inch/cli/trace_helper.rb +1 -1
  60. data/lib/inch/cli/yardopts_helper.rb +4 -3
  61. data/lib/inch/code_object.rb +3 -3
  62. data/lib/inch/code_object/converter.rb +6 -8
  63. data/lib/inch/code_object/provider.rb +11 -11
  64. data/lib/inch/code_object/proxy.rb +61 -30
  65. data/lib/inch/codebase.rb +7 -8
  66. data/lib/inch/codebase/object.rb +60 -0
  67. data/lib/inch/codebase/objects.rb +8 -10
  68. data/lib/inch/codebase/objects_filter.rb +7 -5
  69. data/lib/inch/codebase/proxy.rb +4 -4
  70. data/lib/inch/codebase/serializer.rb +3 -3
  71. data/lib/inch/config.rb +42 -11
  72. data/lib/inch/config/base.rb +8 -29
  73. data/lib/inch/config/codebase.rb +32 -7
  74. data/lib/inch/config/evaluation.rb +61 -0
  75. data/lib/inch/core_ext.rb +1 -1
  76. data/lib/inch/core_ext/string.rb +1 -1
  77. data/lib/inch/evaluation.rb +13 -21
  78. data/lib/inch/evaluation/file.rb +4 -2
  79. data/lib/inch/evaluation/grade_list.rb +4 -4
  80. data/lib/inch/evaluation/priority_range.rb +3 -0
  81. data/lib/inch/evaluation/proxy.rb +139 -14
  82. data/lib/inch/evaluation/role.rb +99 -0
  83. data/lib/inch/language.rb +3 -0
  84. data/lib/inch/language/elixir/code_object/base.rb +197 -0
  85. data/lib/inch/language/elixir/code_object/function_object.rb +74 -0
  86. data/lib/inch/language/elixir/code_object/module_object.rb +23 -0
  87. data/lib/inch/language/elixir/code_object/type_object.rb +11 -0
  88. data/lib/inch/language/elixir/evaluation/base.rb +28 -0
  89. data/lib/inch/language/elixir/evaluation/function_object.rb +31 -0
  90. data/lib/inch/language/elixir/evaluation/module_object.rb +27 -0
  91. data/lib/inch/language/elixir/evaluation/type_object.rb +11 -0
  92. data/lib/inch/language/elixir/import.rb +24 -0
  93. data/lib/inch/language/elixir/provider/reader.rb +19 -0
  94. data/lib/inch/language/elixir/provider/reader/object.rb +63 -0
  95. data/lib/inch/language/elixir/provider/reader/object/base.rb +191 -0
  96. data/lib/inch/language/elixir/provider/reader/object/function_object.rb +26 -0
  97. data/lib/inch/language/elixir/provider/reader/object/module_object.rb +22 -0
  98. data/lib/inch/language/elixir/provider/reader/object/type_object.rb +15 -0
  99. data/lib/inch/language/elixir/provider/reader/parser.rb +55 -0
  100. data/lib/inch/language/elixir/roles/base.rb +32 -0
  101. data/lib/inch/language/elixir/roles/function.rb +112 -0
  102. data/lib/inch/language/elixir/roles/module.rb +64 -0
  103. data/lib/inch/language/elixir/roles/object.rb +76 -0
  104. data/lib/inch/language/elixir/roles/type.rb +13 -0
  105. data/lib/inch/language/nodejs/import.rb +8 -0
  106. data/lib/inch/language/nodejs/provider/jsdoc.rb +19 -0
  107. data/lib/inch/language/nodejs/provider/jsdoc/object.rb +55 -0
  108. data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +191 -0
  109. data/lib/inch/language/nodejs/provider/jsdoc/parser.rb +59 -0
  110. data/lib/inch/language/ruby/code_object/base.rb +197 -0
  111. data/lib/inch/language/ruby/code_object/class_object.rb +10 -0
  112. data/lib/inch/language/ruby/code_object/class_variable_object.rb +10 -0
  113. data/lib/inch/language/ruby/code_object/constant_object.rb +10 -0
  114. data/lib/inch/language/ruby/code_object/method_object.rb +85 -0
  115. data/lib/inch/language/ruby/code_object/method_parameter_object.rb +64 -0
  116. data/lib/inch/language/ruby/code_object/module_object.rb +10 -0
  117. data/lib/inch/language/ruby/code_object/namespace_object.rb +35 -0
  118. data/lib/inch/language/ruby/evaluation/base.rb +45 -0
  119. data/lib/inch/language/ruby/evaluation/class_object.rb +10 -0
  120. data/lib/inch/language/ruby/evaluation/class_variable_object.rb +21 -0
  121. data/lib/inch/language/ruby/evaluation/constant_object.rb +21 -0
  122. data/lib/inch/language/ruby/evaluation/method_object.rb +74 -0
  123. data/lib/inch/language/ruby/evaluation/module_object.rb +10 -0
  124. data/lib/inch/language/ruby/evaluation/namespace_object.rb +30 -0
  125. data/lib/inch/language/ruby/import.rb +34 -0
  126. data/lib/inch/language/ruby/provider/yard.rb +58 -0
  127. data/lib/inch/language/ruby/provider/yard/docstring.rb +162 -0
  128. data/lib/inch/language/ruby/provider/yard/nodoc_helper.rb +97 -0
  129. data/lib/inch/language/ruby/provider/yard/object.rb +63 -0
  130. data/lib/inch/language/ruby/provider/yard/object/base.rb +325 -0
  131. data/lib/inch/language/ruby/provider/yard/object/class_object.rb +14 -0
  132. data/lib/inch/language/ruby/provider/yard/object/class_variable_object.rb +14 -0
  133. data/lib/inch/language/ruby/provider/yard/object/constant_object.rb +14 -0
  134. data/lib/inch/language/ruby/provider/yard/object/method_object.rb +170 -0
  135. data/lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb +94 -0
  136. data/lib/inch/language/ruby/provider/yard/object/method_signature.rb +120 -0
  137. data/lib/inch/language/ruby/provider/yard/object/module_object.rb +14 -0
  138. data/lib/inch/language/ruby/provider/yard/object/namespace_object.rb +46 -0
  139. data/lib/inch/language/ruby/provider/yard/object/root_object.rb +14 -0
  140. data/lib/inch/language/ruby/provider/yard/parser.rb +71 -0
  141. data/lib/inch/language/ruby/roles/base.rb +17 -0
  142. data/lib/inch/language/ruby/roles/class_variable.rb +53 -0
  143. data/lib/inch/language/ruby/roles/constant.rb +53 -0
  144. data/lib/inch/language/ruby/roles/method.rb +112 -0
  145. data/lib/inch/language/ruby/roles/method_parameter.rb +84 -0
  146. data/lib/inch/language/ruby/roles/missing.rb +24 -0
  147. data/lib/inch/language/ruby/roles/namespace.rb +89 -0
  148. data/lib/inch/language/ruby/roles/object.rb +120 -0
  149. data/lib/inch/rake.rb +2 -2
  150. data/lib/inch/rake/suggest.rb +7 -2
  151. data/lib/inch/utils/buffered_ui.rb +16 -0
  152. data/lib/inch/utils/shell_helper.rb +1 -1
  153. data/lib/inch/utils/ui.rb +5 -5
  154. data/lib/inch/utils/weighted_list.rb +2 -3
  155. data/lib/inch/version.rb +1 -1
  156. data/test/fixtures/{code_examples → ruby/code_examples}/lib/foo.rb +0 -0
  157. data/test/fixtures/{diff1 → ruby/diff1}/lib/diff1.rb +0 -0
  158. data/test/fixtures/{diff2 → ruby/diff2}/lib/diff2.rb +0 -0
  159. data/test/fixtures/{inch-yml → ruby/inch-yml}/.inch.yml +0 -0
  160. data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/bar.rb +0 -0
  161. data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/vendor/base.rb +0 -0
  162. data/test/fixtures/{parameters → ruby/parameters}/lib/foo.rb +0 -0
  163. data/test/fixtures/{readme → ruby/readme}/lib/foo.rb +0 -0
  164. data/test/fixtures/{really_good → ruby/really_good}/lib/foo.rb +0 -0
  165. data/test/fixtures/{really_good_pedantic → ruby/really_good_pedantic}/lib/foo.rb +0 -0
  166. data/test/fixtures/{simple → ruby/simple}/README +0 -0
  167. data/test/fixtures/{simple → ruby/simple}/lib/broken.rb +11 -19
  168. data/test/fixtures/ruby/simple/lib/broken_ruby_2_0_features.rb +7 -0
  169. data/test/fixtures/ruby/simple/lib/directives.rb +8 -0
  170. data/test/fixtures/{simple → ruby/simple}/lib/foo.rb +22 -1
  171. data/test/fixtures/{simple → ruby/simple}/lib/nodoc.rb +0 -0
  172. data/test/fixtures/{simple → ruby/simple}/lib/role_methods.rb +0 -0
  173. data/test/fixtures/{simple → ruby/simple}/lib/role_namespaces.rb +0 -0
  174. data/test/fixtures/{visibility → ruby/visibility}/lib/foo.rb +0 -0
  175. data/test/fixtures/{yardopts → ruby/yardopts}/.yardopts +0 -0
  176. data/test/fixtures/{yardopts → ruby/yardopts}/foo/bar.rb +0 -0
  177. data/test/integration/api/compare/codebases.rb +3 -3
  178. data/test/integration/cli/command/console_test.rb +6 -6
  179. data/test/integration/cli/command/diff_test.rb +62 -0
  180. data/test/integration/cli/command/inspect_test.rb +5 -6
  181. data/test/integration/cli/command/list_test.rb +4 -5
  182. data/test/integration/cli/command/show_test.rb +5 -5
  183. data/test/integration/cli/command/stats_test.rb +3 -3
  184. data/test/integration/cli/command/suggest_test.rb +13 -13
  185. data/test/integration/stats_options_test.rb +4 -4
  186. data/test/integration/visibility_options_test.rb +14 -14
  187. data/test/shared/base_list.rb +4 -3
  188. data/test/test_helper.rb +13 -13
  189. data/test/unit/api/filter_test.rb +7 -7
  190. data/test/unit/api/get_test.rb +1 -1
  191. data/test/unit/api/list_test.rb +1 -1
  192. data/test/unit/api/options/base_test.rb +3 -3
  193. data/test/unit/api/stats_test.rb +1 -1
  194. data/test/unit/api/suggest_test.rb +3 -3
  195. data/test/unit/cli/arguments_test.rb +2 -2
  196. data/test/unit/cli/command/base_test.rb +1 -1
  197. data/test/unit/cli/command/options/base_list_test.rb +2 -2
  198. data/test/unit/cli/command/options/base_object_test.rb +1 -1
  199. data/test/unit/cli/command/options/base_test.rb +1 -1
  200. data/test/unit/cli/command_parser_test.rb +3 -3
  201. data/test/unit/cli/trace_helper_test.rb +1 -1
  202. data/test/unit/cli/yardopts_helper_test.rb +6 -5
  203. data/test/unit/code_object/converter_test.rb +1 -1
  204. data/test/unit/code_object/provider_test.rb +2 -2
  205. data/test/unit/code_object/proxy_test.rb +2 -2
  206. data/test/unit/codebase/objects_test.rb +2 -2
  207. data/test/unit/codebase/proxy_test.rb +7 -5
  208. data/test/unit/config/codebase_test.rb +4 -4
  209. data/test/unit/config_test.rb +28 -0
  210. data/test/unit/evaluation/{role/base_test.rb → role_test.rb} +7 -7
  211. data/test/unit/{code_object/proxy → language/ruby/code_object}/method_object_test.rb +66 -21
  212. data/test/unit/{code_object → language/ruby}/provider/yard/docstring_test.rb +74 -38
  213. data/test/unit/{code_object → language/ruby}/provider/yard/nodoc_helper_test.rb +9 -7
  214. data/test/unit/{code_object → language/ruby}/provider/yard/object/method_object_test.rb +21 -11
  215. data/test/unit/language/ruby/provider/yard_test.rb +25 -0
  216. data/test/unit/utils/buffered_ui_test.rb +48 -0
  217. data/test/unit/utils/ui_test.rb +7 -7
  218. data/test/unit/utils/weighted_list_test.rb +7 -4
  219. metadata +139 -93
  220. data/lib/inch/code_object/provider/yard.rb +0 -57
  221. data/lib/inch/code_object/provider/yard/docstring.rb +0 -133
  222. data/lib/inch/code_object/provider/yard/nodoc_helper.rb +0 -93
  223. data/lib/inch/code_object/provider/yard/object.rb +0 -60
  224. data/lib/inch/code_object/provider/yard/object/base.rb +0 -302
  225. data/lib/inch/code_object/provider/yard/object/class_object.rb +0 -12
  226. data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +0 -12
  227. data/lib/inch/code_object/provider/yard/object/constant_object.rb +0 -12
  228. data/lib/inch/code_object/provider/yard/object/method_object.rb +0 -153
  229. data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +0 -88
  230. data/lib/inch/code_object/provider/yard/object/method_signature.rb +0 -114
  231. data/lib/inch/code_object/provider/yard/object/module_object.rb +0 -12
  232. data/lib/inch/code_object/provider/yard/object/namespace_object.rb +0 -47
  233. data/lib/inch/code_object/provider/yard/object/root_object.rb +0 -12
  234. data/lib/inch/code_object/provider/yard/parser.rb +0 -62
  235. data/lib/inch/code_object/proxy/base.rb +0 -241
  236. data/lib/inch/code_object/proxy/class_object.rb +0 -8
  237. data/lib/inch/code_object/proxy/class_variable_object.rb +0 -8
  238. data/lib/inch/code_object/proxy/constant_object.rb +0 -8
  239. data/lib/inch/code_object/proxy/method_object.rb +0 -82
  240. data/lib/inch/code_object/proxy/method_parameter_object.rb +0 -60
  241. data/lib/inch/code_object/proxy/module_object.rb +0 -8
  242. data/lib/inch/code_object/proxy/namespace_object.rb +0 -33
  243. data/lib/inch/evaluation/object_schema.rb +0 -30
  244. data/lib/inch/evaluation/proxy/base.rb +0 -164
  245. data/lib/inch/evaluation/proxy/class_object.rb +0 -8
  246. data/lib/inch/evaluation/proxy/class_variable_object.rb +0 -19
  247. data/lib/inch/evaluation/proxy/constant_object.rb +0 -19
  248. data/lib/inch/evaluation/proxy/method_object.rb +0 -65
  249. data/lib/inch/evaluation/proxy/module_object.rb +0 -8
  250. data/lib/inch/evaluation/proxy/namespace_object.rb +0 -27
  251. data/lib/inch/evaluation/role/base.rb +0 -92
  252. data/lib/inch/evaluation/role/class_variable.rb +0 -55
  253. data/lib/inch/evaluation/role/constant.rb +0 -55
  254. data/lib/inch/evaluation/role/method.rb +0 -126
  255. data/lib/inch/evaluation/role/method_parameter.rb +0 -91
  256. data/lib/inch/evaluation/role/missing.rb +0 -20
  257. data/lib/inch/evaluation/role/namespace.rb +0 -85
  258. data/lib/inch/evaluation/role/object.rb +0 -143
  259. data/test/unit/code_object/provider/yard_test.rb +0 -25
@@ -1,12 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- class ClassObject < NamespaceObject
7
- end
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
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,12 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- class ConstantObject < Base
7
- end
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,153 +0,0 @@
1
- require 'inch/code_object/provider/yard/object/method_signature'
2
-
3
- module Inch
4
- module CodeObject
5
- module Provider
6
- module YARD
7
- module Object
8
- # Proxy class for methods
9
- class MethodObject < Base
10
- def aliases_fullnames
11
- object.aliases.map(&:path)
12
- end
13
-
14
- def bang_name?
15
- name =~ /\!$/
16
- end
17
-
18
- def constructor?
19
- name == :initialize
20
- end
21
-
22
- def getter?
23
- attr_info = object.attr_info || {}
24
- read_info = attr_info[:read]
25
- if read_info
26
- read_info.path == fullname
27
- else
28
- parent.child(:"#{name}=")
29
- end
30
- end
31
-
32
- def has_code_example?
33
- signatures.any? { |s| s.has_code_example? }
34
- end
35
-
36
- def has_doc?
37
- signatures.any? { |s| s.has_doc? }
38
- end
39
-
40
- def method?
41
- true
42
- end
43
-
44
- def parameters
45
- @parameters ||= signatures.map(&:parameters).flatten
46
- end
47
-
48
- def parameter(name)
49
- parameters.detect { |p| p.name == name.to_s }
50
- end
51
-
52
- def overridden?
53
- !!object.overridden_method
54
- end
55
-
56
- def overridden_method
57
- return unless overridden?
58
- @overridden_method ||= YARD::Object.for(object.overridden_method)
59
- end
60
-
61
- def overridden_method_fullname
62
- return unless overridden?
63
- overridden_method.fullname
64
- end
65
-
66
- # Returns +true+ if a return value is described by it's type or
67
- # mentioned in the docstring (e.g. "Returns a String").
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?
71
- end
72
-
73
- # Returns +true+ if a return value is described by words.
74
- def return_described?
75
- return_tags.any? { |t| !t.text.empty? && !YARD.implicit_tag?(t, self) } ||
76
- docstring.describes_return? && !implicit_docstring?
77
- end
78
-
79
- def return_typed?
80
- return_mentioned?
81
- end
82
-
83
- def setter?
84
- name =~ /\=$/ && parameters.size == 1
85
- end
86
-
87
- def signatures
88
- base = MethodSignature.new(self, nil)
89
- overloaded = overload_tags.map do |tag|
90
- MethodSignature.new(self, tag)
91
- end
92
- if overloaded.any? { |s| s.same?(base) }
93
- overloaded
94
- else
95
- [base] + overloaded
96
- end
97
- end
98
-
99
- def questioning_name?
100
- name =~ /\?$/
101
- end
102
-
103
- private
104
-
105
- # Returns @return tags that are assigned to the getter
106
- # corresponding to this setter.
107
- #
108
- # @return [Array<::YARD::Tag>]
109
- def attributed_return_tags
110
- if setter? && object.tags(:return).empty?
111
- method = corresponding_getter
112
- if method
113
- return method.object.tags(:return)
114
- end
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.
126
- def implicit_docstring?
127
- YARD.implicit_docstring?(docstring, self)
128
- end
129
-
130
- # @return [Array<::YARD::Tag>]
131
- def overload_tags
132
- object.tags(:overload)
133
- end
134
-
135
- # @return [Array<::YARD::Tag>]
136
- def overloaded_return_tags
137
- overload_tags.map do |overload_tag|
138
- overload_tag.tag(:return)
139
- end.compact
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
148
- end
149
- end
150
- end
151
- end
152
- end
153
- end
@@ -1,88 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- # Proxy class for method parameters
7
- class MethodParameterObject
8
- attr_reader :name # @return [String]
9
-
10
- # @param method [YARD::Object::MethodObject] the method the parameter belongs to
11
- # @param name [String] the name of the parameter
12
- # @param in_signature [String] how the parameter is noted in the method's signature
13
- # @param tag [YARD::Tags::Tag] the Tag object for the parameter
14
- def initialize(method, name, in_signature, tag)
15
- @method = method
16
- @name = name
17
- @tag = tag
18
- @in_signature = in_signature
19
- end
20
-
21
- BAD_NAME_EXCEPTIONS = %w(id)
22
- BAD_NAME_THRESHOLD = 3
23
-
24
- # @return [Boolean] +true+ if the name of the parameter is uncommunicative
25
- def bad_name?
26
- return false if BAD_NAME_EXCEPTIONS.include?(name)
27
- name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
28
- end
29
-
30
- # @return [Boolean] +true+ if the parameter is a block
31
- def block?
32
- @in_signature.to_s =~ /^\&/
33
- end
34
-
35
- # @return [Boolean] +true+ if an additional description given?
36
- def described?
37
- described_by_tag? || described_by_docstring?
38
- end
39
-
40
- # @return [Boolean] +true+ if the parameter is mentioned in the docs
41
- def mentioned?
42
- !!@tag || mentioned_by_docstring?
43
- end
44
-
45
- # @return [Boolean] +true+ if the parameter is a splat argument
46
- def splat?
47
- @in_signature.to_s =~ /^\*/
48
- end
49
-
50
- # @return [Boolean] +true+ if the type of the parameter is defined
51
- def typed?
52
- @tag && @tag.types && !@tag.types.empty?
53
- end
54
-
55
- # @return [Boolean] +true+ if the parameter is mentioned in the docs, but not present in the method's signature
56
- def wrongly_mentioned?
57
- mentioned? && !@in_signature
58
- end
59
-
60
- private
61
-
62
- def described_by_tag?
63
- @tag && @tag.text && !@tag.text.empty?
64
- end
65
-
66
- def described_by_docstring?
67
- if @method.docstring.describes_parameter?(name)
68
- true
69
- else
70
- unsplatted = name.gsub(/^[\&\*]/, '')
71
- @method.docstring.describes_parameter?(unsplatted)
72
- end
73
- end
74
-
75
- def mentioned_by_docstring?
76
- if @method.docstring.mentions_parameter?(name)
77
- true
78
- else
79
- unsplatted = name.gsub(/^[\&\*]/, '')
80
- @method.docstring.mentions_parameter?(unsplatted)
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,114 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- # Utility class to describe (overloaded) method signatures
7
- class MethodSignature < Struct.new(:method, :yard_tag)
8
- attr_reader :method, :docstring
9
-
10
- # @param method [Provider::YARD::Object::MethodObject]
11
- # @param yard_tag [::YARD::Tags::Tag,nil] if nil, the method's normal signature is used
12
- def initialize(method, yard_tag = nil)
13
- @method = method
14
- @yard_tag = yard_tag
15
- @docstring = Provider::YARD::Docstring.new(relevant_object.docstring)
16
- end
17
-
18
- def all_signature_parameter_names
19
- relevant_object.parameters.map(&:first)
20
- end
21
-
22
- def has_code_example?
23
- if docstring.contains_code_example?
24
- true
25
- else
26
- !relevant_object.tags(:example).empty?
27
- end
28
- end
29
-
30
- def has_doc?
31
- !docstring.empty? && !implicit_docstring?
32
- end
33
-
34
- def parameters
35
- @parameters ||= all_parameter_names.map do |name|
36
- signature_name = in_signature(name)
37
- tag = parameter_tag(name) || parameter_tag(signature_name)
38
- MethodParameterObject.new(method, name, signature_name, tag)
39
- end
40
- end
41
-
42
- # Returns the parameter with the given +name+.
43
- # @param name [String,Symbol]
44
- # @return [MethodParameterObject]
45
- def parameter(name)
46
- parameters.detect { |p| p.name == name.to_s }
47
- end
48
-
49
- # Returns +true+ if the other signature is identical to self
50
- # @param other [MethodSignature]
51
- # @return [Boolean]
52
- def same?(other)
53
- all_signature_parameter_names == other.all_signature_parameter_names
54
- end
55
-
56
- # Returns the actual signature of the method.
57
- # @return [String]
58
- def signature
59
- relevant_object.signature.gsub(/^(def\ )/, '')
60
- end
61
-
62
- private
63
-
64
- def all_parameter_names
65
- all_names = all_signature_parameter_names + parameter_tags.map(&:name)
66
- all_names.map do |name|
67
- normalize_parameter_name(name) if name
68
- end.compact.uniq
69
- end
70
-
71
- # Returns +true+ if the docstring was generated by YARD
72
- def implicit_docstring?
73
- YARD.implicit_docstring?(docstring, method)
74
- end
75
-
76
- # Returns how the given parameter is noted in the method's
77
- # signature.
78
- #
79
- # @param name [String] parameter name
80
- # @return [String]
81
- def in_signature(name)
82
- possible_names = [name, "*#{name}", "&#{name}"]
83
- (all_signature_parameter_names & possible_names).first
84
- end
85
-
86
- # Removes block, splat symbols, dollar sign,
87
- # leading and trailing brackets from a given +name+
88
- # (sometimes used to indicate optional parameters in overload
89
- # signatures).
90
- # @param name [String] parameter name
91
- # @return [String]
92
- def normalize_parameter_name(name)
93
- name.gsub(/[\&\*\$\[\]]/, '')
94
- end
95
-
96
- def parameter_tag(param_name)
97
- parameter_tags.detect do |tag|
98
- tag.name == param_name
99
- end
100
- end
101
-
102
- def parameter_tags
103
- relevant_object.tags(:param)
104
- end
105
-
106
- def relevant_object
107
- @yard_tag || method.object
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,12 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- class ModuleObject < NamespaceObject
7
- end
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,47 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module Object
6
- # a namespace object can have methods and other namespace objects
7
- # inside itself (e.g. classes and modules)
8
- class NamespaceObject < Base
9
- def attributes
10
- object.class_attributes.values + object.instance_attributes.values
11
- end
12
-
13
- def children_fullnames
14
- children.map(&:fullname)
15
- end
16
-
17
- def namespace?
18
- true
19
- end
20
-
21
- def has_methods?
22
- children.any?(&:method?)
23
- end
24
-
25
- def pure_namespace?
26
- children.all?(&:namespace?)
27
- end
28
-
29
- # called by MethodObject#getter?
30
- def child(name)
31
- if children
32
- children.detect { |child| child.name == name }
33
- end
34
- end
35
-
36
- def children
37
- object.children.map do |o|
38
- YARD::Object.for(o)
39
- end
40
- end
41
-
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end