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,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'redefining classes' do
|
5
|
-
example 'update a class when it is redefined' do
|
6
|
-
code = <<-CODE
|
7
|
-
class First
|
8
|
-
end
|
9
|
-
|
10
|
-
class First
|
11
|
-
def example
|
12
|
-
end
|
13
|
-
end
|
14
|
-
CODE
|
15
|
-
|
16
|
-
defs = build_definitions(code)
|
17
|
-
|
18
|
-
defs.lookup(:const, 'First') \
|
19
|
-
.lookup(:instance_method, 'example') \
|
20
|
-
.is_a?(ruby_method) \
|
21
|
-
.should == true
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'updating built-in definitions' do
|
25
|
-
before :all do
|
26
|
-
code = <<-CODE
|
27
|
-
class Integer < Numeric
|
28
|
-
def foobar
|
29
|
-
end
|
30
|
-
end
|
31
|
-
CODE
|
32
|
-
|
33
|
-
defs = build_definitions(code)
|
34
|
-
@integer = defs.lookup(:const, 'Integer')
|
35
|
-
@fixnum = defs.lookup(:const, 'Fixnum')
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'include newly defined methods' do
|
39
|
-
@integer.has_definition?(:instance_method, 'foobar').should == true
|
40
|
-
end
|
41
|
-
|
42
|
-
example 'include existing methods' do
|
43
|
-
@integer.has_definition?(:instance_method, '%').should == true
|
44
|
-
end
|
45
|
-
|
46
|
-
example 'update definitions that point to the redefined definition' do
|
47
|
-
@fixnum.has_definition?(:instance_method, 'foobar').should == true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'using sclass blocks' do
|
5
|
-
example 'define a class method using `class << self`' do
|
6
|
-
code = <<-CODE
|
7
|
-
class First
|
8
|
-
class << self
|
9
|
-
def example
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
CODE
|
14
|
-
|
15
|
-
defs = build_definitions(code)
|
16
|
-
|
17
|
-
defs.lookup(:const, 'First') \
|
18
|
-
.lookup(:method, 'example') \
|
19
|
-
.is_a?(ruby_method) \
|
20
|
-
.should == true
|
21
|
-
end
|
22
|
-
|
23
|
-
example 'define an instance method using `class << self` in the global scope' do
|
24
|
-
code = <<-CODE
|
25
|
-
class << self
|
26
|
-
def example
|
27
|
-
end
|
28
|
-
end
|
29
|
-
CODE
|
30
|
-
|
31
|
-
defs = build_definitions(code)
|
32
|
-
|
33
|
-
defs.lookup(:instance_method, 'example')
|
34
|
-
.is_a?(ruby_method)
|
35
|
-
.should == true
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'define a class method using `class << String`' do
|
39
|
-
code = <<-CODE
|
40
|
-
class << String
|
41
|
-
def example
|
42
|
-
end
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
|
46
|
-
defs = build_definitions(code)
|
47
|
-
|
48
|
-
defs.lookup(:const, 'String') \
|
49
|
-
.lookup(:method, 'example') \
|
50
|
-
.is_a?(ruby_method) \
|
51
|
-
.should == true
|
52
|
-
end
|
53
|
-
|
54
|
-
example 'define a class method using `class << String` nested in a class' do
|
55
|
-
code = <<-CODE
|
56
|
-
class First
|
57
|
-
class << String
|
58
|
-
def example
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
CODE
|
63
|
-
|
64
|
-
defs = build_definitions(code)
|
65
|
-
|
66
|
-
defs.lookup(:const, 'First') \
|
67
|
-
.lookup(:method, 'example') \
|
68
|
-
.is_a?(ruby_method) \
|
69
|
-
.should == false
|
70
|
-
|
71
|
-
defs.lookup(:const, 'String') \
|
72
|
-
.lookup(:method, 'example') \
|
73
|
-
.is_a?(ruby_method) \
|
74
|
-
.should == true
|
75
|
-
end
|
76
|
-
|
77
|
-
example 'define an instance method using `class << variable`' do
|
78
|
-
code = <<-CODE
|
79
|
-
variable = "foo"
|
80
|
-
|
81
|
-
class << variable
|
82
|
-
def example
|
83
|
-
end
|
84
|
-
end
|
85
|
-
CODE
|
86
|
-
|
87
|
-
defs = build_definitions(code)
|
88
|
-
|
89
|
-
defs.lookup(:lvar, 'variable') \
|
90
|
-
.value \
|
91
|
-
.lookup(:instance_method, 'example') \
|
92
|
-
.is_a?(ruby_object) \
|
93
|
-
.should == true
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'scoping class definitions' do
|
5
|
-
example 'process a global class' do
|
6
|
-
defs = build_definitions('class 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 class' do
|
16
|
-
code = <<-CODE
|
17
|
-
class First
|
18
|
-
class 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 class' do
|
36
|
-
code = <<-CODE
|
37
|
-
class First
|
38
|
-
class Second
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class Third
|
43
|
-
end
|
44
|
-
CODE
|
45
|
-
|
46
|
-
defs = build_definitions(code)
|
47
|
-
first = defs.lookup(:const, 'First')
|
48
|
-
|
49
|
-
first.lookup(:const, 'Second').is_a?(ruby_object).should == true
|
50
|
-
first.lookup(:const, 'Third').is_a?(ruby_object).should == true
|
51
|
-
|
52
|
-
first.lookup(:const, 'Second') \
|
53
|
-
.lookup(:const, 'Third') \
|
54
|
-
.is_a?(ruby_object) \
|
55
|
-
.should == true
|
56
|
-
|
57
|
-
defs.lookup(:const, 'Third').is_a?(ruby_object).should == true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'rails' do
|
5
|
-
before :all do
|
6
|
-
code = fixture('complex/rails/basic_controller.rb')
|
7
|
-
@defs = build_definitions(code)
|
8
|
-
@controller = @defs.lookup(:const, 'ApplicationController')
|
9
|
-
end
|
10
|
-
|
11
|
-
example 'inherit the parent controller' do
|
12
|
-
@controller.has_definition?(:instance_method, 'login_required')
|
13
|
-
.should == true
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'include built-in Rails definitions' do
|
17
|
-
@controller.has_definition?(:method, 'allow_forgery_protection')
|
18
|
-
.should == true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
# https://github.com/farrel/RCAP/blob/master/lib/rcap/cap_1_2/alert.rb
|
5
|
-
describe 'rcap' do
|
6
|
-
example 'process the Alert class' do
|
7
|
-
code = fixture('complex/rcap.rb')
|
8
|
-
defs = build_definitions(code)
|
9
|
-
const = defs.lookup_constant_path('RCAP::CAP_1_2::Alert')
|
10
|
-
|
11
|
-
const.lookup(:const, 'CAP_VERSION').value.value.should == '1.2'
|
12
|
-
const.has_definition?(:instance_method, 'xmlns').should == true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'slop' do
|
5
|
-
example 'process the Slop gem' do
|
6
|
-
code = fixture('complex/slop.rb')
|
7
|
-
defs = build_definitions(code)
|
8
|
-
const = defs.lookup(:const, 'Slop')
|
9
|
-
|
10
|
-
const.lookup(:const, 'VERSION').value.value.should == '3.4.5'
|
11
|
-
|
12
|
-
const.has_definition?(:method, 'parse').should == true
|
13
|
-
const.has_definition?(:method, 'parse!').should == true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'generic constants' do
|
5
|
-
# These tests are put in place to ensure that a class/module can refer to
|
6
|
-
# itself without having to look anything up in parent scopes. An example:
|
7
|
-
#
|
8
|
-
# class Foo
|
9
|
-
# Foo # => points to the class
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
example 'add the constant to itself' do
|
13
|
-
code = <<-CODE
|
14
|
-
module A
|
15
|
-
end
|
16
|
-
|
17
|
-
class B
|
18
|
-
end
|
19
|
-
CODE
|
20
|
-
|
21
|
-
defs = build_definitions(code)
|
22
|
-
mod = defs.lookup(:const, 'A')
|
23
|
-
klass = defs.lookup(:const, 'B')
|
24
|
-
|
25
|
-
# `lookup_parent` is set to false to ensure that the code doesn't use
|
26
|
-
# parent scopes to find the constant.
|
27
|
-
mod.lookup(:const, 'A', false).should == mod
|
28
|
-
klass.lookup(:const, 'B', false).should == klass
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Building variable definitions using for loops' do
|
4
|
-
example 'create local variables' do
|
5
|
-
code = <<-CODE
|
6
|
-
for key, value in something
|
7
|
-
|
8
|
-
end
|
9
|
-
CODE
|
10
|
-
|
11
|
-
defs = build_definitions(code)
|
12
|
-
|
13
|
-
defs.lookup(:lvar, 'key').is_a?(ruby_object).should == true
|
14
|
-
defs.lookup(:lvar, 'value').is_a?(ruby_object).should == true
|
15
|
-
end
|
16
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
example 'freeze the VM and all instance variables' do
|
5
|
-
vm = RubyLint::VirtualMachine.new
|
6
|
-
|
7
|
-
vm.freeze
|
8
|
-
|
9
|
-
vm.frozen?.should == true
|
10
|
-
vm.definitions.frozen?.should == true
|
11
|
-
vm.associations.frozen?.should == true
|
12
|
-
end
|
13
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'global variables' do
|
5
|
-
before :all do
|
6
|
-
@vm = RubyLint::VirtualMachine.new
|
7
|
-
@defs = @vm.definitions
|
8
|
-
end
|
9
|
-
|
10
|
-
example 'provide a list of default global variables' do
|
11
|
-
@defs.lookup(:gvar, '$LOAD_PATH').is_a?(ruby_object).should == true
|
12
|
-
@defs.lookup(:gvar, '$9').is_a?(ruby_object).should == true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'inheriting definitions using modules' do
|
5
|
-
example 'modules should inherit from Kernel' do
|
6
|
-
code = 'module Foo; end'
|
7
|
-
defs = build_definitions(code)
|
8
|
-
|
9
|
-
defs.lookup(:const, 'Foo')
|
10
|
-
.lookup(:method, 'alias_method')
|
11
|
-
.is_a?(ruby_method)
|
12
|
-
.should == true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'string interpolation' do
|
5
|
-
example 'process an assignment in a string' do
|
6
|
-
code = '"hello #{number = 10}"'
|
7
|
-
defs = build_definitions(code)
|
8
|
-
|
9
|
-
defs.lookup(:lvar, 'number').value.value.should == 10
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'definition location information' do
|
5
|
-
example 'store location information of a class' do
|
6
|
-
code = <<-CODE
|
7
|
-
# Example class.
|
8
|
-
class Example
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
defs = build_definitions(code)
|
13
|
-
obj = defs.lookup(:const, 'Example')
|
14
|
-
|
15
|
-
obj.line.should == 2
|
16
|
-
obj.column.should == 1
|
17
|
-
obj.file.should == '(ruby-lint)'
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'store location information of a module' do
|
21
|
-
code = <<-CODE
|
22
|
-
# Example module.
|
23
|
-
module Example
|
24
|
-
end
|
25
|
-
CODE
|
26
|
-
|
27
|
-
defs = build_definitions(code)
|
28
|
-
obj = defs.lookup(:const, 'Example')
|
29
|
-
|
30
|
-
obj.line.should == 2
|
31
|
-
obj.column.should == 1
|
32
|
-
obj.file.should == '(ruby-lint)'
|
33
|
-
end
|
34
|
-
|
35
|
-
example 'store location information of a method' do
|
36
|
-
code = <<-CODE
|
37
|
-
# Example module.
|
38
|
-
def example
|
39
|
-
end
|
40
|
-
CODE
|
41
|
-
|
42
|
-
defs = build_definitions(code)
|
43
|
-
obj = defs.lookup(:instance_method, 'example')
|
44
|
-
|
45
|
-
obj.line.should == 2
|
46
|
-
obj.column.should == 1
|
47
|
-
obj.file.should == '(ruby-lint)'
|
48
|
-
end
|
49
|
-
|
50
|
-
example 'store location information of a variable' do
|
51
|
-
code = <<-CODE
|
52
|
-
# Example assignment
|
53
|
-
number = 10
|
54
|
-
CODE
|
55
|
-
|
56
|
-
defs = build_definitions(code)
|
57
|
-
obj = defs.lookup(:lvar, 'number')
|
58
|
-
|
59
|
-
obj.line.should == 2
|
60
|
-
obj.column.should == 1
|
61
|
-
obj.file.should == '(ruby-lint)'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'method call tracking' do
|
5
|
-
before :all do
|
6
|
-
code = <<-CODE
|
7
|
-
def first_method
|
8
|
-
end
|
9
|
-
|
10
|
-
def second_method
|
11
|
-
end
|
12
|
-
|
13
|
-
def third_method
|
14
|
-
first_method
|
15
|
-
second_method
|
16
|
-
String.new
|
17
|
-
end
|
18
|
-
CODE
|
19
|
-
|
20
|
-
definitions = build_definitions(code)
|
21
|
-
@first = definitions.lookup(:instance_method, 'first_method')
|
22
|
-
@second = definitions.lookup(:instance_method, 'second_method')
|
23
|
-
@third = definitions.lookup(:instance_method, 'third_method')
|
24
|
-
@string = definitions.lookup(:const, 'String')
|
25
|
-
end
|
26
|
-
|
27
|
-
example 'track the right amount of method calls' do
|
28
|
-
@third.calls.length.should == 3
|
29
|
-
end
|
30
|
-
|
31
|
-
example 'track call location information' do
|
32
|
-
@third.calls[0].line.should == 8
|
33
|
-
@third.calls[0].column.should == 3
|
34
|
-
|
35
|
-
@third.calls[1].line.should == 9
|
36
|
-
@third.calls[1].column.should == 3
|
37
|
-
end
|
38
|
-
|
39
|
-
example 'track the call definitions' do
|
40
|
-
@third.calls[0].definition.should == @first
|
41
|
-
@third.calls[1].definition.should == @second
|
42
|
-
end
|
43
|
-
|
44
|
-
example 'track call location information in inverse direction' do
|
45
|
-
@first.callers[0].line.should == 8
|
46
|
-
@first.callers[0].column.should == 3
|
47
|
-
|
48
|
-
@second.callers[0].line.should == 9
|
49
|
-
@second.callers[0].column.should == 3
|
50
|
-
end
|
51
|
-
|
52
|
-
example 'track method calls in inverse direction' do
|
53
|
-
@first.callers[0].definition.should == @third
|
54
|
-
@second.callers[0].definition.should == @third
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|