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
data/Rakefile CHANGED
@@ -1,4 +1,10 @@
1
+ require File.expand_path('../lib/ruby-lint/extensions/string', __FILE__)
2
+ require File.expand_path('../lib/ruby-lint/inspector', __FILE__)
3
+ require File.expand_path('../lib/ruby-lint/definition_generator', __FILE__)
4
+
5
+ require 'yaml'
1
6
  require 'rubygems/package_task'
7
+ require 'digest/sha2'
2
8
 
3
9
  GEMSPEC = Gem::Specification.load('ruby-lint.gemspec')
4
10
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path('../../lib/ruby-lint', __FILE__)
4
- require 'ruby-lint/cli'
4
+ require File.expand_path('../../lib/ruby-lint/cli', __FILE__)
5
5
 
6
- RubyLint::CLI.new.run
6
+ RubyLint::CLI.run
File without changes
@@ -0,0 +1,26 @@
1
+ # @title DCO
2
+ # Developer's Certificate of Origin 1.0
3
+
4
+ By making a contribution to this project, I certify that:
5
+
6
+ 1. The contribution was created in whole or in part by me and I
7
+ have the right to submit it under the open source license
8
+ indicated in the file LICENSE; or
9
+
10
+ 2. The contribution is based upon previous work that, to the best
11
+ of my knowledge, is covered under an appropriate open source
12
+ license and I have the right under that license to submit that
13
+ work with modifications, whether created in whole or in part
14
+ by me, under the same open source license (unless I am
15
+ permitted to submit under a different license), as indicated
16
+ in the file LICENSE; or
17
+
18
+ 3. The contribution was provided directly to me by some other
19
+ person who certified (1), (2) or (3) and I have not modified
20
+ it.
21
+
22
+ 4. I understand and agree that this project and the contribution
23
+ are public and that a record of the contribution (including all
24
+ personal information I submit with it, including my sign-off) is
25
+ maintained indefinitely and may be redistributed consistent with
26
+ this project or the open source license(s) involved.
@@ -0,0 +1,63 @@
1
+ # @title Architecture
2
+ # Architecture
3
+
4
+ The process of analysing Ruby source code is broken up into several separate
5
+ steps. The basic flow of this process looks like the following:
6
+
7
+ ![ruby-lint flow](images/flow.png)
8
+
9
+ Most third-party code will only deal with the last 3 steps.
10
+
11
+ This chapter takes a brief look at the various parts that make up ruby-lint.
12
+ Some of these parts are discussed more in depth in which case a link to these
13
+ chapters can be found below.
14
+
15
+ ## The Parser
16
+
17
+ The {RubyLint::Parser parser} converts raw Ruby source code into an AST. The
18
+ AST is built up by nodes formatted as S expressions. A node for a simple String
19
+ would look like the following:
20
+
21
+ (string "hello")
22
+
23
+ Each node is an instance of {RubyLint::Node}. Each node can contain a number of
24
+ child nodes. If one were to format the above S expression as an Array you'd get
25
+ the following:
26
+
27
+ [:string, ["hello"]]
28
+
29
+ For more information see the documentation of {RubyLint::Node} and the
30
+ corresponding tests found in `spec/ruby-lint/parser/`.
31
+
32
+ Currently the parser is based on Ripper, a library that comes with MRI 1.9 and
33
+ newer. Because of this ruby-lint will be unable to support Rubinius and Jruby
34
+ for the time being. In the future this parser will be replaced with something
35
+ that runs on all the common Ruby implementations.
36
+
37
+ ## Definitions Builder
38
+
39
+ The {RubyLint::DefinitionsBuilder definitions builder} iterates over the AST
40
+ and evaluates it so that variables can be created, methods can be defined and
41
+ so on. Once finished a single {RubyLint::Definition::RubyObject} definition is
42
+ created that contains all the Ruby data of a block of Ruby code.
43
+
44
+ One can see the definitions builder as a very basic virtual machine.
45
+
46
+ ## Analysis
47
+
48
+ This is where the real work start. The analysis step consists out of various
49
+ Ruby classes of which each performs its own type of analysis. For example,
50
+ {RubyLint::Analyze::UndefinedMethods} checks for the use of undefined methods.
51
+
52
+ ## Reports
53
+
54
+ Reports are used for storing a set of {RubyLint::Report::Entry} instances that
55
+ contain information about a block of Ruby code that is being analyzed. Each
56
+ entry contains some location information (line and column number for example)
57
+ as well as a message (e.g. an error message).
58
+
59
+ ## Presenters
60
+
61
+ Presenters are classes tasked with the job of presenting a report. Currently
62
+ ruby-lint ships with a presenter that outputs a report in plain text as well as
63
+ one that outputs a report in JSON.
@@ -0,0 +1,90 @@
1
+ # @title Code Analysis
2
+ # Code Analysis
3
+
4
+ Code analysis in ruby-lint is done using a set of classes that extend
5
+ {RubyLint::Iterator}. This base class provides various methods for easily
6
+ walking over an AST by using callback methods based on the node types. For
7
+ example, the callback method `on_string` is used before a `(string)` node is
8
+ processed. For more low level details see the API documentation of
9
+ {RubyLint::Iterator}.
10
+
11
+ For this guide we'll be creating an analysis class that checks for local
12
+ variables written in camelCase. Whenever it finds these variables a warning
13
+ will be added informing the developer that he/she should use snake\_case
14
+ instead.
15
+
16
+ At the most basic level this class looks like the following:
17
+
18
+ class CamelCaseVariables < RubyLint::Iterator
19
+
20
+ end
21
+
22
+ By extending the base class your own class already comes with a method for
23
+ walking the AST and calling callbacks as well as a few helper methods for
24
+ adding errors and the likes.
25
+
26
+ To use this class you'll have to create an instance of it and call
27
+ {RubyLint::Iterator#iterate} and pass it an AST:
28
+
29
+ ast = RubyLint::Parser.new('exampleNumber = 10').parse
30
+ iterator = CamelCaseVariables.new
31
+
32
+ iterator.iterate(ast)
33
+
34
+ When running the above code you'll notice that nothing actually happens. This
35
+ is because no callback methods have been added yet. There are two types of
36
+ callback methods that can be added:
37
+
38
+ * `on_X`
39
+ * `after_X`
40
+
41
+ Here X is the name of the node type. Methods that start with `on_` will be
42
+ executed before any child nodes (of the current node) are processed. Methods
43
+ that start with `after_` will be executed after the node and its child nodes
44
+ have been processed. Each callback method takes a single argument: an instance
45
+ of {RubyLint::Node} containing information about the current node.
46
+
47
+ In the above example we only need an `on_` callback:
48
+
49
+ class CamelCaseVariables < RubyLint::Iterator
50
+ def on_local_variable(node)
51
+ if node.name =~ /[a-z][A-Z]/
52
+ warning('use snake_case for local variables', node)
53
+ end
54
+ end
55
+ end
56
+
57
+ If you now were to run the above it would technically work but still you won't
58
+ see anything. This is because you also need to specify a {RubyLint::Report}
59
+ instance to use for storing data such as warnings and error messages. This can
60
+ be done as following:
61
+
62
+ report = RubyLint::Report.new
63
+ iterator = CamelCaseVariables.new(:report => report)
64
+
65
+ The last step is to actually display the report using a presenter. For this
66
+ exercise we'll use {RubyLint::Presenter::Text}. Presenters are quite easy to
67
+ use:
68
+
69
+ presenter = RubyLint::Presenter::Text.new
70
+
71
+ presenter.present(report)
72
+
73
+ The full code of this exercise looks like the following:
74
+
75
+ class CamelCaseVariables < RubyLint::Iterator
76
+ def on_local_variable(node)
77
+ if node.name =~ /[a-z][A-Z]/
78
+ warning('use snake_case for local variables', node)
79
+ end
80
+ end
81
+ end
82
+
83
+ ast = RubyLint::Parser.new('exampleNumber = 10').parse
84
+ report = RubyLint::Report.new
85
+ iterator = CamelCaseVariables.new(:report => report)
86
+ presenter = RubyLint::Presenter::Text.new
87
+
88
+ iterator.iterate(ast)
89
+
90
+ puts presenter.present(report)
@@ -0,0 +1,86 @@
1
+ # @title Configuration
2
+ # Configuration
3
+
4
+ The default configuration of ruby-lint should be suitable for most people.
5
+ However, depending on your code base you may get an usual amount of false
6
+ positives. In particular the class {RubyLint::Analyze::UndefinedMethods} can
7
+ produce a lot of false positives.
8
+
9
+ ruby-lint allows developers to customize the various parts of the tool such as
10
+ what kind of messages to report and what types of analysis to run. This can be
11
+ done in two different ways:
12
+
13
+ 1. Using CLI options
14
+ 2. Using a configuration file
15
+
16
+ The first option is useful if you want to change something only once or if
17
+ you're messing around with the various options. If you actually want your
18
+ changes to stick around you'll want to use a configuration file instead.
19
+
20
+ ## File Locations
21
+
22
+ When running the CLI ruby-lint will try to load one of the following two
23
+ configuration files:
24
+
25
+ * $PWD/ruby-lint.rb
26
+ * $HOME/.ruby-lint.rb
27
+
28
+ Here `$PWD` refers to the current working directory and `$HOME` to the user's
29
+ home directory. If ruby-lint finds a configuration file in the current working
30
+ directory the global one will *not* be loaded. This allows you to use project
31
+ specific settings in combination with a global configuration file as a
32
+ fallback.
33
+
34
+ ## Configuring ruby-lint
35
+
36
+ The various configuration settings are set using plain old Ruby, there's no
37
+ YAML nonsense that gets in your way.
38
+
39
+ Configuration settings are stored in {RubyLint.configuration} (as an instance
40
+ of {RubyLint::Configuration}). Although you can access this object directly in
41
+ the form of `RubyLint.configuration.foo = :bar` it's recommended that you use
42
+ {RubyLint.configure} instead since it provides a shorter and friendlier syntax.
43
+
44
+ The boilerplate for configuring ruby-lint looks like the following:
45
+
46
+ RubyLint.configure do |config|
47
+
48
+ end
49
+
50
+ To change the presenter to use you'd use the following:
51
+
52
+ RubyLint.configure do |config|
53
+ config.presenter = RubyLint::Presenter::JSON
54
+ end
55
+
56
+ Changing the analysis classes is done as following:
57
+
58
+ RubyLint.configure do |config|
59
+ # Only use the two classes listed below.
60
+ config.analysis = [
61
+ RubyLint::Analysis::UndefinedVariables,
62
+ RubyLint::Analysis::ShadowingVariables
63
+ ]
64
+ end
65
+
66
+ And changing the reporting levels:
67
+
68
+ RubyLint.configure do |config|
69
+ config.report_levels = [:error]
70
+ end
71
+
72
+ Combined together this leads to the following configuration:
73
+
74
+ RubyLint.configure do |config|
75
+ config.presenter = RubyLint::Presenter::JSON
76
+
77
+ # Only use the two classes listed below.
78
+ config.analysis = [
79
+ RubyLint::Analysis::UndefinedVariables,
80
+ RubyLint::Analysis::ShadowingVariables
81
+ ]
82
+
83
+ config.report_levels = [:error]
84
+ end
85
+
86
+ For more information see the documentation of {RubyLint::Configuration}.
@@ -0,0 +1,16 @@
1
+ # @title Contributing
2
+ # Contributing
3
+
4
+ Developers wishing to contribute to ruby-lint are required to follow a specific
5
+ set of requirements. These requirements are described in the following article:
6
+ <http://yorickpeterse.com/articles/contributing-to-my-code/>.
7
+
8
+ These requirements are put in place to ensure a consistent code base, a
9
+ streamlined development process and clear rules about what is and is not
10
+ accepted. Although these requirements may seem a little bit daunting at first
11
+ the whole process of making sure everything is set up correctly should take no
12
+ more than a few minutes. In case you make a mistake or simply aren't sure about
13
+ something I'll do my best to help you out.
14
+
15
+ A copy of the DCO mentioned in the above article can be found in the file
16
+ {file:DCO} A copy of the license can be found in the file {file:LICENSE}
@@ -0,0 +1,7 @@
1
+ // Graphviz graph that shows the basic flow of the analysis process of
2
+ // ruby-lint.
3
+
4
+ digraph flow {
5
+ "Source" -> "Parser" -> "Definitions Builder" -> "Analysis";
6
+ "Analysis" -> "Report" -> "Presenter";
7
+ }
File without changes
Binary file
@@ -1,37 +1,37 @@
1
1
  require 'ripper'
2
+ require 'ast/node'
2
3
 
3
- unless $:.include?(File.expand_path('../', __FILE__))
4
- $:.unshift(File.expand_path('../', __FILE__))
5
- end
6
-
7
- require 'ruby-lint/version'
8
- require 'ruby-lint/parser'
9
- require 'ruby-lint/token/token'
10
- require 'ruby-lint/token/variable_token'
11
- require 'ruby-lint/token/statement_token'
12
- require 'ruby-lint/token/begin_rescue_token'
13
- require 'ruby-lint/token/method_definition_token'
14
- require 'ruby-lint/token/parameters_token'
15
- require 'ruby-lint/token/method_token'
16
- require 'ruby-lint/token/block_token'
17
- require 'ruby-lint/token/assignment_token'
18
- require 'ruby-lint/token/case_token'
19
- require 'ruby-lint/token/regexp_token'
20
- require 'ruby-lint/token/class_token'
21
- require 'ruby-lint/token/keyword_token'
22
- require 'ruby-lint/parser_error'
23
- require 'ruby-lint/iterator'
24
- require 'ruby-lint/callback'
25
- require 'ruby-lint/report'
26
- require 'ruby-lint/definition'
27
- require 'ruby-lint/constant_importer'
28
- require 'ruby-lint/formatter/text'
29
- require 'ruby-lint/helper/scoping'
30
- require 'ruby-lint/helper/definition_resolver'
31
- require 'ruby-lint/analyze/coding_style'
32
- require 'ruby-lint/analyze/definitions'
33
- require 'ruby-lint/analyze/unused_variables'
34
- require 'ruby-lint/analyze/undefined_variables'
35
- require 'ruby-lint/analyze/shadowing_variables'
36
- require 'ruby-lint/analyze/method_validation'
37
- require 'ruby-lint/options'
4
+ require_relative 'ruby-lint/extensions/string'
5
+
6
+ require_relative 'ruby-lint/variable_predicates'
7
+ require_relative 'ruby-lint/node'
8
+ require_relative 'ruby-lint/parser'
9
+ require_relative 'ruby-lint/parser_error'
10
+ require_relative 'ruby-lint/iterator'
11
+ require_relative 'ruby-lint/definitions_builder'
12
+ require_relative 'ruby-lint/constant_loader'
13
+
14
+ require_relative 'ruby-lint/configuration'
15
+ require_relative 'ruby-lint/version'
16
+ require_relative 'ruby-lint/base'
17
+
18
+ require_relative 'ruby-lint/definition/ruby_object'
19
+ require_relative 'ruby-lint/definition/ruby_method'
20
+ require_relative 'ruby-lint/definitions/core'
21
+
22
+ require_relative 'ruby-lint/helper/conversion'
23
+ require_relative 'ruby-lint/helper/current_scope'
24
+ require_relative 'ruby-lint/helper/constant_paths'
25
+ require_relative 'ruby-lint/helper/methods'
26
+
27
+ require_relative 'ruby-lint/analyze/unused_variables'
28
+ require_relative 'ruby-lint/analyze/shadowing_variables'
29
+ require_relative 'ruby-lint/analyze/undefined_variables'
30
+ require_relative 'ruby-lint/analyze/undefined_methods'
31
+ require_relative 'ruby-lint/analyze/argument_amount'
32
+
33
+ require_relative 'ruby-lint/report'
34
+ require_relative 'ruby-lint/report/entry'
35
+
36
+ require_relative 'ruby-lint/presenter/text'
37
+ require_relative 'ruby-lint/presenter/json'
@@ -0,0 +1,73 @@
1
+ module RubyLint
2
+ module Analyze
3
+ ##
4
+ # The ArgumentAmount class is an analysis class that verifies the amount of
5
+ # arguments given with each method call and adds errors whenever an invalid
6
+ # amount was given.
7
+ #
8
+ class ArgumentAmount < Iterator
9
+ include Helper::Methods
10
+
11
+ ##
12
+ # @param [RubyLint::Node] node
13
+ #
14
+ def on_method(node)
15
+ return if invalid_receiver?(node) || !method_defined?(node)
16
+
17
+ definition = lookup_method(node)
18
+ specified = node.gather_arguments.length
19
+ minimum = definition.length_of(:arguments)
20
+ optional = definition.length_of(:optional_arguments)
21
+ maximum = minimum + optional
22
+ rest = !definition.rest_argument.nil?
23
+ expected_text = expected_text(minimum, maximum, optional)
24
+
25
+ unless correct_argument_amount(minimum, maximum, specified, rest)
26
+ error(
27
+ "wrong number of arguments (expected #{expected_text} but " \
28
+ "got #{specified})",
29
+ node
30
+ )
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ ##
37
+ # @param [Numeric] minimum
38
+ # @param [Numeric] maximum
39
+ # @param [Numeric] specified
40
+ # @param [TrueClass|FalseClass] rest
41
+ # @return [TrueClass|FalseClass]
42
+ #
43
+ def correct_argument_amount(minimum, maximum, specified, rest = false)
44
+ valid = false
45
+
46
+ if rest
47
+ valid = specified >= minimum
48
+ else
49
+ valid = specified >= minimum && specified <= maximum
50
+ end
51
+
52
+ return valid
53
+ end
54
+
55
+ ##
56
+ # Creates a string that indicates the amount of parameters that can be
57
+ # specified for a method.
58
+ #
59
+ # @param [Numeric] minimum
60
+ # @param [Numeric] maximum
61
+ # @param [Numeric] optional
62
+ # @return [String]
63
+ #
64
+ def expected_text(minimum, maximum, optional)
65
+ if optional > 0
66
+ return "#{minimum}..#{maximum}"
67
+ else
68
+ return minimum.to_s
69
+ end
70
+ end
71
+ end # ArgumentAmount
72
+ end # Analyze
73
+ end # RubyLint