ruby-lint 0.0.1a → 0.0.1a1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/MANIFEST +65 -62
- data/README.md +114 -13
- data/bin/ruby-lint +6 -0
- data/lib/ruby-lint.rb +36 -0
- data/lib/{rlint → ruby-lint}/analyze/coding_style.rb +32 -32
- data/lib/{rlint → ruby-lint}/analyze/definitions.rb +13 -13
- data/lib/{rlint → ruby-lint}/analyze/method_validation.rb +5 -5
- data/lib/{rlint → ruby-lint}/analyze/shadowing_variables.rb +5 -5
- data/lib/{rlint → ruby-lint}/analyze/undefined_variables.rb +7 -7
- data/lib/{rlint → ruby-lint}/analyze/unused_variables.rb +6 -6
- data/lib/{rlint → ruby-lint}/callback.rb +11 -11
- data/lib/{rlint → ruby-lint}/cli.rb +17 -17
- data/lib/{rlint → ruby-lint}/constant_importer.rb +18 -8
- data/lib/{rlint → ruby-lint}/definition.rb +10 -10
- data/lib/{rlint → ruby-lint}/formatter/text.rb +6 -6
- data/lib/{rlint → ruby-lint}/helper/definition_resolver.rb +11 -11
- data/lib/{rlint → ruby-lint}/helper/scoping.rb +14 -14
- data/lib/{rlint → ruby-lint}/iterator.rb +22 -22
- data/lib/{rlint → ruby-lint}/options.rb +9 -9
- data/lib/{rlint → ruby-lint}/parser.rb +111 -111
- data/lib/{rlint → ruby-lint}/parser_error.rb +3 -3
- data/lib/{rlint → ruby-lint}/report.rb +8 -8
- data/lib/{rlint → ruby-lint}/token/assignment_token.rb +4 -4
- data/lib/{rlint → ruby-lint}/token/begin_rescue_token.rb +7 -7
- data/lib/{rlint → ruby-lint}/token/block_token.rb +12 -3
- data/lib/{rlint → ruby-lint}/token/case_token.rb +5 -5
- data/lib/{rlint → ruby-lint}/token/class_token.rb +3 -3
- data/lib/{rlint → ruby-lint}/token/method_definition_token.rb +8 -8
- data/lib/{rlint → ruby-lint}/token/method_token.rb +9 -7
- data/lib/{rlint → ruby-lint}/token/parameters_token.rb +6 -6
- data/lib/{rlint → ruby-lint}/token/regexp_token.rb +2 -2
- data/lib/{rlint → ruby-lint}/token/statement_token.rb +6 -6
- data/lib/{rlint → ruby-lint}/token/token.rb +8 -6
- data/lib/{rlint → ruby-lint}/token/variable_token.rb +3 -3
- data/lib/ruby-lint/version.rb +3 -0
- data/ruby-lint.gemspec +5 -5
- data/spec/benchmarks/memory.rb +7 -7
- data/spec/benchmarks/parse_parser.rb +5 -5
- data/spec/fixtures/stdlib/un.rb +348 -0
- data/spec/helper.rb +3 -1
- data/spec/{rlint → ruby-lint}/analyze/coding_style.rb +30 -30
- data/spec/ruby-lint/analyze/complex/un.rb +29 -0
- data/spec/{rlint → ruby-lint}/analyze/definitions/classes.rb +25 -25
- data/spec/{rlint → ruby-lint}/analyze/definitions/methods.rb +22 -22
- data/spec/{rlint → ruby-lint}/analyze/definitions/modules.rb +42 -42
- data/spec/{rlint → ruby-lint}/analyze/definitions/variables.rb +27 -27
- data/spec/{rlint → ruby-lint}/analyze/method_validation.rb +31 -31
- data/spec/{rlint → ruby-lint}/analyze/shadowing_variables.rb +6 -6
- data/spec/{rlint → ruby-lint}/analyze/undefined_variables.rb +37 -37
- data/spec/{rlint → ruby-lint}/analyze/unused_variables.rb +21 -21
- data/spec/{rlint → ruby-lint}/callback.rb +7 -7
- data/spec/{rlint → ruby-lint}/constant_importer.rb +6 -6
- data/spec/{rlint → ruby-lint}/definition.rb +25 -25
- data/spec/{rlint → ruby-lint}/formatter/text.rb +4 -4
- data/spec/{rlint → ruby-lint}/iterator.rb +38 -38
- data/spec/{rlint → ruby-lint}/parser/arrays.rb +28 -28
- data/spec/{rlint → ruby-lint}/parser/classes.rb +23 -23
- data/spec/{rlint → ruby-lint}/parser/errors.rb +4 -4
- data/spec/{rlint → ruby-lint}/parser/hashes.rb +24 -24
- data/spec/{rlint → ruby-lint}/parser/methods.rb +50 -50
- data/spec/{rlint → ruby-lint}/parser/modules.rb +8 -8
- data/spec/{rlint → ruby-lint}/parser/objects.rb +8 -8
- data/spec/{rlint → ruby-lint}/parser/operators.rb +14 -14
- data/spec/{rlint → ruby-lint}/parser/procs.rb +26 -26
- data/spec/{rlint → ruby-lint}/parser/ranges.rb +9 -9
- data/spec/{rlint → ruby-lint}/parser/regexp.rb +5 -5
- data/spec/{rlint → ruby-lint}/parser/scalars.rb +17 -17
- data/spec/{rlint → ruby-lint}/parser/statements.rb +94 -94
- data/spec/{rlint → ruby-lint}/parser/variables.rb +37 -37
- data/spec/{rlint → ruby-lint}/report.rb +4 -4
- data/task/manifest.rake +8 -0
- data/task/test.rake +1 -1
- metadata +69 -66
- data/bin/rlint +0 -6
- data/lib/rlint.rb +0 -36
- data/lib/rlint/version.rb +0 -3
data/spec/helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Analyze::CodingStyle' do
|
4
4
|
it 'Check the casing of method names and variables' do
|
5
5
|
code = <<-CODE
|
6
6
|
def getNumber(theNumber = 10)
|
@@ -10,11 +10,11 @@ def getNumber(theNumber = 10)
|
|
10
10
|
end
|
11
11
|
CODE
|
12
12
|
|
13
|
-
tokens =
|
14
|
-
report =
|
15
|
-
iterator =
|
13
|
+
tokens = RubyLint::Parser.new(code).parse
|
14
|
+
report = RubyLint::Report.new
|
15
|
+
iterator = RubyLint::Iterator.new(report)
|
16
16
|
|
17
|
-
iterator.bind(
|
17
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
18
18
|
iterator.run(tokens)
|
19
19
|
|
20
20
|
messages = report.messages[:info]
|
@@ -51,16 +51,16 @@ this_variable_is_fine = 10
|
|
51
51
|
THIS_CONSTANT_NAME_IS_WAY_TOO_LONG = 10
|
52
52
|
CODE
|
53
53
|
|
54
|
-
tokens =
|
55
|
-
report =
|
56
|
-
iterator =
|
54
|
+
tokens = RubyLint::Parser.new(code).parse
|
55
|
+
report = RubyLint::Report.new
|
56
|
+
iterator = RubyLint::Iterator.new(report)
|
57
57
|
|
58
|
-
iterator.bind(
|
58
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
59
59
|
iterator.run(tokens)
|
60
60
|
|
61
61
|
messages = report.messages[:info]
|
62
62
|
message = "method and variable names should not be longer than " \
|
63
|
-
"#{
|
63
|
+
"#{RubyLint::Analyze::CodingStyle::MAXIMUM_NAME_LENGTH} characters"
|
64
64
|
|
65
65
|
messages[0][:message].should == message
|
66
66
|
messages[0][:line].should == 1
|
@@ -76,11 +76,11 @@ THIS_CONSTANT_NAME_IS_WAY_TOO_LONG = 10
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'Check for the use of class variables' do
|
79
|
-
tokens =
|
80
|
-
report =
|
81
|
-
iterator =
|
79
|
+
tokens = RubyLint::Parser.new('@@number = 10').parse
|
80
|
+
report = RubyLint::Report.new
|
81
|
+
iterator = RubyLint::Iterator.new(report)
|
82
82
|
|
83
|
-
iterator.bind(
|
83
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
84
84
|
iterator.run(tokens)
|
85
85
|
|
86
86
|
info = report.messages[:info][0]
|
@@ -118,11 +118,11 @@ unless ( foobar )
|
|
118
118
|
end
|
119
119
|
CODE
|
120
120
|
|
121
|
-
tokens =
|
122
|
-
report =
|
123
|
-
iterator =
|
121
|
+
tokens = RubyLint::Parser.new(code).parse
|
122
|
+
report = RubyLint::Report.new
|
123
|
+
iterator = RubyLint::Iterator.new(report)
|
124
124
|
|
125
|
-
iterator.bind(
|
125
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
126
126
|
iterator.run(tokens)
|
127
127
|
|
128
128
|
report.messages[:info].class.should == Array
|
@@ -148,11 +148,11 @@ def valid_name?
|
|
148
148
|
end
|
149
149
|
CODE
|
150
150
|
|
151
|
-
tokens =
|
152
|
-
report =
|
153
|
-
iterator =
|
151
|
+
tokens = RubyLint::Parser.new(code).parse
|
152
|
+
report = RubyLint::Report.new
|
153
|
+
iterator = RubyLint::Iterator.new(report)
|
154
154
|
|
155
|
-
iterator.bind(
|
155
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
156
156
|
iterator.run(tokens)
|
157
157
|
|
158
158
|
message = 'predicate methods should end with a question mark'
|
@@ -171,11 +171,11 @@ end
|
|
171
171
|
[].map { |a| }
|
172
172
|
CODE
|
173
173
|
|
174
|
-
tokens =
|
175
|
-
report =
|
176
|
-
iterator =
|
174
|
+
tokens = RubyLint::Parser.new(code).parse
|
175
|
+
report = RubyLint::Report.new
|
176
|
+
iterator = RubyLint::Iterator.new(report)
|
177
177
|
|
178
|
-
iterator.bind(
|
178
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
179
179
|
iterator.run(tokens)
|
180
180
|
|
181
181
|
message = 'it is recommended to use the method "map" instead of "collect"'
|
@@ -201,11 +201,11 @@ def String.class_method
|
|
201
201
|
end
|
202
202
|
CODE
|
203
203
|
|
204
|
-
tokens =
|
205
|
-
report =
|
206
|
-
iterator =
|
204
|
+
tokens = RubyLint::Parser.new(code).parse
|
205
|
+
report = RubyLint::Report.new
|
206
|
+
iterator = RubyLint::Iterator.new(report)
|
207
207
|
|
208
|
-
iterator.bind(
|
208
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
209
209
|
iterator.run(tokens)
|
210
210
|
|
211
211
|
report.messages[:warning].class.should == Array
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../../../../helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'Complex code analysis' do
|
4
|
+
it 'Analyze fixtures/stdlib/un.rb' do
|
5
|
+
code = File.read(File.join(RubyLint::FIXTURES, 'stdlib/un.rb'))
|
6
|
+
tokens = RubyLint::Parser.new(code).parse
|
7
|
+
iterator = RubyLint::Iterator.new
|
8
|
+
|
9
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
10
|
+
iterator.bind(RubyLint::Analyze::CodingStyle)
|
11
|
+
iterator.bind(RubyLint::Analyze::MethodValidation)
|
12
|
+
iterator.bind(RubyLint::Analyze::ShadowingVariables)
|
13
|
+
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
14
|
+
iterator.bind(RubyLint::Analyze::UnusedVariables)
|
15
|
+
iterator.run(tokens)
|
16
|
+
|
17
|
+
scope = iterator.storage[:scope]
|
18
|
+
methods = %w{setup cp ln mv rm mkdir rmdir install chmod
|
19
|
+
touch wait_writable mkmf httpd help}
|
20
|
+
|
21
|
+
scope.class.should == RubyLint::Definition
|
22
|
+
|
23
|
+
scope.lookup(:constant, 'FileUtils').class.should == RubyLint::Definition
|
24
|
+
|
25
|
+
methods.each do |method|
|
26
|
+
scope.lookup(:instance_method, method).class.should == RubyLint::Definition
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Analyze::Definitions: classes' do
|
4
4
|
it 'Define a class in the global scope' do
|
5
5
|
code = <<-CODE
|
6
6
|
class Example
|
@@ -10,18 +10,18 @@ class Example
|
|
10
10
|
end
|
11
11
|
CODE
|
12
12
|
|
13
|
-
tokens =
|
14
|
-
iterator =
|
13
|
+
tokens = RubyLint::Parser.new(code).parse
|
14
|
+
iterator = RubyLint::Iterator.new
|
15
15
|
|
16
|
-
iterator.bind(
|
16
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
17
17
|
iterator.run(tokens)
|
18
18
|
|
19
19
|
scope = iterator.storage[:scope]
|
20
20
|
const = scope.lookup(:constant, 'Example')
|
21
21
|
|
22
|
-
const.class.should ==
|
22
|
+
const.class.should == RubyLint::Definition
|
23
23
|
|
24
|
-
const.token.class.should ==
|
24
|
+
const.token.class.should == RubyLint::Token::ClassToken
|
25
25
|
const.token.name.should == ['Example']
|
26
26
|
const.token.value.nil?.should == true
|
27
27
|
|
@@ -30,9 +30,9 @@ end
|
|
30
30
|
|
31
31
|
method = const.lookup(:instance_method, 'example_method')
|
32
32
|
|
33
|
-
method.class.should ==
|
33
|
+
method.class.should == RubyLint::Definition
|
34
34
|
|
35
|
-
method.token.class.should ==
|
35
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
36
36
|
method.token.name.should == 'example_method'
|
37
37
|
end
|
38
38
|
|
@@ -45,10 +45,10 @@ class Example
|
|
45
45
|
end
|
46
46
|
CODE
|
47
47
|
|
48
|
-
tokens =
|
49
|
-
iterator =
|
48
|
+
tokens = RubyLint::Parser.new(code).parse
|
49
|
+
iterator = RubyLint::Iterator.new
|
50
50
|
|
51
|
-
iterator.bind(
|
51
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
52
52
|
iterator.run(tokens)
|
53
53
|
|
54
54
|
scope = iterator.storage[:scope]
|
@@ -57,10 +57,10 @@ end
|
|
57
57
|
|
58
58
|
const = scope.lookup(:constant, 'Example')
|
59
59
|
|
60
|
-
const.class.should ==
|
60
|
+
const.class.should == RubyLint::Definition
|
61
61
|
|
62
62
|
const.lookup(:instance_method, 'example_method').nil?.should == true
|
63
|
-
const.lookup(:method, 'example_method').class.should ==
|
63
|
+
const.lookup(:method, 'example_method').class.should == RubyLint::Definition
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'Inherit methods from a parent class' do
|
@@ -76,10 +76,10 @@ class B < A
|
|
76
76
|
end
|
77
77
|
CODE
|
78
78
|
|
79
|
-
tokens =
|
80
|
-
iterator =
|
79
|
+
tokens = RubyLint::Parser.new(code).parse
|
80
|
+
iterator = RubyLint::Iterator.new
|
81
81
|
|
82
|
-
iterator.bind(
|
82
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
83
83
|
iterator.run(tokens)
|
84
84
|
|
85
85
|
scope = iterator.storage[:scope]
|
@@ -88,27 +88,27 @@ end
|
|
88
88
|
b = scope.lookup(:constant, 'B')
|
89
89
|
|
90
90
|
# check class A
|
91
|
-
a.class.should ==
|
91
|
+
a.class.should == RubyLint::Definition
|
92
92
|
|
93
|
-
a.token.class.should ==
|
93
|
+
a.token.class.should == RubyLint::Token::ClassToken
|
94
94
|
a.token.name.should == ['A']
|
95
95
|
a.token.parent.should == ['Object']
|
96
96
|
|
97
|
-
a.lookup(:method, :methods).class.should ==
|
98
|
-
a.lookup(:instance_method, :methods).class.should ==
|
97
|
+
a.lookup(:method, :methods).class.should == RubyLint::Definition
|
98
|
+
a.lookup(:instance_method, :methods).class.should == RubyLint::Definition
|
99
99
|
|
100
100
|
# check class B
|
101
|
-
b.class.should ==
|
101
|
+
b.class.should == RubyLint::Definition
|
102
102
|
|
103
|
-
b.token.class.should ==
|
103
|
+
b.token.class.should == RubyLint::Token::ClassToken
|
104
104
|
b.token.name.should == ['B']
|
105
105
|
b.token.parent.should == ['A']
|
106
106
|
|
107
107
|
b.lookup(:instance_method, 'parent_method') \
|
108
108
|
.class \
|
109
|
-
.should ==
|
109
|
+
.should == RubyLint::Definition
|
110
110
|
|
111
|
-
b.lookup(:method, :methods).class.should ==
|
112
|
-
b.lookup(:instance_method, :methods).class.should ==
|
111
|
+
b.lookup(:method, :methods).class.should == RubyLint::Definition
|
112
|
+
b.lookup(:instance_method, :methods).class.should == RubyLint::Definition
|
113
113
|
end
|
114
114
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Analyze::Definitions: methods' do
|
4
4
|
it 'Build a list of globally defined methods' do
|
5
5
|
code = <<-CODE
|
6
6
|
def example_method
|
@@ -12,25 +12,25 @@ def another_example_method
|
|
12
12
|
end
|
13
13
|
CODE
|
14
14
|
|
15
|
-
tokens =
|
16
|
-
iterator =
|
15
|
+
tokens = RubyLint::Parser.new(code).parse
|
16
|
+
iterator = RubyLint::Iterator.new
|
17
17
|
|
18
|
-
iterator.bind(
|
18
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
19
19
|
iterator.run(tokens)
|
20
20
|
|
21
21
|
scope = iterator.storage[:scope]
|
22
22
|
|
23
|
-
scope.class.should ==
|
23
|
+
scope.class.should == RubyLint::Definition
|
24
24
|
|
25
25
|
method_1 = scope.lookup(:instance_method, 'example_method')
|
26
26
|
method_2 = scope.lookup(:instance_method, 'another_example_method')
|
27
27
|
|
28
|
-
method_1.class.should ==
|
29
|
-
method_1.token.class.should ==
|
28
|
+
method_1.class.should == RubyLint::Definition
|
29
|
+
method_1.token.class.should == RubyLint::Token::MethodDefinitionToken
|
30
30
|
method_1.token.name.should == 'example_method'
|
31
31
|
|
32
|
-
method_2.class.should ==
|
33
|
-
method_2.token.class.should ==
|
32
|
+
method_2.class.should == RubyLint::Definition
|
33
|
+
method_2.token.class.should == RubyLint::Token::MethodDefinitionToken
|
34
34
|
method_2.token.name.should == 'another_example_method'
|
35
35
|
end
|
36
36
|
|
@@ -41,20 +41,20 @@ def self.example_method
|
|
41
41
|
end
|
42
42
|
CODE
|
43
43
|
|
44
|
-
tokens =
|
45
|
-
iterator =
|
44
|
+
tokens = RubyLint::Parser.new(code).parse
|
45
|
+
iterator = RubyLint::Iterator.new
|
46
46
|
|
47
|
-
iterator.bind(
|
47
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
48
48
|
iterator.run(tokens)
|
49
49
|
|
50
50
|
scope = iterator.storage[:scope]
|
51
51
|
|
52
|
-
scope.class.should ==
|
52
|
+
scope.class.should == RubyLint::Definition
|
53
53
|
|
54
54
|
method = scope.lookup(:method, 'example_method')
|
55
55
|
|
56
|
-
method.class.should ==
|
57
|
-
method.token.class.should ==
|
56
|
+
method.class.should == RubyLint::Definition
|
57
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
58
58
|
method.token.name.should == 'example_method'
|
59
59
|
end
|
60
60
|
|
@@ -65,27 +65,27 @@ def String.example_method
|
|
65
65
|
end
|
66
66
|
CODE
|
67
67
|
|
68
|
-
tokens =
|
69
|
-
iterator =
|
68
|
+
tokens = RubyLint::Parser.new(code).parse
|
69
|
+
iterator = RubyLint::Iterator.new
|
70
70
|
|
71
|
-
iterator.bind(
|
71
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
72
72
|
iterator.run(tokens)
|
73
73
|
|
74
74
|
scope = iterator.storage[:scope]
|
75
75
|
|
76
|
-
scope.class.should ==
|
76
|
+
scope.class.should == RubyLint::Definition
|
77
77
|
|
78
78
|
scope.lookup(:instance_method, 'example_method').nil?.should == true
|
79
79
|
scope.lookup(:method, 'example_method').nil?.should == true
|
80
80
|
|
81
81
|
string = scope.lookup(:constant, 'String')
|
82
82
|
|
83
|
-
string.class.should ==
|
83
|
+
string.class.should == RubyLint::Definition
|
84
84
|
|
85
85
|
method = string.lookup(:method, 'example_method')
|
86
86
|
|
87
|
-
method.class.should ==
|
88
|
-
method.token.class.should ==
|
87
|
+
method.class.should == RubyLint::Definition
|
88
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
89
89
|
method.token.name.should == 'example_method'
|
90
90
|
end
|
91
91
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Analyze::Definitions: modules' do
|
4
4
|
it 'Define a module in the global scope' do
|
5
5
|
code = <<-CODE
|
6
6
|
module Example
|
@@ -10,18 +10,18 @@ module Example
|
|
10
10
|
end
|
11
11
|
CODE
|
12
12
|
|
13
|
-
tokens =
|
14
|
-
iterator =
|
13
|
+
tokens = RubyLint::Parser.new(code).parse
|
14
|
+
iterator = RubyLint::Iterator.new
|
15
15
|
|
16
|
-
iterator.bind(
|
16
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
17
17
|
iterator.run(tokens)
|
18
18
|
|
19
19
|
scope = iterator.storage[:scope]
|
20
20
|
const = scope.lookup(:constant, 'Example')
|
21
21
|
|
22
|
-
const.class.should ==
|
22
|
+
const.class.should == RubyLint::Definition
|
23
23
|
|
24
|
-
const.token.class.should ==
|
24
|
+
const.token.class.should == RubyLint::Token::Token
|
25
25
|
const.token.type.should == :module
|
26
26
|
const.token.name.should == ['Example']
|
27
27
|
|
@@ -29,9 +29,9 @@ end
|
|
29
29
|
|
30
30
|
method = const.lookup(:instance_method, 'example_method')
|
31
31
|
|
32
|
-
method.class.should ==
|
32
|
+
method.class.should == RubyLint::Definition
|
33
33
|
|
34
|
-
method.token.class.should ==
|
34
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
35
35
|
method.token.name.should == 'example_method'
|
36
36
|
end
|
37
37
|
|
@@ -44,18 +44,18 @@ module Example
|
|
44
44
|
end
|
45
45
|
CODE
|
46
46
|
|
47
|
-
tokens =
|
48
|
-
iterator =
|
47
|
+
tokens = RubyLint::Parser.new(code).parse
|
48
|
+
iterator = RubyLint::Iterator.new
|
49
49
|
|
50
|
-
iterator.bind(
|
50
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
51
51
|
iterator.run(tokens)
|
52
52
|
|
53
53
|
scope = iterator.storage[:scope]
|
54
54
|
const = scope.lookup(:constant, 'Example')
|
55
55
|
|
56
|
-
const.class.should ==
|
56
|
+
const.class.should == RubyLint::Definition
|
57
57
|
|
58
|
-
const.token.class.should ==
|
58
|
+
const.token.class.should == RubyLint::Token::Token
|
59
59
|
const.token.type.should == :module
|
60
60
|
const.token.name.should == ['Example']
|
61
61
|
|
@@ -63,9 +63,9 @@ end
|
|
63
63
|
|
64
64
|
method = const.lookup(:method, 'example_method')
|
65
65
|
|
66
|
-
method.class.should ==
|
66
|
+
method.class.should == RubyLint::Definition
|
67
67
|
|
68
|
-
method.token.class.should ==
|
68
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
69
69
|
method.token.name.should == 'example_method'
|
70
70
|
end
|
71
71
|
|
@@ -82,24 +82,24 @@ class B
|
|
82
82
|
end
|
83
83
|
CODE
|
84
84
|
|
85
|
-
tokens =
|
86
|
-
iterator =
|
85
|
+
tokens = RubyLint::Parser.new(code).parse
|
86
|
+
iterator = RubyLint::Iterator.new
|
87
87
|
|
88
|
-
iterator.bind(
|
88
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
89
89
|
iterator.run(tokens)
|
90
90
|
|
91
91
|
scope = iterator.storage[:scope]
|
92
92
|
const = scope.lookup(:constant, 'B')
|
93
93
|
|
94
|
-
const.class.should ==
|
94
|
+
const.class.should == RubyLint::Definition
|
95
95
|
|
96
96
|
const.lookup(:method, 'example_method').nil?.should == true
|
97
97
|
|
98
98
|
method = const.lookup(:instance_method, 'example_method')
|
99
99
|
|
100
|
-
method.class.should ==
|
100
|
+
method.class.should == RubyLint::Definition
|
101
101
|
|
102
|
-
method.token.class.should ==
|
102
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
103
103
|
method.token.name.should == 'example_method'
|
104
104
|
end
|
105
105
|
|
@@ -116,24 +116,24 @@ class B
|
|
116
116
|
end
|
117
117
|
CODE
|
118
118
|
|
119
|
-
tokens =
|
120
|
-
iterator =
|
119
|
+
tokens = RubyLint::Parser.new(code).parse
|
120
|
+
iterator = RubyLint::Iterator.new
|
121
121
|
|
122
|
-
iterator.bind(
|
122
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
123
123
|
iterator.run(tokens)
|
124
124
|
|
125
125
|
scope = iterator.storage[:scope]
|
126
126
|
const = scope.lookup(:constant, 'B')
|
127
127
|
|
128
|
-
const.class.should ==
|
128
|
+
const.class.should == RubyLint::Definition
|
129
129
|
|
130
130
|
const.lookup(:instance_method, 'example_method').nil?.should == true
|
131
131
|
|
132
132
|
method = const.lookup(:method, 'example_method')
|
133
133
|
|
134
|
-
method.class.should ==
|
134
|
+
method.class.should == RubyLint::Definition
|
135
135
|
|
136
|
-
method.token.class.should ==
|
136
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
137
137
|
method.token.name.should == 'example_method'
|
138
138
|
end
|
139
139
|
|
@@ -152,55 +152,55 @@ class C
|
|
152
152
|
end
|
153
153
|
CODE
|
154
154
|
|
155
|
-
tokens =
|
156
|
-
iterator =
|
155
|
+
tokens = RubyLint::Parser.new(code).parse
|
156
|
+
iterator = RubyLint::Iterator.new
|
157
157
|
|
158
|
-
iterator.bind(
|
158
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
159
159
|
iterator.run(tokens)
|
160
160
|
|
161
161
|
scope = iterator.storage[:scope]
|
162
162
|
const = scope.lookup(:constant, 'C')
|
163
163
|
|
164
|
-
const.class.should ==
|
164
|
+
const.class.should == RubyLint::Definition
|
165
165
|
|
166
166
|
const.lookup(:method, 'example_method').nil?.should == true
|
167
167
|
|
168
168
|
method = const.lookup(:instance_method, 'example_method')
|
169
169
|
|
170
|
-
method.class.should ==
|
170
|
+
method.class.should == RubyLint::Definition
|
171
171
|
|
172
|
-
method.token.class.should ==
|
172
|
+
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
173
173
|
method.token.name.should == 'example_method'
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'Define a module in an existing module' do
|
177
177
|
code = <<-CODE
|
178
|
-
module
|
178
|
+
module RubyLint
|
179
179
|
module Derp
|
180
180
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
CODE
|
184
184
|
|
185
|
-
tokens =
|
186
|
-
iterator =
|
185
|
+
tokens = RubyLint::Parser.new(code).parse
|
186
|
+
iterator = RubyLint::Iterator.new
|
187
187
|
|
188
|
-
iterator.bind(
|
188
|
+
iterator.bind(RubyLint::Analyze::Definitions)
|
189
189
|
iterator.run(tokens)
|
190
190
|
|
191
191
|
scope = iterator.storage[:scope]
|
192
192
|
|
193
193
|
scope.lookup(:constant, 'Derp').nil?.should == true
|
194
194
|
|
195
|
-
scope.lookup(:constant, '
|
195
|
+
scope.lookup(:constant, 'RubyLint').class.should == RubyLint::Definition
|
196
196
|
|
197
|
-
scope.lookup(:constant, '
|
197
|
+
scope.lookup(:constant, 'RubyLint') \
|
198
198
|
.lookup(:constant, 'Derp') \
|
199
199
|
.class \
|
200
|
-
.should ==
|
200
|
+
.should == RubyLint::Definition
|
201
201
|
|
202
|
-
|
203
|
-
derp =
|
202
|
+
ruby_lint = scope.lookup(:constant, 'RubyLint')
|
203
|
+
derp = ruby_lint.lookup(:constant, 'Derp')
|
204
204
|
|
205
205
|
derp.parent.length.should == 1
|
206
206
|
end
|