ruby-lint 0.0.2 → 0.0.3

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 (321) hide show
  1. data.tar.gz.asc +17 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +25 -0
  4. data/.yardopts +4 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE +1 -1
  7. data/MANIFEST +238 -49
  8. data/README.md +84 -131
  9. data/Rakefile +6 -0
  10. data/bin/ruby-lint +2 -2
  11. data/checksum/.gitkeep +0 -0
  12. data/doc/DCO.md +26 -0
  13. data/doc/architecture.md +63 -0
  14. data/doc/code_analysis.md +90 -0
  15. data/doc/configuration.md +86 -0
  16. data/doc/contributing.md +16 -0
  17. data/doc/graphviz/flow.dot +7 -0
  18. data/doc/images/.gitkeep +0 -0
  19. data/doc/images/flow.png +0 -0
  20. data/lib/ruby-lint.rb +35 -35
  21. data/lib/ruby-lint/analyze/argument_amount.rb +73 -0
  22. data/lib/ruby-lint/analyze/shadowing_variables.rb +19 -24
  23. data/lib/ruby-lint/analyze/undefined_methods.rb +68 -0
  24. data/lib/ruby-lint/analyze/undefined_variables.rb +42 -69
  25. data/lib/ruby-lint/analyze/unused_variables.rb +23 -78
  26. data/lib/ruby-lint/base.rb +85 -0
  27. data/lib/ruby-lint/cli.rb +23 -167
  28. data/lib/ruby-lint/cli/analyze.rb +99 -0
  29. data/lib/ruby-lint/cli/ast.rb +35 -0
  30. data/lib/ruby-lint/cli/base.rb +120 -0
  31. data/lib/ruby-lint/configuration.rb +112 -0
  32. data/lib/ruby-lint/constant_loader.rb +92 -0
  33. data/lib/ruby-lint/definition/ruby_method.rb +248 -0
  34. data/lib/ruby-lint/definition/ruby_object.rb +757 -0
  35. data/lib/ruby-lint/definition_generator.rb +155 -0
  36. data/lib/ruby-lint/definitions/core.rb +5 -0
  37. data/lib/ruby-lint/definitions/core/arg0.rb +7 -0
  38. data/lib/ruby-lint/definitions/core/argf.rb +7 -0
  39. data/lib/ruby-lint/definitions/core/argument_error.rb +12 -0
  40. data/lib/ruby-lint/definitions/core/argv.rb +7 -0
  41. data/lib/ruby-lint/definitions/core/array.rb +414 -0
  42. data/lib/ruby-lint/definitions/core/autoload.rb +39 -0
  43. data/lib/ruby-lint/definitions/core/basic_object.rb +46 -0
  44. data/lib/ruby-lint/definitions/core/bignum.rb +128 -0
  45. data/lib/ruby-lint/definitions/core/binding.rb +52 -0
  46. data/lib/ruby-lint/definitions/core/class.rb +23 -0
  47. data/lib/ruby-lint/definitions/core/comparable.rb +38 -0
  48. data/lib/ruby-lint/definitions/core/complex.rb +195 -0
  49. data/lib/ruby-lint/definitions/core/condition_variable.rb +19 -0
  50. data/lib/ruby-lint/definitions/core/continuation.rb +8 -0
  51. data/lib/ruby-lint/definitions/core/data.rb +8 -0
  52. data/lib/ruby-lint/definitions/core/date.rb +706 -0
  53. data/lib/ruby-lint/definitions/core/date_time.rb +381 -0
  54. data/lib/ruby-lint/definitions/core/default_record_separator.rb +7 -0
  55. data/lib/ruby-lint/definitions/core/digest.rb +166 -0
  56. data/lib/ruby-lint/definitions/core/dir.rb +496 -0
  57. data/lib/ruby-lint/definitions/core/encoding.rb +2030 -0
  58. data/lib/ruby-lint/definitions/core/encoding_error.rb +8 -0
  59. data/lib/ruby-lint/definitions/core/enumerable.rb +352 -0
  60. data/lib/ruby-lint/definitions/core/enumerator.rb +37 -0
  61. data/lib/ruby-lint/definitions/core/env.rb +7 -0
  62. data/lib/ruby-lint/definitions/core/eoferror.rb +8 -0
  63. data/lib/ruby-lint/definitions/core/erb.rb +304 -0
  64. data/lib/ruby-lint/definitions/core/errno.rb +3331 -0
  65. data/lib/ruby-lint/definitions/core/etc.rb +138 -0
  66. data/lib/ruby-lint/definitions/core/exception.rb +72 -0
  67. data/lib/ruby-lint/definitions/core/false.rb +7 -0
  68. data/lib/ruby-lint/definitions/core/false_class.rb +30 -0
  69. data/lib/ruby-lint/definitions/core/fatal_error.rb +8 -0
  70. data/lib/ruby-lint/definitions/core/fiber.rb +35 -0
  71. data/lib/ruby-lint/definitions/core/fiber_error.rb +8 -0
  72. data/lib/ruby-lint/definitions/core/file.rb +1277 -0
  73. data/lib/ruby-lint/definitions/core/file_list.rb +727 -0
  74. data/lib/ruby-lint/definitions/core/file_test.rb +106 -0
  75. data/lib/ruby-lint/definitions/core/file_utils.rb +1027 -0
  76. data/lib/ruby-lint/definitions/core/fixnum.rb +156 -0
  77. data/lib/ruby-lint/definitions/core/float.rb +307 -0
  78. data/lib/ruby-lint/definitions/core/float_domain_error.rb +8 -0
  79. data/lib/ruby-lint/definitions/core/gc.rb +57 -0
  80. data/lib/ruby-lint/definitions/core/gem.rb +3161 -0
  81. data/lib/ruby-lint/definitions/core/hash.rb +512 -0
  82. data/lib/ruby-lint/definitions/core/immediate_value.rb +19 -0
  83. data/lib/ruby-lint/definitions/core/index_error.rb +8 -0
  84. data/lib/ruby-lint/definitions/core/integer.rb +100 -0
  85. data/lib/ruby-lint/definitions/core/interrupt.rb +14 -0
  86. data/lib/ruby-lint/definitions/core/io.rb +928 -0
  87. data/lib/ruby-lint/definitions/core/ioerror.rb +8 -0
  88. data/lib/ruby-lint/definitions/core/kernel.rb +504 -0
  89. data/lib/ruby-lint/definitions/core/key_error.rb +8 -0
  90. data/lib/ruby-lint/definitions/core/load_error.rb +28 -0
  91. data/lib/ruby-lint/definitions/core/local_jump_error.rb +8 -0
  92. data/lib/ruby-lint/definitions/core/main.rb +25 -0
  93. data/lib/ruby-lint/definitions/core/marshal.rb +466 -0
  94. data/lib/ruby-lint/definitions/core/match_data.rb +73 -0
  95. data/lib/ruby-lint/definitions/core/math.rb +205 -0
  96. data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +8 -0
  97. data/lib/ruby-lint/definitions/core/method.rb +61 -0
  98. data/lib/ruby-lint/definitions/core/module.rb +262 -0
  99. data/lib/ruby-lint/definitions/core/monitor.rb +39 -0
  100. data/lib/ruby-lint/definitions/core/monitor_mixin.rb +59 -0
  101. data/lib/ruby-lint/definitions/core/mutex.rb +32 -0
  102. data/lib/ruby-lint/definitions/core/name_error.rb +16 -0
  103. data/lib/ruby-lint/definitions/core/nil.rb +7 -0
  104. data/lib/ruby-lint/definitions/core/nil_class.rb +46 -0
  105. data/lib/ruby-lint/definitions/core/no_memory_error.rb +8 -0
  106. data/lib/ruby-lint/definitions/core/no_method_error.rb +18 -0
  107. data/lib/ruby-lint/definitions/core/not_implemented_error.rb +8 -0
  108. data/lib/ruby-lint/definitions/core/numeric.rb +123 -0
  109. data/lib/ruby-lint/definitions/core/object.rb +31 -0
  110. data/lib/ruby-lint/definitions/core/object_space.rb +41 -0
  111. data/lib/ruby-lint/definitions/core/open_struct.rb +49 -0
  112. data/lib/ruby-lint/definitions/core/option_parser.rb +1355 -0
  113. data/lib/ruby-lint/definitions/core/precision.rb +21 -0
  114. data/lib/ruby-lint/definitions/core/primitive_failure.rb +8 -0
  115. data/lib/ruby-lint/definitions/core/proc.rb +109 -0
  116. data/lib/ruby-lint/definitions/core/process.rb +602 -0
  117. data/lib/ruby-lint/definitions/core/psych.rb +2231 -0
  118. data/lib/ruby-lint/definitions/core/queue.rb +44 -0
  119. data/lib/ruby-lint/definitions/core/rake.rb +4784 -0
  120. data/lib/ruby-lint/definitions/core/rake_file_utils.rb +203 -0
  121. data/lib/ruby-lint/definitions/core/rakeversion.rb +7 -0
  122. data/lib/ruby-lint/definitions/core/random.rb +38 -0
  123. data/lib/ruby-lint/definitions/core/range.rb +104 -0
  124. data/lib/ruby-lint/definitions/core/range_error.rb +8 -0
  125. data/lib/ruby-lint/definitions/core/rational.rb +96 -0
  126. data/lib/ruby-lint/definitions/core/rb_config.rb +36 -0
  127. data/lib/ruby-lint/definitions/core/regexp.rb +396 -0
  128. data/lib/ruby-lint/definitions/core/regexp_error.rb +8 -0
  129. data/lib/ruby-lint/definitions/core/rubinius.rb +16637 -0
  130. data/lib/ruby-lint/definitions/core/ruby_copyright.rb +7 -0
  131. data/lib/ruby-lint/definitions/core/ruby_description.rb +7 -0
  132. data/lib/ruby-lint/definitions/core/ruby_engine.rb +7 -0
  133. data/lib/ruby-lint/definitions/core/ruby_lint.rb +93 -0
  134. data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +7 -0
  135. data/lib/ruby-lint/definitions/core/ruby_platform.rb +7 -0
  136. data/lib/ruby-lint/definitions/core/ruby_release_date.rb +7 -0
  137. data/lib/ruby-lint/definitions/core/ruby_version.rb +7 -0
  138. data/lib/ruby-lint/definitions/core/runtime_error.rb +8 -0
  139. data/lib/ruby-lint/definitions/core/scan_error.rb +8 -0
  140. data/lib/ruby-lint/definitions/core/script_error.rb +8 -0
  141. data/lib/ruby-lint/definitions/core/security_error.rb +8 -0
  142. data/lib/ruby-lint/definitions/core/shellwords.rb +37 -0
  143. data/lib/ruby-lint/definitions/core/signal.rb +37 -0
  144. data/lib/ruby-lint/definitions/core/signal_exception.rb +19 -0
  145. data/lib/ruby-lint/definitions/core/singleton.rb +37 -0
  146. data/lib/ruby-lint/definitions/core/sized_queue.rb +42 -0
  147. data/lib/ruby-lint/definitions/core/standard_error.rb +8 -0
  148. data/lib/ruby-lint/definitions/core/stderr.rb +7 -0
  149. data/lib/ruby-lint/definitions/core/stdin.rb +7 -0
  150. data/lib/ruby-lint/definitions/core/stdout.rb +7 -0
  151. data/lib/ruby-lint/definitions/core/stop_iteration.rb +8 -0
  152. data/lib/ruby-lint/definitions/core/string.rb +713 -0
  153. data/lib/ruby-lint/definitions/core/string_io.rb +287 -0
  154. data/lib/ruby-lint/definitions/core/string_scanner.rb +158 -0
  155. data/lib/ruby-lint/definitions/core/struct.rb +357 -0
  156. data/lib/ruby-lint/definitions/core/syck.rb +30 -0
  157. data/lib/ruby-lint/definitions/core/symbol.rb +90 -0
  158. data/lib/ruby-lint/definitions/core/syntax_error.rb +44 -0
  159. data/lib/ruby-lint/definitions/core/system_call_error.rb +31 -0
  160. data/lib/ruby-lint/definitions/core/system_exit.rb +19 -0
  161. data/lib/ruby-lint/definitions/core/system_stack_error.rb +8 -0
  162. data/lib/ruby-lint/definitions/core/thread.rb +209 -0
  163. data/lib/ruby-lint/definitions/core/thread_error.rb +8 -0
  164. data/lib/ruby-lint/definitions/core/thread_group.rb +22 -0
  165. data/lib/ruby-lint/definitions/core/time.rb +233 -0
  166. data/lib/ruby-lint/definitions/core/toplevel_binding.rb +7 -0
  167. data/lib/ruby-lint/definitions/core/true.rb +7 -0
  168. data/lib/ruby-lint/definitions/core/true_class.rb +30 -0
  169. data/lib/ruby-lint/definitions/core/type_error.rb +8 -0
  170. data/lib/ruby-lint/definitions/core/unbound_method.rb +51 -0
  171. data/lib/ruby-lint/definitions/core/unmarshalable.rb +13 -0
  172. data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +8 -0
  173. data/lib/ruby-lint/definitions/core/weak_ref.rb +42 -0
  174. data/lib/ruby-lint/definitions/core/zero_division_error.rb +8 -0
  175. data/lib/ruby-lint/definitions_builder.rb +692 -0
  176. data/lib/ruby-lint/extensions/string.rb +15 -0
  177. data/lib/ruby-lint/helper/constant_paths.rb +41 -0
  178. data/lib/ruby-lint/helper/conversion.rb +33 -0
  179. data/lib/ruby-lint/helper/current_scope.rb +98 -0
  180. data/lib/ruby-lint/helper/methods.rb +91 -0
  181. data/lib/ruby-lint/inspector.rb +191 -0
  182. data/lib/ruby-lint/iterator.rb +187 -127
  183. data/lib/ruby-lint/node.rb +107 -0
  184. data/lib/ruby-lint/parser.rb +510 -1137
  185. data/lib/ruby-lint/parser_error.rb +15 -27
  186. data/lib/ruby-lint/presenter/json.rb +19 -0
  187. data/lib/ruby-lint/presenter/text.rb +37 -0
  188. data/lib/ruby-lint/report.rb +95 -53
  189. data/lib/ruby-lint/report/entry.rb +71 -0
  190. data/lib/ruby-lint/template/definition.erb +24 -0
  191. data/lib/ruby-lint/template/scope.rb +25 -0
  192. data/lib/ruby-lint/variable_predicates.rb +109 -0
  193. data/lib/ruby-lint/version.rb +1 -1
  194. data/ruby-lint.gemspec +19 -8
  195. data/spec/helper.rb +10 -2
  196. data/spec/ruby-lint/analyze/argument_amount.rb +91 -0
  197. data/spec/ruby-lint/analyze/shadowing_variables.rb +69 -14
  198. data/spec/ruby-lint/analyze/undefined_methods.rb +174 -0
  199. data/spec/ruby-lint/analyze/undefined_variables.rb +70 -179
  200. data/spec/ruby-lint/analyze/unused_variables.rb +63 -183
  201. data/spec/ruby-lint/configuration.rb +15 -0
  202. data/spec/ruby-lint/constant_loader.rb +32 -0
  203. data/spec/ruby-lint/definition/dsl.rb +142 -0
  204. data/spec/ruby-lint/definition/method_calls.rb +26 -0
  205. data/spec/ruby-lint/definition/ruby_method.rb +175 -0
  206. data/spec/ruby-lint/definition/ruby_object.rb +228 -0
  207. data/spec/ruby-lint/definitions_builder/assignments/arrays.rb +71 -0
  208. data/spec/ruby-lint/definitions_builder/assignments/hashes.rb +65 -0
  209. data/spec/ruby-lint/definitions_builder/assignments/objects.rb +23 -0
  210. data/spec/ruby-lint/definitions_builder/assignments/optional.rb +22 -0
  211. data/spec/ruby-lint/definitions_builder/assignments/return_values.rb +78 -0
  212. data/spec/ruby-lint/definitions_builder/assignments/variables.rb +71 -0
  213. data/spec/ruby-lint/definitions_builder/associate_nodes.rb +17 -0
  214. data/spec/ruby-lint/definitions_builder/blocks.rb +40 -0
  215. data/spec/ruby-lint/definitions_builder/classes.rb +230 -0
  216. data/spec/ruby-lint/definitions_builder/for.rb +16 -0
  217. data/spec/ruby-lint/definitions_builder/methods.rb +147 -0
  218. data/spec/ruby-lint/definitions_builder/modules.rb +175 -0
  219. data/spec/ruby-lint/definitions_builder/reference_amount.rb +31 -0
  220. data/spec/ruby-lint/definitions_builder/unused.rb +15 -0
  221. data/spec/ruby-lint/extensions/string.rb +7 -0
  222. data/spec/ruby-lint/iterator.rb +42 -417
  223. data/spec/ruby-lint/node.rb +38 -0
  224. data/spec/ruby-lint/parser/assignments.rb +225 -0
  225. data/spec/ruby-lint/parser/classes.rb +80 -122
  226. data/spec/ruby-lint/parser/errors.rb +7 -14
  227. data/spec/ruby-lint/parser/metadata.rb +17 -0
  228. data/spec/ruby-lint/parser/method_definitions.rb +111 -0
  229. data/spec/ruby-lint/parser/methods.rb +184 -216
  230. data/spec/ruby-lint/parser/modules.rb +54 -33
  231. data/spec/ruby-lint/parser/operators.rb +30 -65
  232. data/spec/ruby-lint/parser/statements/begin.rb +55 -0
  233. data/spec/ruby-lint/parser/statements/case.rb +34 -0
  234. data/spec/ruby-lint/parser/statements/defined.rb +11 -0
  235. data/spec/ruby-lint/parser/statements/for.rb +34 -0
  236. data/spec/ruby-lint/parser/statements/if.rb +46 -0
  237. data/spec/ruby-lint/parser/statements/return.rb +14 -0
  238. data/spec/ruby-lint/parser/statements/super.rb +49 -0
  239. data/spec/ruby-lint/parser/statements/unless.rb +42 -0
  240. data/spec/ruby-lint/parser/statements/until.rb +25 -0
  241. data/spec/ruby-lint/parser/statements/while.rb +25 -0
  242. data/spec/ruby-lint/parser/statements/yield.rb +18 -0
  243. data/spec/ruby-lint/parser/types/arrays.rb +47 -0
  244. data/spec/ruby-lint/parser/types/booleans.rb +11 -0
  245. data/spec/ruby-lint/parser/types/constants.rb +32 -0
  246. data/spec/ruby-lint/parser/types/hashes.rb +55 -0
  247. data/spec/ruby-lint/parser/types/nil.rb +7 -0
  248. data/spec/ruby-lint/parser/types/numbers.rb +11 -0
  249. data/spec/ruby-lint/parser/types/procs.rb +11 -0
  250. data/spec/ruby-lint/parser/types/ranges.rb +11 -0
  251. data/spec/ruby-lint/parser/types/regexp.rb +27 -0
  252. data/spec/ruby-lint/parser/types/strings.rb +44 -0
  253. data/spec/ruby-lint/parser/types/symbols.rb +15 -0
  254. data/spec/ruby-lint/presenter/json.rb +31 -0
  255. data/spec/ruby-lint/presenter/text.rb +22 -0
  256. data/spec/ruby-lint/report.rb +45 -15
  257. data/spec/ruby-lint/report/entry.rb +24 -0
  258. data/spec/support/bacon.rb +33 -0
  259. data/spec/support/building.rb +43 -0
  260. data/spec/support/definitions.rb +23 -0
  261. data/spec/support/parsing.rb +23 -0
  262. data/spec/support/simplecov.rb +16 -0
  263. data/task/build.rake +9 -0
  264. data/task/checksum.rake +13 -0
  265. data/task/coverage.rake +6 -0
  266. data/task/doc.rake +5 -0
  267. data/task/generate.rake +34 -0
  268. data/task/graphviz.rake +12 -0
  269. data/task/stdlib.rake +2 -9
  270. data/task/tag.rake +6 -0
  271. metadata +337 -68
  272. metadata.gz.asc +17 -0
  273. data/.rbenv-version +0 -1
  274. data/lib/ruby-lint/analyze/coding_style.rb +0 -407
  275. data/lib/ruby-lint/analyze/definitions.rb +0 -244
  276. data/lib/ruby-lint/analyze/method_validation.rb +0 -104
  277. data/lib/ruby-lint/callback.rb +0 -67
  278. data/lib/ruby-lint/constant_importer.rb +0 -112
  279. data/lib/ruby-lint/definition.rb +0 -230
  280. data/lib/ruby-lint/formatter/text.rb +0 -54
  281. data/lib/ruby-lint/helper/definition_resolver.rb +0 -143
  282. data/lib/ruby-lint/helper/scoping.rb +0 -138
  283. data/lib/ruby-lint/options.rb +0 -58
  284. data/lib/ruby-lint/token/assignment_token.rb +0 -35
  285. data/lib/ruby-lint/token/begin_rescue_token.rb +0 -57
  286. data/lib/ruby-lint/token/block_token.rb +0 -26
  287. data/lib/ruby-lint/token/case_token.rb +0 -44
  288. data/lib/ruby-lint/token/class_token.rb +0 -24
  289. data/lib/ruby-lint/token/keyword_token.rb +0 -43
  290. data/lib/ruby-lint/token/method_definition_token.rb +0 -64
  291. data/lib/ruby-lint/token/method_token.rb +0 -56
  292. data/lib/ruby-lint/token/parameters_token.rb +0 -99
  293. data/lib/ruby-lint/token/regexp_token.rb +0 -15
  294. data/lib/ruby-lint/token/statement_token.rb +0 -69
  295. data/lib/ruby-lint/token/token.rb +0 -176
  296. data/lib/ruby-lint/token/variable_token.rb +0 -18
  297. data/spec/benchmarks/memory.rb +0 -52
  298. data/spec/benchmarks/parse_parser.rb +0 -16
  299. data/spec/fixtures/stdlib/un.rb +0 -348
  300. data/spec/ruby-lint/analyze/coding_style.rb +0 -224
  301. data/spec/ruby-lint/analyze/complex/un.rb +0 -29
  302. data/spec/ruby-lint/analyze/definitions/classes.rb +0 -114
  303. data/spec/ruby-lint/analyze/definitions/methods.rb +0 -91
  304. data/spec/ruby-lint/analyze/definitions/modules.rb +0 -207
  305. data/spec/ruby-lint/analyze/definitions/variables.rb +0 -103
  306. data/spec/ruby-lint/analyze/method_validation.rb +0 -177
  307. data/spec/ruby-lint/callback.rb +0 -28
  308. data/spec/ruby-lint/constant_importer.rb +0 -27
  309. data/spec/ruby-lint/definition.rb +0 -96
  310. data/spec/ruby-lint/formatter/text.rb +0 -21
  311. data/spec/ruby-lint/parser/arrays.rb +0 -147
  312. data/spec/ruby-lint/parser/expander_assignments.rb +0 -183
  313. data/spec/ruby-lint/parser/hashes.rb +0 -136
  314. data/spec/ruby-lint/parser/keywords.rb +0 -89
  315. data/spec/ruby-lint/parser/objects.rb +0 -39
  316. data/spec/ruby-lint/parser/procs.rb +0 -113
  317. data/spec/ruby-lint/parser/ranges.rb +0 -49
  318. data/spec/ruby-lint/parser/regexp.rb +0 -31
  319. data/spec/ruby-lint/parser/scalars.rb +0 -93
  320. data/spec/ruby-lint/parser/statements.rb +0 -591
  321. data/spec/ruby-lint/parser/variables.rb +0 -230
@@ -1,3 +1,3 @@
1
1
  module RubyLint
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end # RubyLint
@@ -3,10 +3,10 @@ require File.expand_path('../lib/ruby-lint/version', __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ruby-lint'
5
5
  s.version = RubyLint::VERSION
6
- s.date = '2012-11-15'
6
+ s.date = '2013-04-22'
7
7
  s.authors = ['Yorick Peterse']
8
8
  s.email = 'yorickpeterse@gmail.com'
9
- s.summary = 'Static code analysis tool and linter for Ruby'
9
+ s.summary = 'A linter and static code analysis tool for Ruby.'
10
10
  s.homepage = 'https://github.com/yorickpeterse/ruby-lint/'
11
11
  s.description = s.summary
12
12
  s.executables = ['ruby-lint']
@@ -14,11 +14,22 @@ Gem::Specification.new do |s|
14
14
  s.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n")
15
15
 
16
16
  s.has_rdoc = 'yard'
17
- s.required_ruby_version = '>= 1.9.2'
17
+ s.required_ruby_version = '>= 1.9.3'
18
18
 
19
- s.add_development_dependency('rake', ['>= 0.9.2.2'])
20
- s.add_development_dependency('redcarpet', ['>= 2.1.1'])
21
- s.add_development_dependency('bacon', ['>= 1.1.0'])
22
- s.add_development_dependency('yard', ['>= 0.8.2.1'])
23
- s.add_development_dependency('pry-rescue', ['>= 0.8'])
19
+ s.add_dependency 'ast'
20
+ s.add_dependency 'slop'
21
+
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'bacon', ['>= 1.2.0']
24
+ s.add_development_dependency 'yard'
25
+ s.add_development_dependency 'pry-rescue'
26
+ s.add_development_dependency 'bacon-colored_output'
27
+ s.add_development_dependency 'simplecov'
28
+ s.add_development_dependency 'rubygems-openpgp'
29
+
30
+ # NOTE: This is to prevent Travis CI from soiling its pants. It's not a
31
+ # really nice solution but it seems to be the only way (at least for now).
32
+ if RUBY_PLATFORM != 'java'
33
+ s.add_development_dependency 'redcarpet', ['>= 2.1.1']
34
+ end
24
35
  end
@@ -1,6 +1,14 @@
1
- require File.expand_path('../../lib/ruby-lint', __FILE__)
2
1
  require 'bacon'
2
+ require 'bacon/colored_output'
3
+ require_relative 'support/bacon'
3
4
 
4
- RubyLint::FIXTURES = File.expand_path('../fixtures', __FILE__)
5
+ if ENV['COVERAGE']
6
+ require_relative 'support/simplecov'
7
+ end
8
+
9
+ require_relative '../lib/ruby-lint'
10
+ require_relative 'support/building'
11
+ require_relative 'support/parsing'
12
+ require_relative 'support/definitions'
5
13
 
6
14
  Bacon.summary_on_exit
@@ -0,0 +1,91 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe RubyLint::Analyze::ArgumentAmount do
4
+ should 'validate the amount of required arguments' do
5
+ code = <<-CODE
6
+ def example(first, second)
7
+ end
8
+
9
+ example
10
+ CODE
11
+
12
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
13
+ entry = report.entries[0]
14
+
15
+ entry.is_a?(RubyLint::Report::Entry).should == true
16
+
17
+ entry.line.should == 4
18
+ entry.column.should == 0
19
+ entry.message.should == 'wrong number of arguments (expected 2 but got 0)'
20
+ end
21
+
22
+ should 'validate argument amounts when using optional arguments' do
23
+ code = <<-CODE
24
+ def example(first, second, third = nil)
25
+ end
26
+
27
+ example
28
+ CODE
29
+
30
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
31
+ entry = report.entries[0]
32
+
33
+ entry.is_a?(RubyLint::Report::Entry).should == true
34
+
35
+ entry.line.should == 4
36
+ entry.column.should == 0
37
+ entry.message.should == 'wrong number of arguments ' \
38
+ '(expected 2..3 but got 0)'
39
+ end
40
+
41
+ should 'validate argument amounts when using rest arguments' do
42
+ code = <<-CODE
43
+ def example(first, second, *args)
44
+ end
45
+
46
+ example
47
+ CODE
48
+
49
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
50
+ entry = report.entries[0]
51
+
52
+ entry.is_a?(RubyLint::Report::Entry).should == true
53
+
54
+ entry.line.should == 4
55
+ entry.column.should == 0
56
+ entry.message.should == 'wrong number of arguments ' \
57
+ '(expected 2 but got 0)'
58
+ end
59
+
60
+ should 'validate argument amounts when using a required and rest argument' do
61
+ code = <<-CODE
62
+ def example(required, *numbers)
63
+ end
64
+
65
+ example(10, 20, 30)
66
+ CODE
67
+
68
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
69
+
70
+ report.entries.length.should == 0
71
+ end
72
+
73
+ should 'take variable assignments into account' do
74
+ code = <<-CODE
75
+ name = 'Ruby'
76
+
77
+ name.downcase
78
+ CODE
79
+
80
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
81
+
82
+ report.entries.empty?.should == true
83
+ end
84
+
85
+ should 'not validate methods called on undefined receivers' do
86
+ code = 'A.example_method'
87
+ report = build_report(code, RubyLint::Analyze::ArgumentAmount)
88
+
89
+ report.entries.empty?.should == true
90
+ end
91
+ end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../../helper', __FILE__)
2
2
 
3
- describe 'RubyLint::Analyze::ShadowingVariables' do
4
- it 'Warn for shadowing outer variables' do
3
+ describe RubyLint::Analyze::ShadowingVariables do
4
+ should 'warn for shadowing outer variables' do
5
5
  code = <<-CODE
6
6
  number = 10
7
7
 
@@ -10,21 +10,76 @@ number = 10
10
10
  end
11
11
  CODE
12
12
 
13
- tokens = RubyLint::Parser.new(code).parse
14
- report = RubyLint::Report.new
15
- iterator = RubyLint::Iterator.new(report)
13
+ report = build_report(code, RubyLint::Analyze::ShadowingVariables)
14
+ entry = report.entries[0]
16
15
 
17
- iterator.bind(RubyLint::Analyze::Definitions)
18
- iterator.bind(RubyLint::Analyze::ShadowingVariables)
19
- iterator.run(tokens)
16
+ entry.is_a?(RubyLint::Report::Entry).should == true
20
17
 
21
- report.messages[:warning].class.should == Array
22
- report.messages[:warning].length.should == 1
18
+ entry.line.should == 3
19
+ entry.column.should == 18
20
+ entry.message.should == 'shadowing outer local variable number'
21
+ end
22
+
23
+ should 'not warn for shadowed variables in a new scope' do
24
+ code = <<-CODE
25
+ number = 10
26
+
27
+ def example
28
+ [10, 20].each do |number|
29
+ puts number
30
+ end
31
+ end
32
+ CODE
33
+
34
+ report = build_report(code, RubyLint::Analyze::ShadowingVariables)
35
+
36
+ report.entries.empty?.should == true
37
+ end
38
+
39
+ should 'warn when shadowing variables after a new scope' do
40
+ code = <<-CODE
41
+ number = 10
42
+
43
+ def example; end
44
+
45
+ [10, 20].each do |number|
46
+ puts number
47
+ end
48
+ CODE
49
+
50
+ report = build_report(code, RubyLint::Analyze::ShadowingVariables)
51
+ entry = report.entries[0]
52
+
53
+ entry.is_a?(RubyLint::Report::Entry).should == true
54
+
55
+ entry.line.should == 5
56
+ entry.column.should == 18
57
+ entry.message.should == 'shadowing outer local variable number'
58
+ end
59
+
60
+ should 'not fail when re-using the same block' do
61
+ code = <<-CODE
62
+ number = 10
63
+
64
+ A::B.example do |number|
65
+ number
66
+ end
67
+
68
+ A::B.example do |number|
69
+ number
70
+ end
71
+ CODE
72
+
73
+ report = build_report(code, RubyLint::Analyze::ShadowingVariables)
74
+
75
+ report.entries.length.should == 2
76
+
77
+ first, second = report.entries
23
78
 
24
- warning = report.messages[:warning][0]
79
+ first.line.should == 3
80
+ first.column.should == 17
25
81
 
26
- warning[:message].should == 'shadowing outer local variable number'
27
- warning[:line].should == 3
28
- warning[:column].should == 18
82
+ second.line.should == 7
83
+ second.column.should == 17
29
84
  end
30
85
  end
@@ -0,0 +1,174 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ describe RubyLint::Analyze::UndefinedMethods do
4
+ should 'add an error for calling an undefined method' do
5
+ report = build_report('example_method', RubyLint::Analyze::UndefinedMethods)
6
+ entry = report.entries[0]
7
+
8
+ entry.is_a?(RubyLint::Report::Entry).should == true
9
+
10
+ entry.line.should == 1
11
+ entry.column.should == 0
12
+ entry.message.should == 'undefined method example_method'
13
+ end
14
+
15
+ should 'add an error for calling an undefined method with a receiver' do
16
+ code = <<-CODE
17
+ class << self
18
+ def example_method
19
+ end
20
+ end
21
+
22
+ String.example_method
23
+ CODE
24
+
25
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
26
+ entry = report.entries[0]
27
+
28
+ entry.is_a?(RubyLint::Report::Entry).should == true
29
+
30
+ entry.line.should == 6
31
+ entry.column.should == 7
32
+ entry.message.should == 'undefined method example_method on String'
33
+ end
34
+
35
+ should 'add an error for calling an undefined method on a receiver instance' do
36
+ code = '"hello".example_method'
37
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
38
+ entry = report.entries[0]
39
+
40
+ entry.is_a?(RubyLint::Report::Entry).should == true
41
+
42
+ entry.line.should == 1
43
+ entry.column.should == 8
44
+ entry.message.should == 'undefined method example_method ' \
45
+ 'on an instance of String'
46
+ end
47
+
48
+ should 'add an error when calling a method defined in a different scope' do
49
+ code = <<-CODE
50
+ class Person
51
+ def name
52
+ return 'name'
53
+ end
54
+
55
+ def greet
56
+ name
57
+ end
58
+ end
59
+
60
+ name
61
+ CODE
62
+
63
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
64
+
65
+ report.entries.length.should == 1
66
+
67
+ entry = report.entries[0]
68
+
69
+ entry.is_a?(RubyLint::Report::Entry).should == true
70
+
71
+ entry.line.should == 11
72
+ entry.column.should == 0
73
+ entry.message.should == 'undefined method name'
74
+ end
75
+
76
+ describe 'core Ruby types' do
77
+ should 'not add errors for calling defined methods on a Fixnum' do
78
+ report = build_report('10.to_s', RubyLint::Analyze::UndefinedMethods)
79
+
80
+ report.entries.empty?.should == true
81
+ end
82
+
83
+ should 'not add errors for calling defined methods on a Float' do
84
+ report = build_report('(10.0).to_s', RubyLint::Analyze::UndefinedMethods)
85
+
86
+ report.entries.empty?.should == true
87
+ end
88
+
89
+ should 'not add errors for calling defined methods on a String' do
90
+ report = build_report('"10".to_s', RubyLint::Analyze::UndefinedMethods)
91
+
92
+ report.entries.empty?.should == true
93
+ end
94
+
95
+ should 'not add errors for calling defined methods on a Hash' do
96
+ report = build_report('{}.to_s', RubyLint::Analyze::UndefinedMethods)
97
+
98
+ report.entries.empty?.should == true
99
+ end
100
+
101
+ should 'not add errors for calling defined methods on an Array' do
102
+ report = build_report('[].to_s', RubyLint::Analyze::UndefinedMethods)
103
+
104
+ report.entries.empty?.should == true
105
+ end
106
+ end
107
+
108
+ should 'not add errors for variables created using blocks' do
109
+ code = <<-CODE
110
+ [10, 20].each do |number|
111
+ number.to_s
112
+ end
113
+ CODE
114
+
115
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
116
+
117
+ report.entries.empty?.should == true
118
+ end
119
+
120
+ should 'take variable assignments into account' do
121
+ code = <<-CODE
122
+ name = 'Ruby'
123
+
124
+ name.downcase
125
+ name.downcasex
126
+ CODE
127
+
128
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
129
+
130
+ report.entries.length.should == 1
131
+
132
+ entry = report.entries[0]
133
+
134
+ entry.line.should == 4
135
+ entry.column.should == 5
136
+ entry.message.should == 'undefined method downcasex on an instance of String'
137
+ end
138
+
139
+ should 'not add errors when calling a method on an undefined constant' do
140
+ code = 'A.example_method'
141
+
142
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
143
+
144
+ report.entries.empty?.should == true
145
+ end
146
+
147
+ should 'not add errors for methods called on variables without values' do
148
+ code = <<-CODE
149
+ def example(number)
150
+ number.to_s
151
+ end
152
+ CODE
153
+
154
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
155
+
156
+ report.entries.empty?.should == true
157
+ end
158
+
159
+ should 'report the right receiver name in multiple variable assignments' do
160
+ code = <<-CODE
161
+ number = 10
162
+
163
+ first = second = number.foobar
164
+ CODE
165
+
166
+ report = build_report(code, RubyLint::Analyze::UndefinedMethods)
167
+
168
+ report.entries.length.should == 1
169
+
170
+ entry = report.entries[0]
171
+
172
+ entry.message.should == 'undefined method foobar on an instance of Fixnum'
173
+ end
174
+ end
@@ -1,230 +1,121 @@
1
1
  require File.expand_path('../../../helper', __FILE__)
2
2
 
3
- describe 'RubyLint::Analyze::UndefinedVariables' do
4
- it 'Use of undefined variables' do
5
- code = <<-CODE
6
- number = 10
7
-
8
- puts numberx
9
- puts @number
10
- puts @@number
11
- puts $number
12
- puts NUMBER
13
-
14
- # The code below should not add any errors.
15
- numberx = 10
16
- @number = 10
17
- @@number = 10
18
- $number = 10
19
- NUMBER = 10
20
-
21
- puts numberx
22
- puts @number
23
- puts @@number
24
- puts $number
25
- puts NUMBER
26
- CODE
27
-
28
- tokens = RubyLint::Parser.new(code).parse
29
- report = RubyLint::Report.new
30
- iterator = RubyLint::Iterator.new(report)
3
+ describe RubyLint::Analyze::UndefinedVariables do
4
+ should 'add an error for using an undefined instance variable' do
5
+ report = build_report('@number', RubyLint::Analyze::UndefinedVariables)
6
+ entry = report.entries[0]
31
7
 
32
- iterator.bind(RubyLint::Analyze::Definitions)
33
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
34
- iterator.run(tokens)
8
+ entry.is_a?(RubyLint::Report::Entry).should == true
35
9
 
36
- report.messages[:error].class.should == Array
37
- report.messages[:error].length.should == 5
10
+ entry.line.should == 1
11
+ entry.column.should == 0
12
+ entry.message.should == 'undefined instance variable @number'
13
+ end
38
14
 
39
- errors = report.messages[:error]
15
+ should 'add an error for using an undefined class variable' do
16
+ report = build_report('@@number', RubyLint::Analyze::UndefinedVariables)
17
+ entry = report.entries[0]
40
18
 
41
- errors[0][:message].should == 'undefined local variable or method numberx'
42
- errors[0][:line].should == 3
43
- errors[0][:column].should == 5
19
+ entry.is_a?(RubyLint::Report::Entry).should == true
44
20
 
45
- errors[1][:message].should == 'undefined instance variable @number'
46
- errors[1][:line].should == 4
47
- errors[1][:column].should == 5
21
+ entry.line.should == 1
22
+ entry.column.should == 0
23
+ entry.message.should == 'undefined class variable @@number'
24
+ end
48
25
 
49
- errors[2][:message].should == 'undefined class variable @@number'
50
- errors[2][:line].should == 5
51
- errors[2][:column].should == 5
26
+ should 'add an error for using an undefined global variable' do
27
+ report = build_report('$number', RubyLint::Analyze::UndefinedVariables)
28
+ entry = report.entries[0]
52
29
 
53
- errors[3][:message].should == 'undefined global variable $number'
54
- errors[3][:line].should == 6
55
- errors[3][:column].should == 5
30
+ entry.is_a?(RubyLint::Report::Entry).should == true
56
31
 
57
- errors[4][:message].should == 'undefined constant NUMBER'
58
- errors[4][:line].should == 7
59
- errors[4][:column].should == 5
32
+ entry.line.should == 1
33
+ entry.column.should == 0
34
+ entry.message.should == 'undefined global variable $number'
60
35
  end
61
36
 
62
- it 'Default global variables should not trigger errors' do
63
- code = Kernel.global_variables.join("\n")
64
- tokens = RubyLint::Parser.new(code).parse
65
- report = RubyLint::Report.new
66
- iterator = RubyLint::Iterator.new(report)
37
+ should 'add an error for using an undefined constant' do
38
+ report = build_report('NUMBER', RubyLint::Analyze::UndefinedVariables)
39
+ entry = report.entries[0]
67
40
 
68
- iterator.bind(RubyLint::Analyze::Definitions)
69
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
70
- iterator.run(tokens)
41
+ entry.is_a?(RubyLint::Report::Entry).should == true
71
42
 
72
- report.messages[:error].nil?.should == true
43
+ entry.line.should == 1
44
+ entry.column.should == 0
45
+ entry.message.should == 'undefined constant NUMBER'
73
46
  end
74
47
 
75
- it 'Use of undefined variables using a method scope' do
48
+ should 'add an error for using an undefined constant in a constant path' do
76
49
  code = <<-CODE
77
- a = 10
78
- @a = 10
50
+ # This is to ensure that the on_constant() callback isn't used to check for "B"
51
+ # in the global scope.
52
+ B = 10
79
53
 
80
- def number
81
- b = 10
82
-
83
- puts @a # @a should be available as it's an instance method
84
- puts a # a is defined outside of this scope
85
- puts c # c simply doesn't exist
54
+ module A
86
55
  end
87
56
 
88
- puts a
89
- puts b # b was defined inside the method and isn't available outside it
57
+ A::B
90
58
  CODE
91
59
 
92
- tokens = RubyLint::Parser.new(code).parse
93
- report = RubyLint::Report.new
94
- iterator = RubyLint::Iterator.new(report)
95
-
96
- iterator.bind(RubyLint::Analyze::Definitions)
97
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
98
- iterator.run(tokens)
99
-
100
- report.messages[:error].class.should == Array
101
- report.messages[:error].length.should == 3
60
+ report = build_report(code, RubyLint::Analyze::UndefinedVariables)
61
+ entry = report.entries[0]
102
62
 
103
- errors = report.messages[:error]
63
+ entry.is_a?(RubyLint::Report::Entry).should == true
104
64
 
105
- errors[0][:message].should == 'undefined local variable or method a'
106
- errors[0][:line].should == 8
107
- errors[0][:column].should == 7
108
-
109
- errors[1][:message].should == 'undefined local variable or method c'
110
- errors[1][:line].should == 9
111
- errors[1][:column].should == 7
112
-
113
- errors[2][:message].should == 'undefined local variable or method b'
114
- errors[2][:line].should == 13
115
- errors[2][:column].should == 5
65
+ entry.line.should == 8
66
+ entry.column.should == 3
67
+ entry.message.should == 'undefined constant B'
116
68
  end
117
69
 
118
- it 'Instance variables should be available outside a method' do
119
- code = <<-CODE
120
- def number
121
- @number = 10
122
- end
70
+ should 'add an error when the entire constant path does not exist' do
71
+ code = 'A::B::C'
72
+ report = build_report(code, RubyLint::Analyze::UndefinedVariables)
123
73
 
124
- puts @number
125
- CODE
74
+ report.entries.length.should == 1
126
75
 
127
- tokens = RubyLint::Parser.new(code).parse
128
- report = RubyLint::Report.new
129
- iterator = RubyLint::Iterator.new(report)
76
+ entry = report.entries[0]
130
77
 
131
- iterator.bind(RubyLint::Analyze::Definitions)
132
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
133
- iterator.run(tokens)
134
-
135
- report.messages[:error].nil?.should == true
78
+ entry.line.should == 1
79
+ entry.column.should == 0
80
+ entry.message.should == 'undefined constant A'
136
81
  end
137
82
 
138
- it 'Instance variables should be available across a class\' methods' do
83
+ should 'not depend on the order of variable definitions' do
139
84
  code = <<-CODE
140
85
  class Person
141
- def initialize
142
- @name = 'Ruby'
86
+ def first
87
+ @number = 10
143
88
  end
144
89
 
145
- def some_method
146
- @name.upcase
147
- @namex.upcase
90
+ def second
91
+ return @number
148
92
  end
149
93
  end
150
94
  CODE
151
95
 
152
- tokens = RubyLint::Parser.new(code).parse
153
- report = RubyLint::Report.new
154
- iterator = RubyLint::Iterator.new(report)
155
-
156
- iterator.bind(RubyLint::Analyze::Definitions)
157
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
158
- iterator.run(tokens)
159
-
160
- report.messages[:error].class.should == Array
161
- report.messages[:error].length.should == 1
162
-
163
- error = report.messages[:error][0]
96
+ report = build_report(code, RubyLint::Analyze::UndefinedVariables)
164
97
 
165
- error[:message].should == 'undefined instance variable @namex'
166
- error[:line].should == 8
167
- error[:column].should == 4
98
+ report.entries.empty?.should == true
168
99
  end
169
100
 
170
- it 'Add errors for non existing constant paths' do
171
- code = <<-CODE
172
- A::B = 10
173
-
174
- module A
175
-
176
- end
177
-
178
- puts A::B
179
- CODE
180
-
181
- tokens = RubyLint::Parser.new(code).parse
182
- report = RubyLint::Report.new
183
- iterator = RubyLint::Iterator.new(report)
184
-
185
- iterator.bind(RubyLint::Analyze::Definitions)
186
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
187
- iterator.run(tokens)
101
+ should 'not add errors when autoloading constants' do
102
+ code = 'Encoding::BIG5'
103
+ report = build_report(code, RubyLint::Analyze::UndefinedVariables)
188
104
 
189
- report.messages[:error].class.should == Array
190
- report.messages[:error].length.should == 2
191
-
192
- errors = report.messages[:error]
193
-
194
- errors[0][:message].should == 'undefined constant A'
195
- errors[0][:line].should == 1
196
- errors[0][:column].should == 0
197
-
198
- errors[1][:message].should == 'undefined constant A::B'
199
- errors[1][:line].should == 7
200
- errors[1][:column].should == 5
105
+ report.entries.empty?.should == true
201
106
  end
202
107
 
203
- it 'Look up a constant using an implicit constant path' do
108
+ should 'not error when inheriting data in a block' do
204
109
  code = <<-CODE
205
- module RubyLint
206
- module Derp
207
- Foobar.name
208
- ConstantImporter.name
209
- end
210
- end
211
- CODE
212
-
213
- tokens = RubyLint::Parser.new(code).parse
214
- report = RubyLint::Report.new
215
- iterator = RubyLint::Iterator.new(report)
110
+ NUMBER = 10
216
111
 
217
- iterator.bind(RubyLint::Analyze::Definitions)
218
- iterator.bind(RubyLint::Analyze::UndefinedVariables)
219
- iterator.run(tokens)
220
-
221
- report.messages[:error].class.should == Array
222
- report.messages[:error].length.should == 1
112
+ example_method do
113
+ NUMBER
114
+ end
115
+ CODE
223
116
 
224
- error = report.messages[:error][0]
117
+ report = build_report(code, RubyLint::Analyze::UndefinedVariables)
225
118
 
226
- error[:message].should == 'undefined constant Foobar'
227
- error[:line].should == 3
228
- error[:column].should == 4
119
+ report.entries.empty?.should == true
229
120
  end
230
121
  end