inch 0.5.0.rc8 → 0.5.0.rc9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/inch/language/elixir/code_object/function_object.rb +3 -1
- data/lib/inch/language/elixir/code_object/function_parameter_object.rb +64 -0
- data/lib/inch/language/elixir/evaluation/function_object.rb +33 -0
- data/lib/inch/language/elixir/import.rb +1 -0
- data/lib/inch/language/elixir/provider/reader/object/base.rb +2 -1
- data/lib/inch/language/elixir/provider/reader/object/function_object.rb +24 -0
- data/lib/inch/language/elixir/provider/reader/object/function_parameter_object.rb +66 -0
- data/lib/inch/language/elixir/roles/function_parameter.rb +84 -0
- data/lib/inch/language/nodejs/code_object/function_object.rb +3 -1
- data/lib/inch/language/nodejs/code_object/function_parameter_object.rb +64 -0
- data/lib/inch/language/nodejs/evaluation/function_object.rb +33 -3
- data/lib/inch/language/nodejs/import.rb +1 -0
- data/lib/inch/language/nodejs/provider/jsdoc/docstring.rb +52 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +9 -2
- data/lib/inch/language/nodejs/provider/jsdoc/object/function_object.rb +2 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object/function_parameter_object.rb +66 -0
- data/lib/inch/language/nodejs/roles/function_parameter.rb +84 -0
- data/lib/inch/language/ruby/provider/yard/docstring.rb +20 -14
- data/lib/inch/version.rb +1 -1
- data/test/unit/language/elixir/code_object/function_object_test.rb +13 -1
- data/test/unit/language/nodejs/provider/jsdoc/docstring_test.rb +109 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 307bb0b28d76ee1c7f05a226cfaf421ba6620077
|
4
|
+
data.tar.gz: 4e9b727f8db07d2da162538d0db12eb143aa3d43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5540bb674d846f63d1a41f530d2bdb9ad4b93555b3f837c728d0f2e082ecb1bf87615d0416d849a6ca7c05d77cb4c1588f09c8f4f630722648ab96e68e9e626
|
7
|
+
data.tar.gz: ffa06231bf7c91dc536ec131e3c0e9b2993207b7b022e3852db3304bb378f0eab3214f844dd2e98f3860126769eef50f959b6165adb2f9a831a09b7745879bbf
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.1.
|
1
|
+
ruby-2.1.3
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'inch/language/elixir/code_object/function_parameter_object'
|
2
|
+
|
1
3
|
module Inch
|
2
4
|
module Language
|
3
5
|
module Elixir
|
@@ -31,7 +33,7 @@ module Inch
|
|
31
33
|
|
32
34
|
def parameters
|
33
35
|
@parameters ||= self[:parameters].map do |param_attr|
|
34
|
-
|
36
|
+
FunctionParameterObject.new(param_attr)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Elixir
|
4
|
+
module CodeObject
|
5
|
+
# Proxy class for method parameters
|
6
|
+
class FunctionParameterObject
|
7
|
+
def initialize(attributes)
|
8
|
+
@attributes = attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](key)
|
12
|
+
@attributes[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
BAD_NAME_EXCEPTIONS = %w(id)
|
16
|
+
BAD_NAME_THRESHOLD = 3
|
17
|
+
|
18
|
+
# @return [Boolean] +true+ if the name of the parameter is
|
19
|
+
# uncommunicative
|
20
|
+
def bad_name?
|
21
|
+
return false if BAD_NAME_EXCEPTIONS.include?(name)
|
22
|
+
name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean] +true+ if the parameter is a block
|
26
|
+
def block?
|
27
|
+
self[:block?]
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] +true+ if an additional description given?
|
31
|
+
def described?
|
32
|
+
self[:described?]
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the docs
|
36
|
+
def mentioned?
|
37
|
+
self[:mentioned?]
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
self[:name]
|
42
|
+
end
|
43
|
+
alias_method :fullname, :name
|
44
|
+
|
45
|
+
# @return [Boolean] +true+ if the parameter is a splat argument
|
46
|
+
def splat?
|
47
|
+
self[:splat?]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Boolean] +true+ if the type of the parameter is defined
|
51
|
+
def typed?
|
52
|
+
self[:typed?]
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the docs,
|
56
|
+
# but not present in the method's signature
|
57
|
+
def wrongly_mentioned?
|
58
|
+
self[:wrongly_mentioned?]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -4,12 +4,28 @@ module Inch
|
|
4
4
|
module Evaluation
|
5
5
|
# Proxy class for functions
|
6
6
|
class FunctionObject < Base
|
7
|
+
def evaluate
|
8
|
+
super
|
9
|
+
evaluate_parameters
|
10
|
+
end
|
11
|
+
|
7
12
|
protected
|
8
13
|
|
9
14
|
def relevant_roles
|
10
15
|
relevant_base_roles.merge(relevant_function_roles)
|
11
16
|
end
|
12
17
|
|
18
|
+
private
|
19
|
+
|
20
|
+
def evaluate_parameters
|
21
|
+
params = object.parameters
|
22
|
+
per_param = score_for_single_parameter
|
23
|
+
params.each do |param|
|
24
|
+
role_classes = relevant_parameter_roles(param, per_param)
|
25
|
+
__evaluate(param, role_classes)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
def relevant_function_roles
|
14
30
|
{
|
15
31
|
Role::Function::Getter => nil,
|
@@ -24,6 +40,23 @@ module Inch
|
|
24
40
|
Role::Function::WithQuestioningName => nil
|
25
41
|
}
|
26
42
|
end
|
43
|
+
|
44
|
+
def relevant_parameter_roles(param, per_param)
|
45
|
+
{
|
46
|
+
Role::FunctionParameter::WithWrongMention =>
|
47
|
+
-score_for(:parameters),
|
48
|
+
Role::FunctionParameter::WithMention => per_param * 0.5,
|
49
|
+
Role::FunctionParameter::WithoutMention => per_param * 0.5,
|
50
|
+
Role::FunctionParameter::WithType => per_param * 0.5,
|
51
|
+
Role::FunctionParameter::WithoutType => per_param * 0.5,
|
52
|
+
Role::FunctionParameter::WithBadName => nil,
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def score_for_single_parameter
|
57
|
+
@param_score ||= score_for(:parameters) / object.parameters.size
|
58
|
+
end
|
59
|
+
|
27
60
|
end
|
28
61
|
end
|
29
62
|
end
|
@@ -21,4 +21,5 @@ require 'inch/language/elixir/roles/base'
|
|
21
21
|
require 'inch/language/elixir/roles/object'
|
22
22
|
require 'inch/language/elixir/roles/module'
|
23
23
|
require 'inch/language/elixir/roles/function'
|
24
|
+
require 'inch/language/elixir/roles/function_parameter'
|
24
25
|
require 'inch/language/elixir/roles/type'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'inch/language/elixir/provider/reader/object/function_parameter_object'
|
2
|
+
|
1
3
|
module Inch
|
2
4
|
module Language
|
3
5
|
module Elixir
|
@@ -17,6 +19,28 @@ module Inch
|
|
17
19
|
def method?
|
18
20
|
true
|
19
21
|
end
|
22
|
+
|
23
|
+
def parameters
|
24
|
+
names = FunctionSignature.new(name, @hash['signature']).parameter_names
|
25
|
+
names.map do |name|
|
26
|
+
FunctionParameterObject.new(self, name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
class FunctionSignature < Struct.new(:fun_name, :signature)
|
33
|
+
def parameter_names
|
34
|
+
base_name = fun_name.split('/').first
|
35
|
+
signature.gsub(/^(#{base_name}\()/, '').gsub(/(\))$/, '')
|
36
|
+
.gsub( /\([^\)]+\)/, '' )
|
37
|
+
.split(',')
|
38
|
+
.map do |param|
|
39
|
+
name = param.split("\\\\").first
|
40
|
+
name && name.strip
|
41
|
+
end.compact
|
42
|
+
end
|
43
|
+
end
|
20
44
|
end
|
21
45
|
end
|
22
46
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Elixir
|
4
|
+
module Provider
|
5
|
+
module Reader
|
6
|
+
module Object
|
7
|
+
# Proxy class for function parameters
|
8
|
+
class FunctionParameterObject
|
9
|
+
attr_reader :name # @return [String]
|
10
|
+
|
11
|
+
# @param method [YARD::Object::MethodObject] the method the
|
12
|
+
# parameter belongs to
|
13
|
+
# @param name [String] the name of the parameter
|
14
|
+
def initialize(method, name)
|
15
|
+
@method = method
|
16
|
+
@name = name
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Boolean] +true+ if the parameter is a block
|
20
|
+
def block?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Boolean] +true+ if an additional description is given?
|
25
|
+
def described?
|
26
|
+
described_by_docstring?
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the
|
30
|
+
# docs
|
31
|
+
def mentioned?
|
32
|
+
mentioned_by_docstring?
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] +true+ if the parameter is a splat argument
|
36
|
+
def splat?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean] +true+ if the type of the parameter is defined
|
41
|
+
def typed?
|
42
|
+
false # TODO: parse types of params
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the
|
46
|
+
# docs, but not present in the method's signature
|
47
|
+
def wrongly_mentioned?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def described_by_docstring?
|
54
|
+
@method.docstring.describes_parameter?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def mentioned_by_docstring?
|
58
|
+
@method.docstring.mentions_parameter?(name)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Elixir
|
4
|
+
module Evaluation
|
5
|
+
module Role
|
6
|
+
# Roles assigned to method parameters
|
7
|
+
#
|
8
|
+
# @note The +object+ is a MethodParameterObject here!
|
9
|
+
module FunctionParameter
|
10
|
+
# Role assigned to parameters that are mentioned in the docs
|
11
|
+
#
|
12
|
+
# @see CodeObject::Ruby::MethodParameterObject#mentioned?
|
13
|
+
class WithMention < Base
|
14
|
+
applicable_if :mentioned?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Role assigned to parameters that are not mentioned in the docs
|
18
|
+
#
|
19
|
+
# @see CodeObject::Ruby::MethodParameterObject#mentioned?
|
20
|
+
class WithoutMention < Missing
|
21
|
+
applicable_unless :mentioned?
|
22
|
+
|
23
|
+
def suggestion
|
24
|
+
"Describe the parameter '#{object.name}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Role assigned to parameters that are typed in the docs
|
29
|
+
#
|
30
|
+
# @see CodeObject::Ruby::MethodParameterObject#typed?
|
31
|
+
class WithType < Base
|
32
|
+
applicable_if :typed?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Role assigned to parameters that are not typed in the docs
|
36
|
+
#
|
37
|
+
# @see CodeObject::Ruby::MethodParameterObject#typed?
|
38
|
+
class WithoutType < Missing
|
39
|
+
applicable_unless :typed?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Role assigned to parameters that are spalts, e.g. +*args+
|
43
|
+
#
|
44
|
+
# @see CodeObject::Ruby::MethodParameterObject#splat?
|
45
|
+
class Splat < Base
|
46
|
+
applicable_if :splat?
|
47
|
+
priority +1
|
48
|
+
end
|
49
|
+
|
50
|
+
# Role assigned to parameters that are blocks, e.g. +&block+
|
51
|
+
#
|
52
|
+
# @see CodeObject::Ruby::MethodParameterObject#block?
|
53
|
+
class Block < Base
|
54
|
+
applicable_if :block?
|
55
|
+
priority +1
|
56
|
+
end
|
57
|
+
|
58
|
+
# Role assigned to parameters that are documented, but not part of
|
59
|
+
# the method signature
|
60
|
+
#
|
61
|
+
# @see CodeObject::Ruby::MethodParameterObject#wrongly_mentioned?
|
62
|
+
class WithWrongMention < Base
|
63
|
+
applicable_if :wrongly_mentioned?
|
64
|
+
priority +1
|
65
|
+
|
66
|
+
def suggestion
|
67
|
+
"The parameter '#{object.name}' seems not to be part of the " \
|
68
|
+
'signature.'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Role assigned to parameters that have a 'bad' name
|
73
|
+
#
|
74
|
+
# @see CodeObject::Ruby::MethodParameterObject#bad_name?
|
75
|
+
class WithBadName < Base
|
76
|
+
applicable_if :bad_name?
|
77
|
+
priority +1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'inch/language/nodejs/code_object/function_parameter_object'
|
2
|
+
|
1
3
|
module Inch
|
2
4
|
module Language
|
3
5
|
module Nodejs
|
@@ -31,7 +33,7 @@ module Inch
|
|
31
33
|
|
32
34
|
def parameters
|
33
35
|
@parameters ||= self[:parameters].map do |param_attr|
|
34
|
-
|
36
|
+
FunctionParameterObject.new(param_attr)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Nodejs
|
4
|
+
module CodeObject
|
5
|
+
# Proxy class for method parameters
|
6
|
+
class FunctionParameterObject
|
7
|
+
def initialize(attributes)
|
8
|
+
@attributes = attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](key)
|
12
|
+
@attributes[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
BAD_NAME_EXCEPTIONS = %w(id)
|
16
|
+
BAD_NAME_THRESHOLD = 3
|
17
|
+
|
18
|
+
# @return [Boolean] +true+ if the name of the parameter is
|
19
|
+
# uncommunicative
|
20
|
+
def bad_name?
|
21
|
+
return false if BAD_NAME_EXCEPTIONS.include?(name)
|
22
|
+
name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean] +true+ if the parameter is a block
|
26
|
+
def block?
|
27
|
+
self[:block?]
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] +true+ if an additional description given?
|
31
|
+
def described?
|
32
|
+
self[:described?]
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the docs
|
36
|
+
def mentioned?
|
37
|
+
self[:mentioned?]
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
self[:name]
|
42
|
+
end
|
43
|
+
alias_method :fullname, :name
|
44
|
+
|
45
|
+
# @return [Boolean] +true+ if the parameter is a splat argument
|
46
|
+
def splat?
|
47
|
+
self[:splat?]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Boolean] +true+ if the type of the parameter is defined
|
51
|
+
def typed?
|
52
|
+
self[:typed?]
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the docs,
|
56
|
+
# but not present in the method's signature
|
57
|
+
def wrongly_mentioned?
|
58
|
+
self[:wrongly_mentioned?]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -4,12 +4,28 @@ module Inch
|
|
4
4
|
module Evaluation
|
5
5
|
# Proxy class for functions
|
6
6
|
class FunctionObject < Base
|
7
|
+
def evaluate
|
8
|
+
super
|
9
|
+
evaluate_parameters
|
10
|
+
end
|
11
|
+
|
7
12
|
protected
|
8
13
|
|
9
14
|
def relevant_roles
|
10
15
|
relevant_base_roles.merge(relevant_function_roles)
|
11
16
|
end
|
12
17
|
|
18
|
+
private
|
19
|
+
|
20
|
+
def evaluate_parameters
|
21
|
+
params = object.parameters
|
22
|
+
per_param = score_for_single_parameter
|
23
|
+
params.each do |param|
|
24
|
+
role_classes = relevant_parameter_roles(param, per_param)
|
25
|
+
__evaluate(param, role_classes)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
def relevant_function_roles
|
14
30
|
{
|
15
31
|
Role::Function::Getter => nil,
|
@@ -19,11 +35,25 @@ module Inch
|
|
19
35
|
object.overridden_method.score
|
20
36
|
else
|
21
37
|
nil
|
22
|
-
end
|
23
|
-
Role::Function::WithBangName => nil,
|
24
|
-
Role::Function::WithQuestioningName => nil
|
38
|
+
end
|
25
39
|
}
|
26
40
|
end
|
41
|
+
|
42
|
+
def relevant_parameter_roles(param, per_param)
|
43
|
+
{
|
44
|
+
Role::FunctionParameter::WithWrongMention =>
|
45
|
+
-score_for(:parameters),
|
46
|
+
Role::FunctionParameter::WithMention => per_param * 0.5,
|
47
|
+
Role::FunctionParameter::WithoutMention => per_param * 0.5,
|
48
|
+
Role::FunctionParameter::WithType => per_param * 0.5,
|
49
|
+
Role::FunctionParameter::WithoutType => per_param * 0.5,
|
50
|
+
Role::FunctionParameter::WithBadName => nil,
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def score_for_single_parameter
|
55
|
+
@param_score ||= score_for(:parameters) / object.parameters.size
|
56
|
+
end
|
27
57
|
end
|
28
58
|
end
|
29
59
|
end
|
@@ -21,4 +21,5 @@ require 'inch/language/nodejs/roles/base'
|
|
21
21
|
require 'inch/language/nodejs/roles/object'
|
22
22
|
require 'inch/language/nodejs/roles/module'
|
23
23
|
require 'inch/language/nodejs/roles/function'
|
24
|
+
require 'inch/language/nodejs/roles/function_parameter'
|
24
25
|
require 'inch/language/nodejs/roles/member'
|
@@ -5,6 +5,58 @@ module Inch
|
|
5
5
|
module Provider
|
6
6
|
module JSDoc
|
7
7
|
class Docstring < Ruby::Provider::YARD::Docstring
|
8
|
+
# Removes the comment markers // /* */ from the docstring.
|
9
|
+
#
|
10
|
+
# Docstring.new("// test").without_comment_markers
|
11
|
+
# # => "test"
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
def without_comment_markers
|
15
|
+
@text.lines.map do |line|
|
16
|
+
line.strip.gsub(/^(\s*(\/\*+|\/\/|\*+\/|\*)+\s?)/m, '')
|
17
|
+
end.join("\n").strip
|
18
|
+
end
|
19
|
+
|
20
|
+
def describes_internal_api?
|
21
|
+
tag?(:api, :private) || super
|
22
|
+
end
|
23
|
+
|
24
|
+
def describes_parameter?(name)
|
25
|
+
return false if name.nil?
|
26
|
+
parameter = parameter_notations(name)
|
27
|
+
tag?(:param, /#{parameter}\s+\S+/)
|
28
|
+
end
|
29
|
+
|
30
|
+
def mentions_parameter?(name)
|
31
|
+
return false if name.nil?
|
32
|
+
parameter = parameter_notations(name)
|
33
|
+
tag?(:param, /#{parameter}/) || super
|
34
|
+
end
|
35
|
+
|
36
|
+
def mentions_return?
|
37
|
+
tag?(:return) || super
|
38
|
+
end
|
39
|
+
|
40
|
+
def describes_return?
|
41
|
+
type_notation = /(\{[^\}]+\}|\[[^\]]+\])/
|
42
|
+
tag?(:return, /#{type_notation}*(\s\w+)/) || super
|
43
|
+
end
|
44
|
+
|
45
|
+
def visibility
|
46
|
+
%w(public protected private).detect do |v|
|
47
|
+
tag?(v)
|
48
|
+
end || 'public'
|
49
|
+
end
|
50
|
+
|
51
|
+
def tag?(tagname, regex = nil)
|
52
|
+
if without_comment_markers =~ /^\s*\@#{tagname}([^\n]*)$/m
|
53
|
+
if regex.nil?
|
54
|
+
true
|
55
|
+
else
|
56
|
+
$1 =~ /#{regex}/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
8
60
|
end
|
9
61
|
end
|
10
62
|
end
|
@@ -147,7 +147,14 @@ module Inch
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def parameters
|
150
|
-
|
150
|
+
if meta? && meta['code']
|
151
|
+
names = meta['code']['paramnames'] || []
|
152
|
+
names.map do |name|
|
153
|
+
FunctionParameterObject.new(self, name)
|
154
|
+
end
|
155
|
+
else
|
156
|
+
[]
|
157
|
+
end
|
151
158
|
end
|
152
159
|
|
153
160
|
def private?
|
@@ -207,7 +214,7 @@ module Inch
|
|
207
214
|
end
|
208
215
|
|
209
216
|
def visibility
|
210
|
-
|
217
|
+
docstring.visibility
|
211
218
|
end
|
212
219
|
|
213
220
|
protected
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Nodejs
|
4
|
+
module Provider
|
5
|
+
module JSDoc
|
6
|
+
module Object
|
7
|
+
# Proxy class for function parameters
|
8
|
+
class FunctionParameterObject
|
9
|
+
attr_reader :name # @return [String]
|
10
|
+
|
11
|
+
# @param method [YARD::Object::MethodObject] the method the
|
12
|
+
# parameter belongs to
|
13
|
+
# @param name [String] the name of the parameter
|
14
|
+
def initialize(method, name)
|
15
|
+
@method = method
|
16
|
+
@name = name
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Boolean] +true+ if the parameter is a block
|
20
|
+
def block?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Boolean] +true+ if an additional description is given?
|
25
|
+
def described?
|
26
|
+
described_by_docstring?
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the
|
30
|
+
# docs
|
31
|
+
def mentioned?
|
32
|
+
mentioned_by_docstring?
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] +true+ if the parameter is a splat argument
|
36
|
+
def splat?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean] +true+ if the type of the parameter is defined
|
41
|
+
def typed?
|
42
|
+
false # TODO: parse types of params
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean] +true+ if the parameter is mentioned in the
|
46
|
+
# docs, but not present in the method's signature
|
47
|
+
def wrongly_mentioned?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def described_by_docstring?
|
54
|
+
@method.docstring.describes_parameter?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def mentioned_by_docstring?
|
58
|
+
@method.docstring.mentions_parameter?(name)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Nodejs
|
4
|
+
module Evaluation
|
5
|
+
module Role
|
6
|
+
# Roles assigned to method parameters
|
7
|
+
#
|
8
|
+
# @note The +object+ is a MethodParameterObject here!
|
9
|
+
module FunctionParameter
|
10
|
+
# Role assigned to parameters that are mentioned in the docs
|
11
|
+
#
|
12
|
+
# @see CodeObject::Ruby::MethodParameterObject#mentioned?
|
13
|
+
class WithMention < Base
|
14
|
+
applicable_if :mentioned?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Role assigned to parameters that are not mentioned in the docs
|
18
|
+
#
|
19
|
+
# @see CodeObject::Ruby::MethodParameterObject#mentioned?
|
20
|
+
class WithoutMention < Missing
|
21
|
+
applicable_unless :mentioned?
|
22
|
+
|
23
|
+
def suggestion
|
24
|
+
"Describe the parameter '#{object.name}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Role assigned to parameters that are typed in the docs
|
29
|
+
#
|
30
|
+
# @see CodeObject::Ruby::MethodParameterObject#typed?
|
31
|
+
class WithType < Base
|
32
|
+
applicable_if :typed?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Role assigned to parameters that are not typed in the docs
|
36
|
+
#
|
37
|
+
# @see CodeObject::Ruby::MethodParameterObject#typed?
|
38
|
+
class WithoutType < Missing
|
39
|
+
applicable_unless :typed?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Role assigned to parameters that are spalts, e.g. +*args+
|
43
|
+
#
|
44
|
+
# @see CodeObject::Ruby::MethodParameterObject#splat?
|
45
|
+
class Splat < Base
|
46
|
+
applicable_if :splat?
|
47
|
+
priority +1
|
48
|
+
end
|
49
|
+
|
50
|
+
# Role assigned to parameters that are blocks, e.g. +&block+
|
51
|
+
#
|
52
|
+
# @see CodeObject::Ruby::MethodParameterObject#block?
|
53
|
+
class Block < Base
|
54
|
+
applicable_if :block?
|
55
|
+
priority +1
|
56
|
+
end
|
57
|
+
|
58
|
+
# Role assigned to parameters that are documented, but not part of
|
59
|
+
# the method signature
|
60
|
+
#
|
61
|
+
# @see CodeObject::Ruby::MethodParameterObject#wrongly_mentioned?
|
62
|
+
class WithWrongMention < Base
|
63
|
+
applicable_if :wrongly_mentioned?
|
64
|
+
priority +1
|
65
|
+
|
66
|
+
def suggestion
|
67
|
+
"The parameter '#{object.name}' seems not to be part of the " \
|
68
|
+
'signature.'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Role assigned to parameters that have a 'bad' name
|
73
|
+
#
|
74
|
+
# @see CodeObject::Ruby::MethodParameterObject#bad_name?
|
75
|
+
class WithBadName < Base
|
76
|
+
applicable_if :bad_name?
|
77
|
+
priority +1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -59,7 +59,7 @@ module Inch
|
|
59
59
|
@text
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
protected
|
63
63
|
|
64
64
|
def first_line
|
65
65
|
@first_line ||= @text.lines.to_a.first
|
@@ -103,23 +103,29 @@ module Inch
|
|
103
103
|
# @param name [String] the name of the method parameter
|
104
104
|
# @return [Array<Regexp>]
|
105
105
|
def mention_parameter_patterns(name)
|
106
|
+
expr = parameter_notations(name)
|
107
|
+
[
|
108
|
+
/#{expr}\:\:/, # param1::
|
109
|
+
/\`#{expr}\`/, # `param1`
|
110
|
+
/\+#{expr}\+/, # +param1+
|
111
|
+
/\+#{expr}\+\:\:/, # +param1+::
|
112
|
+
/<tt>#{expr}<\/tt>/, # <tt>param1</tt>
|
113
|
+
/<tt>#{expr}<\/tt>\:\:/, # <tt>param1</tt>::
|
114
|
+
/^#{expr}\ \-\ / # param1 -
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns possible notations for +name+.
|
119
|
+
# matches "param1" and "param1<String,nil>"
|
120
|
+
# @return [Regexp]
|
121
|
+
def parameter_notations(name)
|
106
122
|
escaped_name = Regexp.escape(name)
|
107
123
|
type = /<[^>]+>/
|
108
|
-
|
109
|
-
escaped_name,
|
110
|
-
/#{escaped_name}#{type}/ # matches "param1<String,nil>"
|
111
|
-
].map do |expr|
|
112
|
-
[
|
113
|
-
/#{expr}\:\:/, # param1::
|
114
|
-
/\+#{expr}\+/, # +param1+
|
115
|
-
/\+#{expr}\+\:\:/, # +param1+::
|
116
|
-
/<tt>#{expr}<\/tt>/, # <tt>param1</tt>
|
117
|
-
/<tt>#{expr}<\/tt>\:\:/, # <tt>param1</tt>::
|
118
|
-
/^#{expr}\ \-\ / # param1 -
|
119
|
-
]
|
120
|
-
end.flatten
|
124
|
+
/(#{escaped_name}|#{escaped_name}#{type})/
|
121
125
|
end
|
122
126
|
|
127
|
+
# Returns regexes to match parameter description on the next
|
128
|
+
# line.
|
123
129
|
def describe_parameter_extra_regexps(name)
|
124
130
|
[
|
125
131
|
"#{name}::",
|
data/lib/inch/version.rb
CHANGED
@@ -10,7 +10,7 @@ describe ::Inch::Language::Elixir::CodeObject::FunctionObject do
|
|
10
10
|
#
|
11
11
|
it 'should not' do
|
12
12
|
m = @objects.find('InchEx.generate_docs/3')
|
13
|
-
assert m.score
|
13
|
+
assert m.score >= 50
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -32,4 +32,16 @@ describe ::Inch::Language::Elixir::CodeObject::FunctionObject do
|
|
32
32
|
m = @objects.find('InchEx.Docs.Formatter.run/2')
|
33
33
|
assert_equal 4, m.depth
|
34
34
|
end
|
35
|
+
|
36
|
+
it "should parse parameters correctly" do
|
37
|
+
m = @objects.find("Mix.Tasks.Inch.run/4")
|
38
|
+
#assert_equal 4, m.parameters.size
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: move to own test file
|
42
|
+
it "should parse parameters correctly 1" do
|
43
|
+
klass = ::Inch::Language::Elixir::Provider::Reader::Object::FunctionObject::FunctionSignature
|
44
|
+
fn = klass.new('run/4', "run(args, config \\\\ Mix.Project.config(), generator \\\\ :erlang.make_fun(InchEx, :generate_docs, 3), reporter \\\\ InchEx.Reporter.Local)")
|
45
|
+
assert_equal %w(args config generator reporter), fn.parameter_names
|
46
|
+
end
|
35
47
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../../test_helper')
|
2
|
+
|
3
|
+
describe ::Inch::Language::Nodejs::Provider::JSDoc::Docstring do
|
4
|
+
let(:described_class) { ::Inch::Language::Nodejs::Provider::JSDoc::Docstring }
|
5
|
+
|
6
|
+
#
|
7
|
+
# JSDoc compatibility
|
8
|
+
#
|
9
|
+
|
10
|
+
it 'should notice things in jsdoc style docs' do
|
11
|
+
text = <<-DOC
|
12
|
+
/**
|
13
|
+
* Set or get the context `Runnable` to `runnable`.
|
14
|
+
*
|
15
|
+
* @param {Runnable} runnable the runnable to execute
|
16
|
+
* @return {Context} the context
|
17
|
+
* @api private
|
18
|
+
*/
|
19
|
+
DOC
|
20
|
+
docstring = described_class.new(text)
|
21
|
+
assert docstring.mentions_parameter?(:runnable)
|
22
|
+
assert docstring.describes_parameter?(:runnable)
|
23
|
+
assert docstring.describes_internal_api?
|
24
|
+
assert docstring.mentions_return?
|
25
|
+
assert docstring.describes_return?
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should notice things in jsdoc style docs 2' do
|
29
|
+
text = <<-DOC
|
30
|
+
/**
|
31
|
+
* Set or get the context `Runnable` to `runnable`.
|
32
|
+
*
|
33
|
+
* @param {Runnable} runnable
|
34
|
+
* @return {Context}
|
35
|
+
*/
|
36
|
+
DOC
|
37
|
+
docstring = described_class.new(text)
|
38
|
+
assert docstring.mentions_parameter?(:runnable)
|
39
|
+
refute docstring.describes_parameter?(:runnable)
|
40
|
+
refute docstring.describes_internal_api?
|
41
|
+
assert docstring.mentions_return?
|
42
|
+
refute docstring.describes_return?
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should notice things in jsdoc style docs' do
|
46
|
+
%w(public protected private).each do |visibility|
|
47
|
+
text = <<-DOC
|
48
|
+
/**
|
49
|
+
* Set or get the context `Runnable` to `runnable`.
|
50
|
+
*
|
51
|
+
* @#{visibility}
|
52
|
+
*/
|
53
|
+
DOC
|
54
|
+
docstring = described_class.new(text)
|
55
|
+
assert_equal visibility, docstring.visibility
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# removing comment slashes
|
61
|
+
|
62
|
+
it 'should remove comment markers for parsing 1' do
|
63
|
+
text = <<-DOC
|
64
|
+
/**
|
65
|
+
* Set or get the context `Runnable` to `runnable`.
|
66
|
+
*
|
67
|
+
* @param {Runnable} runnable the runnable to execute
|
68
|
+
* @return {Context} the context
|
69
|
+
* @api private
|
70
|
+
*/
|
71
|
+
DOC
|
72
|
+
without_comment_markers = <<-DOC
|
73
|
+
Set or get the context `Runnable` to `runnable`.
|
74
|
+
|
75
|
+
@param {Runnable} runnable the runnable to execute
|
76
|
+
@return {Context} the context
|
77
|
+
@api private
|
78
|
+
DOC
|
79
|
+
docstring = described_class.new(text)
|
80
|
+
assert_equal without_comment_markers.strip, docstring.without_comment_markers
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should remove comment markers for parsing 2' do
|
84
|
+
text = <<-DOC
|
85
|
+
/*
|
86
|
+
* Set or get the context `Runnable` to `runnable`.
|
87
|
+
*
|
88
|
+
*/
|
89
|
+
DOC
|
90
|
+
without_comment_markers = <<-DOC
|
91
|
+
Set or get the context `Runnable` to `runnable`.
|
92
|
+
DOC
|
93
|
+
docstring = described_class.new(text)
|
94
|
+
assert_equal without_comment_markers.strip, docstring.without_comment_markers
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
it 'should remove comment markers for parsing 3' do
|
99
|
+
text = <<-DOC
|
100
|
+
//Set or get the context `Runnable` to `runnable`.
|
101
|
+
DOC
|
102
|
+
without_comment_markers = <<-DOC
|
103
|
+
Set or get the context `Runnable` to `runnable`.
|
104
|
+
DOC
|
105
|
+
docstring = described_class.new(text)
|
106
|
+
assert_equal without_comment_markers.strip, docstring.without_comment_markers
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.
|
4
|
+
version: 0.5.0.rc9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Föhring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/inch/language.rb
|
212
212
|
- lib/inch/language/elixir/code_object/base.rb
|
213
213
|
- lib/inch/language/elixir/code_object/function_object.rb
|
214
|
+
- lib/inch/language/elixir/code_object/function_parameter_object.rb
|
214
215
|
- lib/inch/language/elixir/code_object/module_object.rb
|
215
216
|
- lib/inch/language/elixir/code_object/type_object.rb
|
216
217
|
- lib/inch/language/elixir/evaluation/base.rb
|
@@ -223,16 +224,19 @@ files:
|
|
223
224
|
- lib/inch/language/elixir/provider/reader/object.rb
|
224
225
|
- lib/inch/language/elixir/provider/reader/object/base.rb
|
225
226
|
- lib/inch/language/elixir/provider/reader/object/function_object.rb
|
227
|
+
- lib/inch/language/elixir/provider/reader/object/function_parameter_object.rb
|
226
228
|
- lib/inch/language/elixir/provider/reader/object/module_object.rb
|
227
229
|
- lib/inch/language/elixir/provider/reader/object/type_object.rb
|
228
230
|
- lib/inch/language/elixir/provider/reader/parser.rb
|
229
231
|
- lib/inch/language/elixir/roles/base.rb
|
230
232
|
- lib/inch/language/elixir/roles/function.rb
|
233
|
+
- lib/inch/language/elixir/roles/function_parameter.rb
|
231
234
|
- lib/inch/language/elixir/roles/module.rb
|
232
235
|
- lib/inch/language/elixir/roles/object.rb
|
233
236
|
- lib/inch/language/elixir/roles/type.rb
|
234
237
|
- lib/inch/language/nodejs/code_object/base.rb
|
235
238
|
- lib/inch/language/nodejs/code_object/function_object.rb
|
239
|
+
- lib/inch/language/nodejs/code_object/function_parameter_object.rb
|
236
240
|
- lib/inch/language/nodejs/code_object/member_object.rb
|
237
241
|
- lib/inch/language/nodejs/code_object/module_object.rb
|
238
242
|
- lib/inch/language/nodejs/evaluation/base.rb
|
@@ -245,11 +249,13 @@ files:
|
|
245
249
|
- lib/inch/language/nodejs/provider/jsdoc/object.rb
|
246
250
|
- lib/inch/language/nodejs/provider/jsdoc/object/base.rb
|
247
251
|
- lib/inch/language/nodejs/provider/jsdoc/object/function_object.rb
|
252
|
+
- lib/inch/language/nodejs/provider/jsdoc/object/function_parameter_object.rb
|
248
253
|
- lib/inch/language/nodejs/provider/jsdoc/object/member_object.rb
|
249
254
|
- lib/inch/language/nodejs/provider/jsdoc/object/module_object.rb
|
250
255
|
- lib/inch/language/nodejs/provider/jsdoc/parser.rb
|
251
256
|
- lib/inch/language/nodejs/roles/base.rb
|
252
257
|
- lib/inch/language/nodejs/roles/function.rb
|
258
|
+
- lib/inch/language/nodejs/roles/function_parameter.rb
|
253
259
|
- lib/inch/language/nodejs/roles/member.rb
|
254
260
|
- lib/inch/language/nodejs/roles/module.rb
|
255
261
|
- lib/inch/language/nodejs/roles/object.rb
|
@@ -359,6 +365,7 @@ files:
|
|
359
365
|
- test/unit/config_test.rb
|
360
366
|
- test/unit/evaluation/role_test.rb
|
361
367
|
- test/unit/language/elixir/code_object/function_object_test.rb
|
368
|
+
- test/unit/language/nodejs/provider/jsdoc/docstring_test.rb
|
362
369
|
- test/unit/language/ruby/code_object/alias_test.rb
|
363
370
|
- test/unit/language/ruby/code_object/method_object_test.rb
|
364
371
|
- test/unit/language/ruby/provider/yard/docstring_test.rb
|
@@ -451,6 +458,7 @@ test_files:
|
|
451
458
|
- test/unit/config_test.rb
|
452
459
|
- test/unit/evaluation/role_test.rb
|
453
460
|
- test/unit/language/elixir/code_object/function_object_test.rb
|
461
|
+
- test/unit/language/nodejs/provider/jsdoc/docstring_test.rb
|
454
462
|
- test/unit/language/ruby/code_object/alias_test.rb
|
455
463
|
- test/unit/language/ruby/code_object/method_object_test.rb
|
456
464
|
- test/unit/language/ruby/provider/yard/docstring_test.rb
|