inch 0.5.0.rc5 → 0.5.0.rc6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -6
  3. data/.rubocop_todo.yml +40 -34
  4. data/Gemfile +3 -3
  5. data/Rakefile +10 -6
  6. data/bin/inch +5 -5
  7. data/config/base.rb +4 -4
  8. data/config/nodejs.rb +44 -1
  9. data/config/ruby.rb +1 -1
  10. data/inch.gemspec +17 -17
  11. data/lib/inch.rb +13 -13
  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 +1 -1
  15. data/lib/inch/api/diff.rb +1 -1
  16. data/lib/inch/api/options/suggest.rb +1 -1
  17. data/lib/inch/api/suggest.rb +1 -1
  18. data/lib/inch/cli.rb +6 -6
  19. data/lib/inch/cli/command.rb +15 -15
  20. data/lib/inch/cli/command/base.rb +5 -3
  21. data/lib/inch/cli/command/base_list.rb +0 -1
  22. data/lib/inch/cli/command/console.rb +5 -5
  23. data/lib/inch/cli/command/diff.rb +6 -6
  24. data/lib/inch/cli/command/inspect.rb +5 -5
  25. data/lib/inch/cli/command/list.rb +4 -4
  26. data/lib/inch/cli/command/options/base.rb +17 -15
  27. data/lib/inch/cli/command/options/base_list.rb +17 -17
  28. data/lib/inch/cli/command/options/base_object.rb +1 -1
  29. data/lib/inch/cli/command/options/console.rb +13 -13
  30. data/lib/inch/cli/command/options/diff.rb +19 -19
  31. data/lib/inch/cli/command/options/inspect.rb +5 -5
  32. data/lib/inch/cli/command/options/list.rb +7 -7
  33. data/lib/inch/cli/command/options/show.rb +5 -5
  34. data/lib/inch/cli/command/options/stats.rb +2 -2
  35. data/lib/inch/cli/command/options/suggest.rb +12 -12
  36. data/lib/inch/cli/command/output/base.rb +1 -1
  37. data/lib/inch/cli/command/output/diff.rb +9 -9
  38. data/lib/inch/cli/command/output/inspect.rb +13 -13
  39. data/lib/inch/cli/command/output/list.rb +1 -1
  40. data/lib/inch/cli/command/output/show.rb +4 -4
  41. data/lib/inch/cli/command/output/stats.rb +14 -14
  42. data/lib/inch/cli/command/output/suggest.rb +14 -14
  43. data/lib/inch/cli/command/show.rb +4 -4
  44. data/lib/inch/cli/command/stats.rb +4 -4
  45. data/lib/inch/cli/command/suggest.rb +4 -4
  46. data/lib/inch/cli/command_parser.rb +4 -4
  47. data/lib/inch/cli/sparkline_helper.rb +1 -1
  48. data/lib/inch/cli/trace_helper.rb +1 -1
  49. data/lib/inch/cli/yardopts_helper.rb +1 -1
  50. data/lib/inch/code_object.rb +3 -3
  51. data/lib/inch/code_object/provider.rb +3 -3
  52. data/lib/inch/code_object/proxy.rb +3 -4
  53. data/lib/inch/codebase.rb +5 -5
  54. data/lib/inch/codebase/object.rb +2 -1
  55. data/lib/inch/codebase/serializer.rb +2 -2
  56. data/lib/inch/config.rb +6 -6
  57. data/lib/inch/config/codebase.rb +5 -5
  58. data/lib/inch/core_ext.rb +1 -1
  59. data/lib/inch/core_ext/string.rb +1 -1
  60. data/lib/inch/evaluation.rb +8 -8
  61. data/lib/inch/evaluation/proxy.rb +2 -3
  62. data/lib/inch/evaluation/role.rb +1 -1
  63. data/lib/inch/language/elixir/code_object/base.rb +6 -4
  64. data/lib/inch/language/elixir/evaluation/base.rb +2 -1
  65. data/lib/inch/language/elixir/evaluation/function_object.rb +1 -1
  66. data/lib/inch/language/elixir/import.rb +14 -14
  67. data/lib/inch/language/elixir/provider/reader.rb +1 -1
  68. data/lib/inch/language/elixir/provider/reader/docstring.rb +13 -0
  69. data/lib/inch/language/elixir/provider/reader/object.rb +5 -5
  70. data/lib/inch/language/elixir/provider/reader/object/base.rb +13 -5
  71. data/lib/inch/language/elixir/provider/reader/object/function_object.rb +1 -1
  72. data/lib/inch/language/elixir/provider/reader/parser.rb +21 -7
  73. data/lib/inch/language/elixir/roles/base.rb +3 -3
  74. data/lib/inch/language/elixir/roles/function.rb +2 -1
  75. data/lib/inch/language/elixir/roles/object.rb +1 -1
  76. data/lib/inch/language/nodejs/code_object/base.rb +199 -0
  77. data/lib/inch/language/nodejs/code_object/function_object.rb +74 -0
  78. data/lib/inch/language/nodejs/code_object/member_object.rb +11 -0
  79. data/lib/inch/language/nodejs/code_object/module_object.rb +23 -0
  80. data/lib/inch/language/nodejs/evaluation/base.rb +29 -0
  81. data/lib/inch/language/nodejs/evaluation/function_object.rb +31 -0
  82. data/lib/inch/language/nodejs/evaluation/member_object.rb +11 -0
  83. data/lib/inch/language/nodejs/evaluation/module_object.rb +27 -0
  84. data/lib/inch/language/nodejs/import.rb +17 -1
  85. data/lib/inch/language/nodejs/provider/jsdoc.rb +1 -1
  86. data/lib/inch/language/nodejs/provider/jsdoc/docstring.rb +13 -0
  87. data/lib/inch/language/nodejs/provider/jsdoc/object.rb +16 -8
  88. data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +82 -45
  89. data/lib/inch/language/nodejs/provider/jsdoc/object/function_object.rb +18 -0
  90. data/lib/inch/language/nodejs/provider/jsdoc/object/member_object.rb +15 -0
  91. data/lib/inch/language/nodejs/provider/jsdoc/object/module_object.rb +22 -0
  92. data/lib/inch/language/nodejs/provider/jsdoc/parser.rb +9 -10
  93. data/lib/inch/language/nodejs/roles/base.rb +32 -0
  94. data/lib/inch/language/nodejs/roles/function.rb +113 -0
  95. data/lib/inch/language/nodejs/roles/member.rb +13 -0
  96. data/lib/inch/language/nodejs/roles/module.rb +64 -0
  97. data/lib/inch/language/nodejs/roles/object.rb +76 -0
  98. data/lib/inch/language/ruby/code_object/base.rb +6 -4
  99. data/lib/inch/language/ruby/evaluation/base.rb +2 -1
  100. data/lib/inch/language/ruby/evaluation/method_object.rb +2 -1
  101. data/lib/inch/language/ruby/import.rb +24 -24
  102. data/lib/inch/language/ruby/provider/yard.rb +10 -10
  103. data/lib/inch/language/ruby/provider/yard/nodoc_helper.rb +2 -2
  104. data/lib/inch/language/ruby/provider/yard/object.rb +9 -9
  105. data/lib/inch/language/ruby/provider/yard/object/base.rb +25 -28
  106. data/lib/inch/language/ruby/provider/yard/object/method_object.rb +4 -3
  107. data/lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb +4 -3
  108. data/lib/inch/language/ruby/provider/yard/object/method_signature.rb +2 -2
  109. data/lib/inch/language/ruby/provider/yard/object/namespace_object.rb +2 -1
  110. data/lib/inch/language/ruby/provider/yard/parser.rb +2 -2
  111. data/lib/inch/language/ruby/roles/base.rb +1 -1
  112. data/lib/inch/language/ruby/roles/method.rb +2 -1
  113. data/lib/inch/language/ruby/roles/method_parameter.rb +1 -1
  114. data/lib/inch/language/ruby/roles/missing.rb +2 -2
  115. data/lib/inch/language/ruby/roles/object.rb +6 -6
  116. data/lib/inch/rake.rb +2 -2
  117. data/lib/inch/rake/suggest.rb +5 -5
  118. data/lib/inch/utils/code_location.rb +12 -0
  119. data/lib/inch/utils/read_write_methods.rb +2 -2
  120. data/lib/inch/utils/ui.rb +8 -8
  121. data/lib/inch/version.rb +1 -1
  122. data/test/fixtures/elixir/simple/all.json +321 -0
  123. data/test/integration/api/compare/codebases.rb +6 -6
  124. data/test/integration/cli/command/console_test.rb +13 -13
  125. data/test/integration/cli/command/diff_test.rb +12 -14
  126. data/test/integration/cli/command/inspect_test.rb +30 -30
  127. data/test/integration/cli/command/list_test.rb +34 -34
  128. data/test/integration/cli/command/show_test.rb +26 -26
  129. data/test/integration/cli/command/stats_test.rb +23 -23
  130. data/test/integration/cli/command/suggest_test.rb +58 -49
  131. data/test/integration/stats_options_test.rb +9 -9
  132. data/test/integration/visibility_options_test.rb +49 -45
  133. data/test/shared/base_list.rb +41 -41
  134. data/test/test_helper.rb +18 -10
  135. data/test/unit/api/filter_test.rb +9 -9
  136. data/test/unit/api/get_test.rb +6 -6
  137. data/test/unit/api/list_test.rb +3 -3
  138. data/test/unit/api/options/base_test.rb +6 -6
  139. data/test/unit/api/stats_test.rb +3 -3
  140. data/test/unit/api/suggest_test.rb +4 -4
  141. data/test/unit/cli/arguments_test.rb +25 -25
  142. data/test/unit/cli/command/base_test.rb +3 -3
  143. data/test/unit/cli/command/options/base_list_test.rb +14 -14
  144. data/test/unit/cli/command/options/base_object_test.rb +6 -6
  145. data/test/unit/cli/command/options/base_test.rb +3 -3
  146. data/test/unit/cli/command_parser_test.rb +29 -29
  147. data/test/unit/cli/trace_helper_test.rb +2 -2
  148. data/test/unit/cli/yardopts_helper_test.rb +35 -35
  149. data/test/unit/code_object/converter_test.rb +3 -3
  150. data/test/unit/code_object/provider_test.rb +2 -2
  151. data/test/unit/code_object/proxy_test.rb +11 -11
  152. data/test/unit/codebase/objects_test.rb +8 -8
  153. data/test/unit/codebase/proxy_test.rb +5 -5
  154. data/test/unit/config/codebase_test.rb +3 -3
  155. data/test/unit/config_test.rb +4 -4
  156. data/test/unit/evaluation/role_test.rb +8 -8
  157. data/test/unit/language/elixir/code_object/function_object_test.rb +35 -0
  158. data/test/unit/language/ruby/code_object/method_object_test.rb +128 -126
  159. data/test/unit/language/ruby/provider/yard/docstring_test.rb +27 -23
  160. data/test/unit/language/ruby/provider/yard/nodoc_helper_test.rb +21 -20
  161. data/test/unit/language/ruby/provider/yard/object/method_object_test.rb +20 -17
  162. data/test/unit/language/ruby/provider/yard_test.rb +4 -4
  163. data/test/unit/utils/buffered_ui_test.rb +20 -20
  164. data/test/unit/utils/ui_test.rb +20 -20
  165. data/test/unit/utils/weighted_list_test.rb +7 -7
  166. metadata +25 -2
@@ -0,0 +1,18 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Provider
5
+ module JSDoc
6
+ module Object
7
+ # Proxy class for functions
8
+ class FunctionObject < Base
9
+ def method?
10
+ true
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Provider
5
+ module JSDoc
6
+ module Object
7
+ # Proxy class for types
8
+ class MemberObject < Base
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Provider
5
+ module JSDoc
6
+ module Object
7
+ # Proxy class for modules
8
+ class ModuleObject < Base
9
+ def fullname
10
+ @hash['id']
11
+ end
12
+
13
+ def namespace?
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
- require "json"
2
- require "inch/language/nodejs/provider/jsdoc/object"
1
+ require 'json'
2
+ require 'inch/language/nodejs/provider/jsdoc/object'
3
3
 
4
4
  module Inch
5
5
  module Language
@@ -8,12 +8,15 @@ module Inch
8
8
  module JSDoc
9
9
  # Parses the source tree (using JSDoc)
10
10
  class Parser
11
+ IGNORE_TYPES = %w(member package)
12
+
11
13
  attr_reader :parsed_objects
12
14
 
13
15
  # Helper method to parse an instance with the given +args+
14
16
  #
15
17
  # @see #parse
16
- # @return [CodeObject::Provider::JSDoc::Parser] the instance that ran
18
+ # @return [CodeObject::Provider::JSDoc::Parser] the instance that
19
+ # ran
17
20
  def self.parse(*args)
18
21
  parser = new
19
22
  parser.parse(*args)
@@ -32,24 +35,20 @@ module Inch
32
35
 
33
36
  # @return [Array<YARD::Object::Base>]
34
37
  def objects
35
- pp @parsed_objects[10]
36
38
  @objects ||= parsed_objects.map do |o|
37
- JSDoc::Object.for(o) # unless IGNORE_TYPES.include?(o.type)
39
+ JSDoc::Object.for(o) unless IGNORE_TYPES.include?(o['kind'])
38
40
  end.compact
39
- puts "#{@objects.size} objects found."
40
- puts "Rest of implementation: coming soon -.-"
41
- exit 1
42
41
  end
43
42
 
44
43
  private
45
44
 
46
45
  def parse_objects(paths, excluded, read_dump_file = nil)
47
46
  if read_dump_file.nil?
48
- output = %x(jsdoc --explain #{paths.join(' ')})
47
+ fail 'NodeJS analysis only works with --read-from-dump.'
49
48
  else
50
49
  output = File.read(read_dump_file)
51
50
  end
52
- @parsed_objects = JSON[output]
51
+ @parsed_objects = JSON[output]['objects']
53
52
  end
54
53
  end
55
54
  end
@@ -0,0 +1,32 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Evaluation
5
+ module Role
6
+ # @abstract
7
+ class Base < Inch::Evaluation::Role
8
+ # Returns the type of the +object+ that is being evaluated.
9
+ def object_type
10
+ object.class.to_s.split('::').last.gsub(/Object$/, '').downcase
11
+ end
12
+ end
13
+
14
+ # Missing is the base class for things that can be improved in the doc
15
+ #
16
+ class Missing < Base
17
+ def score
18
+ nil
19
+ end
20
+
21
+ # @return [Fixnum]
22
+ # a score that can be achieved by adding the missing thing
23
+ # mentioned by the role
24
+ def potential_score
25
+ @value.to_i
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,113 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Evaluation
5
+ module Role
6
+ module Function
7
+ # Role assigned to methods without parameters
8
+ class WithoutParameters < Base
9
+ applicable_unless :has_parameters?
10
+ end
11
+
12
+ # Role assigned to methods with many parameters
13
+ #
14
+ # @see CodeObject::Ruby::MethodObject#has_many_parameters?
15
+ class WithManyParameters < Base
16
+ applicable_if :has_many_parameters?
17
+ priority +2
18
+ end
19
+
20
+ # Role assigned to methods where the return value is typed in the
21
+ # docs
22
+ class WithReturnType < Base
23
+ applicable_if :return_typed?
24
+ end
25
+
26
+ # Role assigned to methods where the return value is not typed
27
+ class WithoutReturnType < Missing
28
+ applicable_unless :return_typed?
29
+
30
+ def suggestion
31
+ "Describe what '#{object.name}' returns"
32
+ end
33
+ end
34
+
35
+ # Role assigned to methods where the return value is decribed in the
36
+ # docs
37
+ class WithReturnDescription < Base
38
+ applicable_if :return_described?
39
+ end
40
+
41
+ # Role assigned to methods where the return value is not decribed
42
+ class WithoutReturnDescription < Missing
43
+ applicable_unless :return_described?
44
+
45
+ def suggestion
46
+ "Describe what '#{object.name}' returns"
47
+ end
48
+ end
49
+
50
+ # Role assigned to methods with many lines
51
+ #
52
+ # @see CodeObject::Ruby::MethodObject#has_many_lines?
53
+ class WithManyLines < Base
54
+ applicable_if :has_many_lines?
55
+ priority +2
56
+ end
57
+
58
+ # Role assigned to methods whose name end in a '!'
59
+ class WithBangName < Base
60
+ applicable_if :bang_name?
61
+ priority +3
62
+ end
63
+
64
+ # Role assigned to methods whose name end in a '?'
65
+ class WithQuestioningName < Base
66
+ applicable_if :questioning_name?
67
+ priority -4
68
+ end
69
+
70
+ # Role assigned to methods which are aliased
71
+ class HasAlias < Base
72
+ applicable_if :has_alias?
73
+ priority +2
74
+ end
75
+
76
+ # Role assigned to methods that are constructors
77
+ class Constructor < Base
78
+ applicable_if :constructor?
79
+ end
80
+
81
+ # Role assigned to methods that are getters
82
+ class Getter < Base
83
+ applicable_if :getter?
84
+ end
85
+
86
+ # Role assigned to methods that are setters
87
+ class Setter < Base
88
+ applicable_if :setter?
89
+ end
90
+
91
+ # Role assigned to methods that are overriding another method
92
+ class Overridden < Base
93
+ applicable_if :overridden?
94
+ # It seems more important to document the overridden method,
95
+ # than the overriding one
96
+ priority -2
97
+
98
+ # This role doesnot assign a score.
99
+ def score
100
+ nil
101
+ end
102
+
103
+ # This role sets a min_score.
104
+ def min_score
105
+ @value.to_f
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,13 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Evaluation
5
+ module Role
6
+ # Roles assigned to members
7
+ module Member
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,64 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Evaluation
5
+ module Role
6
+ # Roles assigned to modules
7
+ module Module
8
+ # Role assigned to modules with children
9
+ #
10
+ # @see CodeObject::Ruby::NamespaceObject#has_children?
11
+ class WithChildren < Base
12
+ applicable_if :has_children?
13
+
14
+ # This role doesnot assign a score.
15
+ def score
16
+ 0
17
+ end
18
+
19
+ # This role sets a max_score.
20
+ def max_score
21
+ # @value.to_f
22
+ end
23
+ end
24
+
25
+ # Role assigned to modules with many children
26
+ #
27
+ # @see CodeObject::Ruby::NamespaceObject#has_many_children?
28
+ class WithManyChildren < Base
29
+ applicable_if :has_many_children?
30
+
31
+ # +priority
32
+ def priority
33
+ +1
34
+ end
35
+ end
36
+
37
+ # Role assigned to modules without any children
38
+ class WithoutChildren < Base
39
+ applicable_unless :has_children?
40
+ end
41
+
42
+ # Role assigned to modules without any methods
43
+ class WithoutMethods < Base
44
+ applicable_unless :has_methods?
45
+
46
+ def priority
47
+ -2
48
+ end
49
+ end
50
+
51
+ # A 'pure' namespace has only modules as children
52
+ class Pure < Base
53
+ applicable_if :pure_namespace?
54
+
55
+ def priority
56
+ -2
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,76 @@
1
+ module Inch
2
+ module Language
3
+ module Nodejs
4
+ module Evaluation
5
+ module Role
6
+ # Roles assigned to all objects
7
+ module Object
8
+ # Role assigned to objects with a describing comment (docstring)
9
+ class WithDoc < Base
10
+ applicable_if :has_doc?
11
+ end
12
+
13
+ # Role assigned to objects without a docstring
14
+ class WithoutDoc < Missing
15
+ applicable_unless :has_doc?
16
+
17
+ def suggestion
18
+ "Add a comment describing the #{object_type}"
19
+ end
20
+ end
21
+
22
+ # Tagged means tagged in an unconsidred way, i.e. YARD tags not
23
+ # considered by Inch. Since these tags are parsed from the docstring
24
+ # the object seems undocumented to Inch.
25
+ class Tagged < Base
26
+ applicable_if :has_unconsidered_tags?
27
+ priority -1
28
+ end
29
+
30
+ # Role assigned to objects explicitly or implicitly tagged not to be
31
+ # documented.
32
+ #
33
+ # @see CodeObject::NodocHelper
34
+ class TaggedAsNodoc < Base
35
+ applicable_if :nodoc?
36
+ priority -7
37
+ end
38
+
39
+ # Role assigned to objects declared in the top-level namespace
40
+ class InRoot < Base
41
+ applicable_if :in_root?
42
+ priority +3
43
+ end
44
+
45
+ # Role assigned to public objects
46
+ class Public < Base
47
+ applicable_if :public?
48
+ priority 0
49
+ end
50
+
51
+ # Role assigned to objects with a single code example
52
+ class WithCodeExample < Base
53
+ applicable_if do |o|
54
+ o.has_code_example? && !o.has_multiple_code_examples?
55
+ end
56
+ end
57
+
58
+ # Role assigned to objects with multiple code examples
59
+ class WithMultipleCodeExamples < Base
60
+ applicable_if :has_multiple_code_examples?
61
+ end
62
+
63
+ # Role assigned to objects without a code example
64
+ class WithoutCodeExample < Missing
65
+ applicable_unless :has_code_example?
66
+
67
+ def suggestion
68
+ 'Add a code example (optional)'
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,4 +1,4 @@
1
- require "forwardable"
1
+ require 'forwardable'
2
2
 
3
3
  module Inch
4
4
  module Language
@@ -14,7 +14,8 @@ module Inch
14
14
  :ruby
15
15
  end
16
16
 
17
- # @return [Boolean] if the current object is an alias for something else
17
+ # @return [Boolean] if the current object is an alias for something
18
+ # else
18
19
  def alias?
19
20
  !aliased_object.nil?
20
21
  end
@@ -133,7 +134,8 @@ module Inch
133
134
  self[:original_docstring]
134
135
  end
135
136
 
136
- # @return [Boolean] +true+ if the object was tagged not to be documented
137
+ # @return [Boolean] +true+ if the object was tagged not to be
138
+ # documented
137
139
  def nodoc?
138
140
  self[:nodoc?]
139
141
  end
@@ -174,7 +176,7 @@ module Inch
174
176
  end
175
177
 
176
178
  def type
177
- self.class.to_s.gsub(/Object$/, "")
179
+ self.class.to_s.gsub(/Object$/, '')
178
180
  end
179
181
 
180
182
  # @return [Boolean] +true+ if the object has no documentation at all