ruby-lint 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (347) hide show
  1. data.tar.gz.asc +14 -14
  2. data/.gitignore +1 -2
  3. data/.rubocop.yml +59 -0
  4. data/.travis.yml +3 -7
  5. data/.yardopts +2 -2
  6. data/Gemfile +4 -0
  7. data/MANIFEST +103 -67
  8. data/README.md +13 -31
  9. data/Rakefile +1 -6
  10. data/checksum/ruby-lint-0.0.3.gem.sha512 +1 -0
  11. data/debug/memory_usage.rb +14 -0
  12. data/debug/profile.rb +18 -0
  13. data/doc/architecture.md +14 -18
  14. data/doc/changelog.md +29 -0
  15. data/doc/code_analysis.md +12 -12
  16. data/doc/configuration.md +21 -50
  17. data/doc/graphviz/flow.dot +1 -1
  18. data/doc/images/flow.png +0 -0
  19. data/lib/ruby-lint.rb +33 -19
  20. data/lib/ruby-lint/analysis/argument_amount.rb +84 -0
  21. data/lib/ruby-lint/analysis/base.rb +132 -0
  22. data/lib/ruby-lint/analysis/confusing_variables.rb +26 -0
  23. data/lib/ruby-lint/analysis/pedantics.rb +36 -0
  24. data/lib/ruby-lint/analysis/shadowing_variables.rb +47 -0
  25. data/lib/ruby-lint/analysis/undefined_methods.rb +91 -0
  26. data/lib/ruby-lint/analysis/undefined_variables.rb +46 -0
  27. data/lib/ruby-lint/analysis/unused_variables.rb +49 -0
  28. data/lib/ruby-lint/ast/builder.rb +17 -0
  29. data/lib/ruby-lint/ast/node.rb +39 -0
  30. data/lib/ruby-lint/cli.rb +0 -19
  31. data/lib/ruby-lint/cli/analyze.rb +54 -28
  32. data/lib/ruby-lint/cli/ast.rb +21 -6
  33. data/lib/ruby-lint/cli/base.rb +0 -23
  34. data/lib/ruby-lint/configuration.rb +112 -42
  35. data/lib/ruby-lint/constant_loader.rb +10 -28
  36. data/lib/ruby-lint/default_names.rb +19 -0
  37. data/lib/ruby-lint/definition/constant_proxy.rb +56 -0
  38. data/lib/ruby-lint/definition/ruby_method.rb +21 -143
  39. data/lib/ruby-lint/definition/ruby_object.rb +142 -246
  40. data/lib/ruby-lint/definition_builder/base.rb +43 -0
  41. data/lib/ruby-lint/definition_builder/primitive.rb +39 -0
  42. data/lib/ruby-lint/definition_builder/ruby_array.rb +77 -0
  43. data/lib/ruby-lint/definition_builder/ruby_block.rb +34 -0
  44. data/lib/ruby-lint/definition_builder/ruby_class.rb +24 -0
  45. data/lib/ruby-lint/definition_builder/ruby_hash.rb +37 -0
  46. data/lib/ruby-lint/definition_builder/ruby_method.rb +84 -0
  47. data/lib/ruby-lint/definition_builder/ruby_module.rb +68 -0
  48. data/lib/ruby-lint/definition_generator.rb +41 -15
  49. data/lib/ruby-lint/definitions/core/arg0.rb +1 -1
  50. data/lib/ruby-lint/definitions/core/argf.rb +1 -1
  51. data/lib/ruby-lint/definitions/core/argument_error.rb +2 -2
  52. data/lib/ruby-lint/definitions/core/argv.rb +1 -1
  53. data/lib/ruby-lint/definitions/core/array.rb +6 -6
  54. data/lib/ruby-lint/definitions/core/autoload.rb +2 -2
  55. data/lib/ruby-lint/definitions/core/basic_object.rb +3 -3
  56. data/lib/ruby-lint/definitions/core/bignum.rb +2 -2
  57. data/lib/ruby-lint/definitions/core/binding.rb +2 -2
  58. data/lib/ruby-lint/definitions/core/class.rb +2 -2
  59. data/lib/ruby-lint/definitions/core/comparable.rb +1 -1
  60. data/lib/ruby-lint/definitions/core/complex.rb +4 -4
  61. data/lib/ruby-lint/definitions/core/condition_variable.rb +2 -2
  62. data/lib/ruby-lint/definitions/core/continuation.rb +2 -2
  63. data/lib/ruby-lint/definitions/core/data.rb +2 -2
  64. data/lib/ruby-lint/definitions/core/date.rb +34 -34
  65. data/lib/ruby-lint/definitions/core/date_time.rb +26 -26
  66. data/lib/ruby-lint/definitions/core/default_record_separator.rb +1 -1
  67. data/lib/ruby-lint/definitions/core/digest.rb +14 -14
  68. data/lib/ruby-lint/definitions/core/dir.rb +34 -34
  69. data/lib/ruby-lint/definitions/core/encoding.rb +237 -237
  70. data/lib/ruby-lint/definitions/core/encoding_error.rb +2 -2
  71. data/lib/ruby-lint/definitions/core/enumerable.rb +15 -15
  72. data/lib/ruby-lint/definitions/core/enumerator.rb +2 -2
  73. data/lib/ruby-lint/definitions/core/env.rb +1 -1
  74. data/lib/ruby-lint/definitions/core/eoferror.rb +2 -2
  75. data/lib/ruby-lint/definitions/core/erb.rb +22 -22
  76. data/lib/ruby-lint/definitions/core/errno.rb +525 -525
  77. data/lib/ruby-lint/definitions/core/etc.rb +6 -6
  78. data/lib/ruby-lint/definitions/core/exception.rb +2 -2
  79. data/lib/ruby-lint/definitions/core/false.rb +1 -1
  80. data/lib/ruby-lint/definitions/core/false_class.rb +2 -2
  81. data/lib/ruby-lint/definitions/core/fatal_error.rb +2 -2
  82. data/lib/ruby-lint/definitions/core/fiber.rb +2 -2
  83. data/lib/ruby-lint/definitions/core/fiber_error.rb +2 -2
  84. data/lib/ruby-lint/definitions/core/file.rb +68 -68
  85. data/lib/ruby-lint/definitions/core/file_list.rb +2 -2
  86. data/lib/ruby-lint/definitions/core/file_test.rb +1 -1
  87. data/lib/ruby-lint/definitions/core/file_utils.rb +16 -16
  88. data/lib/ruby-lint/definitions/core/fixnum.rb +4 -4
  89. data/lib/ruby-lint/definitions/core/float.rb +16 -16
  90. data/lib/ruby-lint/definitions/core/float_domain_error.rb +2 -2
  91. data/lib/ruby-lint/definitions/core/gc.rb +2 -2
  92. data/lib/ruby-lint/definitions/core/gem.rb +119 -119
  93. data/lib/ruby-lint/definitions/core/hash.rb +14 -14
  94. data/lib/ruby-lint/definitions/core/immediate_value.rb +1 -1
  95. data/lib/ruby-lint/definitions/core/index_error.rb +2 -2
  96. data/lib/ruby-lint/definitions/core/integer.rb +2 -2
  97. data/lib/ruby-lint/definitions/core/interrupt.rb +2 -2
  98. data/lib/ruby-lint/definitions/core/io.rb +38 -38
  99. data/lib/ruby-lint/definitions/core/ioerror.rb +2 -2
  100. data/lib/ruby-lint/definitions/core/kernel.rb +3 -3
  101. data/lib/ruby-lint/definitions/core/key_error.rb +2 -2
  102. data/lib/ruby-lint/definitions/core/load_error.rb +6 -6
  103. data/lib/ruby-lint/definitions/core/local_jump_error.rb +2 -2
  104. data/lib/ruby-lint/definitions/core/main.rb +1 -1
  105. data/lib/ruby-lint/definitions/core/marshal.rb +35 -35
  106. data/lib/ruby-lint/definitions/core/match_data.rb +2 -2
  107. data/lib/ruby-lint/definitions/core/math.rb +7 -7
  108. data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +2 -2
  109. data/lib/ruby-lint/definitions/core/method.rb +2 -2
  110. data/lib/ruby-lint/definitions/core/module.rb +1 -1
  111. data/lib/ruby-lint/definitions/core/monitor.rb +4 -4
  112. data/lib/ruby-lint/definitions/core/monitor_mixin.rb +5 -5
  113. data/lib/ruby-lint/definitions/core/mutex.rb +2 -2
  114. data/lib/ruby-lint/definitions/core/name_error.rb +2 -2
  115. data/lib/ruby-lint/definitions/core/nil.rb +1 -1
  116. data/lib/ruby-lint/definitions/core/nil_class.rb +2 -2
  117. data/lib/ruby-lint/definitions/core/no_memory_error.rb +2 -2
  118. data/lib/ruby-lint/definitions/core/no_method_error.rb +2 -2
  119. data/lib/ruby-lint/definitions/core/not_implemented_error.rb +2 -2
  120. data/lib/ruby-lint/definitions/core/numeric.rb +2 -2
  121. data/lib/ruby-lint/definitions/core/object.rb +2 -2
  122. data/lib/ruby-lint/definitions/core/object_space.rb +1 -1
  123. data/lib/ruby-lint/definitions/core/open_struct.rb +3 -3
  124. data/lib/ruby-lint/definitions/core/option_parser.rb +83 -83
  125. data/lib/ruby-lint/definitions/core/precision.rb +1 -1
  126. data/lib/ruby-lint/definitions/core/primitive_failure.rb +2 -2
  127. data/lib/ruby-lint/definitions/core/proc.rb +2 -2
  128. data/lib/ruby-lint/definitions/core/process.rb +29 -29
  129. data/lib/ruby-lint/definitions/core/psych.rb +149 -149
  130. data/lib/ruby-lint/definitions/core/queue.rb +2 -2
  131. data/lib/ruby-lint/definitions/core/rake.rb +117 -117
  132. data/lib/ruby-lint/definitions/core/rake_file_utils.rb +1 -1
  133. data/lib/ruby-lint/definitions/core/rakeversion.rb +1 -1
  134. data/lib/ruby-lint/definitions/core/random.rb +2 -2
  135. data/lib/ruby-lint/definitions/core/range.rb +4 -4
  136. data/lib/ruby-lint/definitions/core/range_error.rb +2 -2
  137. data/lib/ruby-lint/definitions/core/rational.rb +2 -2
  138. data/lib/ruby-lint/definitions/core/rb_config.rb +3 -3
  139. data/lib/ruby-lint/definitions/core/regexp.rb +28 -28
  140. data/lib/ruby-lint/definitions/core/regexp_error.rb +2 -2
  141. data/lib/ruby-lint/definitions/core/rubinius.rb +1057 -1057
  142. data/lib/ruby-lint/definitions/core/ruby_copyright.rb +1 -1
  143. data/lib/ruby-lint/definitions/core/ruby_description.rb +1 -1
  144. data/lib/ruby-lint/definitions/core/ruby_engine.rb +1 -1
  145. data/lib/ruby-lint/definitions/core/ruby_lint.rb +9 -9
  146. data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +1 -1
  147. data/lib/ruby-lint/definitions/core/ruby_platform.rb +1 -1
  148. data/lib/ruby-lint/definitions/core/ruby_release_date.rb +1 -1
  149. data/lib/ruby-lint/definitions/core/ruby_version.rb +1 -1
  150. data/lib/ruby-lint/definitions/core/runtime_error.rb +2 -2
  151. data/lib/ruby-lint/definitions/core/scan_error.rb +2 -2
  152. data/lib/ruby-lint/definitions/core/script_error.rb +2 -2
  153. data/lib/ruby-lint/definitions/core/security_error.rb +2 -2
  154. data/lib/ruby-lint/definitions/core/shellwords.rb +1 -1
  155. data/lib/ruby-lint/definitions/core/signal.rb +3 -3
  156. data/lib/ruby-lint/definitions/core/signal_exception.rb +2 -2
  157. data/lib/ruby-lint/definitions/core/singleton.rb +2 -2
  158. data/lib/ruby-lint/definitions/core/sized_queue.rb +2 -2
  159. data/lib/ruby-lint/definitions/core/standard_error.rb +2 -2
  160. data/lib/ruby-lint/definitions/core/stderr.rb +1 -1
  161. data/lib/ruby-lint/definitions/core/stdin.rb +1 -1
  162. data/lib/ruby-lint/definitions/core/stdout.rb +1 -1
  163. data/lib/ruby-lint/definitions/core/stop_iteration.rb +2 -2
  164. data/lib/ruby-lint/definitions/core/string.rb +21 -21
  165. data/lib/ruby-lint/definitions/core/string_io.rb +7 -7
  166. data/lib/ruby-lint/definitions/core/string_scanner.rb +4 -4
  167. data/lib/ruby-lint/definitions/core/struct.rb +20 -20
  168. data/lib/ruby-lint/definitions/core/syck.rb +4 -4
  169. data/lib/ruby-lint/definitions/core/symbol.rb +2 -2
  170. data/lib/ruby-lint/definitions/core/syntax_error.rb +2 -2
  171. data/lib/ruby-lint/definitions/core/system_call_error.rb +2 -2
  172. data/lib/ruby-lint/definitions/core/system_exit.rb +2 -2
  173. data/lib/ruby-lint/definitions/core/system_stack_error.rb +2 -2
  174. data/lib/ruby-lint/definitions/core/thread.rb +6 -6
  175. data/lib/ruby-lint/definitions/core/thread_error.rb +2 -2
  176. data/lib/ruby-lint/definitions/core/thread_group.rb +2 -2
  177. data/lib/ruby-lint/definitions/core/time.rb +3 -3
  178. data/lib/ruby-lint/definitions/core/toplevel_binding.rb +1 -1
  179. data/lib/ruby-lint/definitions/core/true.rb +1 -1
  180. data/lib/ruby-lint/definitions/core/true_class.rb +2 -2
  181. data/lib/ruby-lint/definitions/core/type_error.rb +2 -2
  182. data/lib/ruby-lint/definitions/core/unbound_method.rb +2 -2
  183. data/lib/ruby-lint/definitions/core/unmarshalable.rb +1 -1
  184. data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +2 -2
  185. data/lib/ruby-lint/definitions/core/weak_ref.rb +4 -4
  186. data/lib/ruby-lint/definitions/core/zero_division_error.rb +2 -2
  187. data/lib/ruby-lint/definitions/rails.rb +12 -0
  188. data/lib/ruby-lint/definitions/rails/abstract_controller.rb +335 -0
  189. data/lib/ruby-lint/definitions/rails/action_controller.rb +1244 -0
  190. data/lib/ruby-lint/definitions/rails/action_dispatch.rb +741 -0
  191. data/lib/ruby-lint/definitions/rails/action_mailer.rb +502 -0
  192. data/lib/ruby-lint/definitions/rails/action_pack.rb +16 -0
  193. data/lib/ruby-lint/definitions/rails/action_view.rb +898 -0
  194. data/lib/ruby-lint/definitions/rails/active_model.rb +437 -0
  195. data/lib/ruby-lint/definitions/rails/active_record.rb +2901 -0
  196. data/lib/ruby-lint/definitions/rails/active_support.rb +1963 -0
  197. data/lib/ruby-lint/definitions/rails/arel.rb +665 -0
  198. data/lib/ruby-lint/definitions/rails/rails.rb +452 -0
  199. data/lib/ruby-lint/definitions/rails/sprockets.rb +968 -0
  200. data/lib/ruby-lint/generated_constant.rb +33 -0
  201. data/lib/ruby-lint/helper/constant_paths.rb +30 -21
  202. data/lib/ruby-lint/inspector.rb +20 -2
  203. data/lib/ruby-lint/iterator.rb +11 -171
  204. data/lib/ruby-lint/nested_stack.rb +46 -0
  205. data/lib/ruby-lint/parser.rb +24 -806
  206. data/lib/ruby-lint/report.rb +2 -30
  207. data/lib/ruby-lint/report/entry.rb +2 -2
  208. data/lib/ruby-lint/runner.rb +81 -0
  209. data/lib/ruby-lint/template/definition.erb +12 -8
  210. data/lib/ruby-lint/variable_predicates.rb +16 -58
  211. data/lib/ruby-lint/version.rb +1 -1
  212. data/lib/ruby-lint/virtual_machine.rb +1044 -0
  213. data/ruby-lint.gemspec +17 -7
  214. data/spec/fixtures/complex/rails/basic_controller.rb +9 -0
  215. data/spec/fixtures/complex/rcap.rb +38 -0
  216. data/spec/fixtures/complex/slop.rb +680 -0
  217. data/spec/fixtures/config.yml +8 -0
  218. data/spec/fixtures/invalid.rb +3 -0
  219. data/spec/fixtures/invalid_2.rb +3 -0
  220. data/spec/fixtures/syntax_error.rb +1 -0
  221. data/spec/fixtures/valid.rb +3 -0
  222. data/spec/helper.rb +6 -0
  223. data/spec/ruby-lint/{analyze → analysis}/argument_amount.rb +7 -7
  224. data/spec/ruby-lint/analysis/confusing_variables.rb +46 -0
  225. data/spec/ruby-lint/analysis/pedantics.rb +43 -0
  226. data/spec/ruby-lint/{analyze → analysis}/shadowing_variables.rb +5 -5
  227. data/spec/ruby-lint/{analyze → analysis}/undefined_methods.rb +18 -18
  228. data/spec/ruby-lint/{analyze → analysis}/undefined_variables.rb +19 -25
  229. data/spec/ruby-lint/{analyze → analysis}/unused_variables.rb +29 -16
  230. data/spec/ruby-lint/ast/node.rb +33 -0
  231. data/spec/ruby-lint/cli/analyze.rb +31 -0
  232. data/spec/ruby-lint/cli/ast.rb +23 -0
  233. data/spec/ruby-lint/configuration.rb +45 -6
  234. data/spec/ruby-lint/definition/constant_proxy.rb +31 -0
  235. data/spec/ruby-lint/definition/dsl.rb +13 -20
  236. data/spec/ruby-lint/definition/ruby_method.rb +65 -148
  237. data/spec/ruby-lint/definition/ruby_object.rb +60 -96
  238. data/spec/ruby-lint/definition_builder/primitive.rb +62 -0
  239. data/spec/ruby-lint/definition_builder/ruby_class.rb +108 -0
  240. data/spec/ruby-lint/definition_builder/ruby_method.rb +53 -0
  241. data/spec/ruby-lint/definition_builder/ruby_module.rb +50 -0
  242. data/spec/ruby-lint/iterator.rb +40 -16
  243. data/spec/ruby-lint/nested_stack.rb +23 -0
  244. data/spec/ruby-lint/parser.rb +14 -0
  245. data/spec/ruby-lint/report.rb +0 -10
  246. data/spec/ruby-lint/report/entry.rb +8 -4
  247. data/spec/ruby-lint/runner.rb +32 -0
  248. data/spec/ruby-lint/virtual_machine/assignments/arrays.rb +87 -0
  249. data/spec/ruby-lint/virtual_machine/assignments/hashes.rb +52 -0
  250. data/spec/ruby-lint/virtual_machine/assignments/optional.rb +41 -0
  251. data/spec/ruby-lint/{definitions_builder → virtual_machine}/assignments/return_values.rb +11 -11
  252. data/spec/ruby-lint/virtual_machine/assignments/variables.rb +85 -0
  253. data/spec/ruby-lint/virtual_machine/associate_nodes.rb +17 -0
  254. data/spec/ruby-lint/virtual_machine/autoloading.rb +31 -0
  255. data/spec/ruby-lint/virtual_machine/blocks.rb +64 -0
  256. data/spec/ruby-lint/virtual_machine/classes/class_methods.rb +21 -0
  257. data/spec/ruby-lint/virtual_machine/classes/extending.rb +104 -0
  258. data/spec/ruby-lint/virtual_machine/classes/redefining.rb +24 -0
  259. data/spec/ruby-lint/virtual_machine/classes/sclass.rb +94 -0
  260. data/spec/ruby-lint/virtual_machine/classes/scoping.rb +60 -0
  261. data/spec/ruby-lint/virtual_machine/complex/rails.rb +18 -0
  262. data/spec/ruby-lint/virtual_machine/complex/rcap.rb +15 -0
  263. data/spec/ruby-lint/virtual_machine/complex/slop.rb +16 -0
  264. data/spec/ruby-lint/{definitions_builder → virtual_machine}/for.rb +2 -2
  265. data/spec/ruby-lint/virtual_machine/freeze.rb +13 -0
  266. data/spec/ruby-lint/virtual_machine/interpolation.rb +12 -0
  267. data/spec/ruby-lint/virtual_machine/methods/defining.rb +40 -0
  268. data/spec/ruby-lint/virtual_machine/methods/exporting.rb +19 -0
  269. data/spec/ruby-lint/virtual_machine/methods/parameters.rb +77 -0
  270. data/spec/ruby-lint/virtual_machine/methods/patching.rb +26 -0
  271. data/spec/ruby-lint/virtual_machine/methods/scoping.rb +63 -0
  272. data/spec/ruby-lint/virtual_machine/methods/visibility.rb +64 -0
  273. data/spec/ruby-lint/{definitions_builder → virtual_machine}/modules.rb +16 -16
  274. data/spec/ruby-lint/virtual_machine/reference_amount.rb +33 -0
  275. data/spec/ruby-lint/virtual_machine/unused.rb +17 -0
  276. data/spec/support/bacon.rb +13 -13
  277. data/spec/support/building.rb +23 -16
  278. data/spec/support/coveralls.rb +5 -0
  279. data/spec/support/fixtures.rb +20 -0
  280. data/spec/support/parsing.rb +3 -5
  281. data/spec/support/simplecov.rb +5 -3
  282. data/task/build.rake +1 -1
  283. data/task/cop.rake +11 -0
  284. data/task/generate.rake +40 -2
  285. data/task/profile.rake +27 -0
  286. data/task/todo.rake +6 -0
  287. data/task/travis.rake +7 -0
  288. metadata +160 -75
  289. metadata.gz.asc +14 -14
  290. data/doc/build/.gitkeep +0 -0
  291. data/lib/ruby-lint/analyze/argument_amount.rb +0 -73
  292. data/lib/ruby-lint/analyze/shadowing_variables.rb +0 -32
  293. data/lib/ruby-lint/analyze/undefined_methods.rb +0 -68
  294. data/lib/ruby-lint/analyze/undefined_variables.rb +0 -72
  295. data/lib/ruby-lint/analyze/unused_variables.rb +0 -48
  296. data/lib/ruby-lint/base.rb +0 -85
  297. data/lib/ruby-lint/definitions_builder.rb +0 -692
  298. data/lib/ruby-lint/helper/conversion.rb +0 -33
  299. data/lib/ruby-lint/helper/current_scope.rb +0 -98
  300. data/lib/ruby-lint/helper/methods.rb +0 -91
  301. data/lib/ruby-lint/node.rb +0 -107
  302. data/lib/ruby-lint/parser_error.rb +0 -30
  303. data/spec/ruby-lint/constant_loader.rb +0 -32
  304. data/spec/ruby-lint/definition/method_calls.rb +0 -26
  305. data/spec/ruby-lint/definitions_builder/assignments/arrays.rb +0 -71
  306. data/spec/ruby-lint/definitions_builder/assignments/hashes.rb +0 -65
  307. data/spec/ruby-lint/definitions_builder/assignments/objects.rb +0 -23
  308. data/spec/ruby-lint/definitions_builder/assignments/optional.rb +0 -22
  309. data/spec/ruby-lint/definitions_builder/assignments/variables.rb +0 -71
  310. data/spec/ruby-lint/definitions_builder/associate_nodes.rb +0 -17
  311. data/spec/ruby-lint/definitions_builder/blocks.rb +0 -40
  312. data/spec/ruby-lint/definitions_builder/classes.rb +0 -230
  313. data/spec/ruby-lint/definitions_builder/methods.rb +0 -147
  314. data/spec/ruby-lint/definitions_builder/reference_amount.rb +0 -31
  315. data/spec/ruby-lint/definitions_builder/unused.rb +0 -15
  316. data/spec/ruby-lint/node.rb +0 -38
  317. data/spec/ruby-lint/parser/assignments.rb +0 -225
  318. data/spec/ruby-lint/parser/classes.rb +0 -110
  319. data/spec/ruby-lint/parser/errors.rb +0 -12
  320. data/spec/ruby-lint/parser/metadata.rb +0 -17
  321. data/spec/ruby-lint/parser/method_definitions.rb +0 -111
  322. data/spec/ruby-lint/parser/methods.rb +0 -217
  323. data/spec/ruby-lint/parser/modules.rb +0 -70
  324. data/spec/ruby-lint/parser/operators.rb +0 -40
  325. data/spec/ruby-lint/parser/statements/begin.rb +0 -55
  326. data/spec/ruby-lint/parser/statements/case.rb +0 -34
  327. data/spec/ruby-lint/parser/statements/defined.rb +0 -11
  328. data/spec/ruby-lint/parser/statements/for.rb +0 -34
  329. data/spec/ruby-lint/parser/statements/if.rb +0 -46
  330. data/spec/ruby-lint/parser/statements/return.rb +0 -14
  331. data/spec/ruby-lint/parser/statements/super.rb +0 -49
  332. data/spec/ruby-lint/parser/statements/unless.rb +0 -42
  333. data/spec/ruby-lint/parser/statements/until.rb +0 -25
  334. data/spec/ruby-lint/parser/statements/while.rb +0 -25
  335. data/spec/ruby-lint/parser/statements/yield.rb +0 -18
  336. data/spec/ruby-lint/parser/types/arrays.rb +0 -47
  337. data/spec/ruby-lint/parser/types/booleans.rb +0 -11
  338. data/spec/ruby-lint/parser/types/constants.rb +0 -32
  339. data/spec/ruby-lint/parser/types/hashes.rb +0 -55
  340. data/spec/ruby-lint/parser/types/nil.rb +0 -7
  341. data/spec/ruby-lint/parser/types/numbers.rb +0 -11
  342. data/spec/ruby-lint/parser/types/procs.rb +0 -11
  343. data/spec/ruby-lint/parser/types/ranges.rb +0 -11
  344. data/spec/ruby-lint/parser/types/regexp.rb +0 -27
  345. data/spec/ruby-lint/parser/types/strings.rb +0 -44
  346. data/spec/ruby-lint/parser/types/symbols.rb +0 -15
  347. data/task/stdlib.rake +0 -23
@@ -0,0 +1,43 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Base definition builder that provides common methods for individual
5
+ # builder classes.
6
+ #
7
+ # @!attribute [r] node
8
+ # @return [RubyLint::AST::Node]
9
+ # @!attribute [r] definitions
10
+ # @return [RubyLint::Definition::RubyObject]
11
+ #
12
+ class Base
13
+ include Helper::ConstantPaths
14
+
15
+ attr_reader :definitions, :node, :options
16
+
17
+ ##
18
+ # @param [RubyLint::AST::Node] node
19
+ # @param [RubyLint::Definition::RubyObject] definitions
20
+ # @param [Hash] options
21
+ #
22
+ def initialize(node, definitions, options = {})
23
+ @node = node
24
+ @definitions = definitions
25
+ @options = options
26
+
27
+ after_initialize if respond_to?(:after_initialize)
28
+ end
29
+
30
+ protected
31
+
32
+ ##
33
+ # Returns the name of a constant node as a String.
34
+ #
35
+ # @param [RubyLint::AST::Node] node
36
+ # @return [String]
37
+ #
38
+ def constant_name(node)
39
+ return node.children[1].to_s
40
+ end
41
+ end # Base
42
+ end # DefinitionBuilder
43
+ end # RubyLint
@@ -0,0 +1,39 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder used for building primitive Ruby types such as
5
+ # integers and strings.
6
+ #
7
+ class Primitive < Base
8
+ ##
9
+ # @return [RubyLint::Definition::RubyObject]
10
+ #
11
+ def build
12
+ parents = [definition_for_node(node)]
13
+ opts = {
14
+ :type => node.type,
15
+ :value => node.children[0],
16
+ :instance_type => :instance,
17
+ :parents => parents
18
+ }.merge(options)
19
+
20
+ return Definition::RubyObject.new(opts)
21
+ end
22
+
23
+ ##
24
+ # Returns a definition for a given node type.
25
+ #
26
+ # @param [RubyLint::AST::Node] node
27
+ # @return [RubyLint::Definition::RubyObject]
28
+ # @raise ArgumentError Raised when an invalid type was specified.
29
+ #
30
+ def definition_for_node(node)
31
+ ruby_class = node.ruby_class
32
+
33
+ raise(ArgumentError, "The type #{type} is invalid") unless ruby_class
34
+
35
+ return RubyLint::VirtualMachine.global_constant(ruby_class)
36
+ end
37
+ end # Primitive
38
+ end # DefinitionBuilder
39
+ end # RubyLint
@@ -0,0 +1,77 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder for building Ruby arrays.
5
+ #
6
+ class RubyArray < Base
7
+ ##
8
+ # Builds the definition for the array and assigns the values as members.
9
+ #
10
+ # @return [RubyLint::Definition::RubyObject]
11
+ #
12
+ def build
13
+ definition = create_container
14
+
15
+ values.each_with_index do |value, index|
16
+ member = create_member(index.to_s, value)
17
+
18
+ definition.add_definition(member)
19
+ end
20
+
21
+ return definition
22
+ end
23
+
24
+ private
25
+
26
+ ##
27
+ # @return [Array]
28
+ #
29
+ def values
30
+ return options[:values] || []
31
+ end
32
+
33
+ ##
34
+ # @return [Array]
35
+ #
36
+ def parents
37
+ return [RubyLint::VirtualMachine.global_constant('Array')]
38
+ end
39
+
40
+ ##
41
+ # Creates an empty data container for the members.
42
+ #
43
+ # @return [RubyLint::Definition::RubyObject]
44
+ #
45
+ def create_container
46
+ return Definition::RubyObject.new(
47
+ :type => container_type,
48
+ :instance_type => :instance,
49
+ :parents => parents,
50
+ :members_as_value => true
51
+ )
52
+ end
53
+
54
+ ##
55
+ # @return [Symbol]
56
+ #
57
+ def container_type
58
+ return :array
59
+ end
60
+
61
+ ##
62
+ # Creates a new array member definition.
63
+ #
64
+ # @param [String] name
65
+ # @param [RubyLint::Definition::RubyObject] value
66
+ # @return [RubyLint::Definition::RubyObject]
67
+ #
68
+ def create_member(name, value)
69
+ return Definition::RubyObject.new(
70
+ :type => :member,
71
+ :name => name,
72
+ :value => value
73
+ )
74
+ end
75
+ end # RubyArray
76
+ end # DefinitionBuilder
77
+ end # RubyLint
@@ -0,0 +1,34 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder for building Ruby blocks.
5
+ #
6
+ class RubyBlock < Base
7
+ ##
8
+ # @return [RubyLint::Definition::RubyObject]
9
+ #
10
+ def build
11
+ definition = new_definition([definitions])
12
+
13
+ definitions.list(:lvar).each do |variable|
14
+ definition.add_definition(variable)
15
+ end
16
+
17
+ return definition
18
+ end
19
+
20
+ ##
21
+ # @param [Array] parents
22
+ # @return [RubyLint::Definition::RubyObject]
23
+ #
24
+ def new_definition(parents)
25
+ return Definition::RubyObject.new(
26
+ :name => 'block',
27
+ :type => :block,
28
+ :parents => parents,
29
+ :update_parents => [:lvar, :ivar, :cvar, :gvar]
30
+ )
31
+ end
32
+ end # RubyBlock
33
+ end # DefinitionBuilder
34
+ end # RubyLint
@@ -0,0 +1,24 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder used for building Ruby classes.
5
+ #
6
+ class RubyClass < RubyModule
7
+ ##
8
+ # Called after creating a new instance of the class.
9
+ #
10
+ def after_initialize
11
+ options[:parent] ||= RubyLint::VirtualMachine.global_constant('Object')
12
+ end
13
+
14
+ ##
15
+ # Builds the definition for a Ruby class.
16
+ #
17
+ # @see RubyLint::DefinitionBuilder::RubyModule#build
18
+ #
19
+ def build
20
+ return new_definition([options[:parent], definitions])
21
+ end
22
+ end # RubyClass
23
+ end # DefinitionBuilder
24
+ end # RubyLint
@@ -0,0 +1,37 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder for building Ruby hashes.
5
+ #
6
+ class RubyHash < RubyArray
7
+ ##
8
+ # Builds the definition for the Hash and assigns the members.
9
+ #
10
+ # @return [RubyLint::Definition::RubyObject]
11
+ #
12
+ def build
13
+ definition = create_container
14
+
15
+ values.each do |pair|
16
+ definition.add_definition(pair)
17
+ end
18
+
19
+ return definition
20
+ end
21
+
22
+ ##
23
+ # @see RubyLint::DefinitionBuilder::RubyArray#parents
24
+ #
25
+ def parents
26
+ return [RubyLint::VirtualMachine.global_constant('Hash')]
27
+ end
28
+
29
+ ##
30
+ # @return [Symbol]
31
+ #
32
+ def container_type
33
+ return :hash
34
+ end
35
+ end # RubyHash
36
+ end # DefinitionBuilder
37
+ end # RubyLint
@@ -0,0 +1,84 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder for building method definitions. Receivers should be
5
+ # set from the outside (= the VM).
6
+ #
7
+ class RubyMethod < Base
8
+ ##
9
+ # Called after a new instance has been created.
10
+ #
11
+ def after_initialize
12
+ @options[:type] ||= :instance_method
13
+ end
14
+
15
+ ##
16
+ # Builds the definition for the method definition.
17
+ #
18
+ # @see #new_definition
19
+ # @return [RubyLint::Definition::RubyMethod]
20
+ #
21
+ def build
22
+ return new_definition([scope])
23
+ end
24
+
25
+ ##
26
+ # Returns the scope to define the method in.
27
+ #
28
+ # @return [RubyLint::Definition::RubyObject]
29
+ #
30
+ def scope
31
+ scope = definitions
32
+
33
+ if has_receiver? and options[:receiver]
34
+ scope = options[:receiver]
35
+ end
36
+
37
+ return scope
38
+ end
39
+
40
+ private
41
+
42
+ ##
43
+ # @return [String]
44
+ #
45
+ def method_name
46
+ return node.children[name_index].to_s
47
+ end
48
+
49
+ ##
50
+ # @param [Array] parents The parent definitions.
51
+ # @return [RubyLint::Definition::RubyObject]
52
+ #
53
+ def new_definition(parents)
54
+ type = options[:type]
55
+
56
+ if has_receiver?
57
+ type = :method if options[:receiver].class?
58
+ end
59
+
60
+ return Definition::RubyMethod.new(
61
+ :name => method_name,
62
+ :parents => parents,
63
+ :type => type,
64
+ :instance_type => :instance,
65
+ :visibility => options[:visibility]
66
+ )
67
+ end
68
+
69
+ ##
70
+ # @return [TrueClass|FalseClass]
71
+ #
72
+ def has_receiver?
73
+ return node.type == :defs
74
+ end
75
+
76
+ ##
77
+ # @return [Numeric]
78
+ #
79
+ def name_index
80
+ return has_receiver? ? 1 : 0
81
+ end
82
+ end # RubyMethod
83
+ end # DefinitionBuilder
84
+ end # RubyLint
@@ -0,0 +1,68 @@
1
+ module RubyLint
2
+ module DefinitionBuilder
3
+ ##
4
+ # Definition builder used for building Ruby modules as well as providing
5
+ # the groundwork for building Ruby classes.
6
+ #
7
+ class RubyModule < Base
8
+ ##
9
+ # Creates a new module definition.
10
+ #
11
+ # @see #new_definition
12
+ #
13
+ def build
14
+ return new_definition([definitions])
15
+ end
16
+
17
+ ##
18
+ # Determines the scope to define the module in.
19
+ #
20
+ # @return [RubyLint::Definition::RubyObject]
21
+ #
22
+ def scope
23
+ scope = definitions
24
+ name_prefix = node.children[0].children[0]
25
+
26
+ # name_prefix contains the constant path leading up to the name. For
27
+ # example, if the name is `A::B::C` this node would contain `A::B`.
28
+ if name_prefix
29
+ found = resolve_constant_path(name_prefix)
30
+ scope = found if found
31
+ end
32
+
33
+ return scope
34
+ end
35
+
36
+ protected
37
+
38
+ ##
39
+ # Returns the name of the module.
40
+ #
41
+ # @see #constant_name
42
+ #
43
+ def module_name
44
+ return constant_name(node.children[0])
45
+ end
46
+
47
+ ##
48
+ # Creates a new RubyObject definition with the specified parent
49
+ # definitions.
50
+ #
51
+ # @param [Array] parents
52
+ # @return [RubyLint::Definition::RubyObject]
53
+ #
54
+ def new_definition(parents)
55
+ definition = Definition::RubyObject.new(
56
+ :name => module_name,
57
+ :parents => parents,
58
+ :reference_amount => 1,
59
+ :type => :const
60
+ )
61
+
62
+ definition.add(:keyword, 'self', definition)
63
+
64
+ return definition
65
+ end
66
+ end # RubyModule
67
+ end # DefinitionBuilder
68
+ end # RubyLint
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'erb'
3
3
  require_relative 'template/scope'
4
+ require_relative 'generated_constant'
4
5
 
5
6
  module RubyLint
6
7
  ##
@@ -17,10 +18,13 @@ module RubyLint
17
18
  #
18
19
  # @!attribute [r] directory
19
20
  # @return [String] The directory to store the generated definitions in.
21
+ #
20
22
  # @!attribute [r] options
21
23
  # @return [Hash]
22
- # @!attribute [String] template
23
- # @return [String] The filepath to the ERB template to use.
24
+ #
25
+ # @!attribute [r] template
26
+ # @return [String] The ERB template to use.
27
+ #
24
28
  # @!attribute [r] inspector
25
29
  # @return [RubyLint::Inspector]
26
30
  #
@@ -48,8 +52,8 @@ module RubyLint
48
52
  constants = inspector.inspect_constants.sort - options[:ignore]
49
53
 
50
54
  group_constants(constants).each do |root, names|
51
- filepath = File.join(directory, "#{root.snake_case}.rb")
52
- definitions = []
55
+ filepath = File.join(directory, "#{root.snake_case}.rb")
56
+ constants = []
53
57
 
54
58
  if File.file?(filepath) and !options[:overwrite]
55
59
  next
@@ -58,21 +62,26 @@ module RubyLint
58
62
  names.each do |name|
59
63
  current_inspector = Inspector.new(name)
60
64
  inspected_methods = inspect_methods(current_inspector)
61
- variables = {
62
- :methods => method_information(inspected_methods),
63
- :constant => current_inspector.constant,
64
- :constant_name => current_inspector.constant_name,
65
- :superclass => (current_inspector.constant.superclass rescue nil)
66
- }
65
+ superclass = nil
67
66
 
68
- scope = Template::Scope.new(variables)
69
- erb = ERB.new(template, nil, '-').result(scope.get_binding)
67
+ if current_inspector.inspect_superclass
68
+ superclass = current_inspector.inspect_superclass.to_s
69
+ end
70
70
 
71
- definitions << erb
71
+ constant = GeneratedConstant.new(
72
+ :name => current_inspector.constant_name,
73
+ :constant => current_inspector.constant,
74
+ :methods => method_information(inspected_methods),
75
+ :superclass => superclass
76
+ )
77
+
78
+ constants << constant
72
79
  end
73
80
 
81
+ erb = render_template(template, :constants => constants)
82
+
74
83
  File.open(filepath, 'w') do |handle|
75
- handle.write(definitions.join("\n").strip)
84
+ handle.write(erb)
76
85
  end
77
86
  end
78
87
  end
@@ -130,7 +139,7 @@ module RubyLint
130
139
  args = []
131
140
 
132
141
  method.parameters.each do |arg|
133
- args << {:method => arg_mapping[arg[0]], :name => arg[1]}
142
+ args << {:type => arg_mapping[arg[0]], :name => arg[1]}
134
143
  end
135
144
 
136
145
  info[type][method.name] = args
@@ -151,5 +160,22 @@ module RubyLint
151
160
  :block => :block_argument
152
161
  }
153
162
  end
163
+
164
+ ##
165
+ # @param [String] template
166
+ # @param [Hash] variables
167
+ #
168
+ def render_template(template, variables = {})
169
+ scope = Template::Scope.new(variables)
170
+ erb = ERB.new(template, nil, '-').result(scope.get_binding)
171
+
172
+ # Trim excessive newlines.
173
+ erb.gsub!(/\n{3,}/, "\n\n")
174
+
175
+ # Get rid of the occasional empty newline before `end` tokens.
176
+ erb.gsub!(/\n{2,}end/, "\nend")
177
+
178
+ return erb
179
+ end
154
180
  end # DefinitionGenerator
155
181
  end # RubyLint