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,78 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Using return values in assignments' do
|
4
|
-
example 'assign a return value' do
|
5
|
-
code = 'word = String.new'
|
6
|
-
defs = build_definitions(code)
|
7
|
-
value = defs.lookup(:lvar, 'word').value
|
8
|
-
|
9
|
-
value.is_a?(ruby_object).should == true
|
10
|
-
|
11
|
-
value.type.should == :const
|
12
|
-
value.name.should == 'String'
|
13
|
-
value.instance?.should == true
|
14
|
-
end
|
15
|
-
|
16
|
-
example 'assign a nil value for a missing return value' do
|
17
|
-
code = <<-CODE
|
18
|
-
def example
|
19
|
-
end
|
20
|
-
|
21
|
-
number = example
|
22
|
-
CODE
|
23
|
-
|
24
|
-
defs = build_definitions(code)
|
25
|
-
|
26
|
-
defs.lookup(:lvar, 'number').value.type.should == :unknown
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'assign return values when chaining method calls' do
|
30
|
-
code = 'word = String.new.initialize.initialize'
|
31
|
-
defs = build_definitions(code)
|
32
|
-
value = defs.lookup(:lvar, 'word').value
|
33
|
-
|
34
|
-
value.is_a?(ruby_object).should == true
|
35
|
-
|
36
|
-
value.type.should == :const
|
37
|
-
value.name.should == 'String'
|
38
|
-
value.instance?.should == true
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'setting instance types for core Ruby types' do
|
42
|
-
example 'create a new String instance' do
|
43
|
-
defs = build_definitions('number = "10"')
|
44
|
-
|
45
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
46
|
-
end
|
47
|
-
|
48
|
-
example 'create a new Symbol instance' do
|
49
|
-
defs = build_definitions('number = :"10"')
|
50
|
-
|
51
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
52
|
-
end
|
53
|
-
|
54
|
-
example 'create a new Fixnum instance' do
|
55
|
-
defs = build_definitions('number = 10')
|
56
|
-
|
57
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
58
|
-
end
|
59
|
-
|
60
|
-
example 'create a new Float instance' do
|
61
|
-
defs = build_definitions('number = 10.0')
|
62
|
-
|
63
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
64
|
-
end
|
65
|
-
|
66
|
-
example 'create a new Array instance' do
|
67
|
-
defs = build_definitions('number = [10]')
|
68
|
-
|
69
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
70
|
-
end
|
71
|
-
|
72
|
-
example 'create a new Hash instance' do
|
73
|
-
defs = build_definitions('number = {:a => 10}')
|
74
|
-
|
75
|
-
defs.lookup(:lvar, 'number').value.instance?.should == true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'variable assignments' do
|
5
|
-
example 'assign different types of variables' do
|
6
|
-
types = {
|
7
|
-
'number' => :lvar,
|
8
|
-
'@number' => :ivar,
|
9
|
-
'@@number' => :cvar,
|
10
|
-
'$number' => :gvar,
|
11
|
-
'NUMBER' => :const
|
12
|
-
}
|
13
|
-
|
14
|
-
types.each do |name, type|
|
15
|
-
number = build_definitions("#{name} = 10").lookup(type, name)
|
16
|
-
|
17
|
-
number.name.should == name
|
18
|
-
number.value.value.should == 10
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'assign multiple values to multiple variables' do
|
23
|
-
defs = build_definitions('number, numberx = 10, 20')
|
24
|
-
number = defs.lookup(:lvar, 'number')
|
25
|
-
numberx = defs.lookup(:lvar, 'numberx')
|
26
|
-
|
27
|
-
number.is_a?(ruby_object).should == true
|
28
|
-
|
29
|
-
number.name.should == 'number'
|
30
|
-
number.value.value.should == 10
|
31
|
-
|
32
|
-
numberx.is_a?(ruby_object).should == true
|
33
|
-
|
34
|
-
numberx.name.should == 'numberx'
|
35
|
-
numberx.value.value.should == 20
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'assign a value to a constant path' do
|
39
|
-
defs = build_definitions('module Foo; end; Foo::FOO = 10')
|
40
|
-
foo = defs.lookup(:const, 'Foo').lookup(:const, 'FOO')
|
41
|
-
|
42
|
-
foo.is_a?(ruby_object).should == true
|
43
|
-
|
44
|
-
foo.name.should == 'FOO'
|
45
|
-
foo.value.value.should == 10
|
46
|
-
end
|
47
|
-
|
48
|
-
example 'assign a single value to multiple variables' do
|
49
|
-
code = 'first = second = third = 10'
|
50
|
-
defs = build_definitions(code)
|
51
|
-
|
52
|
-
%w{first second third}.each do |name|
|
53
|
-
variable = defs.lookup(:lvar, name)
|
54
|
-
|
55
|
-
variable.is_a?(ruby_object).should == true
|
56
|
-
|
57
|
-
variable.value.type.should == :int
|
58
|
-
variable.value.value.should == 10
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
example 'resolve variables in assignments' do
|
63
|
-
code = <<-CODE
|
64
|
-
a = 1
|
65
|
-
b = a
|
66
|
-
|
67
|
-
foo = 100 # to ensure this code doesn't use the last assigned values.
|
68
|
-
|
69
|
-
c = b
|
70
|
-
d = c
|
71
|
-
CODE
|
72
|
-
|
73
|
-
defs = build_definitions(code)
|
74
|
-
|
75
|
-
%w{a b c d}.each do |name|
|
76
|
-
var = defs.lookup(:lvar, name)
|
77
|
-
|
78
|
-
var.value.type.should == :int
|
79
|
-
var.value.value.should == 1
|
80
|
-
end
|
81
|
-
|
82
|
-
defs.lookup(:lvar, 'foo').value.value.should == 100
|
83
|
-
end
|
84
|
-
|
85
|
-
example 'assign nil to a value' do
|
86
|
-
defs = build_definitions('variable = nil')
|
87
|
-
value = defs.lookup(:lvar, 'variable').value
|
88
|
-
|
89
|
-
value.type.should == :nil
|
90
|
-
value.parents[0].name.should == 'NilClass'
|
91
|
-
end
|
92
|
-
|
93
|
-
example 'assign true to a value' do
|
94
|
-
defs = build_definitions('variable = true')
|
95
|
-
value = defs.lookup(:lvar, 'variable').value
|
96
|
-
|
97
|
-
value.type.should == :true
|
98
|
-
value.parents[0].name.should == 'TrueClass'
|
99
|
-
end
|
100
|
-
|
101
|
-
example 'assign false to a value' do
|
102
|
-
defs = build_definitions('variable = false')
|
103
|
-
value = defs.lookup(:lvar, 'variable').value
|
104
|
-
|
105
|
-
value.type.should == :false
|
106
|
-
value.parents[0].name.should == 'FalseClass'
|
107
|
-
end
|
108
|
-
|
109
|
-
example 'assigning a magic global variable to a variable' do
|
110
|
-
defs = build_definitions('variable = $1')
|
111
|
-
value = defs.lookup(:lvar, 'variable').value
|
112
|
-
|
113
|
-
value.type.should == :unknown
|
114
|
-
end
|
115
|
-
|
116
|
-
example 'global variables should be assigned in the global scope' do
|
117
|
-
code = <<-CODE
|
118
|
-
class Foo
|
119
|
-
def foo
|
120
|
-
$bar = 10
|
121
|
-
end
|
122
|
-
end
|
123
|
-
CODE
|
124
|
-
|
125
|
-
defs = build_definitions(code)
|
126
|
-
|
127
|
-
defs.lookup(:gvar, '$bar').value.value.should == 10
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
example 'associate AST nodes and their definitions' do
|
5
|
-
tokens = parse('def foobar; end', false)
|
6
|
-
vm = RubyLint::VirtualMachine.new
|
7
|
-
|
8
|
-
vm.iterate(tokens)
|
9
|
-
|
10
|
-
defs = vm.definitions
|
11
|
-
assoc = vm.associations
|
12
|
-
method = tokens.children[0]
|
13
|
-
|
14
|
-
assoc.key?(method).should == true
|
15
|
-
assoc[method].should == defs.lookup(:instance_method, 'foobar')
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'method calls' do
|
19
|
-
example 'should not add associations' do
|
20
|
-
associations = build_associations('foo')
|
21
|
-
nodes = associations.keys
|
22
|
-
|
23
|
-
nodes.length.should == 1
|
24
|
-
nodes[0].type.should == :root
|
25
|
-
end
|
26
|
-
|
27
|
-
example 'should not add associations for methods with arguments' do
|
28
|
-
associations = build_associations('foo(:bar)')
|
29
|
-
nodes = associations.keys
|
30
|
-
|
31
|
-
nodes.length.should == 2
|
32
|
-
nodes[0].type.should == :root
|
33
|
-
end
|
34
|
-
|
35
|
-
example 'should not add associations for methods called on methods' do
|
36
|
-
associations = build_associations('foo.bar')
|
37
|
-
nodes = associations.keys
|
38
|
-
values = associations.values
|
39
|
-
|
40
|
-
nodes.length.should == 2
|
41
|
-
nodes[0].type.should == :root
|
42
|
-
nodes[1].type.should == :send
|
43
|
-
|
44
|
-
values[1].type.should == :unknown
|
45
|
-
end
|
46
|
-
|
47
|
-
example 'should not add associations for stacked methods with arguments' do
|
48
|
-
associations = build_associations('foo.bar(:baz)')
|
49
|
-
nodes = associations.keys
|
50
|
-
values = associations.values
|
51
|
-
|
52
|
-
nodes.length.should == 3
|
53
|
-
nodes[0].type.should == :root
|
54
|
-
nodes[1].type.should == :sym
|
55
|
-
nodes[2].type.should == :send
|
56
|
-
|
57
|
-
values[1].type.should == :sym
|
58
|
-
values[2].type.should == :unknown
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
example 'automatically load constants' do
|
5
|
-
definitions = build_definitions('ERB')
|
6
|
-
|
7
|
-
definitions.lookup(:const, 'ERB').is_a?(ruby_object).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
example 'automatically load constant paths' do
|
11
|
-
definitions = build_definitions('Encoding::BINARY')
|
12
|
-
|
13
|
-
definitions.lookup(:const, 'Encoding') \
|
14
|
-
.lookup(:const, 'BINARY') \
|
15
|
-
.is_a?(ruby_object) \
|
16
|
-
.should == true
|
17
|
-
end
|
18
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
example 'make variables available in a block' do
|
5
|
-
code = <<-CODE
|
6
|
-
number = 10
|
7
|
-
|
8
|
-
example do
|
9
|
-
end
|
10
|
-
CODE
|
11
|
-
|
12
|
-
definition = build_associations(code).to_a.last.last
|
13
|
-
|
14
|
-
number = definition.lookup(:lvar, 'number')
|
15
|
-
|
16
|
-
number.is_a?(ruby_object).should == true
|
17
|
-
number.value.value.should == 10
|
18
|
-
end
|
19
|
-
|
20
|
-
example 'make block arguments available as variables inside the block only' do
|
21
|
-
code = <<-CODE
|
22
|
-
example do
|
23
|
-
number = 10
|
24
|
-
end
|
25
|
-
CODE
|
26
|
-
|
27
|
-
associations = build_associations(code).to_a
|
28
|
-
|
29
|
-
root_def = associations.first.last
|
30
|
-
block_def = associations.last.last
|
31
|
-
|
32
|
-
root_def.lookup(:lvar, 'number').nil?.should == true
|
33
|
-
block_def.lookup(:lvar, 'number').value.value.should == 10
|
34
|
-
end
|
35
|
-
|
36
|
-
example 'blocks should be instances by default' do
|
37
|
-
code = <<-CODE
|
38
|
-
example do
|
39
|
-
end
|
40
|
-
CODE
|
41
|
-
|
42
|
-
block = build_associations(code).to_a.last.last
|
43
|
-
|
44
|
-
block.type.should == :block
|
45
|
-
block.instance_type.should == :instance
|
46
|
-
end
|
47
|
-
|
48
|
-
example 'blocks should inherit the instance type from the outer scope' do
|
49
|
-
code = <<-CODE
|
50
|
-
class A
|
51
|
-
example do
|
52
|
-
end
|
53
|
-
end
|
54
|
-
CODE
|
55
|
-
|
56
|
-
block = build_associations(code).to_a.last.last
|
57
|
-
|
58
|
-
block.type.should == :block
|
59
|
-
block.instance_type.should == :class
|
60
|
-
end
|
61
|
-
|
62
|
-
example 'update outer variables modified in the block' do
|
63
|
-
code = <<-CODE
|
64
|
-
number = 10
|
65
|
-
@number = 10
|
66
|
-
@@number = 10
|
67
|
-
$number = 10
|
68
|
-
|
69
|
-
example do
|
70
|
-
number = 20
|
71
|
-
@number = 20
|
72
|
-
@@number = 20
|
73
|
-
$number = 20
|
74
|
-
end
|
75
|
-
CODE
|
76
|
-
|
77
|
-
defs = build_definitions(code)
|
78
|
-
|
79
|
-
variables = {
|
80
|
-
:lvar => 'number',
|
81
|
-
:ivar => '@number',
|
82
|
-
:cvar => '@@number',
|
83
|
-
:gvar => '$number'
|
84
|
-
}
|
85
|
-
|
86
|
-
variables.each do |type, name|
|
87
|
-
defs.lookup(type, name).value.value.should == 20
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'defining class methods' do
|
5
|
-
example 'define a single class method using `self`' do
|
6
|
-
code = <<-CODE
|
7
|
-
class Example
|
8
|
-
def self.class_method
|
9
|
-
end
|
10
|
-
end
|
11
|
-
CODE
|
12
|
-
|
13
|
-
defs = build_definitions(code)
|
14
|
-
|
15
|
-
defs.lookup(:const, 'Example') \
|
16
|
-
.lookup(:method, 'class_method') \
|
17
|
-
.is_a?(ruby_method) \
|
18
|
-
.should == true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'extending classes' do
|
5
|
-
example 'set the default parent class' do
|
6
|
-
defs = build_definitions('class First; end')
|
7
|
-
|
8
|
-
defs.lookup(:const, 'First') \
|
9
|
-
.lookup(:method, 'new') \
|
10
|
-
.is_a?(ruby_method) \
|
11
|
-
.should == true
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'extend a class using a parent' do
|
15
|
-
code = <<-CODE
|
16
|
-
class First
|
17
|
-
def example
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Second < First
|
22
|
-
end
|
23
|
-
CODE
|
24
|
-
|
25
|
-
defs = build_definitions(code)
|
26
|
-
|
27
|
-
defs.lookup(:const, 'Second') \
|
28
|
-
.parents \
|
29
|
-
.map(&:name) \
|
30
|
-
.should == ['First', 'root']
|
31
|
-
|
32
|
-
defs.lookup(:const, 'Second') \
|
33
|
-
.lookup(:instance_method, 'example') \
|
34
|
-
.is_a?(ruby_method) \
|
35
|
-
.should == true
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'extend a class using a constant path as the parent class' do
|
39
|
-
code = <<-CODE
|
40
|
-
class First
|
41
|
-
class Second
|
42
|
-
def example
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Third < First::Second
|
48
|
-
end
|
49
|
-
CODE
|
50
|
-
|
51
|
-
defs = build_definitions(code)
|
52
|
-
|
53
|
-
defs.lookup(:const, 'Third') \
|
54
|
-
.parents \
|
55
|
-
.map(&:name) \
|
56
|
-
.should == ['Second', 'root']
|
57
|
-
|
58
|
-
defs.lookup(:const, 'Third') \
|
59
|
-
.lookup(:instance_method, 'example') \
|
60
|
-
.is_a?(ruby_method) \
|
61
|
-
.should == true
|
62
|
-
end
|
63
|
-
|
64
|
-
example 'extend a class using a variable' do
|
65
|
-
code = <<-CODE
|
66
|
-
parent = String
|
67
|
-
|
68
|
-
class MyString < parent
|
69
|
-
end
|
70
|
-
CODE
|
71
|
-
|
72
|
-
defs = build_definitions(code)
|
73
|
-
|
74
|
-
parents = defs.lookup(:const, 'MyString').parents
|
75
|
-
|
76
|
-
parents.length.should == 2
|
77
|
-
parents.include?(defs.lookup(:const, 'String')).should == true
|
78
|
-
end
|
79
|
-
|
80
|
-
# This is to ensure that ruby-lint doesn't blow itself up when trying to
|
81
|
-
# use a constant as a parent class that can't be found (e.g. a user defined
|
82
|
-
# class).
|
83
|
-
#
|
84
|
-
# See https://github.com/YorickPeterse/ruby-lint/issues/32 for the
|
85
|
-
# motivation behind this fix/test.
|
86
|
-
example 'inherit Object as a fallback when the parent can not be found' do
|
87
|
-
code = <<-CODE
|
88
|
-
class Foo < Bar
|
89
|
-
end
|
90
|
-
CODE
|
91
|
-
|
92
|
-
defs = build_definitions(code)
|
93
|
-
parents = defs.lookup(:const, 'Foo').parents
|
94
|
-
|
95
|
-
parents.length.should == 2
|
96
|
-
|
97
|
-
parents.include?(defs.lookup(:const, 'Object')).should == true
|
98
|
-
end
|
99
|
-
|
100
|
-
example 'inherit from Object when importing String' do
|
101
|
-
defs = build_definitions('String')
|
102
|
-
|
103
|
-
defs.lookup(:const, 'String') \
|
104
|
-
.lookup(:method, 'new') \
|
105
|
-
.is_a?(ruby_method) \
|
106
|
-
.should == true
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|