inch 0.4.6 → 0.4.7
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 +113 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -2
- data/README.md +2 -2
- data/Rakefile +2 -2
- data/bin/inch +3 -2
- data/config/defaults.rb +7 -0
- data/inch.gemspec +7 -7
- data/lib/inch.rb +9 -10
- 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 +6 -9
- data/lib/inch/api/options/base.rb +4 -4
- data/lib/inch/api/options/suggest.rb +1 -1
- data/lib/inch/api/stats.rb +0 -1
- data/lib/inch/api/suggest.rb +8 -9
- data/lib/inch/cli.rb +6 -6
- data/lib/inch/cli/command.rb +15 -15
- data/lib/inch/cli/command/base.rb +2 -2
- data/lib/inch/cli/command/console.rb +5 -5
- data/lib/inch/cli/command/diff.rb +7 -8
- 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 +8 -8
- 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 +6 -4
- data/lib/inch/cli/command/options/inspect.rb +2 -2
- data/lib/inch/cli/command/options/list.rb +4 -3
- 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 +2 -4
- data/lib/inch/cli/command/output/console.rb +4 -5
- 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 +28 -26
- 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 +2 -2
- 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 +1 -1
- data/lib/inch/code_object/provider/yard.rb +10 -12
- data/lib/inch/code_object/provider/yard/docstring.rb +53 -21
- data/lib/inch/code_object/provider/yard/nodoc_helper.rb +3 -3
- data/lib/inch/code_object/provider/yard/object.rb +11 -9
- data/lib/inch/code_object/provider/yard/object/base.rb +33 -9
- data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +12 -0
- data/lib/inch/code_object/provider/yard/object/method_object.rb +36 -11
- data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +2 -2
- data/lib/inch/code_object/provider/yard/object/method_signature.rb +11 -8
- data/lib/inch/code_object/provider/yard/object/namespace_object.rb +1 -4
- data/lib/inch/code_object/provider/yard/parser.rb +2 -2
- data/lib/inch/code_object/proxy.rb +10 -9
- data/lib/inch/code_object/proxy/base.rb +8 -8
- data/lib/inch/code_object/proxy/class_variable_object.rb +8 -0
- data/lib/inch/code_object/proxy/method_object.rb +3 -2
- data/lib/inch/code_object/proxy/method_parameter_object.rb +1 -1
- data/lib/inch/codebase.rb +4 -5
- data/lib/inch/codebase/objects_filter.rb +2 -4
- data/lib/inch/codebase/serializer.rb +3 -3
- data/lib/inch/config.rb +2 -2
- data/lib/inch/config/base.rb +0 -1
- data/lib/inch/config/codebase.rb +3 -3
- data/lib/inch/core_ext.rb +1 -1
- data/lib/inch/core_ext/string.rb +1 -1
- data/lib/inch/evaluation.rb +16 -15
- data/lib/inch/evaluation/grade_list.rb +2 -2
- data/lib/inch/evaluation/object_schema.rb +1 -1
- data/lib/inch/evaluation/proxy.rb +8 -7
- data/lib/inch/evaluation/proxy/base.rb +12 -7
- data/lib/inch/evaluation/proxy/class_variable_object.rb +19 -0
- data/lib/inch/evaluation/proxy/constant_object.rb +1 -1
- data/lib/inch/evaluation/proxy/method_object.rb +12 -5
- data/lib/inch/evaluation/proxy/module_object.rb +1 -1
- data/lib/inch/evaluation/proxy/namespace_object.rb +1 -1
- data/lib/inch/evaluation/role/base.rb +1 -1
- data/lib/inch/evaluation/role/class_variable.rb +55 -0
- data/lib/inch/evaluation/role/method.rb +0 -1
- data/lib/inch/evaluation/role/method_parameter.rb +2 -1
- data/lib/inch/evaluation/role/object.rb +2 -2
- data/lib/inch/rake.rb +2 -2
- data/lib/inch/rake/suggest.rb +2 -2
- 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/simple/lib/broken.rb +35 -7
- data/test/fixtures/simple/lib/broken_ruby_2_0_features.rb +7 -0
- data/test/fixtures/simple/lib/directives.rb +8 -0
- data/test/fixtures/simple/lib/foo.rb +17 -0
- data/test/integration/api/compare/codebases.rb +1 -1
- data/test/integration/cli/command/console_test.rb +5 -5
- data/test/integration/cli/command/inspect_test.rb +4 -5
- data/test/integration/cli/command/list_test.rb +3 -4
- data/test/integration/cli/command/show_test.rb +4 -4
- data/test/integration/cli/command/stats_test.rb +2 -2
- data/test/integration/cli/command/suggest_test.rb +7 -7
- data/test/integration/stats_options_test.rb +3 -3
- data/test/integration/visibility_options_test.rb +13 -13
- data/test/shared/base_list.rb +4 -3
- data/test/test_helper.rb +16 -5
- 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 +1 -1
- 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 +2 -2
- data/test/unit/cli/trace_helper_test.rb +1 -1
- data/test/unit/cli/yardopts_helper_test.rb +4 -3
- data/test/unit/code_object/converter_test.rb +1 -1
- data/test/unit/code_object/provider/yard/docstring_test.rb +105 -28
- data/test/unit/code_object/provider/yard/nodoc_helper_test.rb +5 -5
- data/test/unit/code_object/provider/yard/object/method_object_test.rb +20 -10
- data/test/unit/code_object/provider/yard_test.rb +4 -4
- data/test/unit/code_object/provider_test.rb +1 -1
- data/test/unit/code_object/proxy/method_object_test.rb +366 -262
- data/test/unit/code_object/proxy_test.rb +1 -1
- data/test/unit/codebase/objects_test.rb +2 -2
- data/test/unit/codebase/proxy_test.rb +1 -1
- data/test/unit/config/codebase_test.rb +1 -1
- data/test/unit/evaluation/role/base_test.rb +1 -1
- data/test/unit/utils/ui_test.rb +4 -4
- data/test/unit/utils/weighted_list_test.rb +7 -4
- metadata +12 -2
@@ -0,0 +1,19 @@
|
|
1
|
+
module Inch
|
2
|
+
module Evaluation
|
3
|
+
module Proxy
|
4
|
+
class ClassVariableObject < Base
|
5
|
+
protected
|
6
|
+
|
7
|
+
def relevant_roles
|
8
|
+
{
|
9
|
+
Role::ClassVariable::WithDoc => score_for(:docstring),
|
10
|
+
Role::ClassVariable::WithoutDoc => score_for(:docstring),
|
11
|
+
Role::ClassVariable::TaggedAsNodoc => nil,
|
12
|
+
Role::ClassVariable::Public => nil,
|
13
|
+
Role::ClassVariable::Private => nil
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -29,17 +29,24 @@ module Inch
|
|
29
29
|
Role::Method::Constructor => nil,
|
30
30
|
Role::Method::Getter => nil,
|
31
31
|
Role::Method::Setter => nil,
|
32
|
-
Role::Method::Overridden =>
|
32
|
+
Role::Method::Overridden =>
|
33
|
+
if object.overridden?
|
34
|
+
object.overridden_method.score
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end,
|
33
38
|
Role::Method::WithManyLines => nil,
|
34
39
|
Role::Method::WithBangName => nil,
|
35
40
|
Role::Method::WithQuestioningName => nil,
|
36
41
|
Role::Method::HasAlias => nil,
|
37
42
|
Role::Method::WithReturnType => score_for(:return_type),
|
38
43
|
Role::Method::WithoutReturnType => score_for(:return_type),
|
39
|
-
Role::Method::WithReturnDescription =>
|
40
|
-
|
44
|
+
Role::Method::WithReturnDescription =>
|
45
|
+
score_for(:return_description),
|
46
|
+
Role::Method::WithoutReturnDescription =>
|
47
|
+
score_for(:return_description),
|
41
48
|
Role::Method::WithoutParameters => score_for(:parameters),
|
42
|
-
Role::Method::WithManyParameters => nil
|
49
|
+
Role::Method::WithManyParameters => nil
|
43
50
|
}
|
44
51
|
end
|
45
52
|
|
@@ -52,7 +59,7 @@ module Inch
|
|
52
59
|
Role::MethodParameter::WithoutType => per_param * 0.5,
|
53
60
|
Role::MethodParameter::WithBadName => nil,
|
54
61
|
Role::MethodParameter::Block => nil,
|
55
|
-
Role::MethodParameter::Splat => nil
|
62
|
+
Role::MethodParameter::Splat => nil
|
56
63
|
}
|
57
64
|
end
|
58
65
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Inch
|
2
|
+
module Evaluation
|
3
|
+
module Role
|
4
|
+
# Roles assigned to class variables
|
5
|
+
module ClassVariable
|
6
|
+
class WithDoc < Object::WithDoc
|
7
|
+
applicable_if :has_doc?
|
8
|
+
end
|
9
|
+
class WithoutDoc < Object::WithoutDoc
|
10
|
+
applicable_unless :has_doc?
|
11
|
+
end
|
12
|
+
|
13
|
+
class TaggedAsNodoc < Object::TaggedAsNodoc
|
14
|
+
applicable_if :nodoc?
|
15
|
+
end
|
16
|
+
class InRoot < Object::InRoot
|
17
|
+
applicable_if :in_root?
|
18
|
+
end
|
19
|
+
|
20
|
+
class Public < Object::Public
|
21
|
+
applicable_if :public?
|
22
|
+
|
23
|
+
def priority
|
24
|
+
-1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class Private < Object::Private
|
28
|
+
applicable_if :private?
|
29
|
+
|
30
|
+
def priority
|
31
|
+
-3
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class WithCodeExample < Object::WithCodeExample
|
36
|
+
applicable_if do |o|
|
37
|
+
o.has_code_example? && !o.has_multiple_code_examples?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class WithMultipleCodeExamples < Object::WithMultipleCodeExamples
|
42
|
+
applicable_if :has_multiple_code_examples?
|
43
|
+
end
|
44
|
+
|
45
|
+
class WithoutCodeExample < Object::WithoutCodeExample
|
46
|
+
applicable_unless :has_code_example?
|
47
|
+
|
48
|
+
def suggestion
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -53,8 +53,8 @@ module Inch
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# Role assigned to objects explicitly or implicitly tagged to be part
|
56
|
-
# of an API. If the API is 'private'/'internal' TaggedAsInternalAPI is
|
57
|
-
# instead.
|
56
|
+
# of an API. If the API is 'private'/'internal' TaggedAsInternalAPI is
|
57
|
+
# assigned instead.
|
58
58
|
class TaggedAsAPI < Base
|
59
59
|
applicable_if :api_tag?
|
60
60
|
end
|
data/lib/inch/rake.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "inch"
|
2
|
+
require "inch/rake/suggest"
|
data/lib/inch/rake/suggest.rb
CHANGED
data/lib/inch/utils/ui.rb
CHANGED
@@ -10,9 +10,9 @@ module Inch
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def debug(msg)
|
13
|
-
return unless ENV[
|
13
|
+
return unless ENV["DEBUG"]
|
14
14
|
msg.to_s.lines.each do |line|
|
15
|
-
trace edged :dark, line.gsub(/\n$/,
|
15
|
+
trace edged :dark, line.gsub(/\n$/, "").dark
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -45,12 +45,12 @@ module Inch
|
|
45
45
|
def header(text, color, bg_color = nil)
|
46
46
|
@current_header_color = color
|
47
47
|
trace __header(text, color, bg_color)
|
48
|
-
trace
|
48
|
+
trace unless use_color?
|
49
49
|
end
|
50
50
|
|
51
51
|
# @return [Boolean] true if the UI uses coloring
|
52
52
|
def use_color?
|
53
|
-
Term::ANSIColor
|
53
|
+
Term::ANSIColor.coloring?
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
@@ -61,7 +61,7 @@ module Inch
|
|
61
61
|
|
62
62
|
def __header(text, color, bg_color = nil)
|
63
63
|
bg_color ||= "intense_#{color}"
|
64
|
-
bar = " #{text}".ljust(CLI::COLUMNS-1)
|
64
|
+
bar = " #{text}".ljust(CLI::COLUMNS - 1)
|
65
65
|
.on_color(bg_color).color(:color16)
|
66
66
|
"#".color(color).on_color(color) + bar
|
67
67
|
end
|
@@ -74,9 +74,8 @@ module Inch
|
|
74
74
|
target_count = @max_counts[index]
|
75
75
|
@list[index].concat sublist[0...target_count]
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
end
|
77
|
+
next unless sublist.size < target_count
|
78
|
+
missing += target_count - sublist.size
|
80
79
|
end
|
81
80
|
missing
|
82
81
|
end
|
data/lib/inch/version.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
module Foo
|
2
|
+
# Determines :class_variable
|
3
|
+
@@class_variable = {Ace: 11, Jack: 10, Queen: 10, King: 10}
|
4
|
+
|
2
5
|
# The problem here is that the @param tag is not given the name of the
|
3
6
|
# parameter it documents.
|
4
7
|
#
|
@@ -15,13 +18,6 @@ module Foo
|
|
15
18
|
def method_with_empty_param_tag_text(e)
|
16
19
|
end
|
17
20
|
|
18
|
-
# The problem here is that ...
|
19
|
-
#
|
20
|
-
# @param *names [Array]
|
21
|
-
# @return [String]
|
22
|
-
def method_with_splat_parameter(*names)
|
23
|
-
end
|
24
|
-
|
25
21
|
# The problem here is that ...
|
26
22
|
#
|
27
23
|
# @param names [Array]
|
@@ -34,9 +30,41 @@ module Foo
|
|
34
30
|
# @return HasH
|
35
31
|
def method_with_wrong_return_tag
|
36
32
|
end
|
33
|
+
|
34
|
+
# The problem here is that ...
|
35
|
+
#
|
36
|
+
# @param *names [Array]
|
37
|
+
# @return [String]
|
38
|
+
def method_with_splat_parameter(*names)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initializes a new Connection instance
|
42
|
+
# @param [Hash<Symbol, >] params One or more optional params
|
43
|
+
# @option params [String] :body Default text to be sent over a socket. Only used if :body absent in Connection#request params
|
44
|
+
# @option params [Hash<Symbol, String>] :headers The default headers to supply in a request. Only used if params[:headers] is not supplied to Connection#request
|
45
|
+
def method_with_indented_param_tag(params = {})
|
46
|
+
end
|
37
47
|
end
|
38
48
|
|
39
49
|
module Overloading
|
50
|
+
# @overload many_overloads(&block)
|
51
|
+
# @overload many_overloads(scope, &block)
|
52
|
+
# @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
|
53
|
+
# @overload many_overloads(scope, conditions, &block)
|
54
|
+
# @param scope [Symbol] `:example`, `:context`, or `:suite` (defaults to `:example`)
|
55
|
+
# @param conditions [Hash]
|
56
|
+
# constrains this hook to examples matching these conditions e.g.
|
57
|
+
# `many_overloads(:example, :ui => true) { ... }` will only run with examples or
|
58
|
+
# groups declared with `:ui => true`.
|
59
|
+
# @overload many_overloads(conditions, &block)
|
60
|
+
# @param conditions [Hash]
|
61
|
+
# constrains this hook to examples matching these conditions e.g.
|
62
|
+
# `many_overloads(:example, :ui => true) { ... }` will only run with examples or
|
63
|
+
# groups declared with `:ui => true`.
|
64
|
+
def many_overloads(*args, &block)
|
65
|
+
hooks.register :append, :before, *args, &block
|
66
|
+
end
|
67
|
+
|
40
68
|
# Creates a {Sass::Script::Value::Color Color} object from red, green, and
|
41
69
|
# blue values.
|
42
70
|
#
|
@@ -72,6 +72,23 @@ module Foo
|
|
72
72
|
def method_with_other_rdoc_doc(param1, param2, param3)
|
73
73
|
end
|
74
74
|
|
75
|
+
# Injects text right after the class definition. Since it depends on
|
76
|
+
# insert_into_file, it's reversible.
|
77
|
+
#
|
78
|
+
# ==== Parameters
|
79
|
+
# param1<String>:: path of the file to be changed
|
80
|
+
# param2<String|Class>:: the class to be manipulated
|
81
|
+
#
|
82
|
+
# ==== Examples
|
83
|
+
#
|
84
|
+
# inject_into_class "app/controllers/application_controller.rb", ApplicationController, " filter_parameter :password\n"
|
85
|
+
#
|
86
|
+
# inject_into_class "app/controllers/application_controller.rb", ApplicationController do
|
87
|
+
# " filter_parameter :password\n"
|
88
|
+
# end
|
89
|
+
def method_with_yet_another_rdoc_doc(param1, param2)
|
90
|
+
end
|
91
|
+
|
75
92
|
# An example of a method that takes a parameter (+param1+)
|
76
93
|
# and does nothing. But the previous sentence mentions said
|
77
94
|
# parameter.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) +
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../test_helper")
|
2
2
|
|
3
3
|
class Inch::CLI::Command::Output::Console
|
4
4
|
def run_pry
|
@@ -22,8 +22,8 @@ describe ::Inch::CLI::Command::Console do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should run without args" do
|
25
|
-
|
26
|
-
@prompt = @command.new.run
|
25
|
+
_out, _err = capture_io do
|
26
|
+
@prompt = @command.new.run
|
27
27
|
end
|
28
28
|
assert @prompt.respond_to?(:all)
|
29
29
|
assert @prompt.respond_to?(:ff)
|
@@ -34,7 +34,7 @@ describe ::Inch::CLI::Command::Console do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should run with a definitive object name" do
|
37
|
-
|
37
|
+
_out, _err = capture_io do
|
38
38
|
@prompt = @command.new.run("Foo::Bar#method_with_full_doc")
|
39
39
|
end
|
40
40
|
assert !@prompt.all.empty?
|
@@ -46,7 +46,7 @@ describe ::Inch::CLI::Command::Console do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should run with a partial name" do
|
49
|
-
|
49
|
+
_out, _err = capture_io do
|
50
50
|
@prompt = @command.new.run("Foo::Bar#")
|
51
51
|
end
|
52
52
|
assert @prompt.respond_to?(:all)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) +
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../test_helper")
|
2
2
|
|
3
3
|
describe ::Inch::CLI::Command::Inspect do
|
4
4
|
before do
|
@@ -8,7 +8,7 @@ describe ::Inch::CLI::Command::Inspect do
|
|
8
8
|
|
9
9
|
it "should warn and exit when run without args" do
|
10
10
|
out, err = capture_io do
|
11
|
-
assert_raises(SystemExit) { @command.run
|
11
|
+
assert_raises(SystemExit) { @command.run }
|
12
12
|
end
|
13
13
|
assert out.empty?, "there should be no output"
|
14
14
|
refute err.empty?, "there should be some error message"
|
@@ -33,7 +33,6 @@ describe ::Inch::CLI::Command::Inspect do
|
|
33
33
|
assert err.empty?, "there should be no errors"
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
it "should output some info when run with a definitive object name" do
|
38
37
|
out, err = capture_io do
|
39
38
|
@command.run("Foo::Qux")
|
@@ -53,14 +52,14 @@ describe ::Inch::CLI::Command::Inspect do
|
|
53
52
|
end
|
54
53
|
|
55
54
|
it "should output colored information" do
|
56
|
-
out,
|
55
|
+
out, _err = capture_io do
|
57
56
|
@command.run("Foo::Bar#")
|
58
57
|
end
|
59
58
|
refute_equal out.uncolor, out, "should be colored"
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should output uncolored information when asked" do
|
63
|
-
out,
|
62
|
+
out, _err = capture_io do
|
64
63
|
@command.run("Foo::Bar#", "--no-color")
|
65
64
|
end
|
66
65
|
assert_equal out.uncolor, out, "should not be colored"
|