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,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'RubyLint::Report' do
|
4
|
-
example 'add a message using #add' do
|
5
|
-
report = RubyLint::Report.new
|
6
|
-
|
7
|
-
report.add(
|
8
|
-
:level => :info,
|
9
|
-
:message => 'info message',
|
10
|
-
:line => 1,
|
11
|
-
:column => 2,
|
12
|
-
:file => 'file.rb'
|
13
|
-
)
|
14
|
-
|
15
|
-
report.entries.length.should == 1
|
16
|
-
|
17
|
-
entry = report.entries[0]
|
18
|
-
|
19
|
-
entry.level.should == :info
|
20
|
-
entry.message.should == 'info message'
|
21
|
-
entry.line.should == 1
|
22
|
-
entry.column.should == 2
|
23
|
-
entry.file.should == 'file.rb'
|
24
|
-
end
|
25
|
-
|
26
|
-
example 'ignore invalid reporting levels' do
|
27
|
-
report = RubyLint::Report.new
|
28
|
-
|
29
|
-
report.add(
|
30
|
-
:level => :test,
|
31
|
-
:message => 'invalid message',
|
32
|
-
:line => 1,
|
33
|
-
:column => 1,
|
34
|
-
:file => 'file.rb'
|
35
|
-
)
|
36
|
-
|
37
|
-
report.entries.empty?.should == true
|
38
|
-
end
|
39
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Runner do
|
4
|
-
before do
|
5
|
-
@configuration = RubyLint::Configuration.new
|
6
|
-
@cache_dir = Dir.mktmpdir('ruby-lint')
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
FileUtils.rm_rf(@cache_dir)
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'run analysis on a single file' do
|
14
|
-
files = [fixture_path('invalid.rb')]
|
15
|
-
runner = RubyLint::Runner.new(@configuration)
|
16
|
-
output = runner.analyze(files)
|
17
|
-
|
18
|
-
output.should =~ /undefined method foobar on an instance of String/
|
19
|
-
end
|
20
|
-
|
21
|
-
example 'run analysis on multiple files' do
|
22
|
-
files = [fixture_path('invalid.rb'), fixture_path('invalid_2.rb')]
|
23
|
-
runner = RubyLint::Runner.new(@configuration)
|
24
|
-
output = runner.analyze(files)
|
25
|
-
|
26
|
-
output.should =~ /undefined method foobar on an instance of String/
|
27
|
-
output.should =~ /undefined method derp on an instance of String/
|
28
|
-
end
|
29
|
-
|
30
|
-
example 'add syntax errors to the report' do
|
31
|
-
files = [fixture_path('syntax_error.rb')]
|
32
|
-
runner = RubyLint::Runner.new(@configuration)
|
33
|
-
output = runner.analyze(files)
|
34
|
-
|
35
|
-
output.should =~ /unexpected token \$end/
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'add errors when using externally defined constants' do
|
39
|
-
files = [fixture_path('uses_external_invalid.rb')]
|
40
|
-
dirs = [fixture_path('file_scanner/rails')]
|
41
|
-
config = RubyLint::Configuration.new(:directories => dirs)
|
42
|
-
runner = RubyLint::Runner.new(config)
|
43
|
-
output = runner.analyze(files)
|
44
|
-
|
45
|
-
output.should =~ /undefined method foobar on an instance of User/
|
46
|
-
end
|
47
|
-
|
48
|
-
example 'associating nodes with external definitions' do
|
49
|
-
files = [fixture_path('associating.rb')]
|
50
|
-
dirs = [fixture_path('file_scanner/lib/ruby-lint')]
|
51
|
-
config = RubyLint::Configuration.new(:directories => dirs)
|
52
|
-
runner = RubyLint::Runner.new(config)
|
53
|
-
output = runner.analyze(files)
|
54
|
-
|
55
|
-
output.empty?.should == true
|
56
|
-
end
|
57
|
-
|
58
|
-
example 'conditionally disable analysis classes' do
|
59
|
-
# This analysis class triggers the "undefined method foobar..." error.
|
60
|
-
RubyLint::Analysis::UndefinedMethods.stub(:analyze?) do |ast, vm|
|
61
|
-
# This ensures that the passed arguments are passed in the right order
|
62
|
-
# and of the right type.
|
63
|
-
!(ast.is_a?(RubyLint::AST::Node) && vm.is_a?(RubyLint::VirtualMachine))
|
64
|
-
end
|
65
|
-
|
66
|
-
files = [fixture_path('uses_external_invalid.rb')]
|
67
|
-
dirs = [fixture_path('file_scanner/rails')]
|
68
|
-
config = RubyLint::Configuration.new(:directories => dirs)
|
69
|
-
runner = RubyLint::Runner.new(config)
|
70
|
-
output = runner.analyze(files)
|
71
|
-
|
72
|
-
output.empty?.should == true
|
73
|
-
end
|
74
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VariablePredicates do
|
4
|
-
before :all do
|
5
|
-
@array = s(:array)
|
6
|
-
@hash = s(:hash)
|
7
|
-
@const = s(:const, nil, :A)
|
8
|
-
@path = s(:const, s(:const, nil, :A), :B)
|
9
|
-
end
|
10
|
-
|
11
|
-
example 'check if an object is an array' do
|
12
|
-
@array.array?.should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'check if an object is a hash' do
|
16
|
-
@hash.hash?.should == true
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'check if an object is a constant' do
|
20
|
-
@const.constant?.should == true
|
21
|
-
end
|
22
|
-
|
23
|
-
example 'check if an object is a constant path' do
|
24
|
-
@path.constant_path?.should == true
|
25
|
-
end
|
26
|
-
|
27
|
-
example 'return the Ruby class of an object' do
|
28
|
-
@array.ruby_class.should == 'Array'
|
29
|
-
end
|
30
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'alias' do
|
5
|
-
example 'alias methods' do
|
6
|
-
code = <<-CODE
|
7
|
-
def bar
|
8
|
-
end
|
9
|
-
|
10
|
-
alias foo bar
|
11
|
-
CODE
|
12
|
-
|
13
|
-
defs = build_definitions(code)
|
14
|
-
|
15
|
-
defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
|
16
|
-
defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'alias methods using symbols' do
|
20
|
-
code = <<-CODE
|
21
|
-
def bar
|
22
|
-
end
|
23
|
-
|
24
|
-
alias :foo :bar
|
25
|
-
CODE
|
26
|
-
|
27
|
-
defs = build_definitions(code)
|
28
|
-
|
29
|
-
defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
|
30
|
-
defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
|
31
|
-
end
|
32
|
-
|
33
|
-
example 'alias methods using alias_method' do
|
34
|
-
code = <<-CODE
|
35
|
-
def bar
|
36
|
-
end
|
37
|
-
|
38
|
-
alias_method :foo, :bar
|
39
|
-
CODE
|
40
|
-
|
41
|
-
defs = build_definitions(code)
|
42
|
-
|
43
|
-
defs.lookup(:instance_method, 'bar').is_a?(ruby_method).should == true
|
44
|
-
defs.lookup(:instance_method, 'foo').is_a?(ruby_method).should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
example 'alias global variables' do
|
48
|
-
code = 'alias $ARGV $*'
|
49
|
-
defs = build_definitions(code)
|
50
|
-
|
51
|
-
defs.lookup(:gvar, '$*').is_a?(ruby_object).should == true
|
52
|
-
defs.lookup(:gvar, '$ARGV').is_a?(ruby_object).should == true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'array assignments' do
|
5
|
-
example 'assign an empty array' do
|
6
|
-
defs = build_definitions('numbers = []')
|
7
|
-
value = defs.lookup(:lvar, 'numbers').value
|
8
|
-
|
9
|
-
value.type.should == :array
|
10
|
-
value.instance?.should == true
|
11
|
-
|
12
|
-
value.has_definition?(:instance_method, 'each').should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'assign an array with values' do
|
16
|
-
defs = build_definitions('numbers = [10, 20]')
|
17
|
-
array = defs.lookup(:lvar, 'numbers').value
|
18
|
-
members = [10, 20]
|
19
|
-
|
20
|
-
members.each_with_index do |value, index|
|
21
|
-
index = index.to_s
|
22
|
-
member = array.lookup(:member, index)
|
23
|
-
|
24
|
-
member.name.should == index
|
25
|
-
member.value.type.should == :int
|
26
|
-
member.value.value.should == value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
example 'process single index assignments' do
|
31
|
-
code = <<-CODE
|
32
|
-
numbers = []
|
33
|
-
numbers[0] = 10
|
34
|
-
CODE
|
35
|
-
|
36
|
-
defs = build_definitions(code)
|
37
|
-
numbers = defs.lookup(:lvar, 'numbers')
|
38
|
-
|
39
|
-
numbers.is_a?(ruby_object).should == true
|
40
|
-
numbers.value.is_a?(ruby_object).should == true
|
41
|
-
numbers.value.type.should == :array
|
42
|
-
|
43
|
-
first = numbers.value.lookup(:member, '0')
|
44
|
-
|
45
|
-
first.type.should == :member
|
46
|
-
first.name.should == '0'
|
47
|
-
|
48
|
-
first.value.is_a?(ruby_object).should == true
|
49
|
-
first.value.type.should == :int
|
50
|
-
first.value.value.should == 10
|
51
|
-
end
|
52
|
-
|
53
|
-
example 'process multiple index assignments' do
|
54
|
-
code = <<-CODE
|
55
|
-
numbers = []
|
56
|
-
numbers[0,1] = 10
|
57
|
-
numbers[2,3] = 20, 30
|
58
|
-
numbers[4,5,6] = 40, 50
|
59
|
-
CODE
|
60
|
-
|
61
|
-
defs = build_definitions(code)
|
62
|
-
numbers = defs.lookup(:lvar, 'numbers').value
|
63
|
-
|
64
|
-
numbers.lookup(:member, '0').value.value.should == 10
|
65
|
-
numbers.lookup(:member, '1').value.should == nil
|
66
|
-
numbers.lookup(:member, '2').value.value.should == 20
|
67
|
-
numbers.lookup(:member, '3').value.value.should == 30
|
68
|
-
numbers.lookup(:member, '4').value.value.should == 40
|
69
|
-
numbers.lookup(:member, '5').value.value.should == 50
|
70
|
-
numbers.lookup(:member, '6').value.should == nil
|
71
|
-
end
|
72
|
-
|
73
|
-
example 'process index assignments using variables' do
|
74
|
-
code = <<-CODE
|
75
|
-
index = 1
|
76
|
-
numbers = [10]
|
77
|
-
numbers[index] = 20
|
78
|
-
CODE
|
79
|
-
|
80
|
-
defs = build_definitions(code)
|
81
|
-
numbers = defs.lookup(:lvar, 'numbers').value
|
82
|
-
|
83
|
-
numbers.lookup(:member, '0').value.value.should == 10
|
84
|
-
numbers.lookup(:member, '1').value.value.should == 20
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'variable assignments as method arguments' do
|
5
|
-
example 'assign a local variable in a method argument' do
|
6
|
-
code = 'puts(number = 10)'
|
7
|
-
defs = build_definitions(code)
|
8
|
-
value = defs.lookup(:lvar, 'number').value
|
9
|
-
|
10
|
-
value.type.should == :int
|
11
|
-
value.value.should == 10
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'constants and local variables' do
|
5
|
-
# https://github.com/YorickPeterse/ruby-lint/issues/60
|
6
|
-
example 'access a constant path using a local variable' do
|
7
|
-
code = <<-CODE
|
8
|
-
module Example
|
9
|
-
NUMBER = 10
|
10
|
-
end
|
11
|
-
|
12
|
-
const = Example
|
13
|
-
string = const::NUMBER
|
14
|
-
CODE
|
15
|
-
|
16
|
-
defs = build_definitions(code)
|
17
|
-
value = defs.lookup(:lvar, 'string').value
|
18
|
-
|
19
|
-
value.type.should == :int
|
20
|
-
value.value.should == 10
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
describe 'hash assignments' do
|
5
|
-
example 'assign an empty hash' do
|
6
|
-
defs = build_definitions('numbers = {}')
|
7
|
-
value = defs.lookup(:lvar, 'numbers').value
|
8
|
-
|
9
|
-
value.type.should == :hash
|
10
|
-
value.instance?.should == true
|
11
|
-
|
12
|
-
value.has_definition?(:instance_method, 'each').should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'assign a hash with values' do
|
16
|
-
defs = build_definitions('numbers = {:one => 1, :two => 2}')
|
17
|
-
hash = defs.lookup(:lvar, 'numbers').value
|
18
|
-
members = {'one' => 1, 'two' => 2}
|
19
|
-
|
20
|
-
members.each do |name, value|
|
21
|
-
member = hash.lookup(:member, name)
|
22
|
-
|
23
|
-
member.name.should == name
|
24
|
-
member.value.type.should == :int
|
25
|
-
member.value.value.should == value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'process single key assignments' do
|
30
|
-
defs = build_definitions('numbers = {}; numbers[:one] = 1')
|
31
|
-
hash = defs.lookup(:lvar, 'numbers').value
|
32
|
-
member = hash.lookup(:member, 'one')
|
33
|
-
|
34
|
-
member.value.type.should == :int
|
35
|
-
member.value.value.should == 1
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'process key assignments using variables' do
|
39
|
-
code = <<-CODE
|
40
|
-
key = :two
|
41
|
-
numbers = {:one => 1}
|
42
|
-
numbers[key] = 2
|
43
|
-
CODE
|
44
|
-
|
45
|
-
defs = build_definitions(code)
|
46
|
-
hash = defs.lookup(:lvar, 'numbers').value
|
47
|
-
|
48
|
-
hash.lookup(:member, 'one').value.value.should == 1
|
49
|
-
hash.lookup(:member, 'two').value.value.should == 2
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Building variable definitions' do
|
4
|
-
describe 'OR assignments' do
|
5
|
-
example 'assign a non existing local variable' do
|
6
|
-
defs = build_definitions('number ||= 10')
|
7
|
-
|
8
|
-
defs.lookup(:lvar, 'number').value.value.should == 10
|
9
|
-
end
|
10
|
-
|
11
|
-
example 'not overwrite an existing variable' do
|
12
|
-
code = <<-CODE
|
13
|
-
number = 10
|
14
|
-
number ||= 20
|
15
|
-
CODE
|
16
|
-
|
17
|
-
defs = build_definitions(code)
|
18
|
-
|
19
|
-
defs.lookup(:lvar, 'number').value.value.should == 10
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'AND assignments' do
|
24
|
-
example 'not assign a non existing local variable' do
|
25
|
-
defs = build_definitions('number &&= 10')
|
26
|
-
|
27
|
-
defs.lookup(:lvar, 'number').nil?.should == true
|
28
|
-
end
|
29
|
-
|
30
|
-
example 'overwrite an existing variable' do
|
31
|
-
code = <<-CODE
|
32
|
-
number = 10
|
33
|
-
number &&= 20
|
34
|
-
CODE
|
35
|
-
|
36
|
-
defs = build_definitions(code)
|
37
|
-
|
38
|
-
defs.lookup(:lvar, 'number').value.value.should == 20
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::VirtualMachine do
|
4
|
-
context 'Range definitions' do
|
5
|
-
example 'assign an inclusive range to a variable' do
|
6
|
-
defs = build_definitions('numbers = (0..10)')
|
7
|
-
val = defs.lookup(:lvar, 'numbers').value
|
8
|
-
|
9
|
-
val.type.should == :irange
|
10
|
-
val.ruby_class.should == 'Range'
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'assign an exclusive range to a variable' do
|
14
|
-
defs = build_definitions('numbers = (0...10)')
|
15
|
-
val = defs.lookup(:lvar, 'numbers').value
|
16
|
-
|
17
|
-
val.type.should == :erange
|
18
|
-
val.ruby_class.should == 'Range'
|
19
|
-
end
|
20
|
-
|
21
|
-
example 'associate a Range with the correct built-in definition' do
|
22
|
-
defs = build_definitions('numbers = (0...10)')
|
23
|
-
val = defs.lookup(:lvar, 'numbers').value
|
24
|
-
|
25
|
-
val.has_definition?(:instance_method, 'cover?').should == true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|