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
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Parser' do
|
4
4
|
it 'Parse a class declaration' do
|
5
|
-
token =
|
5
|
+
token = RubyLint::Parser.new('class Foo; end').parse[0]
|
6
6
|
|
7
|
-
token.class.should ==
|
7
|
+
token.class.should == RubyLint::Token::ClassToken
|
8
8
|
token.name.should == ['Foo']
|
9
9
|
token.type.should == :class
|
10
10
|
token.line.should == 1
|
@@ -16,17 +16,17 @@ describe 'Rlint::Parser' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'Parse a top level class declaration' do
|
19
|
-
token =
|
19
|
+
token = RubyLint::Parser.new('class ::Foo; end').parse[0]
|
20
20
|
|
21
|
-
token.class.should ==
|
21
|
+
token.class.should == RubyLint::Token::ClassToken
|
22
22
|
token.name.should == ['Foo']
|
23
23
|
token.type.should == :class
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'Parse a class declaration with a parent class' do
|
27
|
-
token =
|
27
|
+
token = RubyLint::Parser.new('class Foo < Bar; end').parse[0]
|
28
28
|
|
29
|
-
token.class.should ==
|
29
|
+
token.class.should == RubyLint::Token::ClassToken
|
30
30
|
token.name.should == ['Foo']
|
31
31
|
token.parent.should == ['Bar']
|
32
32
|
token.type.should == :class
|
@@ -39,9 +39,9 @@ describe 'Rlint::Parser' do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'Parse a class declaration with multiple name segments' do
|
42
|
-
token =
|
42
|
+
token = RubyLint::Parser.new('class Foo::Bar < A::B; end').parse[0]
|
43
43
|
|
44
|
-
token.class.should ==
|
44
|
+
token.class.should == RubyLint::Token::ClassToken
|
45
45
|
token.type.should == :class
|
46
46
|
token.name.should == ['Foo', 'Bar']
|
47
47
|
|
@@ -52,9 +52,9 @@ describe 'Rlint::Parser' do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'Parse a top level class declaration with multiple name segments' do
|
55
|
-
token =
|
55
|
+
token = RubyLint::Parser.new('class ::Foo::Bar; end').parse[0]
|
56
56
|
|
57
|
-
token.class.should ==
|
57
|
+
token.class.should == RubyLint::Token::ClassToken
|
58
58
|
token.type.should == :class
|
59
59
|
token.name.should == ['Foo', 'Bar']
|
60
60
|
token.line.should == 1
|
@@ -85,29 +85,29 @@ class Second
|
|
85
85
|
end
|
86
86
|
CODE
|
87
87
|
|
88
|
-
first, pub_method, second =
|
88
|
+
first, pub_method, second = RubyLint::Parser.new(code).parse
|
89
89
|
|
90
|
-
first.class.should ==
|
90
|
+
first.class.should == RubyLint::Token::ClassToken
|
91
91
|
first.name.should == ['First']
|
92
92
|
first.line.should == 1
|
93
93
|
first.column.should == 6
|
94
94
|
first.code.should == 'class First'
|
95
95
|
|
96
|
-
first.value[0].class.should ==
|
96
|
+
first.value[0].class.should == RubyLint::Token::MethodDefinitionToken
|
97
97
|
first.value[0].name.should == 'private_method'
|
98
98
|
first.value[0].visibility.should == :private
|
99
99
|
first.value[0].line.should == 4
|
100
100
|
first.value[0].column.should == 6
|
101
101
|
first.value[0].code.should == ' def private_method'
|
102
102
|
|
103
|
-
pub_method.class.should ==
|
103
|
+
pub_method.class.should == RubyLint::Token::MethodDefinitionToken
|
104
104
|
pub_method.name.should == 'public_method'
|
105
105
|
pub_method.visibility.should == :public
|
106
106
|
|
107
|
-
second.class.should ==
|
107
|
+
second.class.should == RubyLint::Token::ClassToken
|
108
108
|
second.name.should == ['Second']
|
109
109
|
|
110
|
-
second.value[0].class.should ==
|
110
|
+
second.value[0].class.should == RubyLint::Token::MethodDefinitionToken
|
111
111
|
second.value[0].name.should == 'protected_method'
|
112
112
|
second.value[0].visibility.should == :protected
|
113
113
|
end
|
@@ -127,9 +127,9 @@ class Person
|
|
127
127
|
end
|
128
128
|
CODE
|
129
129
|
|
130
|
-
token =
|
130
|
+
token = RubyLint::Parser.new(code).parse[0]
|
131
131
|
|
132
|
-
token.class.should ==
|
132
|
+
token.class.should == RubyLint::Token::ClassToken
|
133
133
|
token.name.should == ['Person']
|
134
134
|
|
135
135
|
token.value.class.should == Array
|
@@ -137,16 +137,16 @@ end
|
|
137
137
|
|
138
138
|
method_1, method_2 = token.value
|
139
139
|
|
140
|
-
method_1.class.should ==
|
140
|
+
method_1.class.should == RubyLint::Token::MethodDefinitionToken
|
141
141
|
method_1.name.should == 'class_method_1'
|
142
142
|
|
143
|
-
method_1.receiver.class.should ==
|
143
|
+
method_1.receiver.class.should == RubyLint::Token::VariableToken
|
144
144
|
method_1.receiver.name.should == 'self'
|
145
145
|
|
146
|
-
method_2.class.should ==
|
146
|
+
method_2.class.should == RubyLint::Token::MethodDefinitionToken
|
147
147
|
method_2.name.should == 'class_method_2'
|
148
148
|
|
149
|
-
method_2.receiver.class.should ==
|
149
|
+
method_2.receiver.class.should == RubyLint::Token::VariableToken
|
150
150
|
method_2.receiver.name.should == 'self'
|
151
151
|
end
|
152
152
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Parser' do
|
4
4
|
it 'Parse a syntax error' do
|
5
5
|
code = <<-CODE
|
6
6
|
def example
|
@@ -8,11 +8,11 @@ def example
|
|
8
8
|
end
|
9
9
|
CODE
|
10
10
|
|
11
|
-
error = should.raise?(
|
12
|
-
|
11
|
+
error = should.raise?(RubyLint::ParserError) do
|
12
|
+
RubyLint::Parser.new(code).parse
|
13
13
|
end
|
14
14
|
|
15
|
-
error.file.should == '(
|
15
|
+
error.file.should == '(ruby-lint)'
|
16
16
|
error.line.should == 3
|
17
17
|
error.column.should == 3
|
18
18
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Parser' do
|
4
4
|
it 'Parse a Hash' do
|
5
5
|
input = '{"name" => "Ruby", "Foo" => "Bar"}'
|
6
|
-
token =
|
6
|
+
token = RubyLint::Parser.new(input).parse[0]
|
7
7
|
|
8
|
-
token.class.should ==
|
8
|
+
token.class.should == RubyLint::Token::Token
|
9
9
|
token.line.should == 1
|
10
10
|
token.column.should == 2
|
11
11
|
token.code.should == input
|
@@ -16,28 +16,28 @@ describe 'Rlint::Parser' do
|
|
16
16
|
first = token.value[0]
|
17
17
|
last = token.value[1]
|
18
18
|
|
19
|
-
first.class.should ==
|
19
|
+
first.class.should == RubyLint::Token::Token
|
20
20
|
first.name.should == 'name'
|
21
21
|
first.type.should == :string
|
22
22
|
|
23
|
-
first.value.class.should ==
|
23
|
+
first.value.class.should == RubyLint::Token::Token
|
24
24
|
first.value.type.should == :string
|
25
25
|
first.value.value.should == 'Ruby'
|
26
26
|
|
27
|
-
last.class.should ==
|
27
|
+
last.class.should == RubyLint::Token::Token
|
28
28
|
last.name.should == 'Foo'
|
29
29
|
last.type.should == :string
|
30
30
|
|
31
|
-
last.value.class.should ==
|
31
|
+
last.value.class.should == RubyLint::Token::Token
|
32
32
|
last.value.type.should == :string
|
33
33
|
last.value.value.should == 'Bar'
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'Parse a Hash using symbols' do
|
37
37
|
input = '{:name => "Ruby", :Foo => "Bar"}'
|
38
|
-
token =
|
38
|
+
token = RubyLint::Parser.new(input).parse[0]
|
39
39
|
|
40
|
-
token.class.should ==
|
40
|
+
token.class.should == RubyLint::Token::Token
|
41
41
|
token.line.should == 1
|
42
42
|
token.column.should == 2
|
43
43
|
token.code.should == input
|
@@ -48,28 +48,28 @@ describe 'Rlint::Parser' do
|
|
48
48
|
first = token.value[0]
|
49
49
|
last = token.value[1]
|
50
50
|
|
51
|
-
first.class.should ==
|
51
|
+
first.class.should == RubyLint::Token::Token
|
52
52
|
first.name.should == 'name'
|
53
53
|
first.type.should == :symbol
|
54
54
|
|
55
|
-
first.value.class.should ==
|
55
|
+
first.value.class.should == RubyLint::Token::Token
|
56
56
|
first.value.type.should == :string
|
57
57
|
first.value.value.should == 'Ruby'
|
58
58
|
|
59
|
-
last.class.should ==
|
59
|
+
last.class.should == RubyLint::Token::Token
|
60
60
|
last.name.should == 'Foo'
|
61
61
|
last.type.should == :symbol
|
62
62
|
|
63
|
-
last.value.class.should ==
|
63
|
+
last.value.class.should == RubyLint::Token::Token
|
64
64
|
last.value.type.should == :string
|
65
65
|
last.value.value.should == 'Bar'
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'Parse a Hash using symbols and the JSON syntax' do
|
69
69
|
input = '{name: "Ruby"}'
|
70
|
-
token =
|
70
|
+
token = RubyLint::Parser.new(input).parse[0]
|
71
71
|
|
72
|
-
token.class.should ==
|
72
|
+
token.class.should == RubyLint::Token::Token
|
73
73
|
token.line.should == 1
|
74
74
|
token.column.should == 1
|
75
75
|
token.code.should == input
|
@@ -82,16 +82,16 @@ describe 'Rlint::Parser' do
|
|
82
82
|
pair.name.should == 'name:'
|
83
83
|
pair.type.should == :symbol
|
84
84
|
|
85
|
-
pair.value.class.should ==
|
85
|
+
pair.value.class.should == RubyLint::Token::Token
|
86
86
|
pair.value.type.should == :string
|
87
87
|
pair.value.value.should == 'Ruby'
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'Parse a Hash key reference' do
|
91
91
|
input = '{:name => "Ruby"}[:name]'
|
92
|
-
token =
|
92
|
+
token = RubyLint::Parser.new(input).parse[0]
|
93
93
|
|
94
|
-
token.class.should ==
|
94
|
+
token.class.should == RubyLint::Token::Token
|
95
95
|
token.type.should == :hash
|
96
96
|
token.line.should == 1
|
97
97
|
token.column.should == 2
|
@@ -100,7 +100,7 @@ describe 'Rlint::Parser' do
|
|
100
100
|
token.key.class.should == Array
|
101
101
|
token.key.length.should == 1
|
102
102
|
|
103
|
-
token.key[0].class.should ==
|
103
|
+
token.key[0].class.should == RubyLint::Token::Token
|
104
104
|
token.key[0].type.should == :symbol
|
105
105
|
token.key[0].value.should == 'name'
|
106
106
|
|
@@ -109,19 +109,19 @@ describe 'Rlint::Parser' do
|
|
109
109
|
|
110
110
|
pair = token.value[0]
|
111
111
|
|
112
|
-
pair.class.should ==
|
112
|
+
pair.class.should == RubyLint::Token::Token
|
113
113
|
pair.type.should == :symbol
|
114
114
|
pair.name.should == 'name'
|
115
115
|
|
116
|
-
pair.value.class.should ==
|
116
|
+
pair.value.class.should == RubyLint::Token::Token
|
117
117
|
pair.value.value.should == 'Ruby'
|
118
118
|
pair.value.type.should == :string
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'Parse a Hash key reference using a variable' do
|
122
|
-
token =
|
122
|
+
token = RubyLint::Parser.new("hash = {:name => 'Ruby'}\nhash[:name]").parse[1]
|
123
123
|
|
124
|
-
token.class.should ==
|
124
|
+
token.class.should == RubyLint::Token::VariableToken
|
125
125
|
token.line.should == 2
|
126
126
|
token.column.should == 0
|
127
127
|
token.code.should == 'hash[:name]'
|
@@ -129,7 +129,7 @@ describe 'Rlint::Parser' do
|
|
129
129
|
token.key.class.should == Array
|
130
130
|
token.key.length.should == 1
|
131
131
|
|
132
|
-
token.key[0].class.should ==
|
132
|
+
token.key[0].class.should == RubyLint::Token::Token
|
133
133
|
token.key[0].value.should == 'name'
|
134
134
|
token.key[0].type.should == :symbol
|
135
135
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'RubyLint::Parser' do
|
4
4
|
it 'Parse a method definition' do
|
5
|
-
token =
|
5
|
+
token = RubyLint::Parser.new('def number; return 10; end').parse[0]
|
6
6
|
|
7
|
-
token.class.should ==
|
7
|
+
token.class.should == RubyLint::Token::MethodDefinitionToken
|
8
8
|
token.line.should == 1
|
9
9
|
token.column.should == 4
|
10
10
|
token.name.should == 'number'
|
11
11
|
token.visibility.should == :public
|
12
12
|
token.type.should == :method_definition
|
13
13
|
|
14
|
-
token.parameters.class.should ==
|
14
|
+
token.parameters.class.should == RubyLint::Token::ParametersToken
|
15
15
|
|
16
16
|
token.value.class.should == Array
|
17
17
|
token.value.length.should == 1
|
18
18
|
|
19
|
-
token.value[0].class.should ==
|
19
|
+
token.value[0].class.should == RubyLint::Token::StatementToken
|
20
20
|
token.value[0].type.should == :return
|
21
21
|
|
22
22
|
token.value[0].value.class.should == Array
|
@@ -24,7 +24,7 @@ describe 'Rlint::Parser' do
|
|
24
24
|
|
25
25
|
value = token.value[0].value[0]
|
26
26
|
|
27
|
-
value.class.should ==
|
27
|
+
value.class.should == RubyLint::Token::Token
|
28
28
|
value.type.should == :integer
|
29
29
|
value.value.should == '10'
|
30
30
|
end
|
@@ -36,21 +36,21 @@ def number(a, b = 10, *args, more, &block)
|
|
36
36
|
end
|
37
37
|
CODE
|
38
38
|
|
39
|
-
token =
|
39
|
+
token = RubyLint::Parser.new(code).parse[0]
|
40
40
|
|
41
|
-
token.class.should ==
|
41
|
+
token.class.should == RubyLint::Token::MethodDefinitionToken
|
42
42
|
token.name.should == 'number'
|
43
43
|
token.line.should == 1
|
44
44
|
token.column.should == 4
|
45
45
|
|
46
46
|
params = token.parameters
|
47
47
|
|
48
|
-
params.class.should ==
|
48
|
+
params.class.should == RubyLint::Token::ParametersToken
|
49
49
|
params.value.class.should == Array
|
50
50
|
|
51
51
|
# Required parameters
|
52
52
|
params.value.length.should == 1
|
53
|
-
params.value[0].class.should ==
|
53
|
+
params.value[0].class.should == RubyLint::Token::VariableToken
|
54
54
|
params.value[0].name.should == 'a'
|
55
55
|
|
56
56
|
# Optional parameters
|
@@ -59,16 +59,16 @@ end
|
|
59
59
|
|
60
60
|
optional = params.optional[0]
|
61
61
|
|
62
|
-
optional.class.should ==
|
62
|
+
optional.class.should == RubyLint::Token::VariableToken
|
63
63
|
optional.name.should == 'b'
|
64
64
|
|
65
|
-
optional.value.class.should ==
|
65
|
+
optional.value.class.should == RubyLint::Token::Token
|
66
66
|
optional.value.type.should == :integer
|
67
67
|
optional.value.value.should == '10'
|
68
68
|
|
69
69
|
# Rest parameters
|
70
70
|
params.rest.name.should == 'args'
|
71
|
-
params.rest.class.should ==
|
71
|
+
params.rest.class.should == RubyLint::Token::VariableToken
|
72
72
|
|
73
73
|
# More parameters
|
74
74
|
params.more.class.should == Array
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
params.more[0].name.should == 'more'
|
77
77
|
|
78
78
|
# Block parameters
|
79
|
-
params.block.class.should ==
|
79
|
+
params.block.class.should == RubyLint::Token::VariableToken
|
80
80
|
params.block.name.should == 'block'
|
81
81
|
end
|
82
82
|
|
@@ -87,20 +87,20 @@ def self.example(number = 10)
|
|
87
87
|
end
|
88
88
|
CODE
|
89
89
|
|
90
|
-
token =
|
90
|
+
token = RubyLint::Parser.new(code).parse[0]
|
91
91
|
|
92
|
-
token.class.should ==
|
92
|
+
token.class.should == RubyLint::Token::MethodDefinitionToken
|
93
93
|
token.name.should == 'example'
|
94
94
|
|
95
|
-
token.receiver.class.should ==
|
95
|
+
token.receiver.class.should == RubyLint::Token::VariableToken
|
96
96
|
token.receiver.name.should == 'self'
|
97
97
|
token.receiver.type.should == :keyword
|
98
98
|
|
99
|
-
token.operator.class.should ==
|
99
|
+
token.operator.class.should == RubyLint::Token::Token
|
100
100
|
token.operator.value.should == '.'
|
101
101
|
token.operator.type.should == :period
|
102
102
|
|
103
|
-
token.parameters.class.should ==
|
103
|
+
token.parameters.class.should == RubyLint::Token::ParametersToken
|
104
104
|
token.parameters.optional.class.should == Array
|
105
105
|
token.parameters.optional.length.should == 1
|
106
106
|
end
|
@@ -114,9 +114,9 @@ def example
|
|
114
114
|
end
|
115
115
|
CODE
|
116
116
|
|
117
|
-
token =
|
117
|
+
token = RubyLint::Parser.new(code).parse[1]
|
118
118
|
|
119
|
-
token.class.should ==
|
119
|
+
token.class.should == RubyLint::Token::MethodDefinitionToken
|
120
120
|
token.name.should == 'example'
|
121
121
|
token.visibility.should == :private
|
122
122
|
|
@@ -125,23 +125,23 @@ end
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'Parse a method call' do
|
128
|
-
token =
|
128
|
+
token = RubyLint::Parser.new('puts').parse[0]
|
129
129
|
|
130
|
-
token.class.should ==
|
130
|
+
token.class.should == RubyLint::Token::MethodToken
|
131
131
|
token.name.should == 'puts'
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'Parse a method call with parenthesis' do
|
135
|
-
token =
|
135
|
+
token = RubyLint::Parser.new('puts()').parse[0]
|
136
136
|
|
137
|
-
token.class.should ==
|
137
|
+
token.class.should == RubyLint::Token::MethodToken
|
138
138
|
token.name.should == 'puts'
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'Parse a method call with parenthesis and parameters' do
|
142
|
-
token =
|
142
|
+
token = RubyLint::Parser.new('puts(10)').parse[0]
|
143
143
|
|
144
|
-
token.class.should ==
|
144
|
+
token.class.should == RubyLint::Token::MethodToken
|
145
145
|
token.name.should == 'puts'
|
146
146
|
|
147
147
|
token.parameters.class.should == Array
|
@@ -149,15 +149,15 @@ end
|
|
149
149
|
|
150
150
|
param = token.parameters[0]
|
151
151
|
|
152
|
-
param.class.should ==
|
152
|
+
param.class.should == RubyLint::Token::Token
|
153
153
|
param.type.should == :integer
|
154
154
|
param.value.should == '10'
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'Parse a method call with parameters but without parenthesis' do
|
158
|
-
token =
|
158
|
+
token = RubyLint::Parser.new('puts 10').parse[0]
|
159
159
|
|
160
|
-
token.class.should ==
|
160
|
+
token.class.should == RubyLint::Token::MethodToken
|
161
161
|
token.name.should == 'puts'
|
162
162
|
|
163
163
|
token.parameters.class.should == Array
|
@@ -165,85 +165,85 @@ end
|
|
165
165
|
|
166
166
|
param = token.parameters[0]
|
167
167
|
|
168
|
-
param.class.should ==
|
168
|
+
param.class.should == RubyLint::Token::Token
|
169
169
|
param.type.should == :integer
|
170
170
|
param.value.should == '10'
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'Parse a method called on an object with parenthesis' do
|
174
|
-
token =
|
174
|
+
token = RubyLint::Parser.new('Struct.new(:name)').parse[0]
|
175
175
|
|
176
|
-
token.class.should ==
|
176
|
+
token.class.should == RubyLint::Token::MethodToken
|
177
177
|
token.name.should == 'new'
|
178
178
|
|
179
|
-
token.receiver.class.should ==
|
179
|
+
token.receiver.class.should == RubyLint::Token::VariableToken
|
180
180
|
token.receiver.type.should == :constant
|
181
181
|
token.receiver.name.should == 'Struct'
|
182
182
|
|
183
183
|
token.parameters.class.should == Array
|
184
184
|
token.parameters.length.should == 1
|
185
185
|
|
186
|
-
token.parameters[0].class.should ==
|
186
|
+
token.parameters[0].class.should == RubyLint::Token::Token
|
187
187
|
token.parameters[0].type.should == :symbol
|
188
188
|
token.parameters[0].value.should == 'name'
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'Parse a method called on an object without parenthesis' do
|
192
|
-
token =
|
192
|
+
token = RubyLint::Parser.new('Struct.new :name').parse[0]
|
193
193
|
|
194
|
-
token.class.should ==
|
194
|
+
token.class.should == RubyLint::Token::MethodToken
|
195
195
|
token.name.should == 'new'
|
196
196
|
|
197
|
-
token.receiver.class.should ==
|
197
|
+
token.receiver.class.should == RubyLint::Token::VariableToken
|
198
198
|
token.receiver.type.should == :constant
|
199
199
|
token.receiver.name.should == 'Struct'
|
200
200
|
|
201
201
|
token.parameters.class.should == Array
|
202
202
|
token.parameters.length.should == 1
|
203
203
|
|
204
|
-
token.parameters[0].class.should ==
|
204
|
+
token.parameters[0].class.should == RubyLint::Token::Token
|
205
205
|
token.parameters[0].type.should == :symbol
|
206
206
|
token.parameters[0].value.should == 'name'
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'Parse a method called on an object with a block passed' do
|
210
|
-
token =
|
210
|
+
token = RubyLint::Parser.new('Foo.bar { |example| example }').parse[0]
|
211
211
|
|
212
|
-
token.class.should ==
|
212
|
+
token.class.should == RubyLint::Token::MethodToken
|
213
213
|
token.name.should == 'bar'
|
214
214
|
|
215
|
-
token.receiver.class.should ==
|
215
|
+
token.receiver.class.should == RubyLint::Token::VariableToken
|
216
216
|
token.receiver.type.should == :constant
|
217
217
|
token.receiver.name.should == 'Foo'
|
218
218
|
|
219
|
-
token.block.class.should ==
|
220
|
-
token.block.parameters.class.should ==
|
219
|
+
token.block.class.should == RubyLint::Token::BlockToken
|
220
|
+
token.block.parameters.class.should == RubyLint::Token::ParametersToken
|
221
221
|
|
222
222
|
token.block.parameters.value.class.should == Array
|
223
223
|
token.block.parameters.value.length.should == 1
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'Parse a method call with a bare Hash as a parameter' do
|
227
|
-
token =
|
227
|
+
token = RubyLint::Parser.new('language(:name => "Ruby")').parse[0]
|
228
228
|
|
229
|
-
token.class.should ==
|
229
|
+
token.class.should == RubyLint::Token::MethodToken
|
230
230
|
|
231
231
|
token.parameters.class.should == Array
|
232
232
|
token.parameters.length.should == 1
|
233
233
|
|
234
|
-
token.parameters[0].class.should ==
|
234
|
+
token.parameters[0].class.should == RubyLint::Token::Token
|
235
235
|
token.parameters[0].type.should == :hash
|
236
236
|
end
|
237
237
|
|
238
238
|
it 'Parse a method call with a bare JSON style Hash as a parameter' do
|
239
|
-
token =
|
239
|
+
token = RubyLint::Parser.new('language(name: "Ruby")').parse[0]
|
240
240
|
|
241
|
-
token.class.should ==
|
241
|
+
token.class.should == RubyLint::Token::MethodToken
|
242
242
|
|
243
243
|
token.parameters.class.should == Array
|
244
244
|
token.parameters.length.should == 1
|
245
245
|
|
246
|
-
token.parameters[0].class.should ==
|
246
|
+
token.parameters[0].class.should == RubyLint::Token::Token
|
247
247
|
token.parameters[0].type.should == :hash
|
248
248
|
end
|
249
249
|
end
|