ruby-lint 0.0.1a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/.gitignore +5 -0
  2. data/.rbenv-version +1 -0
  3. data/.yardopts +10 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +19 -0
  6. data/MANIFEST +79 -0
  7. data/README.md +48 -0
  8. data/Rakefile +14 -0
  9. data/bin/rlint +6 -0
  10. data/doc/.gitkeep +0 -0
  11. data/doc/build/.gitkeep +0 -0
  12. data/doc/css/.gitkeep +0 -0
  13. data/doc/css/common.css +68 -0
  14. data/lib/rlint/analyze/coding_style.rb +407 -0
  15. data/lib/rlint/analyze/definitions.rb +244 -0
  16. data/lib/rlint/analyze/method_validation.rb +104 -0
  17. data/lib/rlint/analyze/shadowing_variables.rb +37 -0
  18. data/lib/rlint/analyze/undefined_variables.rb +99 -0
  19. data/lib/rlint/analyze/unused_variables.rb +103 -0
  20. data/lib/rlint/callback.rb +67 -0
  21. data/lib/rlint/cli.rb +167 -0
  22. data/lib/rlint/constant_importer.rb +102 -0
  23. data/lib/rlint/definition.rb +230 -0
  24. data/lib/rlint/formatter/text.rb +54 -0
  25. data/lib/rlint/helper/definition_resolver.rb +143 -0
  26. data/lib/rlint/helper/scoping.rb +138 -0
  27. data/lib/rlint/iterator.rb +193 -0
  28. data/lib/rlint/options.rb +58 -0
  29. data/lib/rlint/parser.rb +1252 -0
  30. data/lib/rlint/parser_error.rb +42 -0
  31. data/lib/rlint/report.rb +98 -0
  32. data/lib/rlint/token/assignment_token.rb +46 -0
  33. data/lib/rlint/token/begin_rescue_token.rb +57 -0
  34. data/lib/rlint/token/block_token.rb +17 -0
  35. data/lib/rlint/token/case_token.rb +44 -0
  36. data/lib/rlint/token/class_token.rb +24 -0
  37. data/lib/rlint/token/method_definition_token.rb +64 -0
  38. data/lib/rlint/token/method_token.rb +58 -0
  39. data/lib/rlint/token/parameters_token.rb +99 -0
  40. data/lib/rlint/token/regexp_token.rb +15 -0
  41. data/lib/rlint/token/statement_token.rb +69 -0
  42. data/lib/rlint/token/token.rb +162 -0
  43. data/lib/rlint/token/variable_token.rb +18 -0
  44. data/lib/rlint/version.rb +3 -0
  45. data/lib/rlint.rb +36 -0
  46. data/ruby-lint.gemspec +23 -0
  47. data/spec/benchmarks/memory.rb +52 -0
  48. data/spec/benchmarks/parse_parser.rb +16 -0
  49. data/spec/helper.rb +4 -0
  50. data/spec/rlint/analyze/coding_style.rb +224 -0
  51. data/spec/rlint/analyze/definitions/classes.rb +114 -0
  52. data/spec/rlint/analyze/definitions/methods.rb +91 -0
  53. data/spec/rlint/analyze/definitions/modules.rb +207 -0
  54. data/spec/rlint/analyze/definitions/variables.rb +103 -0
  55. data/spec/rlint/analyze/method_validation.rb +177 -0
  56. data/spec/rlint/analyze/shadowing_variables.rb +30 -0
  57. data/spec/rlint/analyze/undefined_variables.rb +230 -0
  58. data/spec/rlint/analyze/unused_variables.rb +225 -0
  59. data/spec/rlint/callback.rb +28 -0
  60. data/spec/rlint/constant_importer.rb +27 -0
  61. data/spec/rlint/definition.rb +96 -0
  62. data/spec/rlint/formatter/text.rb +21 -0
  63. data/spec/rlint/iterator.rb +452 -0
  64. data/spec/rlint/parser/arrays.rb +147 -0
  65. data/spec/rlint/parser/classes.rb +152 -0
  66. data/spec/rlint/parser/errors.rb +19 -0
  67. data/spec/rlint/parser/hashes.rb +136 -0
  68. data/spec/rlint/parser/methods.rb +249 -0
  69. data/spec/rlint/parser/modules.rb +49 -0
  70. data/spec/rlint/parser/objects.rb +39 -0
  71. data/spec/rlint/parser/operators.rb +75 -0
  72. data/spec/rlint/parser/procs.rb +113 -0
  73. data/spec/rlint/parser/ranges.rb +49 -0
  74. data/spec/rlint/parser/regexp.rb +31 -0
  75. data/spec/rlint/parser/scalars.rb +93 -0
  76. data/spec/rlint/parser/statements.rb +550 -0
  77. data/spec/rlint/parser/variables.rb +181 -0
  78. data/spec/rlint/report.rb +30 -0
  79. data/task/test.rake +6 -0
  80. metadata +188 -0
@@ -0,0 +1,181 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Parser' do
4
+ it 'Parse the assignment of a local variable' do
5
+ token = Rlint::Parser.new('number = 10').parse[0]
6
+
7
+ token.class.should == Rlint::Token::AssignmentToken
8
+ token.line.should == 1
9
+ token.column.should == 0
10
+
11
+ token.name.should == 'number'
12
+ token.type.should == :local_variable
13
+
14
+ token.value.class.should == Rlint::Token::Token
15
+ token.value.type.should == :integer
16
+ token.value.value.should == '10'
17
+ end
18
+
19
+ it 'Parse the assignment of a global variable' do
20
+ token = Rlint::Parser.new('$number = 10').parse[0]
21
+
22
+ token.class.should == Rlint::Token::AssignmentToken
23
+ token.line.should == 1
24
+ token.column.should == 0
25
+
26
+ token.name.should == '$number'
27
+ token.type.should == :global_variable
28
+
29
+ token.value.class.should == Rlint::Token::Token
30
+ token.value.type.should == :integer
31
+ token.value.value.should == '10'
32
+ end
33
+
34
+ it 'Parse the assignment of an instance variable' do
35
+ token = Rlint::Parser.new('@number = 10').parse[0]
36
+
37
+ token.class.should == Rlint::Token::AssignmentToken
38
+ token.line.should == 1
39
+ token.column.should == 0
40
+
41
+ token.name.should == '@number'
42
+ token.type.should == :instance_variable
43
+
44
+ token.value.class.should == Rlint::Token::Token
45
+ token.value.type.should == :integer
46
+ token.value.value.should == '10'
47
+ end
48
+
49
+ it 'Parse the assignment of a class variable' do
50
+ token = Rlint::Parser.new('@@number = 10').parse[0]
51
+
52
+ token.class.should == Rlint::Token::AssignmentToken
53
+ token.line.should == 1
54
+ token.column.should == 0
55
+
56
+ token.name.should == '@@number'
57
+ token.type.should == :class_variable
58
+
59
+ token.value.class.should == Rlint::Token::Token
60
+ token.value.type.should == :integer
61
+ token.value.value.should == '10'
62
+ end
63
+
64
+ it 'Parse the assignment of a constant' do
65
+ token = Rlint::Parser.new('NUMBER = 10').parse[0]
66
+
67
+ token.class.should == Rlint::Token::AssignmentToken
68
+ token.line.should == 1
69
+ token.column.should == 0
70
+
71
+ token.name.should == 'NUMBER'
72
+ token.type.should == :constant
73
+
74
+ token.value.class.should == Rlint::Token::Token
75
+ token.value.type.should == :integer
76
+ token.value.value.should == '10'
77
+ end
78
+
79
+ it 'Parse a reference to a local variable' do
80
+ token = Rlint::Parser.new("number = 10\nnumber").parse[1]
81
+
82
+ token.class.should == Rlint::Token::VariableToken
83
+ token.line.should == 2
84
+ token.column.should == 0
85
+ token.type.should == :local_variable
86
+ token.name.should == 'number'
87
+ end
88
+
89
+ it 'Parse a reference to a global variable' do
90
+ token = Rlint::Parser.new("$number = 10\n$number").parse[1]
91
+
92
+ token.class.should == Rlint::Token::VariableToken
93
+ token.line.should == 2
94
+ token.column.should == 0
95
+ token.type.should == :global_variable
96
+ token.name.should == '$number'
97
+ end
98
+
99
+ it 'Parse a reference to a instance variable' do
100
+ token = Rlint::Parser.new("@number = 10\n@number").parse[1]
101
+
102
+ token.class.should == Rlint::Token::VariableToken
103
+ token.line.should == 2
104
+ token.column.should == 0
105
+ token.type.should == :instance_variable
106
+ token.name.should == '@number'
107
+ end
108
+
109
+ it 'Parse a reference to a class variable' do
110
+ token = Rlint::Parser.new("@@number = 10\n@@number").parse[1]
111
+
112
+ token.class.should == Rlint::Token::VariableToken
113
+ token.line.should == 2
114
+ token.column.should == 0
115
+ token.type.should == :class_variable
116
+ token.name.should == '@@number'
117
+ end
118
+
119
+ it 'Parse a reference to a constant' do
120
+ token = Rlint::Parser.new("NUMBER = 10\nNUMBER").parse[1]
121
+
122
+ token.class.should == Rlint::Token::VariableToken
123
+ token.line.should == 2
124
+ token.column.should == 0
125
+ token.type.should == :constant
126
+ token.name.should == 'NUMBER'
127
+ end
128
+
129
+ it 'Parse the mass assignment of multiple variables' do
130
+ token = Rlint::Parser.new('foo, bar = 10, 20').parse[0]
131
+
132
+ token.class.should == Rlint::Token::AssignmentToken
133
+
134
+ token.name.class.should == Array
135
+ token.name.length.should == 2
136
+ token.type.should == :mass_assignment
137
+
138
+ token.name[0].class.should == Rlint::Token::Token
139
+ token.name[0].name.should == 'foo'
140
+ token.name[0].type.should == :local_variable
141
+
142
+ token.name[1].class.should == Rlint::Token::Token
143
+ token.name[1].name.should == 'bar'
144
+ token.name[1].type.should == :local_variable
145
+
146
+ token.value.class.should == Array
147
+ token.value.length.should == 2
148
+
149
+ token.value[0].class.should == Rlint::Token::Token
150
+ token.value[0].value.should == '10'
151
+ token.value[0].type.should == :integer
152
+
153
+ token.value[1].class.should == Rlint::Token::Token
154
+ token.value[1].value.should == '20'
155
+ token.value[1].type.should == :integer
156
+ end
157
+
158
+ it 'Parse the reference of a constant path' do
159
+ token = Rlint::Parser.new('A::B::C').parse[0]
160
+
161
+ token.class.should == Rlint::Token::VariableToken
162
+ token.type.should == :constant_path
163
+ token.name.should == ['A', 'B', 'C']
164
+ token.line.should == 1
165
+ token.column.should == 0
166
+ end
167
+
168
+ it 'Parse the assignment of a constant path' do
169
+ token = Rlint::Parser.new('A::B::C = 10').parse[0]
170
+
171
+ token.class.should == Rlint::Token::AssignmentToken
172
+ token.type.should == :constant_path
173
+ token.name.should == ['A', 'B', 'C']
174
+ token.line.should == 1
175
+ token.column.should == 0
176
+
177
+ token.value.class.should == Rlint::Token::Token
178
+ token.value.type.should == :integer
179
+ token.value.value.should == '10'
180
+ end
181
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ describe 'Rlint::Report' do
4
+ it 'Add an error message to a report' do
5
+ report = Rlint::Report.new
6
+
7
+ report.add(:error, 'test error', 1, 1)
8
+
9
+ report.messages.class.should == Hash
10
+ report.messages.length.should == 1
11
+
12
+ report.messages[:error].class.should == Array
13
+ report.messages[:error].length.should == 1
14
+
15
+ report.messages[:error][0][:message].should == 'test error'
16
+ report.messages[:error][0][:line].should == 1
17
+ report.messages[:error][0][:column].should == 1
18
+
19
+ report.file.should == '(rlint)'
20
+ end
21
+
22
+ it 'Ignore disabled reporting levels' do
23
+ report = Rlint::Report.new('(rlint)', [:error])
24
+
25
+ report.add(:info, 'test info', 1, 1)
26
+
27
+ report.messages.class.should == Hash
28
+ report.messages[:info].nil?.should == true
29
+ end
30
+ end
data/task/test.rake ADDED
@@ -0,0 +1,6 @@
1
+ desc 'Runs all the tests'
2
+ task :test do
3
+ glob = File.expand_path('../../spec/rlint/**/*.rb', __FILE__)
4
+
5
+ Dir[glob].each { |file| require(file) }
6
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Yorick Peterse
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.1.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.1.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: bacon
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.2.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.2.1
78
+ description: Static code analysis tool and linter for Ruby
79
+ email: yorickpeterse@gmail.com
80
+ executables:
81
+ - rlint
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rbenv-version
87
+ - .yardopts
88
+ - Gemfile
89
+ - LICENSE
90
+ - MANIFEST
91
+ - README.md
92
+ - Rakefile
93
+ - bin/rlint
94
+ - doc/.gitkeep
95
+ - doc/build/.gitkeep
96
+ - doc/css/.gitkeep
97
+ - doc/css/common.css
98
+ - lib/rlint.rb
99
+ - lib/rlint/analyze/coding_style.rb
100
+ - lib/rlint/analyze/definitions.rb
101
+ - lib/rlint/analyze/method_validation.rb
102
+ - lib/rlint/analyze/shadowing_variables.rb
103
+ - lib/rlint/analyze/undefined_variables.rb
104
+ - lib/rlint/analyze/unused_variables.rb
105
+ - lib/rlint/callback.rb
106
+ - lib/rlint/cli.rb
107
+ - lib/rlint/constant_importer.rb
108
+ - lib/rlint/definition.rb
109
+ - lib/rlint/formatter/text.rb
110
+ - lib/rlint/helper/definition_resolver.rb
111
+ - lib/rlint/helper/scoping.rb
112
+ - lib/rlint/iterator.rb
113
+ - lib/rlint/options.rb
114
+ - lib/rlint/parser.rb
115
+ - lib/rlint/parser_error.rb
116
+ - lib/rlint/report.rb
117
+ - lib/rlint/token/assignment_token.rb
118
+ - lib/rlint/token/begin_rescue_token.rb
119
+ - lib/rlint/token/block_token.rb
120
+ - lib/rlint/token/case_token.rb
121
+ - lib/rlint/token/class_token.rb
122
+ - lib/rlint/token/method_definition_token.rb
123
+ - lib/rlint/token/method_token.rb
124
+ - lib/rlint/token/parameters_token.rb
125
+ - lib/rlint/token/regexp_token.rb
126
+ - lib/rlint/token/statement_token.rb
127
+ - lib/rlint/token/token.rb
128
+ - lib/rlint/token/variable_token.rb
129
+ - lib/rlint/version.rb
130
+ - ruby-lint.gemspec
131
+ - spec/benchmarks/memory.rb
132
+ - spec/benchmarks/parse_parser.rb
133
+ - spec/helper.rb
134
+ - spec/rlint/analyze/coding_style.rb
135
+ - spec/rlint/analyze/definitions/classes.rb
136
+ - spec/rlint/analyze/definitions/methods.rb
137
+ - spec/rlint/analyze/definitions/modules.rb
138
+ - spec/rlint/analyze/definitions/variables.rb
139
+ - spec/rlint/analyze/method_validation.rb
140
+ - spec/rlint/analyze/shadowing_variables.rb
141
+ - spec/rlint/analyze/undefined_variables.rb
142
+ - spec/rlint/analyze/unused_variables.rb
143
+ - spec/rlint/callback.rb
144
+ - spec/rlint/constant_importer.rb
145
+ - spec/rlint/definition.rb
146
+ - spec/rlint/formatter/text.rb
147
+ - spec/rlint/iterator.rb
148
+ - spec/rlint/parser/arrays.rb
149
+ - spec/rlint/parser/classes.rb
150
+ - spec/rlint/parser/errors.rb
151
+ - spec/rlint/parser/hashes.rb
152
+ - spec/rlint/parser/methods.rb
153
+ - spec/rlint/parser/modules.rb
154
+ - spec/rlint/parser/objects.rb
155
+ - spec/rlint/parser/operators.rb
156
+ - spec/rlint/parser/procs.rb
157
+ - spec/rlint/parser/ranges.rb
158
+ - spec/rlint/parser/regexp.rb
159
+ - spec/rlint/parser/scalars.rb
160
+ - spec/rlint/parser/statements.rb
161
+ - spec/rlint/parser/variables.rb
162
+ - spec/rlint/report.rb
163
+ - task/test.rake
164
+ homepage: https://github.com/yorickpeterse/rlint/
165
+ licenses: []
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: 1.9.2
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>'
180
+ - !ruby/object:Gem::Version
181
+ version: 1.3.1
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 1.8.24
185
+ signing_key:
186
+ specification_version: 3
187
+ summary: Static code analysis tool and linter for Ruby
188
+ test_files: []