rubocop 0.12.0 → 0.13.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 (279) hide show
  1. data/CHANGELOG.md +40 -0
  2. data/README.md +49 -8
  3. data/config/default.yml +40 -0
  4. data/config/enabled.yml +37 -9
  5. data/lib/rubocop.rb +24 -10
  6. data/lib/rubocop/cli.rb +41 -106
  7. data/lib/rubocop/config.rb +3 -2
  8. data/lib/rubocop/cop/commissioner.rb +15 -5
  9. data/lib/rubocop/cop/cop.rb +47 -32
  10. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
  11. data/lib/rubocop/cop/lint/block_alignment.rb +30 -9
  12. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  13. data/lib/rubocop/cop/lint/end_alignment.rb +4 -4
  14. data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
  15. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  16. data/lib/rubocop/cop/lint/eval.rb +1 -3
  17. data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
  18. data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -4
  19. data/lib/rubocop/cop/lint/loop.rb +1 -1
  20. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  21. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  22. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -8
  23. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  24. data/lib/rubocop/cop/lint/useless_assignment.rb +57 -60
  25. data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
  26. data/lib/rubocop/cop/lint/useless_setter_call.rb +85 -0
  27. data/lib/rubocop/cop/lint/void.rb +6 -8
  28. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  29. data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
  30. data/lib/rubocop/cop/rails/validation.rb +1 -1
  31. data/lib/rubocop/cop/style/access_control.rb +4 -6
  32. data/lib/rubocop/cop/style/alias.rb +1 -3
  33. data/lib/rubocop/cop/style/align_array.rb +47 -0
  34. data/lib/rubocop/cop/style/align_hash.rb +145 -0
  35. data/lib/rubocop/cop/style/align_parameters.rb +9 -3
  36. data/lib/rubocop/cop/style/and_or.rb +3 -4
  37. data/lib/rubocop/cop/style/ascii_comments.rb +1 -3
  38. data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
  39. data/lib/rubocop/cop/style/attr.rb +1 -4
  40. data/lib/rubocop/cop/style/begin_block.rb +1 -1
  41. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  42. data/lib/rubocop/cop/style/block_nesting.rb +2 -2
  43. data/lib/rubocop/cop/style/blocks.rb +14 -2
  44. data/lib/rubocop/cop/style/case_equality.rb +1 -3
  45. data/lib/rubocop/cop/style/case_indentation.rb +1 -1
  46. data/lib/rubocop/cop/style/character_literal.rb +1 -2
  47. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
  48. data/lib/rubocop/cop/style/class_methods.rb +1 -3
  49. data/lib/rubocop/cop/style/{avoid_class_vars.rb → class_vars.rb} +6 -2
  50. data/lib/rubocop/cop/style/collection_methods.rb +7 -9
  51. data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
  52. data/lib/rubocop/cop/style/comment_annotation.rb +6 -6
  53. data/lib/rubocop/cop/style/constant_name.rb +1 -3
  54. data/lib/rubocop/cop/style/def_parentheses.rb +4 -12
  55. data/lib/rubocop/cop/style/documentation.rb +2 -2
  56. data/lib/rubocop/cop/style/dot_position.rb +2 -4
  57. data/lib/rubocop/cop/style/empty_line_between_defs.rb +21 -6
  58. data/lib/rubocop/cop/style/empty_lines.rb +1 -1
  59. data/lib/rubocop/cop/style/empty_literal.rb +3 -12
  60. data/lib/rubocop/cop/style/encoding.rb +6 -6
  61. data/lib/rubocop/cop/style/end_block.rb +1 -1
  62. data/lib/rubocop/cop/style/end_of_line.rb +5 -5
  63. data/lib/rubocop/cop/style/even_odd.rb +2 -2
  64. data/lib/rubocop/cop/style/favor_join.rb +1 -3
  65. data/lib/rubocop/cop/style/favor_modifier.rb +7 -3
  66. data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
  67. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
  68. data/lib/rubocop/cop/style/final_newline.rb +23 -0
  69. data/lib/rubocop/cop/style/{avoid_for.rb → for.rb} +2 -2
  70. data/lib/rubocop/cop/style/{avoid_global_vars.rb → global_vars.rb} +19 -6
  71. data/lib/rubocop/cop/style/hash_methods.rb +3 -5
  72. data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
  73. data/lib/rubocop/cop/style/if_then_else.rb +1 -1
  74. data/lib/rubocop/cop/style/indentation_width.rb +4 -4
  75. data/lib/rubocop/cop/style/lambda.rb +2 -2
  76. data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
  77. data/lib/rubocop/cop/style/line_length.rb +7 -8
  78. data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +1 -1
  79. data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -4
  80. data/lib/rubocop/cop/style/method_length.rb +4 -4
  81. data/lib/rubocop/cop/style/module_function.rb +1 -3
  82. data/lib/rubocop/cop/style/multiline_block_chain.rb +44 -0
  83. data/lib/rubocop/cop/style/nil_comparison.rb +1 -3
  84. data/lib/rubocop/cop/style/not.rb +1 -1
  85. data/lib/rubocop/cop/style/numeric_literals.rb +26 -6
  86. data/lib/rubocop/cop/style/op_method.rb +2 -2
  87. data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
  88. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  89. data/lib/rubocop/cop/style/perl_backrefs.rb +26 -0
  90. data/lib/rubocop/cop/style/proc.rb +1 -3
  91. data/lib/rubocop/cop/style/reduce_arguments.rb +7 -5
  92. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  93. data/lib/rubocop/cop/style/redundant_return.rb +9 -2
  94. data/lib/rubocop/cop/style/redundant_self.rb +9 -2
  95. data/lib/rubocop/cop/style/regexp_literal.rb +7 -8
  96. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  97. data/lib/rubocop/cop/style/semicolon.rb +10 -10
  98. data/lib/rubocop/cop/style/signal_exception.rb +2 -4
  99. data/lib/rubocop/cop/style/single_line_methods.rb +2 -4
  100. data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -1
  101. data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
  102. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
  103. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +34 -0
  104. data/lib/rubocop/cop/style/{avoid_perlisms.rb → special_global_vars.rb} +17 -8
  105. data/lib/rubocop/cop/style/string_literals.rb +1 -2
  106. data/lib/rubocop/cop/style/surrounding_space.rb +9 -8
  107. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  108. data/lib/rubocop/cop/style/symbol_name.rb +9 -2
  109. data/lib/rubocop/cop/style/tab.rb +5 -5
  110. data/lib/rubocop/cop/style/ternary_operator.rb +2 -6
  111. data/lib/rubocop/cop/style/trailing_blank_lines.rb +32 -0
  112. data/lib/rubocop/cop/style/trailing_whitespace.rb +5 -6
  113. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  114. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  115. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -3
  116. data/lib/rubocop/cop/style/when_then.rb +1 -4
  117. data/lib/rubocop/cop/style/while_until_do.rb +7 -5
  118. data/lib/rubocop/cop/style/word_array.rb +1 -1
  119. data/lib/rubocop/cop/team.rb +100 -0
  120. data/lib/rubocop/cop/variable_inspector.rb +323 -235
  121. data/lib/rubocop/cop/variable_inspector/assignment.rb +103 -0
  122. data/lib/rubocop/cop/variable_inspector/locatable.rb +162 -0
  123. data/lib/rubocop/cop/variable_inspector/reference.rb +31 -0
  124. data/lib/rubocop/cop/variable_inspector/scope.rb +70 -0
  125. data/lib/rubocop/cop/variable_inspector/variable.rb +87 -0
  126. data/lib/rubocop/cop/variable_inspector/variable_table.rb +129 -0
  127. data/lib/rubocop/formatter/json_formatter.rb +8 -8
  128. data/lib/rubocop/formatter/progress_formatter.rb +4 -4
  129. data/lib/rubocop/processed_source.rb +22 -1
  130. data/lib/rubocop/version.rb +1 -1
  131. data/rubocop.gemspec +1 -1
  132. data/spec/rubocop/cli_spec.rb +32 -30
  133. data/spec/rubocop/config_spec.rb +4 -6
  134. data/spec/rubocop/cop/commissioner_spec.rb +4 -5
  135. data/spec/rubocop/cop/cop_spec.rb +8 -26
  136. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +5 -9
  137. data/spec/rubocop/cop/lint/block_alignment_spec.rb +105 -57
  138. data/spec/rubocop/cop/lint/empty_ensure_spec.rb +1 -1
  139. data/spec/rubocop/cop/lint/end_alignment_spec.rb +1 -1
  140. data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
  141. data/spec/rubocop/cop/lint/ensure_return_spec.rb +1 -1
  142. data/spec/rubocop/cop/lint/eval_spec.rb +3 -3
  143. data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +2 -2
  144. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +1 -1
  145. data/spec/rubocop/cop/lint/loop_spec.rb +1 -1
  146. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +1 -1
  147. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +5 -5
  148. data/spec/rubocop/cop/lint/unreachable_code_spec.rb +1 -1
  149. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1545 -108
  150. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
  151. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +101 -0
  152. data/spec/rubocop/cop/lint/void_spec.rb +1 -1
  153. data/spec/rubocop/cop/offence_spec.rb +4 -4
  154. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
  155. data/spec/rubocop/cop/rails/read_attribute_spec.rb +1 -1
  156. data/spec/rubocop/cop/rails/validation_spec.rb +1 -1
  157. data/spec/rubocop/cop/style/access_control_spec.rb +20 -20
  158. data/spec/rubocop/cop/style/alias_spec.rb +3 -3
  159. data/spec/rubocop/cop/style/align_array_spec.rb +62 -0
  160. data/spec/rubocop/cop/style/align_hash_spec.rb +267 -0
  161. data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
  162. data/spec/rubocop/cop/style/and_or_spec.rb +1 -1
  163. data/spec/rubocop/cop/style/ascii_comments_spec.rb +2 -2
  164. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
  165. data/spec/rubocop/cop/style/attr_spec.rb +1 -1
  166. data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
  167. data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
  168. data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
  169. data/spec/rubocop/cop/style/blocks_spec.rb +25 -1
  170. data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
  171. data/spec/rubocop/cop/style/case_indentation_spec.rb +5 -5
  172. data/spec/rubocop/cop/style/character_literal_spec.rb +1 -1
  173. data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +1 -1
  174. data/spec/rubocop/cop/style/class_methods_spec.rb +1 -1
  175. data/spec/rubocop/cop/style/class_vars_spec.rb +25 -0
  176. data/spec/rubocop/cop/style/collection_methods_spec.rb +5 -6
  177. data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -3
  178. data/spec/rubocop/cop/style/comment_annotation_spec.rb +20 -18
  179. data/spec/rubocop/cop/style/constant_name_spec.rb +1 -1
  180. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
  181. data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +1 -1
  182. data/spec/rubocop/cop/style/documentation_spec.rb +1 -1
  183. data/spec/rubocop/cop/style/dot_position_spec.rb +5 -5
  184. data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +35 -4
  185. data/spec/rubocop/cop/style/empty_lines_spec.rb +1 -1
  186. data/spec/rubocop/cop/style/empty_literal_spec.rb +7 -7
  187. data/spec/rubocop/cop/style/encoding_spec.rb +11 -5
  188. data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
  189. data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -3
  190. data/spec/rubocop/cop/style/even_odd_spec.rb +1 -1
  191. data/spec/rubocop/cop/style/favor_join_spec.rb +2 -2
  192. data/spec/rubocop/cop/style/favor_modifier_spec.rb +13 -10
  193. data/spec/rubocop/cop/style/favor_sprintf_spec.rb +4 -4
  194. data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
  195. data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +4 -4
  196. data/spec/rubocop/cop/style/final_newline_spec.rb +25 -0
  197. data/spec/rubocop/cop/style/{avoid_for_spec.rb → for_spec.rb} +8 -12
  198. data/spec/rubocop/cop/style/{avoid_global_vars_spec.rb → global_vars_spec.rb} +13 -3
  199. data/spec/rubocop/cop/style/hash_methods_spec.rb +1 -1
  200. data/spec/rubocop/cop/style/hash_syntax_spec.rb +20 -9
  201. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +3 -3
  202. data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -19
  203. data/spec/rubocop/cop/style/lambda_spec.rb +6 -6
  204. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +1 -1
  205. data/spec/rubocop/cop/style/line_length_spec.rb +3 -3
  206. data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +8 -9
  207. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +1 -1
  208. data/spec/rubocop/cop/style/method_length_spec.rb +18 -17
  209. data/spec/rubocop/cop/style/module_function_spec.rb +1 -1
  210. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +84 -0
  211. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
  212. data/spec/rubocop/cop/style/nil_comparison_spec.rb +1 -1
  213. data/spec/rubocop/cop/style/not_spec.rb +1 -1
  214. data/spec/rubocop/cop/style/numeric_literals_spec.rb +15 -25
  215. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -2
  216. data/spec/rubocop/cop/style/op_method_spec.rb +3 -3
  217. data/spec/rubocop/cop/style/parameter_lists_spec.rb +5 -5
  218. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +4 -8
  219. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +23 -0
  220. data/spec/rubocop/cop/style/proc_spec.rb +1 -1
  221. data/spec/rubocop/cop/style/reduce_arguments_spec.rb +18 -11
  222. data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
  223. data/spec/rubocop/cop/style/redundant_return_spec.rb +16 -1
  224. data/spec/rubocop/cop/style/redundant_self_spec.rb +6 -1
  225. data/spec/rubocop/cop/style/regexp_literal_spec.rb +19 -23
  226. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +3 -3
  227. data/spec/rubocop/cop/style/semicolon_spec.rb +3 -3
  228. data/spec/rubocop/cop/style/signal_exception_spec.rb +1 -1
  229. data/spec/rubocop/cop/style/single_line_methods_spec.rb +22 -18
  230. data/spec/rubocop/cop/style/space_after_colon_spec.rb +4 -4
  231. data/spec/rubocop/cop/style/space_after_comma_spec.rb +4 -4
  232. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +1 -1
  233. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +1 -1
  234. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +3 -3
  235. data/spec/rubocop/cop/style/space_around_braces_spec.rb +13 -12
  236. data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +3 -3
  237. data/spec/rubocop/cop/style/space_around_operators_spec.rb +25 -25
  238. data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +53 -0
  239. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +9 -9
  240. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +47 -61
  241. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +4 -4
  242. data/spec/rubocop/cop/style/special_global_vars_spec.rb +52 -0
  243. data/spec/rubocop/cop/style/string_literals_spec.rb +5 -5
  244. data/spec/rubocop/cop/style/symbol_array_spec.rb +1 -1
  245. data/spec/rubocop/cop/style/symbol_name_spec.rb +27 -18
  246. data/spec/rubocop/cop/style/tab_spec.rb +1 -1
  247. data/spec/rubocop/cop/style/ternary_operator_spec.rb +2 -2
  248. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +24 -0
  249. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -7
  250. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -14
  251. data/spec/rubocop/cop/style/unless_else_spec.rb +3 -3
  252. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +5 -5
  253. data/spec/rubocop/cop/style/when_then_spec.rb +15 -15
  254. data/spec/rubocop/cop/style/while_until_do_spec.rb +3 -3
  255. data/spec/rubocop/cop/style/word_array_spec.rb +1 -1
  256. data/spec/rubocop/cop/team_spec.rb +158 -0
  257. data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +217 -0
  258. data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +740 -0
  259. data/spec/rubocop/cop/variable_inspector/scope_spec.rb +191 -0
  260. data/spec/rubocop/cop/variable_inspector/variable_spec.rb +79 -0
  261. data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +275 -0
  262. data/spec/rubocop/cop/variable_inspector_spec.rb +13 -533
  263. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +4 -4
  264. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
  265. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
  266. data/spec/rubocop/formatter/file_list_formatter_spec.rb +3 -3
  267. data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
  268. data/spec/spec_helper.rb +5 -1
  269. data/spec/support/ast_helper.rb +15 -0
  270. data/spec/support/shared_context.rb +18 -0
  271. data/spec/support/shared_examples.rb +1 -1
  272. metadata +95 -32
  273. checksums.yaml +0 -7
  274. data/lib/rubocop/cop/lint/unused_local_variable.rb +0 -32
  275. data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +0 -19
  276. data/spec/rubocop/cop/lint/unused_local_variable_spec.rb +0 -588
  277. data/spec/rubocop/cop/style/avoid_class_vars_spec.rb +0 -27
  278. data/spec/rubocop/cop/style/avoid_perl_backrefs_spec.rb +0 -20
  279. data/spec/rubocop/cop/style/avoid_perlisms_spec.rb +0 -47
@@ -6,18 +6,18 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe IfWithSemicolon do
9
- let(:iws) { IfWithSemicolon.new }
9
+ subject(:iws) { IfWithSemicolon.new }
10
10
 
11
11
  it 'registers an offence for one line if/;/end' do
12
12
  inspect_source(iws, ['if cond; run else dont end'])
13
- expect(iws.offences.map(&:message)).to eq(
13
+ expect(iws.messages).to eq(
14
14
  ['Never use if x; Use the ternary operator instead.'])
15
15
  end
16
16
 
17
17
  it 'can handle modifier conditionals' do
18
18
  inspect_source(iws, ['class Hash',
19
19
  'end if RUBY_VERSION < "1.8.7"'])
20
- expect(iws.offences.map(&:message)).to be_empty
20
+ expect(iws.messages).to be_empty
21
21
  end
22
22
  end
23
23
  end
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe IndentationWidth do
9
- let(:cop) { described_class.new }
9
+ subject(:cop) { described_class.new }
10
10
 
11
11
  context 'with if statement' do
12
12
  it 'registers an offence for bad indentation of an if body' do
@@ -14,7 +14,7 @@ module Rubocop
14
14
  ['if cond',
15
15
  ' func',
16
16
  'end'])
17
- expect(cop.offences.map(&:message))
17
+ expect(cop.messages)
18
18
  .to eq(['Use 2 (not 1) spaces for indentation.'])
19
19
  end
20
20
 
@@ -25,7 +25,7 @@ module Rubocop
25
25
  'else',
26
26
  ' func2',
27
27
  'end'])
28
- expect(cop.offences.map(&:message))
28
+ expect(cop.messages)
29
29
  .to eq(['Use 2 (not 1) spaces for indentation.'])
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ module Rubocop
38
38
  'else',
39
39
  ' c',
40
40
  'end'])
41
- expect(cop.offences.map(&:message))
41
+ expect(cop.messages)
42
42
  .to eq(['Use 2 (not 1) spaces for indentation.'])
43
43
  end
44
44
 
@@ -49,7 +49,7 @@ module Rubocop
49
49
  'else',
50
50
  ' x ? y : z',
51
51
  'end'])
52
- expect(cop.offences.map(&:message))
52
+ expect(cop.messages)
53
53
  .to eq(['Use 2 (not 5) spaces for indentation.'])
54
54
  end
55
55
 
@@ -60,7 +60,7 @@ module Rubocop
60
60
  'else',
61
61
  ' x if y',
62
62
  'end'])
63
- expect(cop.offences.map(&:message))
63
+ expect(cop.messages)
64
64
  .to eq(['Use 2 (not 3) spaces for indentation.'])
65
65
  end
66
66
 
@@ -128,7 +128,7 @@ module Rubocop
128
128
  ['unless cond',
129
129
  ' func',
130
130
  'end'])
131
- expect(cop.offences.map(&:message))
131
+ expect(cop.messages)
132
132
  .to eq(['Use 2 (not 1) spaces for indentation.'])
133
133
  end
134
134
 
@@ -148,7 +148,7 @@ module Rubocop
148
148
  'when b',
149
149
  ' c',
150
150
  'end'])
151
- expect(cop.offences.map(&:message))
151
+ expect(cop.messages)
152
152
  .to eq(['Use 2 (not 1) spaces for indentation.'])
153
153
  end
154
154
 
@@ -162,7 +162,7 @@ module Rubocop
162
162
  'else',
163
163
  ' f',
164
164
  'end'])
165
- expect(cop.offences.map(&:message))
165
+ expect(cop.messages)
166
166
  .to eq(['Use 2 (not 3) spaces for indentation.'])
167
167
  end
168
168
 
@@ -227,7 +227,7 @@ module Rubocop
227
227
  ['while cond',
228
228
  ' func',
229
229
  'end'])
230
- expect(cop.offences.map(&:message))
230
+ expect(cop.messages)
231
231
  .to eq(['Use 2 (not 1) spaces for indentation.'])
232
232
  end
233
233
 
@@ -237,7 +237,7 @@ module Rubocop
237
237
  ' func1',
238
238
  ' func2',
239
239
  'end while cond'])
240
- expect(cop.offences.map(&:message))
240
+ expect(cop.messages)
241
241
  .to eq(['Use 2 (not 1) spaces for indentation.',
242
242
  'Use 2 (not 3) spaces for indentation.'])
243
243
  end
@@ -247,7 +247,7 @@ module Rubocop
247
247
  ['until cond',
248
248
  ' func',
249
249
  'end'])
250
- expect(cop.offences.map(&:message))
250
+ expect(cop.messages)
251
251
  .to eq(['Use 2 (not 1) spaces for indentation.'])
252
252
  end
253
253
 
@@ -265,7 +265,7 @@ module Rubocop
265
265
  ['for var in 1..10',
266
266
  ' func',
267
267
  'end'])
268
- expect(cop.offences.map(&:message))
268
+ expect(cop.messages)
269
269
  .to eq(['Use 2 (not 1) spaces for indentation.'])
270
270
  end
271
271
 
@@ -284,7 +284,7 @@ module Rubocop
284
284
  ' func1',
285
285
  ' func2', # No offence registered for this.
286
286
  'end'])
287
- expect(cop.offences.map(&:message))
287
+ expect(cop.messages)
288
288
  .to eq(['Use 2 (not 4) spaces for indentation.'])
289
289
  end
290
290
 
@@ -293,7 +293,7 @@ module Rubocop
293
293
  ['def self.test',
294
294
  ' func',
295
295
  'end'])
296
- expect(cop.offences.map(&:message))
296
+ expect(cop.messages)
297
297
  .to eq(['Use 2 (not 3) spaces for indentation.'])
298
298
  end
299
299
 
@@ -319,7 +319,7 @@ module Rubocop
319
319
  ' def func',
320
320
  ' end',
321
321
  'end'])
322
- expect(cop.offences.map(&:message))
322
+ expect(cop.messages)
323
323
  .to eq(['Use 2 (not 4) spaces for indentation.'])
324
324
  end
325
325
 
@@ -338,7 +338,7 @@ module Rubocop
338
338
  ' def func',
339
339
  ' end',
340
340
  'end'])
341
- expect(cop.offences.map(&:message))
341
+ expect(cop.messages)
342
342
  .to eq(['Use 2 (not 4) spaces for indentation.'])
343
343
  end
344
344
 
@@ -356,7 +356,7 @@ module Rubocop
356
356
  ['a = func do',
357
357
  ' b',
358
358
  'end'])
359
- expect(cop.offences.map(&:message))
359
+ expect(cop.messages)
360
360
  .to eq(['Use 2 (not 1) spaces for indentation.'])
361
361
  end
362
362
 
@@ -365,7 +365,7 @@ module Rubocop
365
365
  ['func {',
366
366
  ' b',
367
367
  '}'])
368
- expect(cop.offences.map(&:message))
368
+ expect(cop.messages)
369
369
  .to eq(['Use 2 (not 3) spaces for indentation.'])
370
370
  end
371
371
 
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe Lambda do
9
- let(:lambda) { Lambda.new }
9
+ subject(:lambda) { Lambda.new }
10
10
 
11
11
  it 'registers an offence for an old single-line lambda call' do
12
12
  inspect_source(lambda, ['f = lambda { |x| x }'])
@@ -16,22 +16,22 @@ module Rubocop
16
16
 
17
17
  it 'accepts the new lambda literal with single-line body' do
18
18
  inspect_source(lambda, ['lambda = ->(x) { x }',
19
- 'lambda.(1)'])
19
+ 'lambda.(1)'])
20
20
  expect(lambda.offences).to be_empty
21
21
  end
22
22
 
23
23
  it 'registers an offence for a new multi-line lambda call' do
24
24
  inspect_source(lambda, ['f = ->(x) do',
25
- ' x',
26
- 'end'])
25
+ ' x',
26
+ 'end'])
27
27
  expect(lambda.offences.size).to eq(1)
28
28
  expect(lambda.messages).to eq([Lambda::MULTI_MSG])
29
29
  end
30
30
 
31
31
  it 'accepts the old lambda syntax with multi-line body' do
32
32
  inspect_source(lambda, ['l = lambda do |x|',
33
- ' x',
34
- 'end'])
33
+ ' x',
34
+ 'end'])
35
35
  expect(lambda.offences).to be_empty
36
36
  end
37
37
 
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe LeadingCommentSpace do
9
- let(:lcs) { LeadingCommentSpace.new }
9
+ subject(:lcs) { LeadingCommentSpace.new }
10
10
 
11
11
  it 'registers an offence for comment without leading space' do
12
12
  inspect_source(lcs,
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  module Style
8
- describe LineLength do
9
- let(:ll) { LineLength.new }
10
- before { LineLength.config = { 'Max' => 79 } }
8
+ describe LineLength, :config do
9
+ subject(:ll) { LineLength.new(config) }
10
+ let(:cop_config) { { 'Max' => 79 } }
11
11
 
12
12
  it "registers an offence for a line that's 80 characters wide" do
13
13
  inspect_source(ll, ['#' * 80])
@@ -6,15 +6,14 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe MethodAndVariableSnakeCase do
9
- let(:cop) { described_class.new }
10
- let(:highlights) { cop.offences.map { |o| o.location.source } }
9
+ subject(:cop) { described_class.new }
11
10
 
12
11
  it 'registers an offence for camel case in instance method name' do
13
12
  inspect_source(cop, ['def myMethod',
14
13
  ' # ...',
15
14
  'end'])
16
15
  expect(cop.offences).to have(1).item
17
- expect(highlights).to eq(['myMethod'])
16
+ expect(cop.highlights).to eq(['myMethod'])
18
17
  end
19
18
 
20
19
  it 'registers an offence for camel case in singleton method name' do
@@ -22,32 +21,32 @@ module Rubocop
22
21
  ' # ...',
23
22
  'end'])
24
23
  expect(cop.offences).to have(1).item
25
- expect(highlights).to eq(['myMethod'])
24
+ expect(cop.highlights).to eq(['myMethod'])
26
25
  end
27
26
 
28
27
  it 'registers an offence for camel case in local variable name' do
29
28
  inspect_source(cop, 'myLocal = 1')
30
29
  expect(cop.offences).to have(1).item
31
- expect(highlights).to eq(['myLocal'])
30
+ expect(cop.highlights).to eq(['myLocal'])
32
31
  end
33
32
 
34
33
  it 'registers an offence for camel case in instance variable name' do
35
34
  inspect_source(cop, '@myAttribute = 3')
36
35
  expect(cop.offences).to have(1).item
37
- expect(highlights).to eq(['@myAttribute'])
36
+ expect(cop.highlights).to eq(['@myAttribute'])
38
37
  end
39
38
 
40
39
  it 'registers an offence for camel case in setter name' do
41
40
  inspect_source(cop, 'self.mySetter = 2')
42
41
  expect(cop.offences).to have(1).item
43
- expect(highlights).to eq(['mySetter'])
42
+ expect(cop.highlights).to eq(['mySetter'])
44
43
  end
45
44
 
46
45
  it 'registers an offence for capitalized camel case' do
47
46
  inspect_source(cop, ['def MyMethod',
48
47
  'end'])
49
48
  expect(cop.offences).to have(1).item
50
- expect(highlights).to eq(['MyMethod'])
49
+ expect(cop.highlights).to eq(['MyMethod'])
51
50
  end
52
51
 
53
52
  it 'accepts snake case in names' do
@@ -63,7 +62,7 @@ module Rubocop
63
62
  inspect_source(cop, ['def visit_Arel_Nodes_SelectStatement',
64
63
  'end'])
65
64
  expect(cop.offences).to have(1).item
66
- expect(highlights).to eq(['visit_Arel_Nodes_SelectStatement'])
65
+ expect(cop.highlights).to eq(['visit_Arel_Nodes_SelectStatement'])
67
66
  end
68
67
 
69
68
  it 'accepts screaming snake case globals' do
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe MethodCallParentheses do
9
- let(:cop) { described_class.new }
9
+ subject(:cop) { described_class.new }
10
10
 
11
11
  it 'registers an offence for parens in method call without args' do
12
12
  inspect_source(cop, ['top.test()'])
@@ -5,11 +5,9 @@ require 'spec_helper'
5
5
  module Rubocop
6
6
  module Cop
7
7
  module Style
8
- describe MethodLength do
9
- let(:method_length) { MethodLength.new }
10
- before do
11
- MethodLength.config = { 'Max' => 5, 'CountComments' => false }
12
- end
8
+ describe MethodLength, :config do
9
+ subject(:method_length) { MethodLength.new(config) }
10
+ let(:cop_config) { { 'Max' => 5, 'CountComments' => false } }
13
11
 
14
12
  it 'rejects a method with more than 5 lines' do
15
13
  inspect_source(method_length, ['def m()',
@@ -132,18 +130,21 @@ module Rubocop
132
130
  expect(method_length.offences).to be_empty
133
131
  end
134
132
 
135
- it 'has the option of counting commented lines' do
136
- MethodLength.config['CountComments'] = true
137
- inspect_source(method_length, ['def m()',
138
- ' a = 1',
139
- ' #a = 2',
140
- ' a = 3',
141
- ' #a = 4',
142
- ' a = 5',
143
- ' a = 6',
144
- 'end'])
145
- expect(method_length.offences.size).to eq(1)
146
- expect(method_length.offences.map(&:line).sort).to eq([1])
133
+ context 'when CountComments is enabled' do
134
+ before { cop_config['CountComments'] = true }
135
+
136
+ it 'also counts commented lines' do
137
+ inspect_source(method_length, ['def m()',
138
+ ' a = 1',
139
+ ' #a = 2',
140
+ ' a = 3',
141
+ ' #a = 4',
142
+ ' a = 5',
143
+ ' a = 6',
144
+ 'end'])
145
+ expect(method_length.offences.size).to eq(1)
146
+ expect(method_length.offences.map(&:line).sort).to eq([1])
147
+ end
147
148
  end
148
149
  end
149
150
  end
@@ -6,7 +6,7 @@ module Rubocop
6
6
  module Cop
7
7
  module Style
8
8
  describe ModuleFunction do
9
- let(:cop) { described_class.new }
9
+ subject(:cop) { described_class.new }
10
10
 
11
11
  it 'registers an offence for extend self in module' do
12
12
  inspect_source(cop,
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ module Style
8
+ describe MultilineBlockChain do
9
+ subject(:cop) { described_class.new }
10
+
11
+ context 'with multi-line block chaining' do
12
+ it 'registers an offence for a simple case' do
13
+ inspect_source(cop, ['a do',
14
+ ' b',
15
+ 'end.c do',
16
+ ' d',
17
+ 'end'])
18
+ expect(cop.offences).to have(1).item
19
+ expect(cop.highlights).to eq(['end.c'])
20
+ end
21
+
22
+ it 'registers an offence for a slightly more complicated case' do
23
+ inspect_source(cop, ['a do',
24
+ ' b',
25
+ 'end.c1.c2 do',
26
+ ' d',
27
+ 'end'])
28
+ expect(cop.offences).to have(1).item
29
+ expect(cop.highlights).to eq(['end.c1.c2'])
30
+ end
31
+
32
+ it 'registers two offences for a chain of three blocks' do
33
+ inspect_source(cop, ['a do',
34
+ ' b',
35
+ 'end.c do',
36
+ ' d',
37
+ 'end.e do',
38
+ ' f',
39
+ 'end'])
40
+ expect(cop.offences).to have(2).item
41
+ expect(cop.highlights).to eq(['end.c', 'end.e'])
42
+ end
43
+
44
+ it 'registers an offence for a chain where the second block is ' +
45
+ 'single-line' do
46
+ inspect_source(cop, ['Thread.list.find_all { |t|',
47
+ ' t.alive?',
48
+ '}.map { |thread| thread.object_id }'])
49
+ expect(cop.offences).to have(1).item
50
+ expect(cop.highlights).to eq(['}.map'])
51
+ end
52
+
53
+ it 'accepts a chain where the first block is single-line' do
54
+ inspect_source(cop,
55
+ ['Thread.list.find_all { |t| t.alive? }.map { |t| ',
56
+ ' t.object_id',
57
+ '}'])
58
+ expect(cop.offences).to be_empty
59
+ end
60
+ end
61
+
62
+ it 'accepts a chain of blocks spanning one line' do
63
+ inspect_source(cop, ['a { b }.c { d }',
64
+ 'w do x end.y do z end'])
65
+ expect(cop.offences).to be_empty
66
+ end
67
+
68
+ it 'accepts a multi-line block chained with calls on one line' do
69
+ inspect_source(cop, ['a do',
70
+ ' b',
71
+ 'end.c.d'])
72
+ expect(cop.offences).to be_empty
73
+ end
74
+
75
+ it 'accepts a chain of calls followed by a multi-line block' do
76
+ inspect_source(cop, ['a1.a2.a3 do',
77
+ ' b',
78
+ 'end'])
79
+ expect(cop.offences).to be_empty
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end