ruby-lint 0.0.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.asc +14 -14
  3. data/.gitignore +1 -0
  4. data/.yardopts +1 -1
  5. data/Gemfile +3 -3
  6. data/MANIFEST +16 -3
  7. data/benchmark/virtual_machine.rb +17 -0
  8. data/checksum/ruby-lint-0.0.5.gem.sha512 +1 -0
  9. data/doc/changelog.md +42 -0
  10. data/doc/configuration.md +133 -13
  11. data/lib/ruby-lint/analysis/shadowing_variables.rb +8 -14
  12. data/lib/ruby-lint/analysis/unused_variables.rb +17 -0
  13. data/lib/ruby-lint/ast/node.rb +18 -3
  14. data/lib/ruby-lint/cache.rb +121 -0
  15. data/lib/ruby-lint/cache_entry.rb +44 -0
  16. data/lib/ruby-lint/cli/analyze.rb +37 -18
  17. data/lib/ruby-lint/cli/plot.rb +94 -0
  18. data/lib/ruby-lint/cli.rb +1 -0
  19. data/lib/ruby-lint/configuration.rb +48 -3
  20. data/lib/ruby-lint/definition/ruby_method.rb +28 -1
  21. data/lib/ruby-lint/definition/ruby_object.rb +37 -3
  22. data/lib/ruby-lint/definition_builder/ruby_method.rb +4 -1
  23. data/lib/ruby-lint/definition_builder/ruby_module.rb +4 -1
  24. data/lib/ruby-lint/definition_generator.rb +3 -2
  25. data/lib/ruby-lint/definitions/core/arg0.rb +3 -1
  26. data/lib/ruby-lint/definitions/core/argf.rb +3 -1
  27. data/lib/ruby-lint/definitions/core/argument_error.rb +3 -1
  28. data/lib/ruby-lint/definitions/core/argv.rb +3 -1
  29. data/lib/ruby-lint/definitions/core/array.rb +3 -1
  30. data/lib/ruby-lint/definitions/core/autoload.rb +3 -1
  31. data/lib/ruby-lint/definitions/core/basic_object.rb +2 -0
  32. data/lib/ruby-lint/definitions/core/bignum.rb +3 -1
  33. data/lib/ruby-lint/definitions/core/binding.rb +3 -1
  34. data/lib/ruby-lint/definitions/core/class.rb +2 -0
  35. data/lib/ruby-lint/definitions/core/comparable.rb +3 -1
  36. data/lib/ruby-lint/definitions/core/complex.rb +3 -1
  37. data/lib/ruby-lint/definitions/core/condition_variable.rb +3 -1
  38. data/lib/ruby-lint/definitions/core/continuation.rb +3 -1
  39. data/lib/ruby-lint/definitions/core/data.rb +3 -1
  40. data/lib/ruby-lint/definitions/core/date.rb +3 -1
  41. data/lib/ruby-lint/definitions/core/date_time.rb +3 -1
  42. data/lib/ruby-lint/definitions/core/default_record_separator.rb +3 -1
  43. data/lib/ruby-lint/definitions/core/digest.rb +3 -1
  44. data/lib/ruby-lint/definitions/core/dir.rb +3 -1
  45. data/lib/ruby-lint/definitions/core/encoding.rb +3 -1
  46. data/lib/ruby-lint/definitions/core/encoding_error.rb +3 -1
  47. data/lib/ruby-lint/definitions/core/enumerable.rb +3 -1
  48. data/lib/ruby-lint/definitions/core/enumerator.rb +3 -1
  49. data/lib/ruby-lint/definitions/core/env.rb +4 -1
  50. data/lib/ruby-lint/definitions/core/eoferror.rb +3 -1
  51. data/lib/ruby-lint/definitions/core/erb.rb +2 -0
  52. data/lib/ruby-lint/definitions/core/errno.rb +3 -1
  53. data/lib/ruby-lint/definitions/core/etc.rb +3 -1
  54. data/lib/ruby-lint/definitions/core/exception.rb +3 -1
  55. data/lib/ruby-lint/definitions/core/false.rb +3 -1
  56. data/lib/ruby-lint/definitions/core/false_class.rb +3 -1
  57. data/lib/ruby-lint/definitions/core/fatal_error.rb +3 -1
  58. data/lib/ruby-lint/definitions/core/fiber.rb +3 -1
  59. data/lib/ruby-lint/definitions/core/fiber_error.rb +3 -1
  60. data/lib/ruby-lint/definitions/core/file.rb +3 -1
  61. data/lib/ruby-lint/definitions/core/file_list.rb +3 -1
  62. data/lib/ruby-lint/definitions/core/file_test.rb +3 -1
  63. data/lib/ruby-lint/definitions/core/file_utils.rb +3 -1
  64. data/lib/ruby-lint/definitions/core/fixnum.rb +3 -1
  65. data/lib/ruby-lint/definitions/core/float.rb +3 -1
  66. data/lib/ruby-lint/definitions/core/float_domain_error.rb +3 -1
  67. data/lib/ruby-lint/definitions/core/gc.rb +3 -1
  68. data/lib/ruby-lint/definitions/core/gem.rb +3 -1
  69. data/lib/ruby-lint/definitions/core/hash.rb +3 -1
  70. data/lib/ruby-lint/definitions/core/immediate_value.rb +3 -1
  71. data/lib/ruby-lint/definitions/core/index_error.rb +3 -1
  72. data/lib/ruby-lint/definitions/core/integer.rb +3 -1
  73. data/lib/ruby-lint/definitions/core/interrupt.rb +3 -1
  74. data/lib/ruby-lint/definitions/core/io.rb +3 -1
  75. data/lib/ruby-lint/definitions/core/ioerror.rb +3 -1
  76. data/lib/ruby-lint/definitions/core/kernel.rb +2 -0
  77. data/lib/ruby-lint/definitions/core/key_error.rb +3 -1
  78. data/lib/ruby-lint/definitions/core/load_error.rb +3 -1
  79. data/lib/ruby-lint/definitions/core/local_jump_error.rb +3 -1
  80. data/lib/ruby-lint/definitions/core/marshal.rb +3 -1
  81. data/lib/ruby-lint/definitions/core/match_data.rb +3 -1
  82. data/lib/ruby-lint/definitions/core/math.rb +3 -1
  83. data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +3 -1
  84. data/lib/ruby-lint/definitions/core/method.rb +3 -1
  85. data/lib/ruby-lint/definitions/core/module.rb +2 -0
  86. data/lib/ruby-lint/definitions/core/monitor.rb +3 -1
  87. data/lib/ruby-lint/definitions/core/monitor_mixin.rb +3 -1
  88. data/lib/ruby-lint/definitions/core/mutex.rb +3 -1
  89. data/lib/ruby-lint/definitions/core/name_error.rb +3 -1
  90. data/lib/ruby-lint/definitions/core/nil.rb +3 -1
  91. data/lib/ruby-lint/definitions/core/nil_class.rb +3 -1
  92. data/lib/ruby-lint/definitions/core/no_memory_error.rb +3 -1
  93. data/lib/ruby-lint/definitions/core/no_method_error.rb +3 -1
  94. data/lib/ruby-lint/definitions/core/not_implemented_error.rb +3 -1
  95. data/lib/ruby-lint/definitions/core/numeric.rb +3 -1
  96. data/lib/ruby-lint/definitions/core/object.rb +3 -1
  97. data/lib/ruby-lint/definitions/core/object_space.rb +3 -1
  98. data/lib/ruby-lint/definitions/core/open_struct.rb +3 -1
  99. data/lib/ruby-lint/definitions/core/option_parser.rb +3 -1
  100. data/lib/ruby-lint/definitions/core/precision.rb +3 -1
  101. data/lib/ruby-lint/definitions/core/primitive_failure.rb +3 -1
  102. data/lib/ruby-lint/definitions/core/proc.rb +3 -1
  103. data/lib/ruby-lint/definitions/core/process.rb +3 -1
  104. data/lib/ruby-lint/definitions/core/queue.rb +3 -1
  105. data/lib/ruby-lint/definitions/core/rake.rb +3 -1
  106. data/lib/ruby-lint/definitions/core/rake_file_utils.rb +3 -1
  107. data/lib/ruby-lint/definitions/core/rakeversion.rb +3 -1
  108. data/lib/ruby-lint/definitions/core/random.rb +3 -1
  109. data/lib/ruby-lint/definitions/core/range.rb +3 -1
  110. data/lib/ruby-lint/definitions/core/range_error.rb +3 -1
  111. data/lib/ruby-lint/definitions/core/rational.rb +3 -1
  112. data/lib/ruby-lint/definitions/core/rb_config.rb +3 -1
  113. data/lib/ruby-lint/definitions/core/regexp.rb +3 -1
  114. data/lib/ruby-lint/definitions/core/regexp_error.rb +3 -1
  115. data/lib/ruby-lint/definitions/core/ruby_copyright.rb +3 -1
  116. data/lib/ruby-lint/definitions/core/ruby_description.rb +3 -1
  117. data/lib/ruby-lint/definitions/core/ruby_engine.rb +3 -1
  118. data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +3 -1
  119. data/lib/ruby-lint/definitions/core/ruby_platform.rb +3 -1
  120. data/lib/ruby-lint/definitions/core/ruby_release_date.rb +3 -1
  121. data/lib/ruby-lint/definitions/core/ruby_version.rb +3 -1
  122. data/lib/ruby-lint/definitions/core/runtime_error.rb +3 -1
  123. data/lib/ruby-lint/definitions/core/scan_error.rb +3 -1
  124. data/lib/ruby-lint/definitions/core/script_error.rb +3 -1
  125. data/lib/ruby-lint/definitions/core/security_error.rb +3 -1
  126. data/lib/ruby-lint/definitions/core/shellwords.rb +3 -1
  127. data/lib/ruby-lint/definitions/core/signal.rb +3 -1
  128. data/lib/ruby-lint/definitions/core/signal_exception.rb +3 -1
  129. data/lib/ruby-lint/definitions/core/singleton.rb +3 -1
  130. data/lib/ruby-lint/definitions/core/sized_queue.rb +3 -1
  131. data/lib/ruby-lint/definitions/core/standard_error.rb +3 -1
  132. data/lib/ruby-lint/definitions/core/stderr.rb +2 -0
  133. data/lib/ruby-lint/definitions/core/stdin.rb +2 -0
  134. data/lib/ruby-lint/definitions/core/stdout.rb +2 -0
  135. data/lib/ruby-lint/definitions/core/stop_iteration.rb +3 -1
  136. data/lib/ruby-lint/definitions/core/string.rb +3 -1
  137. data/lib/ruby-lint/definitions/core/string_io.rb +3 -1
  138. data/lib/ruby-lint/definitions/core/string_scanner.rb +3 -1
  139. data/lib/ruby-lint/definitions/core/struct.rb +3 -1
  140. data/lib/ruby-lint/definitions/core/syck.rb +3 -1
  141. data/lib/ruby-lint/definitions/core/symbol.rb +3 -1
  142. data/lib/ruby-lint/definitions/core/syntax_error.rb +3 -1
  143. data/lib/ruby-lint/definitions/core/system_call_error.rb +3 -1
  144. data/lib/ruby-lint/definitions/core/system_exit.rb +3 -1
  145. data/lib/ruby-lint/definitions/core/system_stack_error.rb +3 -1
  146. data/lib/ruby-lint/definitions/core/thread.rb +3 -1
  147. data/lib/ruby-lint/definitions/core/thread_error.rb +3 -1
  148. data/lib/ruby-lint/definitions/core/thread_group.rb +3 -1
  149. data/lib/ruby-lint/definitions/core/time.rb +3 -1
  150. data/lib/ruby-lint/definitions/core/toplevel_binding.rb +3 -1
  151. data/lib/ruby-lint/definitions/core/true.rb +3 -1
  152. data/lib/ruby-lint/definitions/core/true_class.rb +3 -1
  153. data/lib/ruby-lint/definitions/core/type_error.rb +3 -1
  154. data/lib/ruby-lint/definitions/core/unbound_method.rb +3 -1
  155. data/lib/ruby-lint/definitions/core/unmarshalable.rb +3 -1
  156. data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +3 -1
  157. data/lib/ruby-lint/definitions/core/weak_ref.rb +3 -1
  158. data/lib/ruby-lint/definitions/core/yaml.rb +1 -0
  159. data/lib/ruby-lint/definitions/core/zero_division_error.rb +3 -1
  160. data/lib/ruby-lint/definitions/core/zlib.rb +8840 -0
  161. data/lib/ruby-lint/definitions/rails/abstract_controller.rb +1 -0
  162. data/lib/ruby-lint/definitions/rails/action_controller.rb +1 -0
  163. data/lib/ruby-lint/definitions/rails/action_dispatch.rb +1 -0
  164. data/lib/ruby-lint/definitions/rails/action_mailer.rb +1 -0
  165. data/lib/ruby-lint/definitions/rails/action_pack.rb +1 -0
  166. data/lib/ruby-lint/definitions/rails/action_view.rb +1 -0
  167. data/lib/ruby-lint/definitions/rails/active_model.rb +1 -0
  168. data/lib/ruby-lint/definitions/rails/active_record.rb +1 -0
  169. data/lib/ruby-lint/definitions/rails/active_support.rb +1 -0
  170. data/lib/ruby-lint/definitions/rails/arel.rb +1 -0
  171. data/lib/ruby-lint/definitions/rails/rails.rb +1 -0
  172. data/lib/ruby-lint/definitions/rails/sprockets.rb +1 -0
  173. data/lib/ruby-lint/file_scanner.rb +2 -0
  174. data/lib/ruby-lint/iterator.rb +21 -12
  175. data/lib/ruby-lint/method_call_info.rb +31 -0
  176. data/lib/ruby-lint/node_hash.rb +105 -0
  177. data/lib/ruby-lint/parser.rb +4 -2
  178. data/lib/ruby-lint/runner.rb +62 -6
  179. data/lib/ruby-lint/template/definition.erb +2 -0
  180. data/lib/ruby-lint/version.rb +1 -1
  181. data/lib/ruby-lint/virtual_machine.rb +75 -43
  182. data/lib/ruby-lint.rb +20 -2
  183. data/profiling/virtual_machine.rb +20 -0
  184. data/ruby-lint.gemspec +2 -1
  185. data/spec/fixtures/complex/rcap.rb +29 -0
  186. data/spec/fixtures/complex/slop.rb +21 -0
  187. data/spec/fixtures/file_scanner/lib/ruby-lint/definition/constant_proxy.rb +6 -0
  188. data/spec/fixtures/file_scanner/lib/ruby-lint/global_scope.rb +6 -0
  189. data/spec/ruby-lint/analysis/unused_variables_spec.rb +114 -0
  190. data/spec/ruby-lint/cache_entry_spec.rb +25 -0
  191. data/spec/ruby-lint/cache_spec.rb +53 -0
  192. data/spec/ruby-lint/definition/ruby_method_spec.rb +4 -4
  193. data/spec/ruby-lint/definition/ruby_object_spec.rb +33 -0
  194. data/spec/ruby-lint/iterator_spec.rb +15 -0
  195. data/spec/ruby-lint/node_hash_spec.rb +56 -0
  196. data/spec/ruby-lint/runner_spec.rb +6 -1
  197. data/spec/ruby-lint/virtual_machine/assignments/variables_spec.rb +2 -2
  198. data/spec/ruby-lint/virtual_machine/location_spec.rb +64 -0
  199. data/spec/ruby-lint/virtual_machine/method_call_tracking_spec.rb +64 -0
  200. data/spec/spec_helper.rb +7 -0
  201. data/task/generate.rake +1 -1
  202. data.tar.gz.asc +14 -14
  203. metadata +34 -7
  204. metadata.gz.asc +14 -14
  205. data/debug/memory_usage.rb +0 -14
  206. data/debug/profile.rb +0 -18
  207. data/task/profile.rake +0 -27
data/lib/ruby-lint.rb CHANGED
@@ -1,9 +1,22 @@
1
- gem 'parser', '>= 2.0.0.pre6'
1
+ gem 'parser', '>= 2.0.0'
2
2
 
3
3
  require 'parser'
4
- require 'parser/current'
4
+
5
+ # Try to load the latest parser and fall back to 2.0. This should only occur on
6
+ # Ruby versions >= 2.1 (e.g. Rubinius HEAD).
7
+ begin
8
+ require 'parser/current'
9
+ rescue NotImplementedError => error
10
+ warn "Falling back to Ruby 2.0: #{error.message}"
11
+
12
+ require 'parser/ruby20'
13
+ Parser::CurrentRuby = Parser::Ruby20
14
+ end
15
+
5
16
  require 'yaml'
6
17
  require 'set'
18
+ require 'digest/sha1'
19
+ require 'zlib'
7
20
 
8
21
  require_relative 'ruby-lint/extensions/string'
9
22
 
@@ -18,6 +31,10 @@ require_relative 'ruby-lint/docstring/param_tag'
18
31
  require_relative 'ruby-lint/docstring/return_tag'
19
32
  require_relative 'ruby-lint/docstring/mapping'
20
33
 
34
+ require_relative 'ruby-lint/node_hash'
35
+ require_relative 'ruby-lint/cache'
36
+ require_relative 'ruby-lint/cache_entry'
37
+
21
38
  require_relative 'ruby-lint/helper/constant_paths'
22
39
 
23
40
  require_relative 'ruby-lint/definition_builder/base'
@@ -41,6 +58,7 @@ require_relative 'ruby-lint/global_scope'
41
58
  require_relative 'ruby-lint/virtual_machine'
42
59
  require_relative 'ruby-lint/constant_loader'
43
60
  require_relative 'ruby-lint/file_loader'
61
+ require_relative 'ruby-lint/method_call_info'
44
62
 
45
63
  require_relative 'ruby-lint/definition/ruby_object'
46
64
  require_relative 'ruby-lint/definition/ruby_method'
@@ -0,0 +1,20 @@
1
+ require 'ruby-prof'
2
+
3
+ require_relative '../lib/ruby-lint'
4
+
5
+ parser = RubyLint::Parser.new
6
+ file = File.expand_path('../../lib/ruby-lint/virtual_machine.rb', __FILE__)
7
+ ast = parser.parse(File.read(file), file)
8
+ amount = 1000
9
+
10
+ result = RubyProf.profile do
11
+ amount.times do
12
+ RubyLint::VirtualMachine.new.run(ast)
13
+ end
14
+ end
15
+
16
+ result.eliminate_methods!([/Integer#times/])
17
+
18
+ printer = RubyProf::GraphHtmlPrinter.new(result)
19
+
20
+ printer.print(STDOUT, :sort_method => :self_time)
data/ruby-lint.gemspec CHANGED
@@ -29,7 +29,7 @@ using the handle "yorickpeterse".
29
29
  s.has_rdoc = 'yard'
30
30
  s.required_ruby_version = '>= 1.9.3'
31
31
 
32
- s.add_dependency 'parser', ['>= 2.0.0.pre6']
32
+ s.add_dependency 'parser', ['>= 2.0.0']
33
33
  s.add_dependency 'slop'
34
34
 
35
35
  s.add_development_dependency 'rake'
@@ -42,4 +42,5 @@ using the handle "yorickpeterse".
42
42
  s.add_development_dependency 'json'
43
43
  s.add_development_dependency 'kramdown'
44
44
  s.add_development_dependency 'redcard'
45
+ s.add_development_dependency 'gnuplot'
45
46
  end
@@ -1,3 +1,32 @@
1
+ # RCAP is released under the BSD License.
2
+ #
3
+ # Copyright 2010 - 2013 AIMRED CC. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY AIMRED CC ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18
+ # EVENT SHALL AIMRED CC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+ # The views and conclusions contained in the software and documentation are
27
+ # those of the authors and should not be interpreted as representing official
28
+ # policies, either expressed or implied, of AIMRED CC.
29
+
1
30
  module RCAP
2
31
  # The VM will raise an error if this class doesn't exist.
3
32
  module Base
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2012 Lee Jarvis
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
1
22
  require 'slop/option'
2
23
  require 'slop/commands'
3
24
 
@@ -0,0 +1,6 @@
1
+ module Definition
2
+ class ConstantProxy
3
+ def initialize(definitions, name)
4
+ end
5
+ end # ConstantProxy
6
+ end # Definition
@@ -0,0 +1,6 @@
1
+ module RubyLint
2
+ module GlobalScope
3
+ def self.definitions
4
+ end
5
+ end # GlobalScope
6
+ end # RubyLint
@@ -142,4 +142,118 @@ def number; end
142
142
 
143
143
  report.entries.empty?.should == true
144
144
  end
145
+
146
+ context 'method arguments' do
147
+ example 'warn for a unused argument' do
148
+ code = <<-CODE
149
+ def multiply(number)
150
+ end
151
+ CODE
152
+
153
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
154
+ entry = report.entries[0]
155
+
156
+ entry.message.should == 'unused argument number'
157
+ entry.line.should == 1
158
+ entry.column.should == 13
159
+ end
160
+
161
+ example 'warn for a unused optional argument' do
162
+ code = <<-CODE
163
+ def multiply(amount = 2)
164
+ end
165
+ CODE
166
+
167
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
168
+ entry = report.entries[0]
169
+
170
+ entry.message.should == 'unused argument amount'
171
+ entry.line.should == 1
172
+ entry.column.should == 13
173
+ end
174
+
175
+ example 'warn for a unused rest argument' do
176
+ code = <<-CODE
177
+ def multiply(*args)
178
+ end
179
+ CODE
180
+
181
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
182
+ entry = report.entries[0]
183
+
184
+ entry.message.should == 'unused argument args'
185
+ entry.line.should == 1
186
+ entry.column.should == 13
187
+ end
188
+
189
+ example 'warn for a unused block argument' do
190
+ code = <<-CODE
191
+ def multiply(&block)
192
+ end
193
+ CODE
194
+
195
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
196
+ entry = report.entries[0]
197
+
198
+ entry.message.should == 'unused argument block'
199
+ entry.line.should == 1
200
+ entry.column.should == 13
201
+ end
202
+
203
+ specific_ruby_version '2.0' do
204
+ example 'warn for a unused keyword argument' do
205
+ code = <<-CODE
206
+ def multiply(amount: 10)
207
+ end
208
+ CODE
209
+
210
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
211
+ entry = report.entries[0]
212
+
213
+ entry.message.should == 'unused argument amount'
214
+ entry.line.should == 1
215
+ entry.column.should == 13
216
+ end
217
+ end
218
+
219
+ example 'do not warn for a used argument' do
220
+ code = <<-CODE
221
+ def multiply(number)
222
+ return number * 2
223
+ end
224
+ CODE
225
+
226
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
227
+
228
+ report.entries.empty?.should == true
229
+ end
230
+ end
231
+
232
+ context 'block arguments' do
233
+ example 'warn for a unused argument' do
234
+ code = <<-CODE
235
+ [10, 20].each do |number|
236
+ end
237
+ CODE
238
+
239
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
240
+ entry = report.entries[0]
241
+
242
+ entry.message.should == 'unused argument number'
243
+ entry.line.should == 1
244
+ entry.column.should == 18
245
+ end
246
+
247
+ example 'do not warn for a used argument' do
248
+ code = <<-CODE
249
+ [10, 20].each do |number|
250
+ number
251
+ end
252
+ CODE
253
+
254
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
255
+
256
+ report.entries.empty?.should == true
257
+ end
258
+ end
145
259
  end
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,53 @@
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,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RubyLint::Definition::RubyObject do
4
- describe 'method definition DSL' do
4
+ context 'method definition DSL' do
5
5
  before do
6
6
  @method = ruby_method.new(:name => 'example', :type => :instance_method)
7
7
  end
8
8
 
9
- describe 'return values' do
9
+ context 'return values' do
10
10
  example 'return a static value' do
11
11
  @method.returns(10)
12
12
 
@@ -23,7 +23,7 @@ describe RubyLint::Definition::RubyObject do
23
23
  end
24
24
  end
25
25
 
26
- describe 'calling methods' do
26
+ context 'calling methods' do
27
27
  before do
28
28
  @method.returns(10)
29
29
  end
@@ -56,7 +56,7 @@ describe RubyLint::Definition::RubyObject do
56
56
  end
57
57
  end
58
58
 
59
- describe 'defining arguments' do
59
+ context 'defining arguments' do
60
60
  example 'define an argument' do
61
61
  @method.define_argument('number')
62
62
 
@@ -194,4 +194,37 @@ describe ruby_object do
194
194
 
195
195
  target.lookup(:const, 'Foo').should == const
196
196
  end
197
+
198
+ example 'storing location information in a definition' do
199
+ obj = ruby_object.new(:line => 10, :column => 2, :file => '(ruby-lint)')
200
+
201
+ obj.line.should == 10
202
+ obj.column.should == 2
203
+ obj.file.should == '(ruby-lint)'
204
+ end
205
+
206
+ context 'deep freezing definitions' do
207
+ before :all do
208
+ @const = ruby_object.new(:type => :const, :name => 'Foo')
209
+ @method = ruby_method.new(:type => :method, :name => 'test')
210
+
211
+ @const.add_definition(@method)
212
+
213
+ @const.deep_freeze
214
+ end
215
+
216
+ example 'freeze the root constant' do
217
+ @const.frozen?.should == true
218
+ end
219
+
220
+ example 'freeze the definitions list of the root constant' do
221
+ @const.definitions.frozen?.should == true
222
+ end
223
+
224
+ example 'freeze child definitions' do
225
+ @method.frozen?.should == true
226
+ @method.calls.frozen?.should == true
227
+ @method.callers.frozen?.should == true
228
+ end
229
+ end
197
230
  end
@@ -133,4 +133,19 @@ end
133
133
  iterator.options[:module].should == true
134
134
  iterator.options[:class].should == false
135
135
  end
136
+
137
+ example 'allow callbacks without arguments' do
138
+ ast = parse('10', false)
139
+ iterator = Class.new(RubyLint::Iterator) do
140
+ attr_reader :number
141
+
142
+ def on_int
143
+ @number = true
144
+ end
145
+ end.new
146
+
147
+ iterator.iterate(ast)
148
+
149
+ iterator.number.should == true
150
+ end
136
151
  end