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.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +94 -0
- data/CHANGELOG.md +26 -2
- data/Gemfile +5 -2
- data/README.md +3 -3
- data/Rakefile +6 -2
- data/bin/inch +3 -3
- data/config/{example.yml → .inch.yml.sample} +1 -0
- data/config/base.rb +53 -0
- data/config/elixir.rb +43 -0
- data/config/nodejs.rb +10 -0
- data/config/{defaults.rb → ruby.rb} +5 -54
- data/inch.gemspec +7 -7
- data/lib/inch.rb +14 -9
- data/lib/inch/api.rb +10 -10
- data/lib/inch/api/compare.rb +2 -2
- data/lib/inch/api/compare/code_objects.rb +2 -3
- data/lib/inch/api/compare/codebases.rb +1 -1
- data/lib/inch/api/diff.rb +13 -16
- data/lib/inch/api/filter.rb +1 -1
- data/lib/inch/api/get.rb +2 -2
- data/lib/inch/api/options/base.rb +4 -4
- data/lib/inch/api/options/filter.rb +0 -4
- data/lib/inch/api/options/suggest.rb +2 -6
- data/lib/inch/api/stats.rb +0 -1
- data/lib/inch/api/suggest.rb +9 -10
- data/lib/inch/cli.rb +6 -6
- data/lib/inch/cli/arguments.rb +2 -2
- data/lib/inch/cli/command.rb +15 -15
- data/lib/inch/cli/command/base.rb +30 -9
- data/lib/inch/cli/command/base_list.rb +2 -2
- data/lib/inch/cli/command/console.rb +5 -5
- data/lib/inch/cli/command/diff.rb +9 -9
- data/lib/inch/cli/command/inspect.rb +5 -4
- data/lib/inch/cli/command/list.rb +4 -4
- data/lib/inch/cli/command/options/base.rb +17 -16
- data/lib/inch/cli/command/options/base_list.rb +9 -5
- data/lib/inch/cli/command/options/console.rb +4 -3
- data/lib/inch/cli/command/options/diff.rb +8 -6
- data/lib/inch/cli/command/options/inspect.rb +2 -2
- data/lib/inch/cli/command/options/list.rb +3 -2
- data/lib/inch/cli/command/options/show.rb +2 -2
- data/lib/inch/cli/command/options/stats.rb +2 -1
- data/lib/inch/cli/command/options/suggest.rb +6 -3
- data/lib/inch/cli/command/output/base.rb +4 -6
- data/lib/inch/cli/command/output/console.rb +6 -7
- data/lib/inch/cli/command/output/diff.rb +6 -6
- data/lib/inch/cli/command/output/inspect.rb +6 -8
- data/lib/inch/cli/command/output/list.rb +0 -1
- data/lib/inch/cli/command/output/show.rb +4 -5
- data/lib/inch/cli/command/output/stats.rb +21 -21
- data/lib/inch/cli/command/output/suggest.rb +31 -28
- data/lib/inch/cli/command/show.rb +4 -4
- data/lib/inch/cli/command/stats.rb +4 -4
- data/lib/inch/cli/command/suggest.rb +6 -6
- data/lib/inch/cli/command_parser.rb +6 -5
- data/lib/inch/cli/sparkline_helper.rb +6 -6
- data/lib/inch/cli/trace_helper.rb +1 -1
- data/lib/inch/cli/yardopts_helper.rb +4 -3
- data/lib/inch/code_object.rb +3 -3
- data/lib/inch/code_object/converter.rb +6 -8
- data/lib/inch/code_object/provider.rb +11 -11
- data/lib/inch/code_object/proxy.rb +61 -30
- data/lib/inch/codebase.rb +7 -8
- data/lib/inch/codebase/object.rb +60 -0
- data/lib/inch/codebase/objects.rb +8 -10
- data/lib/inch/codebase/objects_filter.rb +7 -5
- data/lib/inch/codebase/proxy.rb +4 -4
- data/lib/inch/codebase/serializer.rb +3 -3
- data/lib/inch/config.rb +42 -11
- data/lib/inch/config/base.rb +8 -29
- data/lib/inch/config/codebase.rb +32 -7
- data/lib/inch/config/evaluation.rb +61 -0
- data/lib/inch/core_ext.rb +1 -1
- data/lib/inch/core_ext/string.rb +1 -1
- data/lib/inch/evaluation.rb +13 -21
- data/lib/inch/evaluation/file.rb +4 -2
- data/lib/inch/evaluation/grade_list.rb +4 -4
- data/lib/inch/evaluation/priority_range.rb +3 -0
- data/lib/inch/evaluation/proxy.rb +139 -14
- data/lib/inch/evaluation/role.rb +99 -0
- data/lib/inch/language.rb +3 -0
- data/lib/inch/language/elixir/code_object/base.rb +197 -0
- data/lib/inch/language/elixir/code_object/function_object.rb +74 -0
- data/lib/inch/language/elixir/code_object/module_object.rb +23 -0
- data/lib/inch/language/elixir/code_object/type_object.rb +11 -0
- data/lib/inch/language/elixir/evaluation/base.rb +28 -0
- data/lib/inch/language/elixir/evaluation/function_object.rb +31 -0
- data/lib/inch/language/elixir/evaluation/module_object.rb +27 -0
- data/lib/inch/language/elixir/evaluation/type_object.rb +11 -0
- data/lib/inch/language/elixir/import.rb +24 -0
- data/lib/inch/language/elixir/provider/reader.rb +19 -0
- data/lib/inch/language/elixir/provider/reader/object.rb +63 -0
- data/lib/inch/language/elixir/provider/reader/object/base.rb +191 -0
- data/lib/inch/language/elixir/provider/reader/object/function_object.rb +26 -0
- data/lib/inch/language/elixir/provider/reader/object/module_object.rb +22 -0
- data/lib/inch/language/elixir/provider/reader/object/type_object.rb +15 -0
- data/lib/inch/language/elixir/provider/reader/parser.rb +55 -0
- data/lib/inch/language/elixir/roles/base.rb +32 -0
- data/lib/inch/language/elixir/roles/function.rb +112 -0
- data/lib/inch/language/elixir/roles/module.rb +64 -0
- data/lib/inch/language/elixir/roles/object.rb +76 -0
- data/lib/inch/language/elixir/roles/type.rb +13 -0
- data/lib/inch/language/nodejs/import.rb +8 -0
- data/lib/inch/language/nodejs/provider/jsdoc.rb +19 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object.rb +55 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +191 -0
- data/lib/inch/language/nodejs/provider/jsdoc/parser.rb +59 -0
- data/lib/inch/language/ruby/code_object/base.rb +197 -0
- data/lib/inch/language/ruby/code_object/class_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/class_variable_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/constant_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/method_object.rb +85 -0
- data/lib/inch/language/ruby/code_object/method_parameter_object.rb +64 -0
- data/lib/inch/language/ruby/code_object/module_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/namespace_object.rb +35 -0
- data/lib/inch/language/ruby/evaluation/base.rb +45 -0
- data/lib/inch/language/ruby/evaluation/class_object.rb +10 -0
- data/lib/inch/language/ruby/evaluation/class_variable_object.rb +21 -0
- data/lib/inch/language/ruby/evaluation/constant_object.rb +21 -0
- data/lib/inch/language/ruby/evaluation/method_object.rb +74 -0
- data/lib/inch/language/ruby/evaluation/module_object.rb +10 -0
- data/lib/inch/language/ruby/evaluation/namespace_object.rb +30 -0
- data/lib/inch/language/ruby/import.rb +34 -0
- data/lib/inch/language/ruby/provider/yard.rb +58 -0
- data/lib/inch/language/ruby/provider/yard/docstring.rb +162 -0
- data/lib/inch/language/ruby/provider/yard/nodoc_helper.rb +97 -0
- data/lib/inch/language/ruby/provider/yard/object.rb +63 -0
- data/lib/inch/language/ruby/provider/yard/object/base.rb +325 -0
- data/lib/inch/language/ruby/provider/yard/object/class_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/class_variable_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/constant_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/method_object.rb +170 -0
- data/lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb +94 -0
- data/lib/inch/language/ruby/provider/yard/object/method_signature.rb +120 -0
- data/lib/inch/language/ruby/provider/yard/object/module_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/namespace_object.rb +46 -0
- data/lib/inch/language/ruby/provider/yard/object/root_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/parser.rb +71 -0
- data/lib/inch/language/ruby/roles/base.rb +17 -0
- data/lib/inch/language/ruby/roles/class_variable.rb +53 -0
- data/lib/inch/language/ruby/roles/constant.rb +53 -0
- data/lib/inch/language/ruby/roles/method.rb +112 -0
- data/lib/inch/language/ruby/roles/method_parameter.rb +84 -0
- data/lib/inch/language/ruby/roles/missing.rb +24 -0
- data/lib/inch/language/ruby/roles/namespace.rb +89 -0
- data/lib/inch/language/ruby/roles/object.rb +120 -0
- data/lib/inch/rake.rb +2 -2
- data/lib/inch/rake/suggest.rb +7 -2
- data/lib/inch/utils/buffered_ui.rb +16 -0
- data/lib/inch/utils/shell_helper.rb +1 -1
- data/lib/inch/utils/ui.rb +5 -5
- data/lib/inch/utils/weighted_list.rb +2 -3
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/{code_examples → ruby/code_examples}/lib/foo.rb +0 -0
- data/test/fixtures/{diff1 → ruby/diff1}/lib/diff1.rb +0 -0
- data/test/fixtures/{diff2 → ruby/diff2}/lib/diff2.rb +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/.inch.yml +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/bar.rb +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/vendor/base.rb +0 -0
- data/test/fixtures/{parameters → ruby/parameters}/lib/foo.rb +0 -0
- data/test/fixtures/{readme → ruby/readme}/lib/foo.rb +0 -0
- data/test/fixtures/{really_good → ruby/really_good}/lib/foo.rb +0 -0
- data/test/fixtures/{really_good_pedantic → ruby/really_good_pedantic}/lib/foo.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/README +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/broken.rb +11 -19
- data/test/fixtures/ruby/simple/lib/broken_ruby_2_0_features.rb +7 -0
- data/test/fixtures/ruby/simple/lib/directives.rb +8 -0
- data/test/fixtures/{simple → ruby/simple}/lib/foo.rb +22 -1
- data/test/fixtures/{simple → ruby/simple}/lib/nodoc.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/role_methods.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/role_namespaces.rb +0 -0
- data/test/fixtures/{visibility → ruby/visibility}/lib/foo.rb +0 -0
- data/test/fixtures/{yardopts → ruby/yardopts}/.yardopts +0 -0
- data/test/fixtures/{yardopts → ruby/yardopts}/foo/bar.rb +0 -0
- data/test/integration/api/compare/codebases.rb +3 -3
- data/test/integration/cli/command/console_test.rb +6 -6
- data/test/integration/cli/command/diff_test.rb +62 -0
- data/test/integration/cli/command/inspect_test.rb +5 -6
- data/test/integration/cli/command/list_test.rb +4 -5
- data/test/integration/cli/command/show_test.rb +5 -5
- data/test/integration/cli/command/stats_test.rb +3 -3
- data/test/integration/cli/command/suggest_test.rb +13 -13
- data/test/integration/stats_options_test.rb +4 -4
- data/test/integration/visibility_options_test.rb +14 -14
- data/test/shared/base_list.rb +4 -3
- data/test/test_helper.rb +13 -13
- data/test/unit/api/filter_test.rb +7 -7
- data/test/unit/api/get_test.rb +1 -1
- data/test/unit/api/list_test.rb +1 -1
- data/test/unit/api/options/base_test.rb +3 -3
- data/test/unit/api/stats_test.rb +1 -1
- data/test/unit/api/suggest_test.rb +3 -3
- data/test/unit/cli/arguments_test.rb +2 -2
- data/test/unit/cli/command/base_test.rb +1 -1
- data/test/unit/cli/command/options/base_list_test.rb +2 -2
- data/test/unit/cli/command/options/base_object_test.rb +1 -1
- data/test/unit/cli/command/options/base_test.rb +1 -1
- data/test/unit/cli/command_parser_test.rb +3 -3
- data/test/unit/cli/trace_helper_test.rb +1 -1
- data/test/unit/cli/yardopts_helper_test.rb +6 -5
- data/test/unit/code_object/converter_test.rb +1 -1
- data/test/unit/code_object/provider_test.rb +2 -2
- data/test/unit/code_object/proxy_test.rb +2 -2
- data/test/unit/codebase/objects_test.rb +2 -2
- data/test/unit/codebase/proxy_test.rb +7 -5
- data/test/unit/config/codebase_test.rb +4 -4
- data/test/unit/config_test.rb +28 -0
- data/test/unit/evaluation/{role/base_test.rb → role_test.rb} +7 -7
- data/test/unit/{code_object/proxy → language/ruby/code_object}/method_object_test.rb +66 -21
- data/test/unit/{code_object → language/ruby}/provider/yard/docstring_test.rb +74 -38
- data/test/unit/{code_object → language/ruby}/provider/yard/nodoc_helper_test.rb +9 -7
- data/test/unit/{code_object → language/ruby}/provider/yard/object/method_object_test.rb +21 -11
- data/test/unit/language/ruby/provider/yard_test.rb +25 -0
- data/test/unit/utils/buffered_ui_test.rb +48 -0
- data/test/unit/utils/ui_test.rb +7 -7
- data/test/unit/utils/weighted_list_test.rb +7 -4
- metadata +139 -93
- data/lib/inch/code_object/provider/yard.rb +0 -57
- data/lib/inch/code_object/provider/yard/docstring.rb +0 -133
- data/lib/inch/code_object/provider/yard/nodoc_helper.rb +0 -93
- data/lib/inch/code_object/provider/yard/object.rb +0 -60
- data/lib/inch/code_object/provider/yard/object/base.rb +0 -302
- data/lib/inch/code_object/provider/yard/object/class_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/constant_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/method_object.rb +0 -153
- data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +0 -88
- data/lib/inch/code_object/provider/yard/object/method_signature.rb +0 -114
- data/lib/inch/code_object/provider/yard/object/module_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/namespace_object.rb +0 -47
- data/lib/inch/code_object/provider/yard/object/root_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/parser.rb +0 -62
- data/lib/inch/code_object/proxy/base.rb +0 -241
- data/lib/inch/code_object/proxy/class_object.rb +0 -8
- data/lib/inch/code_object/proxy/class_variable_object.rb +0 -8
- data/lib/inch/code_object/proxy/constant_object.rb +0 -8
- data/lib/inch/code_object/proxy/method_object.rb +0 -82
- data/lib/inch/code_object/proxy/method_parameter_object.rb +0 -60
- data/lib/inch/code_object/proxy/module_object.rb +0 -8
- data/lib/inch/code_object/proxy/namespace_object.rb +0 -33
- data/lib/inch/evaluation/object_schema.rb +0 -30
- data/lib/inch/evaluation/proxy/base.rb +0 -164
- data/lib/inch/evaluation/proxy/class_object.rb +0 -8
- data/lib/inch/evaluation/proxy/class_variable_object.rb +0 -19
- data/lib/inch/evaluation/proxy/constant_object.rb +0 -19
- data/lib/inch/evaluation/proxy/method_object.rb +0 -65
- data/lib/inch/evaluation/proxy/module_object.rb +0 -8
- data/lib/inch/evaluation/proxy/namespace_object.rb +0 -27
- data/lib/inch/evaluation/role/base.rb +0 -92
- data/lib/inch/evaluation/role/class_variable.rb +0 -55
- data/lib/inch/evaluation/role/constant.rb +0 -55
- data/lib/inch/evaluation/role/method.rb +0 -126
- data/lib/inch/evaluation/role/method_parameter.rb +0 -91
- data/lib/inch/evaluation/role/missing.rb +0 -20
- data/lib/inch/evaluation/role/namespace.rb +0 -85
- data/lib/inch/evaluation/role/object.rb +0 -143
- data/test/unit/code_object/provider/yard_test.rb +0 -25
@@ -0,0 +1,35 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module CodeObject
|
5
|
+
# a namespace object can have methods and other namespace objects
|
6
|
+
# inside itself (e.g. classes and modules)
|
7
|
+
class NamespaceObject < Base
|
8
|
+
# The wording is a bit redundant, but this means the class and
|
9
|
+
# instance attributes of the namespace
|
10
|
+
def attributes
|
11
|
+
self[:attributes]
|
12
|
+
end
|
13
|
+
|
14
|
+
MANY_ATTRIBUTES_THRESHOLD = 5
|
15
|
+
def has_many_attributes?
|
16
|
+
attributes.size > MANY_ATTRIBUTES_THRESHOLD
|
17
|
+
end
|
18
|
+
|
19
|
+
MANY_CHILDREN_THRESHOLD = 20
|
20
|
+
def has_many_children?
|
21
|
+
children.size > MANY_CHILDREN_THRESHOLD
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_methods?
|
25
|
+
children.any?(&:method?)
|
26
|
+
end
|
27
|
+
|
28
|
+
def pure_namespace?
|
29
|
+
children.all?(&:namespace?)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Evaluation
|
5
|
+
# Base class for all Ruby related evaluations
|
6
|
+
#
|
7
|
+
# @abstract
|
8
|
+
class Base < Inch::Evaluation::Proxy
|
9
|
+
protected
|
10
|
+
|
11
|
+
def relevant_base_roles
|
12
|
+
{
|
13
|
+
Role::Object::InRoot => nil,
|
14
|
+
Role::Object::Public => nil,
|
15
|
+
Role::Object::Protected => nil,
|
16
|
+
Role::Object::Private => nil,
|
17
|
+
Role::Object::TaggedAsNodoc => nil,
|
18
|
+
Role::Object::WithDoc => score_for(:docstring),
|
19
|
+
Role::Object::WithoutDoc => score_for(:docstring),
|
20
|
+
Role::Object::WithCodeExample => score_for(:code_example_single),
|
21
|
+
Role::Object::WithMultipleCodeExamples =>
|
22
|
+
score_for(:code_example_multi),
|
23
|
+
Role::Object::WithoutCodeExample => score_for(:code_example_single),
|
24
|
+
Role::Object::Tagged => score_for_unconsidered_tags,
|
25
|
+
Role::Object::TaggedAsAPI => nil,
|
26
|
+
Role::Object::TaggedAsInternalAPI => nil,
|
27
|
+
Role::Object::TaggedAsPrivate => nil,
|
28
|
+
Role::Object::Alias =>
|
29
|
+
if object.alias?
|
30
|
+
object.aliased_object.score
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def score_for_unconsidered_tags
|
38
|
+
count = object.unconsidered_tag_count
|
39
|
+
score_for(:unconsidered_tag) * count
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Evaluation
|
5
|
+
class ClassVariableObject < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def relevant_roles
|
9
|
+
{
|
10
|
+
Role::ClassVariable::WithDoc => score_for(:docstring),
|
11
|
+
Role::ClassVariable::WithoutDoc => score_for(:docstring),
|
12
|
+
Role::ClassVariable::TaggedAsNodoc => nil,
|
13
|
+
Role::ClassVariable::Public => nil,
|
14
|
+
Role::ClassVariable::Private => nil
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Evaluation
|
5
|
+
class ConstantObject < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def relevant_roles
|
9
|
+
{
|
10
|
+
Role::Constant::WithDoc => score_for(:docstring),
|
11
|
+
Role::Constant::WithoutDoc => score_for(:docstring),
|
12
|
+
Role::Constant::TaggedAsNodoc => nil,
|
13
|
+
Role::Constant::Public => nil,
|
14
|
+
Role::Constant::Private => nil
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Evaluation
|
5
|
+
class MethodObject < Base
|
6
|
+
def evaluate
|
7
|
+
super
|
8
|
+
evaluate_parameters
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def relevant_roles
|
14
|
+
relevant_base_roles.merge(relevant_method_roles)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def evaluate_parameters
|
20
|
+
params = object.parameters
|
21
|
+
per_param = score_for_single_parameter
|
22
|
+
params.each do |param|
|
23
|
+
role_classes = relevant_parameter_roles(param, per_param)
|
24
|
+
__evaluate(param, role_classes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def relevant_method_roles
|
29
|
+
{
|
30
|
+
Role::Method::Constructor => nil,
|
31
|
+
Role::Method::Getter => nil,
|
32
|
+
Role::Method::Setter => nil,
|
33
|
+
Role::Method::Overridden =>
|
34
|
+
if object.overridden?
|
35
|
+
object.overridden_method.score
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end,
|
39
|
+
Role::Method::WithManyLines => nil,
|
40
|
+
Role::Method::WithBangName => nil,
|
41
|
+
Role::Method::WithQuestioningName => nil,
|
42
|
+
Role::Method::HasAlias => nil,
|
43
|
+
Role::Method::WithReturnType => score_for(:return_type),
|
44
|
+
Role::Method::WithoutReturnType => score_for(:return_type),
|
45
|
+
Role::Method::WithReturnDescription =>
|
46
|
+
score_for(:return_description),
|
47
|
+
Role::Method::WithoutReturnDescription =>
|
48
|
+
score_for(:return_description),
|
49
|
+
Role::Method::WithoutParameters => score_for(:parameters),
|
50
|
+
Role::Method::WithManyParameters => nil
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def relevant_parameter_roles(param, per_param)
|
55
|
+
{
|
56
|
+
Role::MethodParameter::WithWrongMention => -score_for(:parameters),
|
57
|
+
Role::MethodParameter::WithMention => per_param * 0.5,
|
58
|
+
Role::MethodParameter::WithoutMention => per_param * 0.5,
|
59
|
+
Role::MethodParameter::WithType => per_param * 0.5,
|
60
|
+
Role::MethodParameter::WithoutType => per_param * 0.5,
|
61
|
+
Role::MethodParameter::WithBadName => nil,
|
62
|
+
Role::MethodParameter::Block => nil,
|
63
|
+
Role::MethodParameter::Splat => nil
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def score_for_single_parameter
|
68
|
+
@param_score ||= score_for(:parameters) / object.parameters.size
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Evaluation
|
5
|
+
# a namespace object can have methods and other namespace objects
|
6
|
+
# inside itself (e.g. classes and modules)
|
7
|
+
class NamespaceObject < Base
|
8
|
+
protected
|
9
|
+
|
10
|
+
def relevant_roles
|
11
|
+
relevant_base_roles.merge(relevant_namespace_roles)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @see Evaluation::Ruby::Base
|
15
|
+
def relevant_namespace_roles
|
16
|
+
{
|
17
|
+
Role::Namespace::Core => nil,
|
18
|
+
Role::Namespace::WithManyAttributes => nil,
|
19
|
+
Role::Namespace::WithoutChildren => nil,
|
20
|
+
Role::Namespace::WithChildren => nil,
|
21
|
+
Role::Namespace::WithManyChildren => nil,
|
22
|
+
Role::Namespace::WithoutMethods => nil,
|
23
|
+
Role::Namespace::Pure => nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require "inch/language/ruby/provider/yard"
|
9
|
+
|
10
|
+
require "inch/language/ruby/code_object/base"
|
11
|
+
require "inch/language/ruby/code_object/namespace_object"
|
12
|
+
require "inch/language/ruby/code_object/class_object"
|
13
|
+
require "inch/language/ruby/code_object/class_variable_object"
|
14
|
+
require "inch/language/ruby/code_object/constant_object"
|
15
|
+
require "inch/language/ruby/code_object/method_object"
|
16
|
+
require "inch/language/ruby/code_object/method_parameter_object"
|
17
|
+
require "inch/language/ruby/code_object/module_object"
|
18
|
+
|
19
|
+
require "inch/language/ruby/evaluation/base"
|
20
|
+
require "inch/language/ruby/evaluation/namespace_object"
|
21
|
+
require "inch/language/ruby/evaluation/class_object"
|
22
|
+
require "inch/language/ruby/evaluation/class_variable_object"
|
23
|
+
require "inch/language/ruby/evaluation/constant_object"
|
24
|
+
require "inch/language/ruby/evaluation/method_object"
|
25
|
+
require "inch/language/ruby/evaluation/module_object"
|
26
|
+
|
27
|
+
require "inch/language/ruby/roles/base"
|
28
|
+
require "inch/language/ruby/roles/missing"
|
29
|
+
require "inch/language/ruby/roles/object"
|
30
|
+
require "inch/language/ruby/roles/method"
|
31
|
+
require "inch/language/ruby/roles/method_parameter"
|
32
|
+
require "inch/language/ruby/roles/namespace"
|
33
|
+
require "inch/language/ruby/roles/constant"
|
34
|
+
require "inch/language/ruby/roles/class_variable"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Provider
|
5
|
+
# Parses the source tree (using YARD)
|
6
|
+
module YARD
|
7
|
+
# Returns +true+ if the docstring was generated by YARD
|
8
|
+
#
|
9
|
+
# @param docstring [Docstring,String]
|
10
|
+
# @param method [MethodObject]
|
11
|
+
def self.implicit_docstring?(docstring, method)
|
12
|
+
name = method.name
|
13
|
+
if method.getter?
|
14
|
+
docstring.to_s == "Returns the value of attribute #{name}"
|
15
|
+
elsif method.setter?
|
16
|
+
basename = name.to_s.gsub(/(\=)$/, "")
|
17
|
+
docstring.to_s == "Sets the attribute #{basename}"
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns +true+ if the tag was generated by YARD
|
24
|
+
#
|
25
|
+
# @param tag [::YARD::Tag]
|
26
|
+
# @param method [MethodObject]
|
27
|
+
def self.implicit_tag?(tag, method)
|
28
|
+
name = method.name
|
29
|
+
if method.getter?
|
30
|
+
tag.tag_name == "return" &&
|
31
|
+
tag.text == "the current value of #{name}"
|
32
|
+
elsif method.setter?
|
33
|
+
tag.tag_name == "return" &&
|
34
|
+
tag.text == "the newly set value"
|
35
|
+
else
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @see Provider.parse
|
41
|
+
def self.parse(dir, config)
|
42
|
+
Parser.parse(dir, config)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
require "logger"
|
51
|
+
require "yard"
|
52
|
+
|
53
|
+
log.level = ::Logger::UNKNOWN # basically disable YARD's logging
|
54
|
+
|
55
|
+
require "inch/language/ruby/provider/yard/parser"
|
56
|
+
require "inch/language/ruby/provider/yard/docstring"
|
57
|
+
require "inch/language/ruby/provider/yard/nodoc_helper"
|
58
|
+
require "inch/language/ruby/provider/yard/object"
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Inch
|
2
|
+
module Language
|
3
|
+
module Ruby
|
4
|
+
module Provider
|
5
|
+
module YARD
|
6
|
+
class Docstring
|
7
|
+
def initialize(text)
|
8
|
+
@text = text.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def describes_internal_api?
|
12
|
+
first_line =~ /^Internal\:\ .+/
|
13
|
+
end
|
14
|
+
|
15
|
+
def describes_private_object?
|
16
|
+
first_line =~ /^Private\:\ .+/
|
17
|
+
end
|
18
|
+
|
19
|
+
def empty?
|
20
|
+
@text.strip.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def contains_code_example?
|
24
|
+
!code_examples.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def code_examples
|
28
|
+
@code_examples ||= parse_code_examples
|
29
|
+
end
|
30
|
+
|
31
|
+
def describes_parameter?(name)
|
32
|
+
return false if name.nil?
|
33
|
+
describe_parameter_regexps(name).any? do |pattern|
|
34
|
+
@text.index(pattern)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def mentions_parameter?(name)
|
39
|
+
return false if name.nil?
|
40
|
+
mention_parameter_regexps(name).any? do |pattern|
|
41
|
+
@text.index(pattern)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def mentions_return?
|
46
|
+
last_lines.any? do |line|
|
47
|
+
line =~ /^#{tomdoc_modifiers}Returns\ /
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def describes_return?
|
52
|
+
last_lines.any? do |line|
|
53
|
+
line =~ /^#{tomdoc_modifiers}Returns\ (\w+\s){2,}/i ||
|
54
|
+
line =~ /^#{tomdoc_modifiers}Returns\ (nil|nothing)\.*/i
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
@text
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def first_line
|
65
|
+
@first_line ||= @text.lines.to_a.first
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns the last lines of the docstring.
|
69
|
+
# @return [Array<String>] the last line and, if the last line(s) is
|
70
|
+
# indented, the last unindented line
|
71
|
+
def last_lines
|
72
|
+
@last_lines ||= begin
|
73
|
+
list = []
|
74
|
+
@text.lines.to_a.reverse.each do |line|
|
75
|
+
list << line
|
76
|
+
break if line =~ /^\S/
|
77
|
+
end
|
78
|
+
list.reverse
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_code_examples
|
83
|
+
code_examples = []
|
84
|
+
example = nil
|
85
|
+
@text.lines.each do |line|
|
86
|
+
if line =~ /^\s*+$/
|
87
|
+
code_examples << example if example
|
88
|
+
example = []
|
89
|
+
elsif line =~ /^\ {2,}\S+/
|
90
|
+
example << line if example
|
91
|
+
else
|
92
|
+
code_examples << example if example
|
93
|
+
example = nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
code_examples << example if example
|
97
|
+
code_examples.delete_if(&:empty?).map(&:join)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns patterns in which method parameters are mentioned
|
101
|
+
# in inline docs.
|
102
|
+
#
|
103
|
+
# @param name [String] the name of the method parameter
|
104
|
+
# @return [Array<Regexp>]
|
105
|
+
def mention_parameter_patterns(name)
|
106
|
+
escaped_name = Regexp.escape(name)
|
107
|
+
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
|
121
|
+
end
|
122
|
+
|
123
|
+
def describe_parameter_extra_regexps(name)
|
124
|
+
[
|
125
|
+
"#{name}::",
|
126
|
+
"+#{name}+::",
|
127
|
+
"<tt>#{name}</tt>::"
|
128
|
+
].map do |pattern|
|
129
|
+
r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
|
130
|
+
/#{r}\n\ {2,}.+/m
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def describe_parameter_regexps(name)
|
135
|
+
same_line_regexps =
|
136
|
+
mention_parameter_patterns(name).map do |pattern|
|
137
|
+
r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
|
138
|
+
/^#{r}\s?\S+/
|
139
|
+
end
|
140
|
+
same_line_regexps + describe_parameter_extra_regexps(name)
|
141
|
+
end
|
142
|
+
|
143
|
+
def mention_parameter_regexps(name)
|
144
|
+
mention_parameter_patterns(name).map do |pattern|
|
145
|
+
if pattern.is_a?(Regexp)
|
146
|
+
pattern
|
147
|
+
else
|
148
|
+
r = Regexp.escape(pattern)
|
149
|
+
/\W#{r}\W/
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def tomdoc_modifiers
|
155
|
+
/((Public|Private|Internal)\:\ )*/
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|