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::AST::Node do
|
4
|
-
example 'return the value for a scalar' do
|
5
|
-
s(:str, 'hello').children[0].should == 'hello'
|
6
|
-
end
|
7
|
-
|
8
|
-
example 'return the value for an Array' do
|
9
|
-
numbers = s(:array, s(:int, 10), s(:int, 20)).children
|
10
|
-
|
11
|
-
numbers.is_a?(Array).should == true
|
12
|
-
numbers.length.should == 2
|
13
|
-
|
14
|
-
numbers[0].children[0].should == 10
|
15
|
-
numbers[1].children[0].should == 20
|
16
|
-
end
|
17
|
-
|
18
|
-
example 'return the value for a Hash' do
|
19
|
-
pairs = s(:hash, s(:pair, s(:str, 'number'), s(:int, 10))).children
|
20
|
-
|
21
|
-
pairs.is_a?(Array).should == true
|
22
|
-
|
23
|
-
pairs[0].children[1].children[0].should == 10
|
24
|
-
end
|
25
|
-
|
26
|
-
example 'should try to guess the Ruby class of a node' do
|
27
|
-
s(:str, 'foo').ruby_class.should == 'String'
|
28
|
-
end
|
29
|
-
|
30
|
-
example 'check if a node is a constant path' do
|
31
|
-
s(:const, s(:const, nil, :A), :B).constant_path?.should == true
|
32
|
-
end
|
33
|
-
|
34
|
-
example 'inspect a node using #inspect_oneline' do
|
35
|
-
output = '(const (const nil :A) :B)'
|
36
|
-
|
37
|
-
s(:const, s(:const, nil, :A), :B).inspect_oneline.should == output
|
38
|
-
end
|
39
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::CacheEntry do
|
4
|
-
before do
|
5
|
-
@tempfile = Tempfile.new('ruby-lint')
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
File.unlink(@tempfile)
|
10
|
-
end
|
11
|
-
|
12
|
-
example 'should validate the file modification times' do
|
13
|
-
mtimes = {@tempfile.path => @tempfile.mtime}
|
14
|
-
entry = RubyLint::CacheEntry.new(nil, nil, mtimes)
|
15
|
-
|
16
|
-
entry.valid?.should == true
|
17
|
-
|
18
|
-
@tempfile.write('hello')
|
19
|
-
|
20
|
-
# Bit of a hack to ensure that we don't have to use sleep()
|
21
|
-
entry.mtimes[@tempfile.path] = @tempfile.mtime - 10
|
22
|
-
|
23
|
-
entry.valid?.should == false
|
24
|
-
end
|
25
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Cache do
|
4
|
-
before do
|
5
|
-
@directory = Dir.mktmpdir('ruby-lint')
|
6
|
-
@cache = RubyLint::Cache.new(@directory)
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
FileUtils.rm_rf(@directory)
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'create the cache directory' do
|
14
|
-
directory = Dir::Tmpname.create('ruby-lint') { |name| name }
|
15
|
-
cache = RubyLint::Cache.new(directory)
|
16
|
-
|
17
|
-
File.directory?(directory).should == false
|
18
|
-
|
19
|
-
cache.create_directory!
|
20
|
-
|
21
|
-
File.directory?(directory).should == true
|
22
|
-
|
23
|
-
FileUtils.rm_rf(directory)
|
24
|
-
end
|
25
|
-
|
26
|
-
example 'set and get a cache entry' do
|
27
|
-
value = 20
|
28
|
-
|
29
|
-
@cache.set('example', value)
|
30
|
-
|
31
|
-
@cache.get('example').should == value
|
32
|
-
end
|
33
|
-
|
34
|
-
example 'check if a cache entry exists' do
|
35
|
-
@cache.exists?('example').should == false
|
36
|
-
|
37
|
-
@cache.set('example', 20)
|
38
|
-
|
39
|
-
@cache.exists?('example').should == true
|
40
|
-
end
|
41
|
-
|
42
|
-
example 'return nothing if a cache entry does not exist' do
|
43
|
-
@cache.get('foo').nil?.should == true
|
44
|
-
end
|
45
|
-
|
46
|
-
example 'remove a cache entry' do
|
47
|
-
@cache.set('example', 20)
|
48
|
-
|
49
|
-
@cache.exists?('example').should == true
|
50
|
-
@cache.delete('example')
|
51
|
-
@cache.exists?('example').should == false
|
52
|
-
end
|
53
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require File.expand_path('../../../../lib/ruby-lint/cli', __FILE__)
|
3
|
-
|
4
|
-
describe RubyLint::CLI do
|
5
|
-
describe 'analyze' do
|
6
|
-
before do
|
7
|
-
@command = RubyLint::CLI.options.commands['analyze']
|
8
|
-
@output = StringIO.new
|
9
|
-
|
10
|
-
@command.output_destination = @output
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'analyze a valid Ruby file' do
|
14
|
-
file = fixture_path('valid.rb')
|
15
|
-
|
16
|
-
@command.parse([file])
|
17
|
-
|
18
|
-
@output.rewind
|
19
|
-
@output.read.empty?.should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'analyze an invalid Ruby file' do
|
23
|
-
file = fixture_path('invalid.rb')
|
24
|
-
|
25
|
-
@command.parse([file])
|
26
|
-
|
27
|
-
@output.rewind
|
28
|
-
@output.read.should =~ /undefined method foobar/
|
29
|
-
end
|
30
|
-
|
31
|
-
example 'include benchmarking output' do
|
32
|
-
@command.parse(['-b', fixture_path('valid.rb')])
|
33
|
-
|
34
|
-
@output.rewind
|
35
|
-
|
36
|
-
output = @output.read
|
37
|
-
|
38
|
-
output.should =~ /Execution time:/
|
39
|
-
output.should =~ /Memory usage:/
|
40
|
-
end
|
41
|
-
|
42
|
-
example 'run analysis on an entire directory' do
|
43
|
-
@command.parse([fixture_path('deeply')])
|
44
|
-
|
45
|
-
@output.rewind
|
46
|
-
|
47
|
-
output = @output.read
|
48
|
-
|
49
|
-
output.should =~ /undefined method foobar/
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Configuration do
|
4
|
-
context 'default options' do
|
5
|
-
before do
|
6
|
-
@configuration = RubyLint::Configuration.new
|
7
|
-
end
|
8
|
-
|
9
|
-
example 'set the default report levels' do
|
10
|
-
@configuration.report_levels.should == RubyLint::Report::DEFAULT_LEVELS
|
11
|
-
end
|
12
|
-
|
13
|
-
example 'set the default presenter' do
|
14
|
-
@configuration.default_presenter.should == RubyLint::Presenter::Text
|
15
|
-
end
|
16
|
-
|
17
|
-
example 'set the default analysis classes' do
|
18
|
-
@configuration.default_analysis_classes.empty?.should == false
|
19
|
-
end
|
20
|
-
|
21
|
-
example 'set the default debug mode' do
|
22
|
-
@configuration.debug.should == false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'empty and invalid arguments' do
|
27
|
-
before do
|
28
|
-
@configuration = RubyLint::Configuration.new
|
29
|
-
end
|
30
|
-
|
31
|
-
example 'set the report levels' do
|
32
|
-
@configuration.report_levels = []
|
33
|
-
|
34
|
-
@configuration.report_levels
|
35
|
-
.should == @configuration.default_report_levels
|
36
|
-
end
|
37
|
-
|
38
|
-
example 'set an invalid presenter' do
|
39
|
-
blk = lambda { @configuration.presenter = String }
|
40
|
-
|
41
|
-
blk.should raise_error(ArgumentError, /Invalid presenter/)
|
42
|
-
end
|
43
|
-
|
44
|
-
example 'set the analysis classes' do
|
45
|
-
@configuration.analysis_classes = []
|
46
|
-
|
47
|
-
@configuration.analysis_classes
|
48
|
-
.should == @configuration.default_analysis_classes
|
49
|
-
end
|
50
|
-
|
51
|
-
example 'set an invalid directory' do
|
52
|
-
blk = lambda do
|
53
|
-
@configuration.directories = ['idoubtthisdirectoryexists']
|
54
|
-
end
|
55
|
-
|
56
|
-
blk.should raise_error(ArgumentError, /does not exist/)
|
57
|
-
end
|
58
|
-
|
59
|
-
example 'setting the directories to nil' do
|
60
|
-
@configuration.directories = nil
|
61
|
-
|
62
|
-
@configuration.directories.should == []
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'setting options via the constructor' do
|
67
|
-
example 'set the report levels' do
|
68
|
-
conf = RubyLint::Configuration.new(:report_levels => ['info'])
|
69
|
-
|
70
|
-
conf.report_levels.should == [:info]
|
71
|
-
end
|
72
|
-
|
73
|
-
example 'set the presenter' do
|
74
|
-
conf = RubyLint::Configuration.new(:presenter => 'json')
|
75
|
-
|
76
|
-
conf.presenter.should == RubyLint::Presenter::JSON
|
77
|
-
end
|
78
|
-
|
79
|
-
example 'set the analysis classes' do
|
80
|
-
conf = RubyLint::Configuration.new(
|
81
|
-
:analysis_classes => ['undefined_methods']
|
82
|
-
)
|
83
|
-
|
84
|
-
conf.analysis_classes.should == [RubyLint::Analysis::UndefinedMethods]
|
85
|
-
end
|
86
|
-
|
87
|
-
example 'set the debug mode' do
|
88
|
-
conf = RubyLint::Configuration.new(:debug => true)
|
89
|
-
|
90
|
-
conf.debug.should == true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'setting options directly' do
|
95
|
-
before do
|
96
|
-
@configuration = RubyLint::Configuration.new
|
97
|
-
end
|
98
|
-
|
99
|
-
example 'expand the directories set' do
|
100
|
-
@configuration.directories = ['lib']
|
101
|
-
|
102
|
-
@configuration.directories.should == [
|
103
|
-
File.expand_path('lib')
|
104
|
-
]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'setting options via a configuration file' do
|
109
|
-
example 'set the options from a YAML file' do
|
110
|
-
paths = [fixture_path('config.yml')]
|
111
|
-
conf = RubyLint::Configuration.load_from_file(paths)
|
112
|
-
|
113
|
-
conf.report_levels.should == [:info]
|
114
|
-
conf.analysis_classes.should == [RubyLint::Analysis::UndefinedMethods]
|
115
|
-
conf.presenter.should == RubyLint::Presenter::JSON
|
116
|
-
end
|
117
|
-
|
118
|
-
example 'return a default configuration file' do
|
119
|
-
conf = RubyLint::Configuration.load_from_file([])
|
120
|
-
|
121
|
-
conf.is_a?(RubyLint::Configuration).should == true
|
122
|
-
|
123
|
-
conf.report_levels.should == RubyLint::Report::DEFAULT_LEVELS
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::ConstantLoader do
|
4
|
-
before do
|
5
|
-
@definitions = ruby_object.new
|
6
|
-
@loader = RubyLint::ConstantLoader.new(:definitions => @definitions)
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'bootstrapping definitions' do
|
10
|
-
before do
|
11
|
-
@loader.bootstrap
|
12
|
-
end
|
13
|
-
|
14
|
-
example 'bootstrap Module' do
|
15
|
-
@definitions.has_definition?(:const, 'Module').should == true
|
16
|
-
end
|
17
|
-
|
18
|
-
example 'bootstrap Fixnum' do
|
19
|
-
@definitions.has_definition?(:const, 'Fixnum').should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
example 'bootstrap global variables' do
|
23
|
-
@definitions.has_definition?(:gvar, '$LOAD_PATH').should == true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'loading constants' do
|
28
|
-
before do
|
29
|
-
@loader.load_constant('PP')
|
30
|
-
end
|
31
|
-
|
32
|
-
example 'mark bootstrapped constants as loaded' do
|
33
|
-
@loader.bootstrap
|
34
|
-
@loader.loaded?('Module').should == true
|
35
|
-
end
|
36
|
-
|
37
|
-
example 'load a constant' do
|
38
|
-
@loader.loaded?('PP').should == true
|
39
|
-
end
|
40
|
-
|
41
|
-
example 'apply a constant to a definition' do
|
42
|
-
@definitions.has_definition?(:const, 'PP').should == true
|
43
|
-
end
|
44
|
-
|
45
|
-
example 'update the registry' do
|
46
|
-
@loader.registry.include?('PP').should == true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'dealing with case sensitivity' do
|
51
|
-
before do
|
52
|
-
@loader.bootstrap
|
53
|
-
end
|
54
|
-
|
55
|
-
example 'do not raise when loading process.rb for the PROCESS constant' do
|
56
|
-
block = lambda { @loader.load_constant('PROCESS') }
|
57
|
-
|
58
|
-
block.should_not raise_error
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'iterating over an AST' do
|
63
|
-
before do
|
64
|
-
@ast = s(:root, s(:const, nil, 'PP'))
|
65
|
-
end
|
66
|
-
|
67
|
-
example 'load a constant' do
|
68
|
-
@loader.run([@ast])
|
69
|
-
@loader.loaded?('PP').should == true
|
70
|
-
end
|
71
|
-
|
72
|
-
example 'call the correct callbacks' do
|
73
|
-
@loader.should_receive(:on_const)
|
74
|
-
.with(an_instance_of(RubyLint::AST::Node))
|
75
|
-
|
76
|
-
@loader.run([@ast])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::ConstantPath do
|
4
|
-
context 'resolving definitions' do
|
5
|
-
before :all do
|
6
|
-
@scope = ruby_object.new(:type => :const, :name => 'Example')
|
7
|
-
@foo = @scope.define_constant('Foo')
|
8
|
-
@bar = @foo.define_constant('Bar')
|
9
|
-
|
10
|
-
lvar = ruby_object.new(
|
11
|
-
:type => :lvar,
|
12
|
-
:name => 'example',
|
13
|
-
:value => @foo
|
14
|
-
)
|
15
|
-
|
16
|
-
@scope.add_definition(lvar)
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'resolve a path of purely constants' do
|
20
|
-
node = s(:const, s(:const, nil, :Foo), :Bar)
|
21
|
-
defs = RubyLint::ConstantPath.new(node).resolve(@scope)
|
22
|
-
|
23
|
-
defs.is_a?(ruby_object).should == true
|
24
|
-
|
25
|
-
defs.name.should == 'Bar'
|
26
|
-
defs.type.should == :const
|
27
|
-
end
|
28
|
-
|
29
|
-
example 'resolve a path containing a variable' do
|
30
|
-
node = s(:const, s(:lvar, :example), :Bar)
|
31
|
-
defs = RubyLint::ConstantPath.new(node).resolve(@scope)
|
32
|
-
|
33
|
-
defs.is_a?(ruby_object).should == true
|
34
|
-
|
35
|
-
defs.name.should == 'Bar'
|
36
|
-
defs.type.should == :const
|
37
|
-
end
|
38
|
-
|
39
|
-
example 'resolve a path for a constant assignment' do
|
40
|
-
node = s(:casgn, s(:const, nil, :Foo), :Bar, s(:int, 10))
|
41
|
-
defs = RubyLint::ConstantPath.new(node).resolve(@scope)
|
42
|
-
|
43
|
-
defs.is_a?(ruby_object).should == true
|
44
|
-
|
45
|
-
defs.name.should == 'Bar'
|
46
|
-
defs.type.should == :const
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
example 'return the root node of a constant path' do
|
51
|
-
node = s(:const, s(:const, nil, :Foo), :Bar)
|
52
|
-
root = RubyLint::ConstantPath.new(node).root_node
|
53
|
-
|
54
|
-
root.should == [:const, 'Foo']
|
55
|
-
end
|
56
|
-
|
57
|
-
example 'generate the name of a constant path' do
|
58
|
-
node = s(:const, s(:const, nil, :Foo), :Bar)
|
59
|
-
name = RubyLint::ConstantPath.new(node).to_s
|
60
|
-
|
61
|
-
name.should == 'Foo::Bar'
|
62
|
-
end
|
63
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RubyLint::Definition::ConstantProxy do
|
4
|
-
context 'without a registry' do
|
5
|
-
before do
|
6
|
-
@source = ruby_object.new(:name => 'global', :type => :global)
|
7
|
-
@proxy = RubyLint::Definition::ConstantProxy.new(@source, 'Foo')
|
8
|
-
end
|
9
|
-
|
10
|
-
example 'create a new constant proxy' do
|
11
|
-
@proxy.proxy_source.should == @source
|
12
|
-
@proxy.proxy_name.should == 'Foo'
|
13
|
-
end
|
14
|
-
|
15
|
-
example 'act like a RubyObject definition' do
|
16
|
-
@proxy.lookup(:const, 'Bar').nil?.should == true
|
17
|
-
end
|
18
|
-
|
19
|
-
example 'cache the definition when it exists' do
|
20
|
-
@proxy.name.nil?.should == true
|
21
|
-
@proxy.type.nil?.should == true
|
22
|
-
|
23
|
-
@proxy.lookup(:const, 'VERSION').nil?.should == true
|
24
|
-
|
25
|
-
@source.define_constant('Foo').define_constant('VERSION')
|
26
|
-
|
27
|
-
@proxy.name.should == 'Foo'
|
28
|
-
@proxy.type.should == :const
|
29
|
-
|
30
|
-
@proxy.lookup(:const, 'VERSION').is_a?(ruby_object).should == true
|
31
|
-
end
|
32
|
-
|
33
|
-
example 'delegating #inspect' do
|
34
|
-
foo = @source.define_constant('Foo')
|
35
|
-
|
36
|
-
@proxy.inspect.should == foo.inspect
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with a registry' do
|
41
|
-
before do
|
42
|
-
@source = ruby_object.new
|
43
|
-
@registry = RubyLint::Definition::Registry.new
|
44
|
-
|
45
|
-
@proxy = RubyLint::Definition::ConstantProxy
|
46
|
-
.new(@source, 'Foo', @registry)
|
47
|
-
end
|
48
|
-
|
49
|
-
example 'do not load anything when the registry is empty' do
|
50
|
-
@proxy.lookup(:const, 'Foo').nil?.should == true
|
51
|
-
end
|
52
|
-
|
53
|
-
example 'autoload a definition when possible' do
|
54
|
-
@registry.register('Foo') { |defs| defs.define_constant('Foo') }
|
55
|
-
|
56
|
-
@proxy.lookup(:const, 'Foo').is_a?(ruby_object).should == true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'loading definitions automatically' do
|
61
|
-
before do
|
62
|
-
@source = ruby_object.new
|
63
|
-
@registry = RubyLint::Definition::Registry.new
|
64
|
-
|
65
|
-
@proxy = RubyLint::Definition::ConstantProxy
|
66
|
-
.new(@source, 'ActionController', @registry)
|
67
|
-
end
|
68
|
-
|
69
|
-
example 'load a definition from the filesystem' do
|
70
|
-
@registry.should_receive(:load).with('ActionController')
|
71
|
-
|
72
|
-
@proxy.lookup(:const, 'Foo')
|
73
|
-
end
|
74
|
-
|
75
|
-
example 'do not load the definition when it is already loaded' do
|
76
|
-
@registry.should_not receive(:load)
|
77
|
-
|
78
|
-
@registry.register('ActionController') do |defs|
|
79
|
-
defs.define_constant('ActionController')
|
80
|
-
end
|
81
|
-
|
82
|
-
@proxy.lookup(:const, 'Foo')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|