rubocop 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (381) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -4
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +70 -1
  5. data/README.md +101 -11
  6. data/config/default.yml +10 -2
  7. data/config/enabled.yml +85 -11
  8. data/lib/rubocop.rb +97 -73
  9. data/lib/rubocop/cli.rb +177 -92
  10. data/lib/rubocop/config.rb +56 -11
  11. data/lib/rubocop/config_store.rb +2 -0
  12. data/lib/rubocop/cop/cop.rb +52 -8
  13. data/lib/rubocop/cop/lint/assignment_in_condition.rb +54 -0
  14. data/lib/rubocop/cop/lint/end_alignment.rb +180 -0
  15. data/lib/rubocop/cop/lint/end_in_method.rb +30 -0
  16. data/lib/rubocop/cop/lint/ensure_return.rb +22 -0
  17. data/lib/rubocop/cop/lint/eval.rb +22 -0
  18. data/lib/rubocop/cop/lint/handle_exceptions.rb +20 -0
  19. data/lib/rubocop/cop/lint/literal_in_condition.rb +63 -0
  20. data/lib/rubocop/cop/lint/loop.rb +29 -0
  21. data/lib/rubocop/cop/lint/rescue_exception.rb +29 -0
  22. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +33 -0
  23. data/lib/rubocop/cop/lint/unreachable_code.rb +35 -0
  24. data/lib/rubocop/cop/lint/unused_local_variable.rb +32 -0
  25. data/lib/rubocop/cop/lint/void.rb +58 -0
  26. data/lib/rubocop/cop/offence.rb +112 -12
  27. data/lib/rubocop/cop/rails/validation.rb +34 -0
  28. data/lib/rubocop/cop/style/access_control.rb +58 -0
  29. data/lib/rubocop/cop/style/alias.rb +28 -0
  30. data/lib/rubocop/cop/style/align_parameters.rb +39 -0
  31. data/lib/rubocop/cop/style/and_or.rb +45 -0
  32. data/lib/rubocop/cop/style/ascii_comments.rb +21 -0
  33. data/lib/rubocop/cop/style/ascii_identifiers.rb +22 -0
  34. data/lib/rubocop/cop/style/attr.rb +20 -0
  35. data/lib/rubocop/cop/style/avoid_class_vars.rb +20 -0
  36. data/lib/rubocop/cop/style/avoid_for.rb +18 -0
  37. data/lib/rubocop/cop/style/avoid_global_vars.rb +65 -0
  38. data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +21 -0
  39. data/lib/rubocop/cop/style/avoid_perlisms.rb +50 -0
  40. data/lib/rubocop/cop/style/begin_block.rb +18 -0
  41. data/lib/rubocop/cop/style/block_comments.rb +20 -0
  42. data/lib/rubocop/cop/style/block_nesting.rb +47 -0
  43. data/lib/rubocop/cop/style/blocks.rb +27 -0
  44. data/lib/rubocop/cop/style/case_equality.rb +22 -0
  45. data/lib/rubocop/cop/style/case_indentation.rb +28 -0
  46. data/lib/rubocop/cop/style/character_literal.rb +37 -0
  47. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +33 -0
  48. data/lib/rubocop/cop/style/class_methods.rb +22 -0
  49. data/lib/rubocop/cop/style/collection_methods.rb +37 -0
  50. data/lib/rubocop/cop/style/colon_method_call.rb +29 -0
  51. data/lib/rubocop/cop/style/constant_name.rb +31 -0
  52. data/lib/rubocop/cop/style/def_parentheses.rb +70 -0
  53. data/lib/rubocop/cop/style/documentation.rb +58 -0
  54. data/lib/rubocop/cop/style/dot_position.rb +25 -0
  55. data/lib/rubocop/cop/style/empty_line_between_defs.rb +26 -0
  56. data/lib/rubocop/cop/style/empty_lines.rb +40 -0
  57. data/lib/rubocop/cop/style/empty_literal.rb +53 -0
  58. data/lib/rubocop/cop/style/encoding.rb +29 -0
  59. data/lib/rubocop/cop/style/end_block.rb +18 -0
  60. data/lib/rubocop/cop/style/end_of_line.rb +23 -0
  61. data/lib/rubocop/cop/style/favor_join.rb +29 -0
  62. data/lib/rubocop/cop/style/favor_modifier.rb +118 -0
  63. data/lib/rubocop/cop/style/favor_sprintf.rb +28 -0
  64. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +54 -0
  65. data/lib/rubocop/cop/style/hash_syntax.rb +47 -0
  66. data/lib/rubocop/cop/style/if_then_else.rb +80 -0
  67. data/lib/rubocop/cop/style/lambda.rb +47 -0
  68. data/lib/rubocop/cop/style/leading_comment_space.rb +25 -0
  69. data/lib/rubocop/cop/style/line_continuation.rb +26 -0
  70. data/lib/rubocop/cop/style/line_length.rb +30 -0
  71. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +61 -0
  72. data/lib/rubocop/cop/style/method_call_parentheses.rb +22 -0
  73. data/lib/rubocop/cop/style/method_length.rb +57 -0
  74. data/lib/rubocop/cop/style/not.rb +24 -0
  75. data/lib/rubocop/cop/style/numeric_literals.rb +25 -0
  76. data/lib/rubocop/cop/{op_method.rb → style/op_method.rb} +4 -3
  77. data/lib/rubocop/cop/style/parameter_lists.rb +42 -0
  78. data/lib/rubocop/cop/style/parentheses_around_condition.rb +42 -0
  79. data/lib/rubocop/cop/style/proc.rb +30 -0
  80. data/lib/rubocop/cop/style/reduce_arguments.rb +34 -0
  81. data/lib/rubocop/cop/style/regexp_literal.rb +39 -0
  82. data/lib/rubocop/cop/style/rescue_modifier.rb +55 -0
  83. data/lib/rubocop/cop/style/semicolon.rb +51 -0
  84. data/lib/rubocop/cop/style/single_line_methods.rb +48 -0
  85. data/lib/rubocop/cop/style/space_after_comma_etc.rb +69 -0
  86. data/lib/rubocop/cop/style/space_after_control_keyword.rb +32 -0
  87. data/lib/rubocop/cop/style/string_literals.rb +36 -0
  88. data/lib/rubocop/cop/style/surrounding_space.rb +314 -0
  89. data/lib/rubocop/cop/style/symbol_array.rb +31 -0
  90. data/lib/rubocop/cop/style/symbol_name.rb +27 -0
  91. data/lib/rubocop/cop/style/tab.rb +25 -0
  92. data/lib/rubocop/cop/style/ternary_operator.rb +49 -0
  93. data/lib/rubocop/cop/style/trailing_whitespace.rb +24 -0
  94. data/lib/rubocop/cop/style/trivial_accessors.rb +32 -0
  95. data/lib/rubocop/cop/style/unless_else.rb +26 -0
  96. data/lib/rubocop/cop/style/variable_interpolation.rb +32 -0
  97. data/lib/rubocop/cop/style/when_then.rb +25 -0
  98. data/lib/rubocop/cop/style/while_until_do.rb +45 -0
  99. data/lib/rubocop/cop/style/word_array.rb +44 -0
  100. data/lib/rubocop/cop/util.rb +1 -0
  101. data/lib/rubocop/cop/variable_inspector.rb +280 -0
  102. data/lib/rubocop/formatter/base_formatter.rb +119 -0
  103. data/lib/rubocop/formatter/clang_style_formatter.rb +21 -0
  104. data/lib/rubocop/formatter/emacs_style_formatter.rb +17 -0
  105. data/lib/rubocop/formatter/formatter_set.rb +77 -0
  106. data/lib/rubocop/formatter/json_formatter.rb +76 -0
  107. data/lib/rubocop/formatter/progress_formatter.rb +63 -0
  108. data/lib/rubocop/formatter/simple_text_formatter.rb +62 -0
  109. data/lib/rubocop/version.rb +15 -1
  110. data/rubocop.gemspec +1 -2
  111. data/spec/.rubocop.yml +5 -0
  112. data/spec/project_spec.rb +4 -7
  113. data/spec/rubocop/cli_spec.rb +383 -146
  114. data/spec/rubocop/config_spec.rb +61 -0
  115. data/spec/rubocop/config_store_spec.rb +2 -2
  116. data/spec/rubocop/cops/cop_spec.rb +14 -7
  117. data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +111 -0
  118. data/spec/rubocop/cops/lint/end_alignment_spec.rb +426 -0
  119. data/spec/rubocop/cops/lint/end_in_method_spec.rb +35 -0
  120. data/spec/rubocop/cops/lint/ensure_return_spec.rb +37 -0
  121. data/spec/rubocop/cops/lint/eval_spec.rb +41 -0
  122. data/spec/rubocop/cops/lint/handle_exceptions_spec.rb +36 -0
  123. data/spec/rubocop/cops/lint/literal_in_condition_spec.rb +35 -0
  124. data/spec/rubocop/cops/lint/loop_spec.rb +33 -0
  125. data/spec/rubocop/cops/lint/rescue_exception_spec.rb +127 -0
  126. data/spec/rubocop/cops/lint/shadowing_outer_local_variable_spec.rb +180 -0
  127. data/spec/rubocop/cops/lint/unreachable_code_spec.rb +69 -0
  128. data/spec/rubocop/cops/lint/unused_local_variable_spec.rb +484 -0
  129. data/spec/rubocop/cops/lint/void_spec.rb +63 -0
  130. data/spec/rubocop/cops/offence_spec.rb +107 -10
  131. data/spec/rubocop/cops/rails/validation_spec.rb +27 -0
  132. data/spec/rubocop/cops/style/access_control_spec.rb +142 -0
  133. data/spec/rubocop/cops/style/alias_spec.rb +47 -0
  134. data/spec/rubocop/cops/style/align_parameters_spec.rb +199 -0
  135. data/spec/rubocop/cops/style/and_or_spec.rb +39 -0
  136. data/spec/rubocop/cops/style/ascii_comments_spec.rb +28 -0
  137. data/spec/rubocop/cops/style/ascii_identifiers_spec.rb +28 -0
  138. data/spec/rubocop/cops/style/attr_spec.rb +20 -0
  139. data/spec/rubocop/cops/style/avoid_class_vars_spec.rb +27 -0
  140. data/spec/rubocop/cops/style/avoid_for_spec.rb +37 -0
  141. data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +34 -0
  142. data/spec/rubocop/cops/style/avoid_perl_backrefs_spec.rb +20 -0
  143. data/spec/rubocop/cops/style/avoid_perlisms_spec.rb +47 -0
  144. data/spec/rubocop/cops/style/begin_block_spec.rb +19 -0
  145. data/spec/rubocop/cops/style/block_comments_spec.rb +27 -0
  146. data/spec/rubocop/cops/style/block_nesting_spec.rb +159 -0
  147. data/spec/rubocop/cops/style/blocks_spec.rb +35 -0
  148. data/spec/rubocop/cops/style/case_equality_spec.rb +18 -0
  149. data/spec/rubocop/cops/style/case_indentation_spec.rb +88 -0
  150. data/spec/rubocop/cops/style/character_literal_spec.rb +28 -0
  151. data/spec/rubocop/cops/style/class_and_module_camel_case_spec.rb +46 -0
  152. data/spec/rubocop/cops/style/class_methods_spec.rb +51 -0
  153. data/spec/rubocop/cops/style/collection_methods_spec.rb +46 -0
  154. data/spec/rubocop/cops/style/colon_method_call_spec.rb +55 -0
  155. data/spec/rubocop/cops/style/constant_name_spec.rb +56 -0
  156. data/spec/rubocop/cops/style/def_with_parentheses_spec.rb +40 -0
  157. data/spec/rubocop/cops/style/def_without_parentheses_spec.rb +34 -0
  158. data/spec/rubocop/cops/style/documentation_spec.rb +79 -0
  159. data/spec/rubocop/cops/style/dot_position_spec.rb +30 -0
  160. data/spec/rubocop/cops/style/empty_line_between_defs_spec.rb +85 -0
  161. data/spec/rubocop/cops/style/empty_lines_spec.rb +40 -0
  162. data/spec/rubocop/cops/style/empty_literal_spec.rb +91 -0
  163. data/spec/rubocop/cops/style/encoding_spec.rb +49 -0
  164. data/spec/rubocop/cops/style/end_block_spec.rb +19 -0
  165. data/spec/rubocop/cops/style/end_of_line_spec.rb +25 -0
  166. data/spec/rubocop/cops/style/favor_join_spec.rb +37 -0
  167. data/spec/rubocop/cops/style/favor_modifier_spec.rb +160 -0
  168. data/spec/rubocop/cops/style/favor_sprintf_spec.rb +53 -0
  169. data/spec/rubocop/cops/style/favor_unless_over_negated_if_spec.rb +64 -0
  170. data/spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb +47 -0
  171. data/spec/rubocop/cops/style/hash_syntax_spec.rb +51 -0
  172. data/spec/rubocop/cops/style/if_with_semicolon_spec.rb +25 -0
  173. data/spec/rubocop/cops/style/lambda_spec.rb +45 -0
  174. data/spec/rubocop/cops/style/leading_comment_space_spec.rb +65 -0
  175. data/spec/rubocop/cops/style/line_continuation_spec.rb +26 -0
  176. data/spec/rubocop/cops/style/line_length_spec.rb +25 -0
  177. data/spec/rubocop/cops/style/method_and_variable_snake_case_spec.rb +95 -0
  178. data/spec/rubocop/cops/style/method_call_parentheses_spec.rb +25 -0
  179. data/spec/rubocop/cops/style/method_length_spec.rb +151 -0
  180. data/spec/rubocop/cops/style/multiline_if_then_spec.rb +81 -0
  181. data/spec/rubocop/cops/style/not_spec.rb +28 -0
  182. data/spec/rubocop/cops/style/numeric_literals_spec.rb +51 -0
  183. data/spec/rubocop/cops/style/one_line_conditional_spec.rb +18 -0
  184. data/spec/rubocop/cops/style/op_method_spec.rb +80 -0
  185. data/spec/rubocop/cops/style/parameter_lists_spec.rb +49 -0
  186. data/spec/rubocop/cops/style/parentheses_around_condition_spec.rb +59 -0
  187. data/spec/rubocop/cops/style/proc_spec.rb +28 -0
  188. data/spec/rubocop/cops/style/reduce_arguments_spec.rb +59 -0
  189. data/spec/rubocop/cops/style/regexp_literal_spec.rb +83 -0
  190. data/spec/rubocop/cops/style/rescue_modifier_spec.rb +122 -0
  191. data/spec/rubocop/cops/style/semicolon_spec.rb +95 -0
  192. data/spec/rubocop/cops/style/single_line_methods_spec.rb +54 -0
  193. data/spec/rubocop/cops/style/space_after_colon_spec.rb +29 -0
  194. data/spec/rubocop/cops/style/space_after_comma_spec.rb +31 -0
  195. data/spec/rubocop/cops/style/space_after_control_keyword_spec.rb +69 -0
  196. data/spec/rubocop/cops/style/space_after_semicolon_spec.rb +24 -0
  197. data/spec/rubocop/cops/style/space_around_braces_spec.rb +49 -0
  198. data/spec/rubocop/cops/style/space_around_equals_in_default_parameter_spec.rb +34 -0
  199. data/spec/rubocop/cops/style/space_around_operators_spec.rb +216 -0
  200. data/spec/rubocop/cops/style/space_inside_brackets_spec.rb +51 -0
  201. data/spec/rubocop/cops/style/space_inside_hash_literal_braces_spec.rb +99 -0
  202. data/spec/rubocop/cops/style/space_inside_parens_spec.rb +33 -0
  203. data/spec/rubocop/cops/style/string_literals_spec.rb +62 -0
  204. data/spec/rubocop/cops/style/symbol_array_spec.rb +45 -0
  205. data/spec/rubocop/cops/style/symbol_name_spec.rb +122 -0
  206. data/spec/rubocop/cops/style/tab_spec.rb +23 -0
  207. data/spec/rubocop/cops/style/ternary_operator_spec.rb +42 -0
  208. data/spec/rubocop/cops/style/trailing_whitespace_spec.rb +29 -0
  209. data/spec/rubocop/cops/style/trivial_accessors_spec.rb +338 -0
  210. data/spec/rubocop/cops/style/unless_else_spec.rb +31 -0
  211. data/spec/rubocop/cops/style/variable_interpolation_spec.rb +53 -0
  212. data/spec/rubocop/cops/style/when_then_spec.rb +40 -0
  213. data/spec/rubocop/cops/style/while_until_do_spec.rb +47 -0
  214. data/spec/rubocop/cops/style/word_array_spec.rb +61 -0
  215. data/spec/rubocop/cops/variable_inspector_spec.rb +374 -0
  216. data/spec/rubocop/formatter/base_formatter_spec.rb +190 -0
  217. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +70 -0
  218. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +32 -0
  219. data/spec/rubocop/formatter/formatter_set_spec.rb +132 -0
  220. data/spec/rubocop/formatter/json_formatter_spec.rb +142 -0
  221. data/spec/rubocop/formatter/progress_formatter_spec.rb +196 -0
  222. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +74 -0
  223. data/spec/spec_helper.rb +23 -8
  224. data/spec/support/mri_syntax_checker.rb +69 -0
  225. data/spec/support/shared_examples.rb +33 -0
  226. metadata +315 -243
  227. data/lib/rubocop/cop/access_control.rb +0 -41
  228. data/lib/rubocop/cop/alias.rb +0 -17
  229. data/lib/rubocop/cop/align_parameters.rb +0 -37
  230. data/lib/rubocop/cop/and_or.rb +0 -36
  231. data/lib/rubocop/cop/ascii_comments.rb +0 -17
  232. data/lib/rubocop/cop/ascii_identifiers.rb +0 -19
  233. data/lib/rubocop/cop/avoid_class_vars.rb +0 -15
  234. data/lib/rubocop/cop/avoid_for.rb +0 -17
  235. data/lib/rubocop/cop/avoid_global_vars.rb +0 -61
  236. data/lib/rubocop/cop/avoid_perl_backrefs.rb +0 -17
  237. data/lib/rubocop/cop/avoid_perlisms.rb +0 -47
  238. data/lib/rubocop/cop/block_comments.rb +0 -17
  239. data/lib/rubocop/cop/block_nesting.rb +0 -35
  240. data/lib/rubocop/cop/blocks.rb +0 -23
  241. data/lib/rubocop/cop/case_indentation.rb +0 -22
  242. data/lib/rubocop/cop/class_and_module_camel_case.rb +0 -29
  243. data/lib/rubocop/cop/class_methods.rb +0 -15
  244. data/lib/rubocop/cop/collection_methods.rb +0 -29
  245. data/lib/rubocop/cop/colon_method_call.rb +0 -20
  246. data/lib/rubocop/cop/constant_name.rb +0 -24
  247. data/lib/rubocop/cop/def_parentheses.rb +0 -62
  248. data/lib/rubocop/cop/empty_line_between_defs.rb +0 -22
  249. data/lib/rubocop/cop/empty_lines.rb +0 -34
  250. data/lib/rubocop/cop/empty_literal.rb +0 -49
  251. data/lib/rubocop/cop/encoding.rb +0 -19
  252. data/lib/rubocop/cop/end_of_line.rb +0 -15
  253. data/lib/rubocop/cop/ensure_return.rb +0 -19
  254. data/lib/rubocop/cop/eval.rb +0 -19
  255. data/lib/rubocop/cop/favor_join.rb +0 -22
  256. data/lib/rubocop/cop/favor_modifier.rb +0 -92
  257. data/lib/rubocop/cop/favor_percent_r.rb +0 -19
  258. data/lib/rubocop/cop/favor_sprintf.rb +0 -21
  259. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +0 -49
  260. data/lib/rubocop/cop/handle_exceptions.rb +0 -17
  261. data/lib/rubocop/cop/hash_syntax.rb +0 -41
  262. data/lib/rubocop/cop/if_then_else.rb +0 -75
  263. data/lib/rubocop/cop/lambda.rb +0 -42
  264. data/lib/rubocop/cop/leading_comment_space.rb +0 -19
  265. data/lib/rubocop/cop/line_continuation.rb +0 -15
  266. data/lib/rubocop/cop/line_length.rb +0 -23
  267. data/lib/rubocop/cop/loop.rb +0 -33
  268. data/lib/rubocop/cop/method_and_variable_snake_case.rb +0 -55
  269. data/lib/rubocop/cop/method_length.rb +0 -52
  270. data/lib/rubocop/cop/not.rb +0 -21
  271. data/lib/rubocop/cop/numeric_literals.rb +0 -21
  272. data/lib/rubocop/cop/parameter_lists.rb +0 -23
  273. data/lib/rubocop/cop/parentheses_around_condition.rb +0 -40
  274. data/lib/rubocop/cop/percent_r.rb +0 -19
  275. data/lib/rubocop/cop/proc.rb +0 -26
  276. data/lib/rubocop/cop/reduce_arguments.rb +0 -29
  277. data/lib/rubocop/cop/rescue_exception.rb +0 -26
  278. data/lib/rubocop/cop/rescue_modifier.rb +0 -15
  279. data/lib/rubocop/cop/semicolon.rb +0 -31
  280. data/lib/rubocop/cop/single_line_methods.rb +0 -44
  281. data/lib/rubocop/cop/space_after_comma_etc.rb +0 -62
  282. data/lib/rubocop/cop/space_after_control_keyword.rb +0 -29
  283. data/lib/rubocop/cop/string_literals.rb +0 -25
  284. data/lib/rubocop/cop/surrounding_space.rb +0 -285
  285. data/lib/rubocop/cop/symbol_array.rb +0 -31
  286. data/lib/rubocop/cop/symbol_name.rb +0 -23
  287. data/lib/rubocop/cop/syntax.rb +0 -49
  288. data/lib/rubocop/cop/tab.rb +0 -15
  289. data/lib/rubocop/cop/ternary_operator.rb +0 -43
  290. data/lib/rubocop/cop/trailing_whitespace.rb +0 -15
  291. data/lib/rubocop/cop/trivial_accessors.rb +0 -26
  292. data/lib/rubocop/cop/unless_else.rb +0 -23
  293. data/lib/rubocop/cop/variable_interpolation.rb +0 -29
  294. data/lib/rubocop/cop/when_then.rb +0 -17
  295. data/lib/rubocop/cop/word_array.rb +0 -37
  296. data/lib/rubocop/report/emacs_style.rb +0 -17
  297. data/lib/rubocop/report/plain_text.rb +0 -18
  298. data/lib/rubocop/report/report.rb +0 -44
  299. data/spec/rubocop/cops/access_control_spec.rb +0 -129
  300. data/spec/rubocop/cops/alias_spec.rb +0 -39
  301. data/spec/rubocop/cops/align_parameters_spec.rb +0 -197
  302. data/spec/rubocop/cops/and_or_spec.rb +0 -37
  303. data/spec/rubocop/cops/ascii_comments_spec.rb +0 -26
  304. data/spec/rubocop/cops/ascii_identifiers_spec.rb +0 -26
  305. data/spec/rubocop/cops/avoid_class_vars_spec.rb +0 -25
  306. data/spec/rubocop/cops/avoid_for_spec.rb +0 -35
  307. data/spec/rubocop/cops/avoid_global_vars_spec.rb +0 -32
  308. data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +0 -18
  309. data/spec/rubocop/cops/avoid_perlisms_spec.rb +0 -44
  310. data/spec/rubocop/cops/block_comments_spec.rb +0 -25
  311. data/spec/rubocop/cops/block_nesting_spec.rb +0 -148
  312. data/spec/rubocop/cops/blocks_spec.rb +0 -33
  313. data/spec/rubocop/cops/case_indentation_spec.rb +0 -86
  314. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +0 -44
  315. data/spec/rubocop/cops/class_methods_spec.rb +0 -49
  316. data/spec/rubocop/cops/collection_methods_spec.rb +0 -44
  317. data/spec/rubocop/cops/colon_method_call_spec.rb +0 -53
  318. data/spec/rubocop/cops/constant_name_spec.rb +0 -42
  319. data/spec/rubocop/cops/def_with_parentheses_spec.rb +0 -38
  320. data/spec/rubocop/cops/def_without_parentheses_spec.rb +0 -32
  321. data/spec/rubocop/cops/empty_line_between_defs_spec.rb +0 -83
  322. data/spec/rubocop/cops/empty_lines_spec.rb +0 -38
  323. data/spec/rubocop/cops/empty_literal_spec.rb +0 -90
  324. data/spec/rubocop/cops/encoding_spec.rb +0 -47
  325. data/spec/rubocop/cops/end_of_line_spec.rb +0 -23
  326. data/spec/rubocop/cops/ensure_return_spec.rb +0 -35
  327. data/spec/rubocop/cops/eval_spec.rb +0 -39
  328. data/spec/rubocop/cops/favor_join_spec.rb +0 -35
  329. data/spec/rubocop/cops/favor_modifier_spec.rb +0 -146
  330. data/spec/rubocop/cops/favor_percent_r_spec.rb +0 -29
  331. data/spec/rubocop/cops/favor_sprintf_spec.rb +0 -51
  332. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +0 -62
  333. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +0 -45
  334. data/spec/rubocop/cops/handle_exceptions_spec.rb +0 -34
  335. data/spec/rubocop/cops/hash_syntax_spec.rb +0 -49
  336. data/spec/rubocop/cops/if_with_semicolon_spec.rb +0 -23
  337. data/spec/rubocop/cops/lambda_spec.rb +0 -43
  338. data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -54
  339. data/spec/rubocop/cops/line_continuation_spec.rb +0 -24
  340. data/spec/rubocop/cops/line_length_spec.rb +0 -23
  341. data/spec/rubocop/cops/loop_spec.rb +0 -31
  342. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +0 -93
  343. data/spec/rubocop/cops/method_length_spec.rb +0 -147
  344. data/spec/rubocop/cops/multiline_if_then_spec.rb +0 -79
  345. data/spec/rubocop/cops/not_spec.rb +0 -26
  346. data/spec/rubocop/cops/numeric_literals_spec.rb +0 -49
  347. data/spec/rubocop/cops/one_line_conditional_spec.rb +0 -16
  348. data/spec/rubocop/cops/op_method_spec.rb +0 -78
  349. data/spec/rubocop/cops/parameter_lists_spec.rb +0 -24
  350. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +0 -61
  351. data/spec/rubocop/cops/percent_r_spec.rb +0 -29
  352. data/spec/rubocop/cops/proc_spec.rb +0 -26
  353. data/spec/rubocop/cops/reduce_arguments_spec.rb +0 -57
  354. data/spec/rubocop/cops/rescue_exception_spec.rb +0 -125
  355. data/spec/rubocop/cops/rescue_modifier_spec.rb +0 -37
  356. data/spec/rubocop/cops/semicolon_spec.rb +0 -88
  357. data/spec/rubocop/cops/single_line_methods_spec.rb +0 -50
  358. data/spec/rubocop/cops/space_after_colon_spec.rb +0 -27
  359. data/spec/rubocop/cops/space_after_comma_spec.rb +0 -29
  360. data/spec/rubocop/cops/space_after_control_keyword_spec.rb +0 -67
  361. data/spec/rubocop/cops/space_after_semicolon_spec.rb +0 -22
  362. data/spec/rubocop/cops/space_around_braces_spec.rb +0 -47
  363. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +0 -32
  364. data/spec/rubocop/cops/space_around_operators_spec.rb +0 -209
  365. data/spec/rubocop/cops/space_inside_brackets_spec.rb +0 -49
  366. data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +0 -86
  367. data/spec/rubocop/cops/space_inside_parens_spec.rb +0 -31
  368. data/spec/rubocop/cops/string_literals_spec.rb +0 -58
  369. data/spec/rubocop/cops/symbol_array_spec.rb +0 -41
  370. data/spec/rubocop/cops/symbol_name_spec.rb +0 -119
  371. data/spec/rubocop/cops/syntax_spec.rb +0 -41
  372. data/spec/rubocop/cops/tab_spec.rb +0 -21
  373. data/spec/rubocop/cops/ternary_operator_spec.rb +0 -40
  374. data/spec/rubocop/cops/trailing_whitespace_spec.rb +0 -27
  375. data/spec/rubocop/cops/trivial_accessors_spec.rb +0 -337
  376. data/spec/rubocop/cops/unless_else_spec.rb +0 -29
  377. data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -49
  378. data/spec/rubocop/cops/when_then_spec.rb +0 -38
  379. data/spec/rubocop/cops/word_array_spec.rb +0 -47
  380. data/spec/rubocop/reports/emacs_style_spec.rb +0 -25
  381. data/spec/rubocop/reports/report_spec.rb +0 -29
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_ruby_version = '>= 1.9.2'
12
12
  s.authors = ['Bozhidar Batsov']
13
- s.date = '2013-04-17'
14
13
  s.description = <<-EOF
15
14
  Automatic Ruby code style checking tool.
16
15
  Aims to enforce the community-driven Ruby Style Guide.
@@ -28,7 +27,7 @@ Gem::Specification.new do |s|
28
27
  s.summary = 'Automatic Ruby code style checking tool.'
29
28
 
30
29
  s.add_runtime_dependency('rainbow', '>= 1.1.4')
31
- s.add_runtime_dependency('parser', ['2.0.0.beta5'])
30
+ s.add_runtime_dependency('parser', '2.0.0.beta9')
32
31
  s.add_development_dependency('rake', '~> 10.0')
33
32
  s.add_development_dependency('rspec', '~> 2.13')
34
33
  s.add_development_dependency('yard', '~> 0.8')
@@ -0,0 +1,5 @@
1
+ inherit_from: ../.rubocop.yml
2
+
3
+ # The documentation check doesn't make sense for test code
4
+ Documentation:
5
+ Enabled: false
@@ -3,25 +3,22 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'RuboCop Project' do
6
- describe '.rubocop.yml' do
6
+ describe 'default configuration file' do
7
7
  it 'has configuration for all cops' do
8
8
  cop_names = Rubocop::Cop::Cop.all.map(&:cop_name)
9
- expect(Rubocop::Config.load_file('.rubocop.yml').keys.sort)
9
+ expect(Rubocop::Config.load_file('config/default.yml').keys.sort)
10
10
  .to eq((['AllCops'] + cop_names).sort)
11
11
  end
12
12
  end
13
13
 
14
- describe 'source codes', broken: true do
14
+ describe 'source codes' do
15
15
  before { $stdout = StringIO.new }
16
16
  after { $stdout = STDOUT }
17
17
 
18
18
  it 'has no violations' do
19
19
  # Need to pass an empty array explicitly
20
20
  # so that the CLI does not refer arguments of `rspec`
21
- Rubocop::CLI.new.run([])
22
- expect($stdout.string).to match(
23
- /files inspected, no offences detected\n/
24
- )
21
+ expect(Rubocop::CLI.new.run([])).to eq(0)
25
22
  end
26
23
  end
27
24
  end
@@ -9,21 +9,51 @@ module Rubocop
9
9
  include FileHelper
10
10
 
11
11
  let(:cli) { CLI.new }
12
- before(:each) { $stdout = StringIO.new }
13
- after(:each) { $stdout = STDOUT }
12
+
13
+ before(:each) do
14
+ $stdout = StringIO.new
15
+ $stderr = StringIO.new
16
+ end
17
+
18
+ after(:each) do
19
+ $stdout = STDOUT
20
+ $stderr = STDERR
21
+ end
22
+
23
+ def abs(path)
24
+ File.expand_path(path)
25
+ end
14
26
 
15
27
  it 'exits cleanly when -h is used' do
16
28
  expect { cli.run ['-h'] }.to exit_with_code(0)
17
29
  expect { cli.run ['--help'] }.to exit_with_code(0)
18
- message = ['Usage: rubocop [options] [file1, file2, ...]',
19
- ' -d, --debug Display debug info',
20
- ' -e, --emacs Emacs style output',
21
- ' -c, --config FILE Configuration file',
22
- ' --only COP Run just one cop',
23
- ' -s, --silent Silence summary',
24
- ' -n, --no-color Disable color output',
25
- ' -v, --version Display version']
26
- expect($stdout.string).to eq((message * 2).join("\n") + "\n")
30
+ message = <<-END
31
+ Usage: rubocop [options] [file1, file2, ...]
32
+ -d, --debug Display debug info.
33
+ -c, --config FILE Specify configuration file.
34
+ --only COP Run just one cop.
35
+ -f, --format FORMATTER Choose an output formatter. This option
36
+ can be specified multiple times to enable
37
+ multiple formatters at the same time.
38
+ [p]rogress (default)
39
+ [s]imple
40
+ [c]lang
41
+ [e]macs
42
+ [j]son
43
+ custom formatter class name
44
+ -o, --out FILE Write output to a file instead of STDOUT.
45
+ This option applies to the previously
46
+ specified --format, or the default format
47
+ if no format is specified.
48
+ -r, --require FILE Require Ruby file.
49
+ -R, --rails Run extra Rails cops.
50
+ -a, --auto-correct Auto-correct offences.
51
+ -s, --silent Silence summary.
52
+ -n, --no-color Disable color output.
53
+ -v, --version Display version.
54
+ -V, --verbose-version Display verbose version.
55
+ END
56
+ expect($stdout.string).to eq(message * 2)
27
57
  end
28
58
 
29
59
  it 'exits cleanly when -v is used' do
@@ -38,78 +68,65 @@ module Rubocop
38
68
  end
39
69
  end
40
70
 
41
- context 'when interrupted with Ctrl-C' do
71
+ describe '#trap_interrupt' do
42
72
  before do
43
73
  @interrupt_handlers = []
44
74
  Signal.stub(:trap).with('INT') do |&block|
45
75
  @interrupt_handlers << block
46
76
  end
47
-
48
- $stderr = StringIO.new
49
-
50
- create_file('example.rb', '# encoding: utf-8')
51
- end
52
-
53
- after do
54
- $stderr = STDERR
55
- @cli_thread.terminate if @cli_thread
56
77
  end
57
78
 
58
79
  def interrupt
59
80
  @interrupt_handlers.each(&:call)
60
81
  end
61
82
 
62
- def cli_run_in_thread
63
- @cli_thread = Thread.new do
64
- cli.run(['--debug'])
65
- end
66
-
67
- # Wait for start.
68
- loop { break unless $stdout.string.empty? }
69
-
70
- @cli_thread
71
- end
72
-
73
- it 'exits with status 1' do
74
- cli_thread = cli_run_in_thread
75
- interrupt
76
- expect(cli_thread.value).to eq(1)
83
+ it 'adds a handler for SIGINT' do
84
+ expect(@interrupt_handlers).to be_empty
85
+ cli.trap_interrupt
86
+ expect(@interrupt_handlers).to have(1).item
77
87
  end
78
88
 
79
- it 'exits gracefully without dumping backtraces' do
80
- cli_thread = cli_run_in_thread
81
- interrupt
82
- cli_thread.join
83
- expect($stderr.string).not_to match(/from .+:\d+:in /)
84
- end
89
+ context 'with SIGINT once' do
90
+ it 'sets #wants_to_quit? to true' do
91
+ cli.trap_interrupt
92
+ expect(cli.wants_to_quit?).to be_false
93
+ interrupt
94
+ expect(cli.wants_to_quit?).to be_true
95
+ end
85
96
 
86
- context 'with Ctrl-C once' do
87
- it 'reports summary' do
88
- cli_thread = cli_run_in_thread
97
+ it 'does not exit immediately' do
98
+ Object.any_instance.should_not_receive(:exit)
99
+ Object.any_instance.should_not_receive(:exit!)
100
+ cli.trap_interrupt
89
101
  interrupt
90
- cli_thread.join
91
- expect($stdout.string).to match(/files? inspected/)
92
102
  end
93
103
  end
94
104
 
95
- context 'with Ctrl-C twice' do
105
+ context 'with SIGINT twice' do
96
106
  it 'exits immediately' do
97
107
  Object.any_instance.should_receive(:exit!).with(1)
98
- cli_thread = cli_run_in_thread
108
+ cli.trap_interrupt
99
109
  interrupt
100
110
  interrupt
101
- cli_thread.join
102
111
  end
103
112
  end
104
113
  end
105
114
 
115
+ context 'when #wants_to_quit? is true' do
116
+ it 'returns 1' do
117
+ create_file('example.rb', '# encoding: utf-8')
118
+ cli.wants_to_quit = true
119
+ expect(cli.run(['example.rb'])).to eq(1)
120
+ end
121
+ end
122
+
106
123
  it 'checks a given correct file and returns 0' do
107
124
  create_file('example.rb', [
108
125
  '# encoding: utf-8',
109
126
  'x = 0',
110
127
  'puts x'
111
128
  ])
112
- expect(cli.run(['example.rb'])).to eq(0)
129
+ expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(0)
113
130
  expect($stdout.string)
114
131
  .to eq("\n1 file inspected, no offences detected\n")
115
132
  end
@@ -120,10 +137,10 @@ module Rubocop
120
137
  'x = 0 ',
121
138
  'puts x'
122
139
  ])
123
- expect(cli.run(['example.rb'])).to eq(1)
140
+ expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(1)
124
141
  expect($stdout.string)
125
142
  .to eq ['== example.rb ==',
126
- 'C: 2: Trailing whitespace detected.',
143
+ 'C: 2: 6: Trailing whitespace detected.',
127
144
  '',
128
145
  '1 file inspected, 1 offence detected',
129
146
  ''].join("\n")
@@ -139,15 +156,17 @@ module Rubocop
139
156
  "\tx = 0",
140
157
  'puts x'
141
158
  ])
142
- expect(cli.run(['--emacs', 'example1.rb', 'example2.rb'])).to eq(1)
159
+ expect(cli.run(['--format', 'emacs', 'example1.rb', 'example2.rb']))
160
+ .to eq(1)
143
161
  expect($stdout.string)
144
162
  .to eq(
145
- ['example1.rb:1: C: Missing utf-8 encoding comment.',
146
- 'example1.rb:1: C: Trailing whitespace detected.',
147
- "example1.rb:1: C: Surrounding space missing for operator '='.",
148
- 'example1.rb:2: C: Trailing whitespace detected.',
149
- 'example2.rb:1: C: Missing utf-8 encoding comment.',
150
- 'example2.rb:1: C: Tab detected.',
163
+ ["#{abs('example1.rb')}:1:1: C: Missing utf-8 encoding comment.",
164
+ "#{abs('example1.rb')}:1:2: C: Surrounding space missing" +
165
+ " for operator '='.",
166
+ "#{abs('example1.rb')}:1:5: C: Trailing whitespace detected.",
167
+ "#{abs('example1.rb')}:2:2: C: Trailing whitespace detected.",
168
+ "#{abs('example2.rb')}:1:1: C: Missing utf-8 encoding comment.",
169
+ "#{abs('example2.rb')}:1:1: C: Tab detected.",
151
170
  '',
152
171
  '2 files inspected, 6 offences detected',
153
172
  ''].join("\n"))
@@ -163,18 +182,55 @@ module Rubocop
163
182
  "\tx = 0",
164
183
  'puts x'
165
184
  ])
166
- expect(cli.run(['--emacs', 'example1.rb', 'example2.rb'])).to eq(1)
185
+ expect(cli.run(['--format', 'emacs', 'example1.rb', 'example2.rb']))
186
+ .to eq(1)
167
187
  expect($stdout.string)
168
188
  .to eq(
169
- ['example1.rb:1: C: Trailing whitespace detected.',
170
- "example1.rb:1: C: Surrounding space missing for operator '='.",
171
- 'example1.rb:2: C: Trailing whitespace detected.',
172
- 'example2.rb:1: C: Tab detected.',
189
+ ["#{abs('example1.rb')}:1:2: C: Surrounding space missing" +
190
+ " for operator '='.",
191
+ "#{abs('example1.rb')}:1:5: C: Trailing whitespace detected.",
192
+ "#{abs('example1.rb')}:2:2: C: Trailing whitespace detected.",
193
+ "#{abs('example2.rb')}:1:1: C: Tab detected.",
173
194
  '',
174
195
  '2 files inspected, 4 offences detected',
175
196
  ''].join("\n"))
176
197
  end
177
198
 
199
+ it 'can report in clang style' do
200
+ create_file('example1.rb', ['# encoding: utf-8',
201
+ 'x= 0 ',
202
+ '#' * 85,
203
+ 'y ',
204
+ 'puts x'])
205
+ create_file('example2.rb', ['# encoding: utf-8',
206
+ "\tx = 0",
207
+ 'puts x'])
208
+ expect(cli.run(['--format', 'clang', 'example1.rb', 'example2.rb']))
209
+ .to eq(1)
210
+ expect($stdout.string)
211
+ .to eq(['example1.rb:2:2: C: Surrounding space missing for operator ' +
212
+ "'='.",
213
+ 'x= 0 ',
214
+ ' ^',
215
+ 'example1.rb:2:5: C: Trailing whitespace detected.',
216
+ 'x= 0 ',
217
+ ' ^',
218
+ 'example1.rb:3:80: C: Line is too long. [85/79]',
219
+ '###########################################################' +
220
+ '##########################',
221
+ ' ' +
222
+ ' ^^^^^^',
223
+ 'example1.rb:4:2: C: Trailing whitespace detected.',
224
+ 'y ',
225
+ ' ^',
226
+ 'example2.rb:2:1: C: Tab detected.',
227
+ "\tx = 0",
228
+ '^',
229
+ '',
230
+ '2 files inspected, 5 offences detected',
231
+ ''].join("\n"))
232
+ end
233
+
178
234
  it 'runs just one cop if --only is passed' do
179
235
  create_file('example.rb', ['if x== 0 ',
180
236
  "\ty",
@@ -182,12 +238,13 @@ module Rubocop
182
238
  # IfUnlessModifier depends on the configuration of LineLength.
183
239
  # That configuration might have been set by other spec examples
184
240
  # so we reset it to emulate a start from scratch.
185
- Cop::LineLength.config = nil
241
+ Cop::Style::LineLength.config = nil
186
242
 
187
- expect(cli.run(['--only', 'IfUnlessModifier', 'example.rb'])).to eq(1)
243
+ expect(cli.run(['--format', 'simple',
244
+ '--only', 'IfUnlessModifier', 'example.rb'])).to eq(1)
188
245
  expect($stdout.string)
189
246
  .to eq(['== example.rb ==',
190
- 'C: 1: Favor modifier if/unless usage when you have a ' +
247
+ 'C: 1: 1: Favor modifier if/unless usage when you have a ' +
191
248
  'single-line body. Another good alternative is the usage of ' +
192
249
  'control flow &&/||.',
193
250
  '',
@@ -197,45 +254,48 @@ module Rubocop
197
254
 
198
255
  it 'exits with error if an incorrect cop name is passed to --only' do
199
256
  expect(cli.run(%w(--only 123))).to eq(1)
200
- expect($stdout.string).to eq("Unrecognized cop name: 123.\n")
257
+ expect($stderr.string).to eq("Unrecognized cop name: 123.\n")
201
258
  end
202
259
 
203
260
  it 'ommits summary when --silent passed', ruby: 1.9 do
204
261
  create_file('example1.rb', 'puts 0 ')
205
262
  create_file('example2.rb', "\tputs 0")
206
- expect(cli.run(['--emacs',
263
+ expect(cli.run(['--format',
264
+ 'emacs',
207
265
  '--silent',
208
266
  'example1.rb',
209
267
  'example2.rb'])).to eq(1)
210
268
  expect($stdout.string).to eq(
211
- ['example1.rb:1: C: Missing utf-8 encoding comment.',
212
- 'example1.rb:1: C: Trailing whitespace detected.',
213
- 'example2.rb:1: C: Missing utf-8 encoding comment.',
214
- 'example2.rb:1: C: Tab detected.',
269
+ ["#{abs('example1.rb')}:1:1: C: Missing utf-8 encoding comment.",
270
+ "#{abs('example1.rb')}:1:7: C: Trailing whitespace detected.",
271
+ "#{abs('example2.rb')}:1:1: C: Missing utf-8 encoding comment.",
272
+ "#{abs('example2.rb')}:1:1: C: Tab detected.",
215
273
  ''].join("\n"))
216
274
  end
217
275
 
218
276
  it 'ommits summary when --silent passed', ruby: 2.0 do
219
277
  create_file('example1.rb', 'puts 0 ')
220
278
  create_file('example2.rb', "\tputs 0")
221
- expect(cli.run(['--emacs',
279
+ expect(cli.run(['--format',
280
+ 'emacs',
222
281
  '--silent',
223
282
  'example1.rb',
224
283
  'example2.rb'])).to eq(1)
225
284
  expect($stdout.string).to eq(
226
- ['example1.rb:1: C: Trailing whitespace detected.',
227
- 'example2.rb:1: C: Tab detected.',
285
+ ["#{abs('example1.rb')}:1:7: C: Trailing whitespace detected.",
286
+ "#{abs('example2.rb')}:1:1: C: Tab detected.",
228
287
  ''].join("\n"))
229
288
  end
230
289
 
231
290
  it 'shows cop names when --debug is passed', ruby: 2.0 do
232
291
  create_file('example1.rb', "\tputs 0")
233
- expect(cli.run(['--emacs',
292
+ expect(cli.run(['--format',
293
+ 'emacs',
234
294
  '--silent',
235
295
  '--debug',
236
296
  'example1.rb'])).to eq(1)
237
297
  expect($stdout.string.lines[-1]).to eq(
238
- ['example1.rb:1: C: Tab: Tab detected.',
298
+ ["#{abs('example1.rb')}:1:1: C: Tab: Tab detected.",
239
299
  ''].join("\n"))
240
300
  end
241
301
 
@@ -248,10 +308,11 @@ module Rubocop
248
308
  'CaseIndentation:',
249
309
  ' Enabled: false'
250
310
  ])
251
- expect(cli.run(['-c', 'rubocop.yml', 'example1.rb'])).to eq(1)
311
+ expect(cli.run(['--format', 'simple',
312
+ '-c', 'rubocop.yml', 'example1.rb'])).to eq(1)
252
313
  expect($stdout.string).to eq(
253
314
  ['== example1.rb ==',
254
- 'C: 1: Trailing whitespace detected.',
315
+ 'C: 1: 7: Trailing whitespace detected.',
255
316
  '',
256
317
  '1 file inspected, 1 offence detected',
257
318
  ''].join("\n"))
@@ -268,11 +329,13 @@ module Rubocop
268
329
  'LineLength:',
269
330
  ' Enabled: false'
270
331
  ])
271
- result = cli.run(['-c', 'rubocop.yml', 'example1.rb'])
332
+ result = cli.run(['--format', 'simple',
333
+ '-c', 'rubocop.yml', 'example1.rb'])
272
334
  expect($stdout.string).to eq(
273
335
  ['== example1.rb ==',
274
- 'C: 1: Favor modifier if/unless usage when you have a single-line ' +
275
- 'body. Another good alternative is the usage of control flow &&/||.',
336
+ 'C: 1: 1: Favor modifier if/unless usage when you have a ' +
337
+ 'single-line body. Another good alternative is the usage of ' +
338
+ 'control flow &&/||.',
276
339
  '',
277
340
  '1 file inspected, 1 offence detected',
278
341
  ''].join("\n"))
@@ -288,10 +351,11 @@ module Rubocop
288
351
  'CaseIndentation:',
289
352
  ' Enabled: false'
290
353
  ])
291
- expect(cli.run(['example_src/example1.rb'])).to eq(1)
354
+ expect(cli.run(['--format', 'simple',
355
+ 'example_src/example1.rb'])).to eq(1)
292
356
  expect($stdout.string).to eq(
293
357
  ['== example_src/example1.rb ==',
294
- 'C: 1: Trailing whitespace detected.',
358
+ 'C: 1: 7: Trailing whitespace detected.',
295
359
  '',
296
360
  '1 file inspected, 1 offence detected',
297
361
  ''].join("\n"))
@@ -307,7 +371,8 @@ module Rubocop
307
371
  ' Enabled: true',
308
372
  ' Max: 100'
309
373
  ])
310
- expect(cli.run(['example_src/example1.rb'])).to eq(0)
374
+ expect(cli.run(['--format', 'simple',
375
+ 'example_src/example1.rb'])).to eq(0)
311
376
  expect($stdout.string).to eq(
312
377
  ['', '1 file inspected, no offences detected',
313
378
  ''].join("\n"))
@@ -325,10 +390,10 @@ module Rubocop
325
390
  ' Enabled: true',
326
391
  ' Max: 100'
327
392
  ])
328
- expect(cli.run(['example'])).to eq(1)
393
+ expect(cli.run(%w(--format simple example))).to eq(1)
329
394
  expect($stdout.string).to eq(
330
395
  ['== example/lib/example1.rb ==',
331
- 'C: 2: Line is too long. [90/79]',
396
+ 'C: 2: 80: Line is too long. [90/79]',
332
397
  '',
333
398
  '2 files inspected, 1 offence detected',
334
399
  ''].join("\n"))
@@ -349,7 +414,8 @@ module Rubocop
349
414
  ' Enabled: true',
350
415
  ' Max: 80'
351
416
  ])
352
- expect(cli.run(['example_src/example1.rb'])).to eq(0)
417
+ expect(cli.run(['--format', 'simple',
418
+ 'example_src/example1.rb'])).to eq(0)
353
419
  expect($stdout.string).to eq(
354
420
  ['', '1 file inspected, no offences detected',
355
421
  ''].join("\n"))
@@ -371,10 +437,10 @@ module Rubocop
371
437
  ' - tmp/spec/**'
372
438
  ])
373
439
 
374
- expect(cli.run(['example'])).to eq(1)
440
+ expect(cli.run(%w(--format simple example))).to eq(1)
375
441
  expect($stdout.string).to eq(
376
442
  ['== example/tmp/test/example1.rb ==',
377
- 'C: 2: Line is too long. [90/79]',
443
+ 'C: 2: 80: Line is too long. [90/79]',
378
444
  '',
379
445
  '1 file inspected, 1 offence detected',
380
446
  ''].join("\n"))
@@ -392,12 +458,12 @@ module Rubocop
392
458
  ' Max: 100'
393
459
  ])
394
460
 
395
- expect(cli.run(['example'])).to eq(1)
461
+ expect(cli.run(%w(--format simple example))).to eq(1)
396
462
  expect($stdout.string).to eq(
397
463
  ['Warning: unrecognized cop LyneLenth found in ' +
398
464
  File.expand_path('example/.rubocop.yml'),
399
465
  '== example/example1.rb ==',
400
- 'C: 2: Line is too long. [90/79]',
466
+ 'C: 2: 80: Line is too long. [90/79]',
401
467
  '',
402
468
  '1 file inspected, 1 offence detected',
403
469
  ''].join("\n"))
@@ -415,41 +481,52 @@ module Rubocop
415
481
  ' Min: 10'
416
482
  ])
417
483
 
418
- expect(cli.run(['example'])).to eq(1)
484
+ expect(cli.run(%w(--format simple example))).to eq(1)
419
485
  expect($stdout.string).to eq(
420
486
  ['Warning: unrecognized parameter LineLength:Min found in ' +
421
487
  File.expand_path('example/.rubocop.yml'),
422
488
  '== example/example1.rb ==',
423
- 'C: 2: Line is too long. [90/79]',
489
+ 'C: 2: 80: Line is too long. [90/79]',
424
490
  '',
425
491
  '1 file inspected, 1 offence detected',
426
492
  ''].join("\n"))
427
493
  end
428
494
 
429
495
  it 'registers an offence for a syntax error' do
430
- pending
431
496
  create_file('example.rb', [
432
497
  '# encoding: utf-8',
433
498
  'class Test',
434
499
  'en'
435
500
  ])
436
- expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
437
- unexpected_part = RUBY_VERSION >= '2.0' ? 'end-of-input' : '$end'
438
- expect($stdout.string).to eq(
439
- ["example.rb:3: E: Syntax error, unexpected #{unexpected_part}, " +
440
- 'expecting keyword_end',
441
- '',
442
- '1 file inspected, 1 offence detected',
443
- ''].join("\n"))
501
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
502
+ expect($stdout.string)
503
+ .to eq(["#{abs('example.rb')}:3:3: E: unexpected " +
504
+ 'token $end',
505
+ '',
506
+ '1 file inspected, 1 offence detected',
507
+ ''].join("\n"))
508
+ end
509
+
510
+ it 'registers an offence for Parser warnings' do
511
+ create_file('example.rb', [
512
+ '# encoding: utf-8',
513
+ 'puts *test'
514
+ ])
515
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
516
+ expect($stdout.string)
517
+ .to eq(["#{abs('example.rb')}:2:6: W: " +
518
+ "`*' interpreted as argument prefix",
519
+ '',
520
+ '1 file inspected, 1 offence detected',
521
+ ''].join("\n"))
444
522
  end
445
523
 
446
524
  it 'can process a file with an invalid UTF-8 byte sequence' do
447
- pending
448
525
  create_file('example.rb', [
449
526
  '# encoding: utf-8',
450
527
  "# #{'f9'.hex.chr}#{'29'.hex.chr}"
451
528
  ])
452
- expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
529
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
453
530
  end
454
531
 
455
532
  it 'can have all cops disabled in a code section' do
@@ -466,13 +543,13 @@ module Rubocop
466
543
  ' y("123")',
467
544
  'end'
468
545
  ])
469
- expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
546
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
470
547
  # all cops were disabled, then 2 were enabled again, so we
471
548
  # should get 2 offences reported.
472
549
  expect($stdout.string).to eq(
473
- ['example.rb:8: C: Line is too long. [95/79]',
474
- "example.rb:10: C: Prefer single-quoted strings when you don't " +
475
- 'need string interpolation or special symbols.',
550
+ ["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
551
+ "#{abs('example.rb')}:10:5: C: Prefer single-quoted strings when " +
552
+ "you don't need string interpolation or special symbols.",
476
553
  '',
477
554
  '1 file inspected, 2 offences detected',
478
555
  ''].join("\n"))
@@ -492,13 +569,13 @@ module Rubocop
492
569
  ' y("123")',
493
570
  'end'
494
571
  ])
495
- expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
572
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
496
573
  # 3 cops were disabled, then 2 were enabled again, so we
497
574
  # should get 2 offences reported.
498
575
  expect($stdout.string).to eq(
499
- ['example.rb:8: C: Line is too long. [95/79]',
500
- "example.rb:10: C: Prefer single-quoted strings when you don't " +
501
- 'need string interpolation or special symbols.',
576
+ ["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
577
+ "#{abs('example.rb')}:10:5: C: Prefer single-quoted strings when " +
578
+ "you don't need string interpolation or special symbols.",
502
579
  '',
503
580
  '1 file inspected, 2 offences detected',
504
581
  ''].join("\n"))
@@ -509,7 +586,7 @@ module Rubocop
509
586
  '# encoding: utf-8',
510
587
  'y("123", 123456) # rubocop:disable all'
511
588
  ])
512
- expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
589
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
513
590
  expect($stdout.string).to eq(
514
591
  ['',
515
592
  '1 file inspected, no offences detected',
@@ -523,9 +600,9 @@ module Rubocop
523
600
  '#' * 95,
524
601
  'y("123") # rubocop:disable LineLength,StringLiterals'
525
602
  ])
526
- expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
603
+ expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
527
604
  expect($stdout.string).to eq(
528
- ['example.rb:3: C: Line is too long. [95/79]',
605
+ ["#{abs('example.rb')}:3:80: C: Line is too long. [95/79]",
529
606
  '',
530
607
  '1 file inspected, 1 offence detected',
531
608
  ''].join("\n"))
@@ -538,9 +615,7 @@ module Rubocop
538
615
  'x = 0',
539
616
  'puts x'
540
617
  ])
541
- # Need to pass an empty array explicitly
542
- # so that the CLI does not refer arguments of `rspec`
543
- expect(cli.run([])).to eq(0)
618
+ expect(cli.run(%w(--format simple))).to eq(0)
544
619
  expect($stdout.string).to eq(
545
620
  ['', '1 file inspected, no offences detected',
546
621
  ''].join("\n"))
@@ -563,9 +638,7 @@ module Rubocop
563
638
  ' - example',
564
639
  ' - !ruby/regexp /regexp$/'
565
640
  ])
566
- # Need to pass an empty array explicitly
567
- # so that the CLI does not refer arguments of `rspec`
568
- expect(cli.run([])).to eq(0)
641
+ expect(cli.run(%w(--format simple))).to eq(0)
569
642
  expect($stdout.string).to eq(
570
643
  ['', '2 files inspected, no offences detected',
571
644
  ''].join("\n"))
@@ -595,37 +668,201 @@ module Rubocop
595
668
  ' - !ruby/regexp /regexp.rb$/',
596
669
  ' - "exclude_*"'
597
670
  ])
598
- # Need to pass an empty array explicitly
599
- # so that the CLI does not refer arguments of `rspec`
600
- expect(cli.run([])).to eq(0)
671
+ expect(cli.run(%w(--format simple))).to eq(0)
672
+ expect($stdout.string).to eq(
673
+ ['', '0 files inspected, no offences detected',
674
+ ''].join("\n"))
675
+ end
676
+
677
+ # With rubinius 2.0.0.rc1 + rspec 2.13.1,
678
+ # File.stub(:open).and_call_original causes SystemStackError.
679
+ it 'does not read files in excluded list', broken: :rbx do
680
+ %w(rb.rb non-rb.ext without-ext).each do |filename|
681
+ create_file("example/ignored/#{filename}", [
682
+ '# encoding: utf-8',
683
+ '#' * 90
684
+ ])
685
+ end
686
+
687
+ create_file('example/.rubocop.yml', [
688
+ 'AllCops:',
689
+ ' Excludes:',
690
+ ' - ignored/**',
691
+ ])
692
+ File.should_not_receive(:open).with(%r(/ignored/))
693
+ File.stub(:open).and_call_original
694
+ expect(cli.run(%w(--format simple example))).to eq(0)
601
695
  expect($stdout.string).to eq(
602
696
  ['', '0 files inspected, no offences detected',
603
697
  ''].join("\n"))
604
698
  end
605
699
 
606
- describe '#display_summary' do
607
- it 'handles pluralization correctly' do
608
- cli.display_summary(0, 0, [])
609
- expect($stdout.string).to eq(
610
- "\n0 files inspected, no offences detected\n")
611
- $stdout = StringIO.new
612
- cli.display_summary(1, 0, [])
613
- expect($stdout.string).to eq(
614
- "\n1 file inspected, no offences detected\n")
615
- $stdout = StringIO.new
616
- cli.display_summary(1, 1, [])
617
- expect($stdout.string).to eq(
618
- "\n1 file inspected, 1 offence detected\n")
619
- $stdout = StringIO.new
620
- cli.display_summary(2, 2, [])
621
- expect($stdout.string).to eq(
622
- "\n2 files inspected, 2 offences detected\n")
700
+ describe '--require option' do
701
+ let(:required_file_path) { './path/to/required_file.rb' }
702
+
703
+ before do
704
+ create_file('example.rb', '# encoding: utf-8')
705
+
706
+ create_file(required_file_path, [
707
+ '# encoding: utf-8',
708
+ "puts 'Hello from required file!'"
709
+ ])
710
+ end
711
+
712
+ it 'requires the passed path' do
713
+ cli.run(['--require', required_file_path, 'example.rb'])
714
+ expect($stdout.string).to start_with('Hello from required file!')
715
+ end
716
+ end
717
+
718
+ describe '-f/--format option' do
719
+ let(:target_file) { 'example.rb' }
720
+
721
+ before do
722
+ create_file(target_file, [
723
+ '# encoding: utf-8',
724
+ '#' * 90
725
+ ])
623
726
  end
624
727
 
728
+ describe 'builtin formatters' do
729
+ context 'when simple format is specified' do
730
+ it 'outputs with simple format' do
731
+ cli.run(['--format', 'simple', 'example.rb'])
732
+ expect($stdout.string).to include([
733
+ "== #{target_file} ==",
734
+ 'C: 2: 80: Line is too long. [90/79]'
735
+ ].join("\n"))
736
+ end
737
+ end
738
+
739
+ context 'when emacs format is specified' do
740
+ it 'outputs with emacs format' do
741
+ cli.run(['--format', 'emacs', 'example.rb'])
742
+ expect($stdout.string).to include(
743
+ "#{abs(target_file)}:2:80: C: Line is too long. [90/79]")
744
+ end
745
+ end
746
+
747
+ context 'when unknown format name is specified' do
748
+ it 'aborts with error message' do
749
+ expect { cli.run(['--format', 'unknown', 'example.rb']) }
750
+ .to exit_with_code(1)
751
+ expect($stderr.string)
752
+ .to include('No formatter for "unknown"')
753
+ end
754
+ end
755
+ end
756
+
757
+ describe 'custom formatter' do
758
+ let(:target_file) { abs('example.rb') }
759
+
760
+ context 'when a class name is specified' do
761
+ it 'uses the class as a formatter' do
762
+ module ::MyTool
763
+ class RubocopFormatter < Rubocop::Formatter::BaseFormatter
764
+ def started(all_files)
765
+ output.puts "started: #{all_files.join(',')}"
766
+ end
767
+
768
+ def file_started(file, options)
769
+ output.puts "file_started: #{file}"
770
+ end
771
+
772
+ def file_finished(file, offences)
773
+ output.puts "file_finished: #{file}"
774
+ end
775
+
776
+ def finished(processed_files)
777
+ output.puts "finished: #{processed_files.join(',')}"
778
+ end
779
+ end
780
+ end
781
+
782
+ cli.run(['--format', 'MyTool::RubocopFormatter', 'example.rb'])
783
+ expect($stdout.string).to eq([
784
+ "started: #{target_file}",
785
+ "file_started: #{target_file}",
786
+ "file_finished: #{target_file}",
787
+ "finished: #{target_file}",
788
+ ''
789
+ ].join("\n"))
790
+ end
791
+ end
792
+
793
+ context 'when unknown class name is specified' do
794
+ it 'aborts with error message' do
795
+ expect { cli.run(['--format', 'UnknownFormatter', 'example.rb']) }
796
+ .to exit_with_code(1)
797
+ expect($stderr.string).to include('UnknownFormatter')
798
+ end
799
+ end
800
+ end
801
+
802
+ it 'can be used multiple times' do
803
+ cli.run(['--format', 'simple', '--format', 'emacs', 'example.rb'])
804
+ expect($stdout.string).to include([
805
+ "== #{target_file} ==",
806
+ 'C: 2: 80: Line is too long. [90/79]',
807
+ "#{abs(target_file)}:2:80: C: Line is too long. [90/79]"
808
+ ].join("\n"))
809
+ end
810
+ end
811
+
812
+ unless Rubocop::Version::STRING.start_with?('0')
813
+ describe '-e/--emacs option' do
814
+ it 'is dropped in RuboCop 1.0.0' do
815
+ # This spec can be removed once the option is dropped.
816
+ expect(cli.run(['--emacs'])).to eq(1)
817
+ expect($stderr.string).to include('invalid option: --emacs')
818
+ end
819
+ end
820
+ end
821
+
822
+ describe '-o/--out option' do
823
+ let(:target_file) { 'example.rb' }
824
+
825
+ before do
826
+ create_file(target_file, [
827
+ '# encoding: utf-8',
828
+ '#' * 90
829
+ ])
830
+ end
831
+
832
+ it 'redirects output to the specified file' do
833
+ cli.run(['--out', 'output.txt', target_file])
834
+ expect(File.read('output.txt')).to include('Line is too long.')
835
+ end
836
+
837
+ it 'is applied to the previously specified formatter' do
838
+ cli.run([
839
+ '--format', 'simple',
840
+ '--format', 'emacs', '--out', 'emacs_output.txt',
841
+ target_file
842
+ ])
843
+
844
+ expect($stdout.string).to eq([
845
+ "== #{target_file} ==",
846
+ 'C: 2: 80: Line is too long. [90/79]',
847
+ '',
848
+ '1 file inspected, 1 offence detected',
849
+ ''
850
+ ].join("\n"))
851
+
852
+ expect(File.read('emacs_output.txt')).to eq([
853
+ "#{abs(target_file)}:2:80: C: Line is too long. [90/79]",
854
+ '',
855
+ '1 file inspected, 1 offence detected',
856
+ ''
857
+ ].join("\n"))
858
+ end
859
+ end
860
+
861
+ describe '#display_error_summary' do
625
862
  it 'displays an error message when errors are present' do
626
863
  msg = 'An error occurred while Encoding cop was inspecting file.rb.'
627
- cli.display_summary(1, 1, [msg])
628
- expect($stdout.string.lines.to_a[-4..-3])
864
+ cli.display_error_summary([msg])
865
+ expect($stdout.string.lines.to_a[-6..-5])
629
866
  .to eq(["1 error occurred:\n", "#{msg}\n"])
630
867
  end
631
868
  end