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,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'patching methods' do
|
5
|
-
example 'add a class method to the String class' do
|
6
|
-
code = <<-CODE
|
7
|
-
class String
|
8
|
-
def self.foobar
|
9
|
-
end
|
10
|
-
end
|
11
|
-
CODE
|
12
|
-
|
13
|
-
defs = build_definitions(code)
|
14
|
-
|
15
|
-
defs.lookup(:const, 'String') \
|
16
|
-
.has_definition?(:method, 'foobar') \
|
17
|
-
.should == true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'scoping method definitions' do
|
5
|
-
example 'process a global method' do
|
6
|
-
defs = build_definitions('def example; end')
|
7
|
-
example = defs.lookup(:instance_method, 'example')
|
8
|
-
|
9
|
-
example.is_a?(ruby_method).should == true
|
10
|
-
|
11
|
-
example.type.should == :instance_method
|
12
|
-
example.name.should == 'example'
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'process a nested method' do
|
16
|
-
code = <<-CODE
|
17
|
-
def first
|
18
|
-
def second
|
19
|
-
end
|
20
|
-
end
|
21
|
-
CODE
|
22
|
-
|
23
|
-
defs = build_definitions(code)
|
24
|
-
first = defs.lookup(:instance_method, 'first')
|
25
|
-
|
26
|
-
first.is_a?(ruby_method).should == true
|
27
|
-
|
28
|
-
first.lookup(:instance_method, 'second') \
|
29
|
-
.is_a?(ruby_method) \
|
30
|
-
.should == true
|
31
|
-
|
32
|
-
defs.lookup(:instance_method, 'second').nil?.should == true
|
33
|
-
end
|
34
|
-
|
35
|
-
example 'process a global and nested method' do
|
36
|
-
code = <<-CODE
|
37
|
-
def first
|
38
|
-
def second
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def third
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
|
46
|
-
defs = build_definitions(code)
|
47
|
-
first = defs.lookup(:instance_method, 'first')
|
48
|
-
|
49
|
-
first.lookup(:instance_method, 'second') \
|
50
|
-
.is_a?(ruby_method) \
|
51
|
-
.should == true
|
52
|
-
|
53
|
-
first.lookup(:instance_method, 'second') \
|
54
|
-
.lookup(:instance_method, 'third') \
|
55
|
-
.is_a?(ruby_method) \
|
56
|
-
.should == true
|
57
|
-
|
58
|
-
defs.lookup(:instance_method, 'third') \
|
59
|
-
.is_a?(ruby_method) \
|
60
|
-
.should == true
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
# https://github.com/YorickPeterse/ruby-lint/issues/80
|
5
|
-
context 'defining square bracket methods' do
|
6
|
-
before :all do
|
7
|
-
code = <<-CODE
|
8
|
-
class Example
|
9
|
-
def [](key)
|
10
|
-
end
|
11
|
-
|
12
|
-
def []=(key, value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
CODE
|
16
|
-
|
17
|
-
@definitions = build_definitions(code)
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'define the [] method' do
|
21
|
-
@definitions.lookup(:const, 'Example')
|
22
|
-
.has_definition?(:instance_method, '[]')
|
23
|
-
.should == true
|
24
|
-
end
|
25
|
-
|
26
|
-
example 'define the []= method' do
|
27
|
-
@definitions.lookup(:const, 'Example')
|
28
|
-
.has_definition?(:instance_method, '[]=')
|
29
|
-
.should == true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'method visibility' do
|
5
|
-
example 'define a method as public' do
|
6
|
-
code = <<-CODE
|
7
|
-
def example
|
8
|
-
end
|
9
|
-
CODE
|
10
|
-
|
11
|
-
defs = build_definitions(code)
|
12
|
-
|
13
|
-
defs.lookup(:instance_method, 'example').visibility.should == :public
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'define a method as private' do
|
17
|
-
code = <<-CODE
|
18
|
-
private
|
19
|
-
|
20
|
-
def example
|
21
|
-
end
|
22
|
-
CODE
|
23
|
-
|
24
|
-
defs = build_definitions(code)
|
25
|
-
|
26
|
-
defs.lookup(:instance_method, 'example').visibility.should == :private
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'define a method as protected' do
|
30
|
-
code = <<-CODE
|
31
|
-
protected
|
32
|
-
|
33
|
-
def example
|
34
|
-
end
|
35
|
-
CODE
|
36
|
-
|
37
|
-
defs = build_definitions(code)
|
38
|
-
|
39
|
-
defs.lookup(:instance_method, 'example').visibility.should == :protected
|
40
|
-
end
|
41
|
-
|
42
|
-
example 'define a method as private and then reset it' do
|
43
|
-
code = <<-CODE
|
44
|
-
private
|
45
|
-
|
46
|
-
def example
|
47
|
-
end
|
48
|
-
|
49
|
-
public
|
50
|
-
|
51
|
-
def example_public
|
52
|
-
end
|
53
|
-
CODE
|
54
|
-
|
55
|
-
defs = build_definitions(code)
|
56
|
-
|
57
|
-
defs.lookup(:instance_method, 'example').visibility.should == :private
|
58
|
-
|
59
|
-
defs.lookup(:instance_method, 'example_public') \
|
60
|
-
.visibility \
|
61
|
-
.should == :public
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,205 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Building module definitions' do
|
4
|
-
describe 'scoping definitions' do
|
5
|
-
example 'process a global module' do
|
6
|
-
defs = build_definitions('module Example; end')
|
7
|
-
example = defs.lookup(:const, 'Example')
|
8
|
-
|
9
|
-
example.is_a?(ruby_object).should == true
|
10
|
-
|
11
|
-
example.type.should == :const
|
12
|
-
example.name.should == 'Example'
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'process a nested module' do
|
16
|
-
code = <<-CODE
|
17
|
-
module First
|
18
|
-
module Second
|
19
|
-
end
|
20
|
-
end
|
21
|
-
CODE
|
22
|
-
|
23
|
-
defs = build_definitions(code)
|
24
|
-
first = defs.lookup(:const, 'First')
|
25
|
-
|
26
|
-
first.is_a?(ruby_object).should == true
|
27
|
-
|
28
|
-
defs.lookup(:const, 'Second').nil?.should == true
|
29
|
-
|
30
|
-
first.lookup(:const, 'Second') \
|
31
|
-
.is_a?(ruby_object) \
|
32
|
-
.should == true
|
33
|
-
end
|
34
|
-
|
35
|
-
example 'process a global and nested module' do
|
36
|
-
code = <<-CODE
|
37
|
-
module First
|
38
|
-
module Second
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module Third
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
|
46
|
-
defs = build_definitions(code)
|
47
|
-
first = defs.lookup(:const, 'First')
|
48
|
-
|
49
|
-
first.lookup(:const, 'Second') \
|
50
|
-
.is_a?(ruby_object) \
|
51
|
-
.should == true
|
52
|
-
|
53
|
-
# Due to "First" and "Third" being defined in the same scope the "Third"
|
54
|
-
# constant is available inside the "First" module.
|
55
|
-
first.lookup(:const, 'Third') \
|
56
|
-
.is_a?(ruby_object) \
|
57
|
-
.should == true
|
58
|
-
|
59
|
-
first.lookup(:const, 'Second') \
|
60
|
-
.lookup(:const, 'Third') \
|
61
|
-
.is_a?(ruby_object) \
|
62
|
-
.should == true
|
63
|
-
|
64
|
-
defs.lookup(:const, 'Third') \
|
65
|
-
.is_a?(ruby_object) \
|
66
|
-
.should == true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'redefining modules' do
|
71
|
-
example 'update a module when it is redefined' do
|
72
|
-
code = <<-CODE
|
73
|
-
module First
|
74
|
-
end
|
75
|
-
|
76
|
-
module First
|
77
|
-
def example
|
78
|
-
end
|
79
|
-
end
|
80
|
-
CODE
|
81
|
-
|
82
|
-
defs = build_definitions(code)
|
83
|
-
|
84
|
-
defs.lookup(:const, 'First') \
|
85
|
-
.lookup(:instance_method, 'example') \
|
86
|
-
.is_a?(ruby_method) \
|
87
|
-
.should == true
|
88
|
-
end
|
89
|
-
|
90
|
-
example 'should not pollute modules in a different namespace' do
|
91
|
-
code = <<-CODE
|
92
|
-
module Foo
|
93
|
-
module Parser
|
94
|
-
end
|
95
|
-
|
96
|
-
module Bar
|
97
|
-
module Parser
|
98
|
-
def foo
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
CODE
|
104
|
-
|
105
|
-
defs = build_definitions(code)
|
106
|
-
|
107
|
-
first = defs.lookup(:const, 'Foo')
|
108
|
-
.lookup(:const, 'Parser')
|
109
|
-
|
110
|
-
second = defs.lookup(:const, 'Foo')
|
111
|
-
.lookup(:const, 'Bar')
|
112
|
-
.lookup(:const, 'Parser')
|
113
|
-
|
114
|
-
first.should_not == second
|
115
|
-
|
116
|
-
first.lookup(:instance_method, 'foo').is_a?(ruby_object).should == false
|
117
|
-
second.lookup(:instance_method, 'foo').is_a?(ruby_object).should == true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe 'including modules' do
|
122
|
-
example 'include a module' do
|
123
|
-
code = <<-CODE
|
124
|
-
module First
|
125
|
-
def example
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
module Second
|
130
|
-
include First
|
131
|
-
end
|
132
|
-
CODE
|
133
|
-
|
134
|
-
defs = build_definitions(code)
|
135
|
-
|
136
|
-
defs.lookup(:const, 'Second') \
|
137
|
-
.lookup(:instance_method, 'example') \
|
138
|
-
.is_a?(ruby_method) \
|
139
|
-
.should == true
|
140
|
-
end
|
141
|
-
|
142
|
-
example 'extend a module' do
|
143
|
-
code = <<-CODE
|
144
|
-
module First
|
145
|
-
def example
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
module Second
|
150
|
-
extend First
|
151
|
-
end
|
152
|
-
CODE
|
153
|
-
|
154
|
-
defs = build_definitions(code)
|
155
|
-
|
156
|
-
defs.lookup(:const, 'Second') \
|
157
|
-
.lookup(:method, 'example') \
|
158
|
-
.is_a?(ruby_method) \
|
159
|
-
.should == true
|
160
|
-
end
|
161
|
-
|
162
|
-
example 'include a module using a constant path' do
|
163
|
-
code = <<-CODE
|
164
|
-
module First
|
165
|
-
module Second
|
166
|
-
def example
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
module Third
|
172
|
-
include First::Second
|
173
|
-
end
|
174
|
-
CODE
|
175
|
-
|
176
|
-
defs = build_definitions(code)
|
177
|
-
|
178
|
-
defs.lookup(:const, 'Third') \
|
179
|
-
.lookup(:instance_method, 'example') \
|
180
|
-
.is_a?(ruby_method) \
|
181
|
-
.should == true
|
182
|
-
end
|
183
|
-
|
184
|
-
example 'include a module using a variable' do
|
185
|
-
code = <<-CODE
|
186
|
-
module First
|
187
|
-
def example
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
module Second
|
192
|
-
first = First
|
193
|
-
include first
|
194
|
-
end
|
195
|
-
CODE
|
196
|
-
|
197
|
-
defs = build_definitions(code)
|
198
|
-
|
199
|
-
defs.lookup(:const, 'Second') \
|
200
|
-
.lookup(:instance_method, 'example') \
|
201
|
-
.is_a?(ruby_method) \
|
202
|
-
.should == true
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'reference counting' do
|
5
|
-
example 'count the amount of references for a variable' do
|
6
|
-
code = <<-CODE
|
7
|
-
number = 10
|
8
|
-
number
|
9
|
-
number
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
|
14
|
-
defs.lookup(:lvar, 'number').reference_amount.should == 2
|
15
|
-
end
|
16
|
-
|
17
|
-
example 'count the amount of references for a constant path' do
|
18
|
-
code = <<-CODE
|
19
|
-
module A; end
|
20
|
-
A::B = 10
|
21
|
-
A::B
|
22
|
-
A::B
|
23
|
-
CODE
|
24
|
-
|
25
|
-
defs = build_definitions(code)
|
26
|
-
|
27
|
-
defs.lookup(:const, 'A') \
|
28
|
-
.lookup(:const, 'B') \
|
29
|
-
.reference_amount \
|
30
|
-
.should == 2
|
31
|
-
end
|
32
|
-
|
33
|
-
example 'mark variables created using OR/AND assignments as used' do
|
34
|
-
code = <<-CODE
|
35
|
-
number1 = 5
|
36
|
-
|
37
|
-
number ||= 10
|
38
|
-
number1 &&= 10
|
39
|
-
CODE
|
40
|
-
|
41
|
-
defs = build_definitions(code)
|
42
|
-
|
43
|
-
number = defs.lookup(:lvar, 'number')
|
44
|
-
number1 = defs.lookup(:lvar, 'number1')
|
45
|
-
|
46
|
-
number.used?.should == true
|
47
|
-
number1.used?.should == true
|
48
|
-
end
|
49
|
-
|
50
|
-
example 'overwriting a variable should increase the reference amount' do
|
51
|
-
code = <<-CODE
|
52
|
-
number = 10
|
53
|
-
number = 20
|
54
|
-
CODE
|
55
|
-
|
56
|
-
defs = build_definitions(code)
|
57
|
-
|
58
|
-
defs.lookup(:lvar, 'number').reference_amount.should == 1
|
59
|
-
end
|
60
|
-
|
61
|
-
example 'track ivar references in parent scopes' do
|
62
|
-
code = <<-CODE
|
63
|
-
def first
|
64
|
-
@number = 10
|
65
|
-
end
|
66
|
-
|
67
|
-
def second
|
68
|
-
@number = 20
|
69
|
-
@number
|
70
|
-
end
|
71
|
-
CODE
|
72
|
-
|
73
|
-
defs = build_definitions(code)
|
74
|
-
first = defs.lookup(:instance_method, 'first').lookup(:ivar, '@number')
|
75
|
-
second = defs.lookup(:instance_method, 'second').lookup(:ivar, '@number')
|
76
|
-
|
77
|
-
first.reference_amount.should == 2
|
78
|
-
second.reference_amount.should == 2
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|