ruby-lint 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +43 -29
- data/LICENSE +1 -1
- data/README.md +0 -1
- data/bin/ruby-lint +91 -3
- data/checksum/ruby-lint-1.1.0.gem.sha512 +1 -0
- data/doc/changelog.md +30 -0
- data/doc/code_analysis.md +13 -0
- data/doc/configuration.md +5 -24
- data/lib/ruby-lint.rb +7 -10
- data/lib/ruby-lint/analysis/argument_amount.rb +2 -0
- data/lib/ruby-lint/analysis/base.rb +12 -0
- data/lib/ruby-lint/analysis/pedantics.rb +2 -0
- data/lib/ruby-lint/analysis/shadowing_variables.rb +2 -0
- data/lib/ruby-lint/analysis/undefined_methods.rb +5 -2
- data/lib/ruby-lint/analysis/undefined_variables.rb +2 -0
- data/lib/ruby-lint/analysis/unused_variables.rb +2 -0
- data/lib/ruby-lint/analysis/useless_equality_checks.rb +2 -0
- data/lib/ruby-lint/ast/node.rb +0 -15
- data/lib/ruby-lint/command.rb +100 -0
- data/lib/ruby-lint/configuration.rb +35 -66
- data/lib/ruby-lint/constant_path.rb +7 -2
- data/lib/ruby-lint/definition/ruby_object.rb +20 -6
- data/lib/ruby-lint/definitions/core/argf.rb +3 -3
- data/lib/ruby-lint/definitions/gems/minitest.rb +792 -0
- data/lib/ruby-lint/file_list.rb +1 -1
- data/lib/ruby-lint/file_loader.rb +2 -20
- data/lib/ruby-lint/file_scanner.rb +11 -2
- data/lib/ruby-lint/method_evaluation.rb +21 -0
- data/lib/ruby-lint/presenter/base.rb +18 -0
- data/lib/ruby-lint/presenter/json.rb +3 -1
- data/lib/ruby-lint/presenter/syntastic.rb +3 -1
- data/lib/ruby-lint/presenter/text.rb +3 -1
- data/lib/ruby-lint/runner.rb +6 -63
- data/lib/ruby-lint/variable_predicates.rb +3 -3
- data/lib/ruby-lint/version.rb +1 -1
- data/lib/ruby-lint/virtual_machine.rb +4 -1
- data/ruby-lint.gemspec +13 -4
- metadata +12 -187
- data/.editorconfig +0 -15
- data/.gitignore +0 -6
- data/.ruby-version +0 -1
- data/.travis.yml +0 -19
- data/Gemfile +0 -15
- data/MANIFEST +0 -469
- data/Rakefile +0 -25
- data/benchmark/bootup.rb +0 -13
- data/benchmark/virtual_machine.rb +0 -17
- data/checksum/.gitkeep +0 -0
- data/doc/.gitkeep +0 -0
- data/doc/css/.gitkeep +0 -0
- data/doc/images/.gitkeep +0 -0
- data/gen/rails/constants.txt +0 -12
- data/gen/rails/requires.rb +0 -2
- data/gen/stdlib/constants.rb +0 -30
- data/gen/stdlib/constants.txt +0 -214
- data/gen/stdlib/requires.rb +0 -64
- data/lib/ruby-lint/benchmark/average.rb +0 -115
- data/lib/ruby-lint/cache.rb +0 -121
- data/lib/ruby-lint/cache_entry.rb +0 -44
- data/lib/ruby-lint/cli.rb +0 -4
- data/lib/ruby-lint/cli/analyze.rb +0 -209
- data/lib/ruby-lint/cli/base.rb +0 -103
- data/lib/ruby-lint/cli/cache.rb +0 -60
- data/lib/ruby-lint/default_names.rb +0 -19
- data/lib/ruby-lint/definitions/gems/.gitkeep +0 -0
- data/lib/ruby-lint/node_hash.rb +0 -105
- data/misc/stdlib.rb +0 -66
- data/profiling/virtual_machine.rb +0 -20
- data/ruby-lint.yml +0 -7
- data/spec/fixtures/associating.rb +0 -7
- data/spec/fixtures/complex/rails/basic_controller.rb +0 -9
- data/spec/fixtures/complex/rcap.rb +0 -67
- data/spec/fixtures/complex/slop.rb +0 -701
- data/spec/fixtures/config.yml +0 -8
- data/spec/fixtures/deeply/nested/file.rb +0 -1
- data/spec/fixtures/file_scanner/lib/example/recursive/source.rb +0 -6
- data/spec/fixtures/file_scanner/lib/example/recursive/target.rb +0 -8
- data/spec/fixtures/file_scanner/lib/example/user.rb +0 -6
- data/spec/fixtures/file_scanner/lib/ruby-lint/definition/constant_proxy.rb +0 -6
- data/spec/fixtures/file_scanner/lib/ruby-lint/global_scope.rb +0 -6
- data/spec/fixtures/file_scanner/lib/test-dashes/foo.rb +0 -4
- data/spec/fixtures/file_scanner/rails/app/models/example/user.rb +0 -6
- data/spec/fixtures/file_scanner/rails/app/models/user.rb +0 -4
- data/spec/fixtures/invalid.rb +0 -3
- data/spec/fixtures/invalid_2.rb +0 -3
- data/spec/fixtures/syntax_error.rb +0 -1
- data/spec/fixtures/uses_external.rb +0 -1
- data/spec/fixtures/uses_external_invalid.rb +0 -3
- data/spec/fixtures/uses_external_namespace.rb +0 -1
- data/spec/fixtures/valid.rb +0 -3
- data/spec/ruby-lint/analysis/argument_amount_spec.rb +0 -131
- data/spec/ruby-lint/analysis/base_spec.rb +0 -24
- data/spec/ruby-lint/analysis/pedantics_spec.rb +0 -63
- data/spec/ruby-lint/analysis/shadowing_variables_spec.rb +0 -85
- data/spec/ruby-lint/analysis/undefined_methods_spec.rb +0 -337
- data/spec/ruby-lint/analysis/undefined_variables_spec.rb +0 -138
- data/spec/ruby-lint/analysis/unused_variables_spec.rb +0 -270
- data/spec/ruby-lint/analysis/useless_equality_checks_spec.rb +0 -107
- data/spec/ruby-lint/ast/node_spec.rb +0 -39
- data/spec/ruby-lint/cache_entry_spec.rb +0 -25
- data/spec/ruby-lint/cache_spec.rb +0 -53
- data/spec/ruby-lint/cli/analyze_spec.rb +0 -52
- data/spec/ruby-lint/configuration_spec.rb +0 -126
- data/spec/ruby-lint/constant_loader_spec.rb +0 -79
- data/spec/ruby-lint/constant_path.rb +0 -63
- data/spec/ruby-lint/definition/constant_proxy_spec.rb +0 -85
- data/spec/ruby-lint/definition/dsl_spec.rb +0 -135
- data/spec/ruby-lint/definition/registry_spec.rb +0 -106
- data/spec/ruby-lint/definition/ruby_method_spec.rb +0 -106
- data/spec/ruby-lint/definition/ruby_object_spec.rb +0 -264
- data/spec/ruby-lint/definition_builder/primitive_spec.rb +0 -62
- data/spec/ruby-lint/definition_builder/ruby_class_spec.rb +0 -107
- data/spec/ruby-lint/definition_builder/ruby_method_spec.rb +0 -53
- data/spec/ruby-lint/definition_builder/ruby_module_spec.rb +0 -52
- data/spec/ruby-lint/definitions/argv_spec.rb +0 -18
- data/spec/ruby-lint/definitions/env_spec.rb +0 -13
- data/spec/ruby-lint/definitions/file_spec.rb +0 -17
- data/spec/ruby-lint/definitions/fixnum_spec.rb +0 -18
- data/spec/ruby-lint/definitions/io_spec.rb +0 -15
- data/spec/ruby-lint/definitions/kernel_spec.rb +0 -18
- data/spec/ruby-lint/definitions/range_spec.rb +0 -21
- data/spec/ruby-lint/definitions/string_spec.rb +0 -20
- data/spec/ruby-lint/docstring/mapping.rb +0 -27
- data/spec/ruby-lint/docstring/parser_spec.rb +0 -88
- data/spec/ruby-lint/extensions/string_spec.rb +0 -7
- data/spec/ruby-lint/file_list_spec.rb +0 -25
- data/spec/ruby-lint/file_loader_spec.rb +0 -69
- data/spec/ruby-lint/file_scanner_spec.rb +0 -84
- data/spec/ruby-lint/inspector_spec.rb +0 -224
- data/spec/ruby-lint/iterator_spec.rb +0 -151
- data/spec/ruby-lint/method_call/.gitkeep +0 -0
- data/spec/ruby-lint/nested_stack_spec.rb +0 -23
- data/spec/ruby-lint/node_hash_spec.rb +0 -56
- data/spec/ruby-lint/parser_spec.rb +0 -38
- data/spec/ruby-lint/presenter/json_spec.rb +0 -58
- data/spec/ruby-lint/presenter/syntastic_spec.rb +0 -49
- data/spec/ruby-lint/presenter/text_spec.rb +0 -49
- data/spec/ruby-lint/report/entry_spec.rb +0 -58
- data/spec/ruby-lint/report_spec.rb +0 -39
- data/spec/ruby-lint/runner_spec.rb +0 -74
- data/spec/ruby-lint/variable_predicates_spec.rb +0 -30
- data/spec/ruby-lint/virtual_machine/alias_spec.rb +0 -55
- data/spec/ruby-lint/virtual_machine/assignments/arrays_spec.rb +0 -87
- data/spec/ruby-lint/virtual_machine/assignments/assignment_arguments_spec.rb +0 -14
- data/spec/ruby-lint/virtual_machine/assignments/constants_spec.rb +0 -23
- data/spec/ruby-lint/virtual_machine/assignments/hashes_spec.rb +0 -52
- data/spec/ruby-lint/virtual_machine/assignments/optional_spec.rb +0 -41
- data/spec/ruby-lint/virtual_machine/assignments/range_spec.rb +0 -28
- data/spec/ruby-lint/virtual_machine/assignments/return_values_spec.rb +0 -78
- data/spec/ruby-lint/virtual_machine/assignments/variables_spec.rb +0 -130
- data/spec/ruby-lint/virtual_machine/associate_nodes_spec.rb +0 -61
- data/spec/ruby-lint/virtual_machine/autoloading_spec.rb +0 -18
- data/spec/ruby-lint/virtual_machine/blocks_spec.rb +0 -90
- data/spec/ruby-lint/virtual_machine/classes/class_methods_spec.rb +0 -21
- data/spec/ruby-lint/virtual_machine/classes/extending_spec.rb +0 -109
- data/spec/ruby-lint/virtual_machine/classes/redefining_spec.rb +0 -51
- data/spec/ruby-lint/virtual_machine/classes/sclass_spec.rb +0 -96
- data/spec/ruby-lint/virtual_machine/classes/scoping_spec.rb +0 -60
- data/spec/ruby-lint/virtual_machine/complex/rails_spec.rb +0 -21
- data/spec/ruby-lint/virtual_machine/complex/rcap_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/complex/slop_spec.rb +0 -16
- data/spec/ruby-lint/virtual_machine/constants_spec.rb +0 -31
- data/spec/ruby-lint/virtual_machine/for_spec.rb +0 -16
- data/spec/ruby-lint/virtual_machine/freeze_spec.rb +0 -13
- data/spec/ruby-lint/virtual_machine/global_variables_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/inherit_kernel_spec.rb +0 -15
- data/spec/ruby-lint/virtual_machine/interpolation_spec.rb +0 -12
- data/spec/ruby-lint/virtual_machine/location_spec.rb +0 -64
- data/spec/ruby-lint/virtual_machine/method_call_tracking_spec.rb +0 -57
- data/spec/ruby-lint/virtual_machine/methods/attr_spec.rb +0 -182
- data/spec/ruby-lint/virtual_machine/methods/calls_spec.rb +0 -25
- data/spec/ruby-lint/virtual_machine/methods/define_method_spec.rb +0 -41
- data/spec/ruby-lint/virtual_machine/methods/defining_spec.rb +0 -40
- data/spec/ruby-lint/virtual_machine/methods/docstrings_spec.rb +0 -80
- data/spec/ruby-lint/virtual_machine/methods/exporting_spec.rb +0 -19
- data/spec/ruby-lint/virtual_machine/methods/kernel_spec.rb +0 -25
- data/spec/ruby-lint/virtual_machine/methods/parameters_spec.rb +0 -89
- data/spec/ruby-lint/virtual_machine/methods/patching_spec.rb +0 -20
- data/spec/ruby-lint/virtual_machine/methods/scoping_spec.rb +0 -63
- data/spec/ruby-lint/virtual_machine/methods/square_bracket_spec.rb +0 -32
- data/spec/ruby-lint/virtual_machine/methods/visibility_spec.rb +0 -64
- data/spec/ruby-lint/virtual_machine/modules_spec.rb +0 -205
- data/spec/ruby-lint/virtual_machine/reference_amount_spec.rb +0 -81
- data/spec/ruby-lint/virtual_machine/self_spec.rb +0 -37
- data/spec/ruby-lint/virtual_machine/unused_spec.rb +0 -17
- data/spec/spec_helper.rb +0 -28
- data/spec/support/building.rb +0 -50
- data/spec/support/coveralls.rb +0 -5
- data/spec/support/definitions.rb +0 -39
- data/spec/support/fixtures.rb +0 -20
- data/spec/support/parsing.rb +0 -30
- data/spec/support/simplecov.rb +0 -18
- data/spec/support/versions.rb +0 -9
- data/task/build.rake +0 -4
- data/task/checksum.rake +0 -13
- data/task/coverage.rake +0 -6
- data/task/doc.rake +0 -16
- data/task/generate.rake +0 -77
- data/task/graphviz.rake +0 -12
- data/task/manifest.rake +0 -8
- data/task/tag.rake +0 -6
- data/task/test.rake +0 -4
- data/task/todo.rake +0 -6
- data/task/travis.rake +0 -8
@@ -1,182 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'attr methods' do
|
5
|
-
example 'should define a read-only attribute using #attr' do
|
6
|
-
code = <<-CODE
|
7
|
-
class Example
|
8
|
-
attr :number
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
defs.lookup(:const, 'Example')
|
15
|
-
.has_definition?(:instance_method, 'number')
|
16
|
-
.should == true
|
17
|
-
|
18
|
-
defs.lookup(:const, 'Example')
|
19
|
-
.has_definition?(:ivar, '@number')
|
20
|
-
.should == true
|
21
|
-
|
22
|
-
defs.lookup(:const, 'Example')
|
23
|
-
.lookup(:ivar, '@number')
|
24
|
-
.used?
|
25
|
-
.should == true
|
26
|
-
end
|
27
|
-
|
28
|
-
example 'should define an accessor attribute using #attr' do
|
29
|
-
code = <<-CODE
|
30
|
-
class Example
|
31
|
-
attr :number, true
|
32
|
-
end
|
33
|
-
CODE
|
34
|
-
|
35
|
-
defs = build_definitions(code)
|
36
|
-
|
37
|
-
defs.lookup(:const, 'Example')
|
38
|
-
.has_definition?(:instance_method, 'number')
|
39
|
-
.should == true
|
40
|
-
|
41
|
-
defs.lookup(:const, 'Example')
|
42
|
-
.has_definition?(:instance_method, 'number=')
|
43
|
-
.should == true
|
44
|
-
|
45
|
-
defs.lookup(:const, 'Example')
|
46
|
-
.has_definition?(:ivar, '@number')
|
47
|
-
.should == true
|
48
|
-
end
|
49
|
-
|
50
|
-
example 'should define a read-only attribute using #attr_reader' do
|
51
|
-
code = <<-CODE
|
52
|
-
class Example
|
53
|
-
attr_reader :number
|
54
|
-
end
|
55
|
-
CODE
|
56
|
-
|
57
|
-
defs = build_definitions(code)
|
58
|
-
|
59
|
-
defs.lookup(:const, 'Example')
|
60
|
-
.has_definition?(:instance_method, 'number')
|
61
|
-
.should == true
|
62
|
-
|
63
|
-
defs.lookup(:const, 'Example')
|
64
|
-
.has_definition?(:instance_method, 'number=')
|
65
|
-
.should == false
|
66
|
-
|
67
|
-
defs.lookup(:const, 'Example')
|
68
|
-
.has_definition?(:ivar, '@number')
|
69
|
-
.should == true
|
70
|
-
end
|
71
|
-
|
72
|
-
example 'should define a write-only attribute using #attr_writer' do
|
73
|
-
code = <<-CODE
|
74
|
-
class Example
|
75
|
-
attr_writer :number
|
76
|
-
end
|
77
|
-
CODE
|
78
|
-
|
79
|
-
defs = build_definitions(code)
|
80
|
-
|
81
|
-
defs.lookup(:const, 'Example')
|
82
|
-
.has_definition?(:instance_method, 'number')
|
83
|
-
.should == false
|
84
|
-
|
85
|
-
defs.lookup(:const, 'Example')
|
86
|
-
.has_definition?(:instance_method, 'number=')
|
87
|
-
.should == true
|
88
|
-
|
89
|
-
defs.lookup(:const, 'Example')
|
90
|
-
.has_definition?(:ivar, '@number')
|
91
|
-
.should == true
|
92
|
-
end
|
93
|
-
|
94
|
-
example 'should define an accessor attribute using #attr_accessor' do
|
95
|
-
code = <<-CODE
|
96
|
-
class Example
|
97
|
-
attr_accessor :number
|
98
|
-
end
|
99
|
-
CODE
|
100
|
-
|
101
|
-
defs = build_definitions(code)
|
102
|
-
|
103
|
-
defs.lookup(:const, 'Example')
|
104
|
-
.has_definition?(:instance_method, 'number')
|
105
|
-
.should == true
|
106
|
-
|
107
|
-
defs.lookup(:const, 'Example')
|
108
|
-
.has_definition?(:instance_method, 'number=')
|
109
|
-
.should == true
|
110
|
-
|
111
|
-
defs.lookup(:const, 'Example')
|
112
|
-
.has_definition?(:ivar, '@number')
|
113
|
-
.should == true
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'attr methods and argument amounts' do
|
118
|
-
example 'set the arguments for attr' do
|
119
|
-
code = <<-CODE
|
120
|
-
class Example
|
121
|
-
attr :foo
|
122
|
-
end
|
123
|
-
CODE
|
124
|
-
|
125
|
-
defs = build_definitions(code)
|
126
|
-
|
127
|
-
defs.lookup(:const, 'Example')
|
128
|
-
.lookup(:instance_method, 'foo')
|
129
|
-
.arguments
|
130
|
-
.empty?
|
131
|
-
.should == true
|
132
|
-
end
|
133
|
-
|
134
|
-
example 'set the arguments for attr_reader' do
|
135
|
-
code = <<-CODE
|
136
|
-
class Example
|
137
|
-
attr_reader :foo
|
138
|
-
end
|
139
|
-
CODE
|
140
|
-
|
141
|
-
defs = build_definitions(code)
|
142
|
-
|
143
|
-
defs.lookup(:const, 'Example')
|
144
|
-
.lookup(:instance_method, 'foo')
|
145
|
-
.arguments
|
146
|
-
.empty?
|
147
|
-
.should == true
|
148
|
-
end
|
149
|
-
|
150
|
-
example 'set the arguments for attr_writer' do
|
151
|
-
code = <<-CODE
|
152
|
-
class Example
|
153
|
-
attr_writer :foo
|
154
|
-
end
|
155
|
-
CODE
|
156
|
-
|
157
|
-
defs = build_definitions(code)
|
158
|
-
|
159
|
-
defs.lookup(:const, 'Example')
|
160
|
-
.lookup(:instance_method, 'foo=')
|
161
|
-
.arguments
|
162
|
-
.length
|
163
|
-
.should == 1
|
164
|
-
end
|
165
|
-
|
166
|
-
example 'set the arguments for attr_accessor' do
|
167
|
-
code = <<-CODE
|
168
|
-
class Example
|
169
|
-
attr_accessor :foo
|
170
|
-
end
|
171
|
-
CODE
|
172
|
-
|
173
|
-
defs = build_definitions(code)
|
174
|
-
|
175
|
-
defs.lookup(:const, 'Example')
|
176
|
-
.lookup(:instance_method, 'foo=')
|
177
|
-
.arguments
|
178
|
-
.length
|
179
|
-
.should == 1
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'evaluating method calls' do
|
5
|
-
before :all do
|
6
|
-
code = <<-EOF
|
7
|
-
# @return [String]
|
8
|
-
def example
|
9
|
-
return 'foo'
|
10
|
-
end
|
11
|
-
|
12
|
-
variable = example
|
13
|
-
EOF
|
14
|
-
|
15
|
-
@defs = build_definitions(code)
|
16
|
-
end
|
17
|
-
|
18
|
-
example 'assign the correct return value to a local variable' do
|
19
|
-
value = @defs.lookup(:lvar, 'variable').value
|
20
|
-
|
21
|
-
value.type.should == :const
|
22
|
-
value.name.should == 'String'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'define_method' do
|
5
|
-
example 'change the instance type of the block to `:instance`' do
|
6
|
-
code = <<-CODE
|
7
|
-
class A
|
8
|
-
define_method(:example) do
|
9
|
-
end
|
10
|
-
end
|
11
|
-
CODE
|
12
|
-
|
13
|
-
assoc = build_associations(code).to_a[-2].last
|
14
|
-
|
15
|
-
assoc.type.should == :block
|
16
|
-
assoc.instance_type.should == :instance
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'should not mess up nested blocks' do
|
20
|
-
code = <<-CODE
|
21
|
-
class A
|
22
|
-
something.each do
|
23
|
-
define_method(:example) do
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
CODE
|
28
|
-
|
29
|
-
assoc = build_associations(code).to_a
|
30
|
-
|
31
|
-
something = assoc[2].last
|
32
|
-
define = assoc[4].last
|
33
|
-
|
34
|
-
something.type.should == :block
|
35
|
-
something.instance_type.should == :class
|
36
|
-
|
37
|
-
define.type.should == :block
|
38
|
-
define.instance_type.should == :instance
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'defining methods' do
|
5
|
-
example 'process a definition with a variable assignment in the body' do
|
6
|
-
code = <<-CODE
|
7
|
-
def example
|
8
|
-
number = 10
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
defs.lookup(:instance_method, 'example') \
|
15
|
-
.lookup(:lvar, 'number') \
|
16
|
-
.is_a?(ruby_object) \
|
17
|
-
.should == true
|
18
|
-
|
19
|
-
defs.lookup(:lvar, 'number').nil?.should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'process a definition with a receiver' do
|
23
|
-
code = <<-CODE
|
24
|
-
def String.example
|
25
|
-
number = 10
|
26
|
-
end
|
27
|
-
CODE
|
28
|
-
|
29
|
-
defs = build_definitions(code)
|
30
|
-
|
31
|
-
defs.lookup(:const, 'String') \
|
32
|
-
.lookup(:method, 'example') \
|
33
|
-
.is_a?(ruby_method) \
|
34
|
-
.should == true
|
35
|
-
|
36
|
-
defs.lookup(:method, 'example').nil?.should == true
|
37
|
-
defs.lookup(:instance_method, 'example').nil?.should == true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'method arguments and docstrings' do
|
5
|
-
example 'extract the type of a parameter' do
|
6
|
-
code = <<-CODE
|
7
|
-
# @param [Numeric] number
|
8
|
-
def example(number)
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
number = defs.lookup(:instance_method, 'example').lookup(:lvar, 'number')
|
15
|
-
numeric = defs.lookup(:const, 'Numeric')
|
16
|
-
|
17
|
-
number.is_a?(ruby_object).should == true
|
18
|
-
numeric.is_a?(ruby_object).should == true
|
19
|
-
number.parents.include?(numeric).should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'extract the type of a parameter using a method' do
|
23
|
-
code = <<-CODE
|
24
|
-
# @param [#to_s] number
|
25
|
-
def example(number)
|
26
|
-
end
|
27
|
-
CODE
|
28
|
-
|
29
|
-
defs = build_definitions(code)
|
30
|
-
number = defs.lookup(:instance_method, 'example').lookup(:lvar, 'number')
|
31
|
-
|
32
|
-
number.is_a?(ruby_object).should == true
|
33
|
-
number.lookup(:instance_method, 'to_s').is_a?(ruby_method).should == true
|
34
|
-
end
|
35
|
-
|
36
|
-
example 'extract multiple types from a parameter' do
|
37
|
-
code = <<-CODE
|
38
|
-
# @param [Float|Fixnum] number
|
39
|
-
def example(number)
|
40
|
-
end
|
41
|
-
CODE
|
42
|
-
|
43
|
-
defs = build_definitions(code)
|
44
|
-
float = defs.lookup(:const, 'Float')
|
45
|
-
fixnum = defs.lookup(:const, 'Fixnum')
|
46
|
-
|
47
|
-
number = defs.lookup(:instance_method, 'example').lookup(:lvar, 'number')
|
48
|
-
|
49
|
-
number.is_a?(ruby_object).should == true
|
50
|
-
number.parents.include?(float).should == true
|
51
|
-
number.parents.include?(fixnum).should == true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'method return values and docstrings' do
|
56
|
-
before :all do
|
57
|
-
code = <<-CODE
|
58
|
-
# @return [Numeric]
|
59
|
-
def example
|
60
|
-
end
|
61
|
-
CODE
|
62
|
-
|
63
|
-
@defs = build_definitions(code)
|
64
|
-
end
|
65
|
-
|
66
|
-
example 'extract the type of a return tag' do
|
67
|
-
method = @defs.lookup(:instance_method, 'example')
|
68
|
-
numeric = @defs.lookup(:const, 'Numeric')
|
69
|
-
|
70
|
-
method.return_value.type.should == :const
|
71
|
-
method.return_value.name.should == 'Numeric'
|
72
|
-
end
|
73
|
-
|
74
|
-
example 'return values as instances' do
|
75
|
-
method = @defs.lookup(:instance_method, 'example')
|
76
|
-
|
77
|
-
method.return_value.instance?.should == true
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'exporting variables out of method scopes' do
|
5
|
-
example 'export variables to the outer scope' do
|
6
|
-
code = <<-CODE
|
7
|
-
def example
|
8
|
-
@number = 10
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
defs.lookup(:ivar, '@number') \
|
15
|
-
.is_a?(ruby_object) \
|
16
|
-
.should == true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'updating the Kernel module' do
|
5
|
-
before :all do
|
6
|
-
code = <<-CODE
|
7
|
-
module Kernel
|
8
|
-
def foobar
|
9
|
-
end
|
10
|
-
end
|
11
|
-
CODE
|
12
|
-
|
13
|
-
@definitions = build_definitions(code)
|
14
|
-
@kernel = @definitions.lookup(:const, 'Kernel')
|
15
|
-
end
|
16
|
-
|
17
|
-
example 'add the method to the Kernel module' do
|
18
|
-
@kernel.has_definition?(:instance_method, 'foobar').should == true
|
19
|
-
end
|
20
|
-
|
21
|
-
example 'add the method to the global scope' do
|
22
|
-
@definitions.has_definition?(:instance_method, 'foobar').should == true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'creating variables for method parameters' do
|
5
|
-
example 'create local variables' do
|
6
|
-
code = <<-CODE
|
7
|
-
def example(number)
|
8
|
-
return number
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
defs.lookup(:instance_method, 'example') \
|
15
|
-
.lookup(:lvar, 'number') \
|
16
|
-
.is_a?(ruby_object) \
|
17
|
-
.should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'allow the assignment using parameters' do
|
21
|
-
code = <<-CODE
|
22
|
-
def example(number)
|
23
|
-
other_number = number
|
24
|
-
end
|
25
|
-
CODE
|
26
|
-
|
27
|
-
defs = build_definitions(code)
|
28
|
-
|
29
|
-
defs.lookup(:instance_method, 'example') \
|
30
|
-
.lookup(:lvar, 'other_number') \
|
31
|
-
.is_a?(ruby_object) \
|
32
|
-
.should == true
|
33
|
-
end
|
34
|
-
|
35
|
-
example 'take all argument types into account' do
|
36
|
-
code = <<-CODE
|
37
|
-
def example(required, optional = 10, *splat, more, &block)
|
38
|
-
_required = required
|
39
|
-
_optional = optional
|
40
|
-
_splat = splat
|
41
|
-
_more = more
|
42
|
-
_block = block
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
|
46
|
-
defs = build_definitions(code)
|
47
|
-
method = defs.lookup(:instance_method, 'example')
|
48
|
-
|
49
|
-
%w{_required _splat _more _block}.each do |name|
|
50
|
-
method.lookup(:lvar, name).is_a?(ruby_object).should == true
|
51
|
-
end
|
52
|
-
|
53
|
-
method.lookup(:lvar, '_optional').value.value.should == 10
|
54
|
-
end
|
55
|
-
|
56
|
-
example 'store arguments under special types' do
|
57
|
-
code = <<-CODE
|
58
|
-
def example(required, optional = 10, *splat, more, &block)
|
59
|
-
end
|
60
|
-
CODE
|
61
|
-
|
62
|
-
defs = build_definitions(code)
|
63
|
-
method = defs.lookup(:instance_method, 'example')
|
64
|
-
types = [
|
65
|
-
[:arg, 'required'],
|
66
|
-
[:optarg, 'optional'],
|
67
|
-
[:restarg, 'splat'],
|
68
|
-
[:arg, 'more'],
|
69
|
-
[:blockarg, 'block']
|
70
|
-
]
|
71
|
-
|
72
|
-
types.each do |(type, name)|
|
73
|
-
method.lookup(type, name).is_a?(ruby_object).should == true
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Keyword arguments were introduced in Ruby 2.0.
|
78
|
-
specific_ruby_version '2.0' do
|
79
|
-
example 'support keyword arguments' do
|
80
|
-
code = 'def example(number: 10); end'
|
81
|
-
defs = build_definitions(code)
|
82
|
-
method = defs.lookup(:instance_method, 'example')
|
83
|
-
|
84
|
-
method.lookup(:kwoptarg, 'number').value.value.should == 10
|
85
|
-
method.lookup(:lvar, 'number').value.value.should == 10
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|