rubocop 0.18.1 → 0.19.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 (398) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +65 -1
  4. data/Gemfile +0 -3
  5. data/LICENSE.txt +1 -1
  6. data/README.md +179 -77
  7. data/Rakefile +8 -0
  8. data/config/default.yml +151 -14
  9. data/config/enabled.yml +65 -8
  10. data/lib/rubocop.rb +19 -4
  11. data/lib/rubocop/cli.rb +2 -1
  12. data/lib/rubocop/comment_config.rb +97 -0
  13. data/lib/rubocop/config.rb +1 -1
  14. data/lib/rubocop/config_loader.rb +3 -2
  15. data/lib/rubocop/config_store.rb +6 -2
  16. data/lib/rubocop/cop/commissioner.rb +2 -2
  17. data/lib/rubocop/cop/cop.rb +22 -26
  18. data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -2
  19. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +1 -1
  20. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
  21. data/lib/rubocop/cop/lint/block_alignment.rb +6 -6
  22. data/lib/rubocop/cop/lint/condition_position.rb +1 -1
  23. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  24. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +60 -0
  25. data/lib/rubocop/cop/lint/else_layout.rb +1 -1
  26. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  27. data/lib/rubocop/cop/lint/end_alignment.rb +14 -12
  28. data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
  29. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  30. data/lib/rubocop/cop/lint/eval.rb +1 -1
  31. data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
  32. data/lib/rubocop/cop/lint/literal_in_condition.rb +13 -2
  33. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +28 -0
  34. data/lib/rubocop/cop/lint/loop.rb +4 -4
  35. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  36. data/lib/rubocop/cop/lint/require_parentheses.rb +6 -6
  37. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  38. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -2
  39. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +30 -0
  40. data/lib/rubocop/cop/lint/syntax.rb +5 -5
  41. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  42. data/lib/rubocop/cop/lint/useless_assignment.rb +5 -5
  43. data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
  44. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  45. data/lib/rubocop/cop/lint/void.rb +5 -5
  46. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +8 -5
  47. data/lib/rubocop/cop/mixin/code_length.rb +2 -2
  48. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +7 -7
  49. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -1
  50. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  51. data/lib/rubocop/cop/mixin/if_then_else.rb +1 -1
  52. data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
  53. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +2 -2
  54. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +3 -2
  55. data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
  56. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -0
  57. data/lib/rubocop/cop/mixin/string_help.rb +4 -4
  58. data/lib/rubocop/cop/{offence.rb → offense.rb} +7 -7
  59. data/lib/rubocop/cop/rails/action_filter.rb +73 -0
  60. data/lib/rubocop/cop/rails/default_scope.rb +1 -1
  61. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  62. data/lib/rubocop/cop/rails/output.rb +1 -10
  63. data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
  64. data/lib/rubocop/cop/rails/scope_args.rb +33 -0
  65. data/lib/rubocop/cop/rails/validation.rb +1 -1
  66. data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
  67. data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
  68. data/lib/rubocop/cop/style/alias.rb +2 -2
  69. data/lib/rubocop/cop/style/align_array.rb +1 -1
  70. data/lib/rubocop/cop/style/align_hash.rb +29 -2
  71. data/lib/rubocop/cop/style/align_parameters.rb +16 -2
  72. data/lib/rubocop/cop/style/and_or.rb +2 -2
  73. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  74. data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
  75. data/lib/rubocop/cop/style/attr.rb +1 -1
  76. data/lib/rubocop/cop/style/begin_block.rb +1 -1
  77. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  78. data/lib/rubocop/cop/style/block_nesting.rb +1 -1
  79. data/lib/rubocop/cop/style/blocks.rb +2 -2
  80. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -2
  81. data/lib/rubocop/cop/style/case_equality.rb +1 -1
  82. data/lib/rubocop/cop/style/case_indentation.rb +2 -2
  83. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  84. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
  85. data/lib/rubocop/cop/style/class_and_module_children.rb +69 -0
  86. data/lib/rubocop/cop/style/class_methods.rb +1 -1
  87. data/lib/rubocop/cop/style/class_vars.rb +3 -3
  88. data/lib/rubocop/cop/style/collection_methods.rb +4 -4
  89. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  90. data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
  91. data/lib/rubocop/cop/style/constant_name.rb +1 -1
  92. data/lib/rubocop/cop/style/cyclomatic_complexity.rb +2 -2
  93. data/lib/rubocop/cop/style/def_parentheses.rb +2 -2
  94. data/lib/rubocop/cop/style/documentation.rb +1 -1
  95. data/lib/rubocop/cop/style/dot_position.rb +10 -11
  96. data/lib/rubocop/cop/style/double_negation.rb +40 -0
  97. data/lib/rubocop/cop/style/empty_line_between_defs.rb +8 -1
  98. data/lib/rubocop/cop/style/empty_lines.rb +3 -2
  99. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
  100. data/lib/rubocop/cop/style/empty_lines_around_body.rb +1 -1
  101. data/lib/rubocop/cop/style/empty_literal.rb +3 -3
  102. data/lib/rubocop/cop/style/encoding.rb +1 -1
  103. data/lib/rubocop/cop/style/end_block.rb +1 -1
  104. data/lib/rubocop/cop/style/end_of_line.rb +2 -2
  105. data/lib/rubocop/cop/style/even_odd.rb +2 -2
  106. data/lib/rubocop/cop/style/favor_join.rb +1 -1
  107. data/lib/rubocop/cop/style/file_name.rb +29 -0
  108. data/lib/rubocop/cop/style/final_newline.rb +1 -1
  109. data/lib/rubocop/cop/style/flip_flop.rb +2 -2
  110. data/lib/rubocop/cop/style/for.rb +2 -2
  111. data/lib/rubocop/cop/style/format_string.rb +66 -0
  112. data/lib/rubocop/cop/style/global_vars.rb +2 -2
  113. data/lib/rubocop/cop/style/hash_methods.rb +1 -1
  114. data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
  115. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -1
  116. data/lib/rubocop/cop/style/indent_array.rb +41 -0
  117. data/lib/rubocop/cop/style/indent_hash.rb +119 -0
  118. data/lib/rubocop/cop/style/indentation_consistency.rb +3 -11
  119. data/lib/rubocop/cop/style/indentation_width.rb +44 -23
  120. data/lib/rubocop/cop/style/lambda.rb +2 -2
  121. data/lib/rubocop/cop/style/lambda_call.rb +3 -3
  122. data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
  123. data/lib/rubocop/cop/style/line_end_concatenation.rb +7 -3
  124. data/lib/rubocop/cop/style/line_length.rb +2 -2
  125. data/lib/rubocop/cop/style/method_call_parentheses.rb +2 -2
  126. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -2
  127. data/lib/rubocop/cop/style/method_def_parentheses.rb +9 -7
  128. data/lib/rubocop/cop/style/module_function.rb +1 -1
  129. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  130. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
  131. data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -2
  132. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  133. data/lib/rubocop/cop/style/not.rb +1 -1
  134. data/lib/rubocop/cop/style/numeric_literals.rb +5 -5
  135. data/lib/rubocop/cop/style/op_method.rb +2 -2
  136. data/lib/rubocop/cop/style/parameter_lists.rb +1 -1
  137. data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -4
  138. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +143 -0
  139. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  140. data/lib/rubocop/cop/style/predicate_name.rb +1 -1
  141. data/lib/rubocop/cop/style/proc.rb +1 -1
  142. data/lib/rubocop/cop/style/raise_args.rb +2 -2
  143. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  144. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  145. data/lib/rubocop/cop/style/redundant_return.rb +1 -1
  146. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  147. data/lib/rubocop/cop/style/regexp_literal.rb +45 -19
  148. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  149. data/lib/rubocop/cop/style/self_assignment.rb +73 -0
  150. data/lib/rubocop/cop/style/semicolon.rb +12 -8
  151. data/lib/rubocop/cop/style/signal_exception.rb +2 -2
  152. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  153. data/lib/rubocop/cop/style/single_line_methods.rb +38 -1
  154. data/lib/rubocop/cop/style/space_after_colon.rb +3 -3
  155. data/lib/rubocop/cop/style/space_after_comma.rb +1 -1
  156. data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
  157. data/lib/rubocop/cop/style/space_after_method_name.rb +11 -3
  158. data/lib/rubocop/cop/style/space_after_not.rb +1 -1
  159. data/lib/rubocop/cop/style/space_after_semicolon.rb +1 -1
  160. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +41 -6
  161. data/lib/rubocop/cop/style/space_around_operators.rb +4 -4
  162. data/lib/rubocop/cop/style/space_before_block_braces.rb +63 -0
  163. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
  164. data/lib/rubocop/cop/style/{space_around_block_braces.rb → space_inside_block_braces.rb} +15 -24
  165. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +14 -7
  166. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  167. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  168. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  169. data/lib/rubocop/cop/style/tab.rb +1 -1
  170. data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
  171. data/lib/rubocop/cop/style/trailing_comma.rb +4 -4
  172. data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
  173. data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
  174. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  175. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  176. data/lib/rubocop/cop/style/when_then.rb +1 -1
  177. data/lib/rubocop/cop/style/while_until_do.rb +1 -1
  178. data/lib/rubocop/cop/style/while_until_modifier.rb +2 -1
  179. data/lib/rubocop/cop/style/word_array.rb +2 -2
  180. data/lib/rubocop/cop/team.rb +24 -7
  181. data/lib/rubocop/cop/util.rb +3 -3
  182. data/lib/rubocop/cop/variable_inspector.rb +25 -13
  183. data/lib/rubocop/cop/variable_inspector/assignment.rb +1 -1
  184. data/lib/rubocop/cop/variable_inspector/reference.rb +1 -1
  185. data/lib/rubocop/cop/variable_inspector/scope.rb +1 -1
  186. data/lib/rubocop/cop/variable_inspector/variable.rb +2 -2
  187. data/lib/rubocop/cop/variable_inspector/variable_table.rb +1 -1
  188. data/lib/rubocop/file_inspector.rb +12 -13
  189. data/lib/rubocop/formatter/base_formatter.rb +4 -4
  190. data/lib/rubocop/formatter/clang_style_formatter.rb +2 -2
  191. data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -12
  192. data/lib/rubocop/formatter/emacs_style_formatter.rb +3 -2
  193. data/lib/rubocop/formatter/file_list_formatter.rb +4 -4
  194. data/lib/rubocop/formatter/formatter_set.rb +2 -1
  195. data/lib/rubocop/formatter/fuubar_style_formatter.rb +76 -0
  196. data/lib/rubocop/formatter/json_formatter.rb +17 -16
  197. data/lib/rubocop/formatter/offense_count_formatter.rb +54 -0
  198. data/lib/rubocop/formatter/progress_formatter.rb +16 -16
  199. data/lib/rubocop/formatter/simple_text_formatter.rb +25 -25
  200. data/lib/rubocop/options.rb +8 -7
  201. data/lib/rubocop/processed_source.rb +3 -2
  202. data/lib/rubocop/source_parser.rb +1 -59
  203. data/lib/rubocop/version.rb +3 -3
  204. data/relnotes/0.19.0.md +70 -0
  205. data/rubocop-todo.yml +6 -6
  206. data/rubocop.gemspec +2 -1
  207. data/spec/rubocop/cli_spec.rb +431 -268
  208. data/spec/rubocop/comment_config_spec.rb +103 -0
  209. data/spec/rubocop/config_loader_spec.rb +4 -4
  210. data/spec/rubocop/cop/commissioner_spec.rb +7 -7
  211. data/spec/rubocop/cop/cop_spec.rb +17 -17
  212. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +16 -16
  213. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +5 -5
  214. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +19 -19
  215. data/spec/rubocop/cop/lint/block_alignment_spec.rb +52 -52
  216. data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -7
  217. data/spec/rubocop/cop/lint/debugger_spec.rb +10 -10
  218. data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +33 -0
  219. data/spec/rubocop/cop/lint/else_layout_spec.rb +7 -7
  220. data/spec/rubocop/cop/lint/empty_ensure_spec.rb +4 -4
  221. data/spec/rubocop/cop/lint/end_alignment_spec.rb +33 -34
  222. data/spec/rubocop/cop/lint/end_in_method_spec.rb +5 -5
  223. data/spec/rubocop/cop/lint/ensure_return_spec.rb +4 -4
  224. data/spec/rubocop/cop/lint/eval_spec.rb +8 -8
  225. data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +4 -4
  226. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +3 -3
  227. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +65 -10
  228. data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +21 -0
  229. data/spec/rubocop/cop/lint/loop_spec.rb +6 -6
  230. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +14 -14
  231. data/spec/rubocop/cop/lint/require_parentheses_spec.rb +15 -15
  232. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +21 -21
  233. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +16 -16
  234. data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +27 -0
  235. data/spec/rubocop/cop/lint/syntax_spec.rb +11 -11
  236. data/spec/rubocop/cop/lint/unreachable_code_spec.rb +8 -8
  237. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +207 -169
  238. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +5 -5
  239. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +4 -4
  240. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +17 -17
  241. data/spec/rubocop/cop/lint/void_spec.rb +8 -8
  242. data/spec/rubocop/cop/{offence_spec.rb → offense_spec.rb} +17 -17
  243. data/spec/rubocop/cop/rails/action_filter_spec.rb +69 -0
  244. data/spec/rubocop/cop/rails/default_scope_spec.rb +9 -9
  245. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +2 -2
  246. data/spec/rubocop/cop/rails/output_spec.rb +8 -18
  247. data/spec/rubocop/cop/rails/read_attribute_spec.rb +2 -2
  248. data/spec/rubocop/cop/rails/scope_args_spec.rb +25 -0
  249. data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
  250. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +38 -38
  251. data/spec/rubocop/cop/style/accessor_method_name_spec.rb +14 -14
  252. data/spec/rubocop/cop/style/alias_spec.rb +11 -11
  253. data/spec/rubocop/cop/style/align_array_spec.rb +23 -7
  254. data/spec/rubocop/cop/style/align_hash_spec.rb +111 -30
  255. data/spec/rubocop/cop/style/align_parameters_spec.rb +260 -187
  256. data/spec/rubocop/cop/style/and_or_spec.rb +6 -6
  257. data/spec/rubocop/cop/style/ascii_comments_spec.rb +3 -3
  258. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +5 -5
  259. data/spec/rubocop/cop/style/attr_spec.rb +2 -2
  260. data/spec/rubocop/cop/style/begin_block_spec.rb +2 -2
  261. data/spec/rubocop/cop/style/block_comments_spec.rb +3 -3
  262. data/spec/rubocop/cop/style/block_nesting_spec.rb +26 -26
  263. data/spec/rubocop/cop/style/blocks_spec.rb +8 -8
  264. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +8 -8
  265. data/spec/rubocop/cop/style/case_equality_spec.rb +2 -2
  266. data/spec/rubocop/cop/style/case_indentation_spec.rb +21 -21
  267. data/spec/rubocop/cop/style/character_literal_spec.rb +6 -6
  268. data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +4 -4
  269. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +129 -0
  270. data/spec/rubocop/cop/style/class_length_spec.rb +9 -9
  271. data/spec/rubocop/cop/style/class_methods_spec.rb +8 -8
  272. data/spec/rubocop/cop/style/class_vars_spec.rb +4 -4
  273. data/spec/rubocop/cop/style/collection_methods_spec.rb +6 -6
  274. data/spec/rubocop/cop/style/colon_method_call_spec.rb +16 -16
  275. data/spec/rubocop/cop/style/comment_annotation_spec.rb +16 -16
  276. data/spec/rubocop/cop/style/constant_name_spec.rb +12 -12
  277. data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +16 -16
  278. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +6 -6
  279. data/spec/rubocop/cop/style/documentation_spec.rb +14 -14
  280. data/spec/rubocop/cop/style/dot_position_spec.rb +23 -26
  281. data/spec/rubocop/cop/style/double_negation_spec.rb +22 -0
  282. data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +22 -14
  283. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +4 -4
  284. data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +20 -20
  285. data/spec/rubocop/cop/style/empty_lines_spec.rb +17 -6
  286. data/spec/rubocop/cop/style/empty_literal_spec.rb +20 -20
  287. data/spec/rubocop/cop/style/encoding_spec.rb +5 -5
  288. data/spec/rubocop/cop/style/end_block_spec.rb +2 -2
  289. data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -4
  290. data/spec/rubocop/cop/style/even_odd_spec.rb +18 -18
  291. data/spec/rubocop/cop/style/favor_join_spec.rb +7 -7
  292. data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +7 -7
  293. data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +3 -3
  294. data/spec/rubocop/cop/style/file_name_spec.rb +71 -0
  295. data/spec/rubocop/cop/style/final_newline_spec.rb +4 -4
  296. data/spec/rubocop/cop/style/flip_flop_spec.rb +4 -4
  297. data/spec/rubocop/cop/style/for_spec.rb +13 -13
  298. data/spec/rubocop/cop/style/format_string_spec.rb +136 -0
  299. data/spec/rubocop/cop/style/global_vars_spec.rb +7 -7
  300. data/spec/rubocop/cop/style/hash_methods_spec.rb +6 -6
  301. data/spec/rubocop/cop/style/hash_syntax_spec.rb +11 -11
  302. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +29 -11
  303. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +1 -1
  304. data/spec/rubocop/cop/style/indent_array_spec.rb +136 -0
  305. data/spec/rubocop/cop/style/indent_hash_spec.rb +238 -0
  306. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +69 -49
  307. data/spec/rubocop/cop/style/indentation_width_spec.rb +264 -128
  308. data/spec/rubocop/cop/style/lambda_call_spec.rb +14 -14
  309. data/spec/rubocop/cop/style/lambda_spec.rb +7 -7
  310. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +15 -15
  311. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +11 -4
  312. data/spec/rubocop/cop/style/line_length_spec.rb +5 -5
  313. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +5 -5
  314. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +9 -9
  315. data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +19 -19
  316. data/spec/rubocop/cop/style/method_length_spec.rb +17 -17
  317. data/spec/rubocop/cop/style/method_name_spec.rb +21 -21
  318. data/spec/rubocop/cop/style/module_function_spec.rb +3 -3
  319. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +13 -13
  320. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +10 -10
  321. data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +3 -3
  322. data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +3 -3
  323. data/spec/rubocop/cop/style/nil_comparison_spec.rb +7 -7
  324. data/spec/rubocop/cop/style/not_spec.rb +6 -11
  325. data/spec/rubocop/cop/style/numeric_literals_spec.rb +8 -8
  326. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
  327. data/spec/rubocop/cop/style/op_method_spec.rb +13 -13
  328. data/spec/rubocop/cop/style/parameter_lists_spec.rb +6 -6
  329. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +11 -10
  330. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +250 -0
  331. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +2 -2
  332. data/spec/rubocop/cop/style/predicate_name_spec.rb +3 -3
  333. data/spec/rubocop/cop/style/proc_spec.rb +4 -4
  334. data/spec/rubocop/cop/style/raise_args_spec.rb +20 -20
  335. data/spec/rubocop/cop/style/redundant_begin_spec.rb +6 -6
  336. data/spec/rubocop/cop/style/redundant_exception_spec.rb +6 -6
  337. data/spec/rubocop/cop/style/redundant_return_spec.rb +22 -22
  338. data/spec/rubocop/cop/style/redundant_self_spec.rb +14 -14
  339. data/spec/rubocop/cop/style/regexp_literal_spec.rb +88 -67
  340. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +17 -17
  341. data/spec/rubocop/cop/style/self_assignment_spec.rb +43 -0
  342. data/spec/rubocop/cop/style/semicolon_spec.rb +31 -17
  343. data/spec/rubocop/cop/style/signal_exception_spec.rb +29 -29
  344. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +6 -6
  345. data/spec/rubocop/cop/style/single_line_methods_spec.rb +44 -6
  346. data/spec/rubocop/cop/style/space_after_colon_spec.rb +1 -1
  347. data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
  348. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +12 -12
  349. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +8 -8
  350. data/spec/rubocop/cop/style/space_after_not_spec.rb +3 -3
  351. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +1 -1
  352. data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +63 -21
  353. data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -24
  354. data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +72 -0
  355. data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +4 -4
  356. data/spec/rubocop/cop/style/{space_around_block_braces_spec.rb → space_inside_block_braces_spec.rb} +39 -41
  357. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +1 -1
  358. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +15 -15
  359. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
  360. data/spec/rubocop/cop/style/special_global_vars_spec.rb +10 -10
  361. data/spec/rubocop/cop/style/string_literals_spec.rb +31 -31
  362. data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
  363. data/spec/rubocop/cop/style/tab_spec.rb +3 -3
  364. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +3 -3
  365. data/spec/rubocop/cop/style/trailing_comma_spec.rb +32 -32
  366. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +5 -5
  367. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +39 -39
  368. data/spec/rubocop/cop/style/unless_else_spec.rb +1 -1
  369. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +12 -12
  370. data/spec/rubocop/cop/style/variable_name_spec.rb +21 -21
  371. data/spec/rubocop/cop/style/when_then_spec.rb +1 -1
  372. data/spec/rubocop/cop/style/while_until_do_spec.rb +8 -8
  373. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +25 -7
  374. data/spec/rubocop/cop/style/word_array_spec.rb +23 -23
  375. data/spec/rubocop/cop/team_spec.rb +14 -14
  376. data/spec/rubocop/file_inspector_spec.rb +14 -12
  377. data/spec/rubocop/formatter/base_formatter_spec.rb +19 -19
  378. data/spec/rubocop/formatter/clang_style_formatter_spec.rb +14 -14
  379. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +7 -7
  380. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +7 -7
  381. data/spec/rubocop/formatter/file_list_formatter_spec.rb +4 -4
  382. data/spec/rubocop/formatter/fuubar_style_formatter_spec.rb +129 -0
  383. data/spec/rubocop/formatter/json_formatter_spec.rb +23 -19
  384. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +77 -0
  385. data/spec/rubocop/formatter/progress_formatter_spec.rb +27 -27
  386. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +16 -16
  387. data/spec/rubocop/options_spec.rb +7 -8
  388. data/spec/rubocop/source_parser_spec.rb +0 -54
  389. data/spec/spec_helper.rb +11 -7
  390. data/spec/support/file_helper.rb +1 -1
  391. data/spec/support/mri_syntax_checker.rb +4 -4
  392. data/spec/support/shared_examples.rb +6 -6
  393. data/spec/support/statement_modifier_helper.rb +3 -3
  394. metadata +76 -16
  395. data/lib/rubocop/cop/style/favor_sprintf.rb +0 -26
  396. data/lib/rubocop/formatter/offence_count_formatter.rb +0 -49
  397. data/spec/rubocop/cop/style/favor_sprintf_spec.rb +0 -47
  398. data/spec/rubocop/formatter/offence_count_formatter_spec.rb +0 -52
@@ -63,7 +63,7 @@ module Rubocop
63
63
  if style == :semantic
64
64
  each_command(method_name, node) do |send_node|
65
65
  unless ignored_node?(send_node)
66
- add_offence(send_node, :selector, message(method_name))
66
+ add_offense(send_node, :selector, message(method_name))
67
67
  ignore_node(send_node)
68
68
  end
69
69
  end
@@ -71,7 +71,7 @@ module Rubocop
71
71
  _receiver, selector, _args = *node
72
72
 
73
73
  if [:raise, :fail].include?(selector) && selector != method_name
74
- add_offence(node, :selector, message(method_name))
74
+ add_offense(node, :selector, message(method_name))
75
75
  end
76
76
  end
77
77
  end
@@ -26,7 +26,7 @@ module Rubocop
26
26
  return true unless args.all? { |n| n.type == :arg }
27
27
 
28
28
  unless args_match?(method_name, args)
29
- add_offence(args_node, :expression, message(method_name))
29
+ add_offense(args_node, :expression, message(method_name))
30
30
  end
31
31
  end
32
32
 
@@ -23,9 +23,46 @@ module Rubocop
23
23
  empty_body = body.nil?
24
24
 
25
25
  if start_line == end_line && !(allow_empty? && empty_body)
26
- add_offence(node, :expression)
26
+ @body = body
27
+ add_offense(node, :expression)
27
28
  end
28
29
  end
30
+
31
+ def autocorrect(node)
32
+ body = @body
33
+ eol_comment = processed_source.comments.find do |c|
34
+ c.loc.line == node.loc.expression.line
35
+ end
36
+ @corrections << lambda do |corrector|
37
+ if body.type == :begin
38
+ body.children.each do |part|
39
+ break_line_before(part.loc.expression, node, corrector, 1)
40
+ end
41
+ else
42
+ break_line_before(body.loc.expression, node, corrector, 1)
43
+ end
44
+
45
+ break_line_before(node.loc.end, node, corrector, 0)
46
+
47
+ move_comment(eol_comment, node, corrector) if eol_comment
48
+ end
49
+ end
50
+
51
+ def break_line_before(range, node, corrector, indent_steps)
52
+ corrector.insert_before(range,
53
+ "\n" + ' ' * (node.loc.keyword.column +
54
+ indent_steps *
55
+ IndentationWidth::
56
+ CORRECT_INDENTATION))
57
+ end
58
+
59
+ def move_comment(eol_comment, node, corrector)
60
+ text = eol_comment.loc.expression.source
61
+ corrector.insert_before(node.loc.expression,
62
+ text + "\n" +
63
+ ' ' * node.loc.keyword.column)
64
+ corrector.remove(eol_comment.loc.expression)
65
+ end
29
66
  end
30
67
  end
31
68
  end
@@ -3,7 +3,7 @@
3
3
  module Rubocop
4
4
  module Cop
5
5
  module Style
6
- # Checks for colon (:) not follwed by some kind of space.
6
+ # Checks for colon (:) not followed by some kind of space.
7
7
  class SpaceAfterColon < Cop
8
8
  include IfNode
9
9
 
@@ -12,7 +12,7 @@ module Rubocop
12
12
  def on_pair(node)
13
13
  oper = node.loc.operator
14
14
  if oper.is?(':') && oper.source_buffer.source[oper.end_pos] =~ /\S/
15
- add_offence(oper, oper)
15
+ add_offense(oper, oper)
16
16
  end
17
17
  end
18
18
 
@@ -20,7 +20,7 @@ module Rubocop
20
20
  if ternary_op?(node)
21
21
  colon = node.loc.colon
22
22
  if colon.source_buffer.source[colon.end_pos] =~ /\S/
23
- add_offence(colon, colon)
23
+ add_offense(colon, colon)
24
24
  end
25
25
  end
26
26
  end
@@ -3,7 +3,7 @@
3
3
  module Rubocop
4
4
  module Cop
5
5
  module Style
6
- # Checks for comma (,) not follwed by some kind of space.
6
+ # Checks for comma (,) not followed by some kind of space.
7
7
  class SpaceAfterComma < Cop
8
8
  include SpaceAfterPunctuation
9
9
 
@@ -16,7 +16,7 @@ module Rubocop
16
16
  kw = node.loc.keyword
17
17
  kw_offset = kw.begin_pos - exp.begin_pos
18
18
  if exp.source[kw_offset..-1].start_with?(kw.source + '(')
19
- add_offence(node, kw)
19
+ add_offense(node, kw)
20
20
  end
21
21
  end
22
22
 
@@ -3,12 +3,20 @@
3
3
  module Rubocop
4
4
  module Cop
5
5
  module Style
6
- # Checks for space between a method name and a left parenthesis.
6
+ # Checks for space between a method name and a left parenthesis in defs.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # def func (x) ... end
12
+ #
13
+ # # good
14
+ # def func(x) ... end
7
15
  class SpaceAfterMethodName < Cop
8
16
  include CheckMethods
9
17
 
10
18
  MSG = 'Never put a space between a method name and the opening ' \
11
- 'parenthesis.'
19
+ 'parenthesis.'
12
20
 
13
21
  def check(_node, _method_name, args, body)
14
22
  return unless args.loc.begin && args.loc.begin.is?('(')
@@ -17,7 +25,7 @@ module Rubocop
17
25
  expr.begin_pos - 1,
18
26
  expr.begin_pos)
19
27
  if pos_before_left_paren.source =~ /\s/
20
- add_offence(pos_before_left_paren, pos_before_left_paren)
28
+ add_offense(pos_before_left_paren, pos_before_left_paren)
21
29
  end
22
30
  end
23
31
 
@@ -21,7 +21,7 @@ module Rubocop
21
21
 
22
22
  if node.loc.expression.source =~ /^!\s+\w+/
23
23
  # TODO: Improve source range to highlight the redundant whitespace.
24
- add_offence(node, :selector)
24
+ add_offense(node, :selector)
25
25
  end
26
26
  end
27
27
 
@@ -3,7 +3,7 @@
3
3
  module Rubocop
4
4
  module Cop
5
5
  module Style
6
- # Checks for semicolon (;) not follwed by some kind of space.
6
+ # Checks for semicolon (;) not followed by some kind of space.
7
7
  class SpaceAfterSemicolon < Cop
8
8
  include SpaceAfterPunctuation
9
9
 
@@ -4,10 +4,10 @@ module Rubocop
4
4
  module Cop
5
5
  module Style
6
6
  # Checks that the equals signs in parameter default assignments
7
- # have surrounding space.
7
+ # have or don't have surrounding space depending on configuration.
8
8
  class SpaceAroundEqualsInParameterDefault < Cop
9
9
  include SurroundingSpace
10
- MSG = 'Surrounding space missing in default value assignment.'
10
+ include ConfigurableEnforcedStyle
11
11
 
12
12
  def investigate(processed_source)
13
13
  return unless processed_source.ast
@@ -15,16 +15,51 @@ module Rubocop
15
15
  on_node(:optarg, processed_source.ast) do |optarg|
16
16
  index = index_of_first_token(optarg)
17
17
  arg, equals, value = processed_source.tokens[index, 3]
18
- unless space_between?(arg, equals) && space_between?(equals, value)
19
- add_offence(equals.pos, equals.pos)
18
+ check_optarg(arg, equals, value)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def check_optarg(arg, equals, value)
25
+ space_on_both_sides = space_on_both_sides?(arg, equals, value)
26
+ no_surrounding_space = no_surrounding_space?(arg, equals, value)
27
+
28
+ if style == :space && space_on_both_sides ||
29
+ style == :no_space && no_surrounding_space
30
+ correct_style_detected
31
+ else
32
+ range = Parser::Source::Range.new(processed_source.buffer,
33
+ arg.pos.end_pos,
34
+ value.pos.begin_pos)
35
+ add_offense(range, range) do
36
+ if style == :space && no_surrounding_space ||
37
+ style == :no_space && space_on_both_sides
38
+ opposite_style_detected
39
+ else
40
+ unrecognized_style_detected
41
+ end
20
42
  end
21
43
  end
22
44
  end
23
45
 
46
+ def space_on_both_sides?(arg, equals, value)
47
+ space_between?(arg, equals) && space_between?(equals, value)
48
+ end
49
+
50
+ def no_surrounding_space?(arg, equals, value)
51
+ !space_between?(arg, equals) && !space_between?(equals, value)
52
+ end
53
+
54
+ def message(_)
55
+ format('Surrounding space %s in default value assignment.',
56
+ style == :space ? 'missing' : 'detected')
57
+ end
58
+
24
59
  def autocorrect(range)
60
+ replacement = style == :space ? ' = ' : '='
25
61
  @corrections << lambda do |corrector|
26
- corrector.insert_before(range, ' ')
27
- corrector.insert_after(range, ' ')
62
+ corrector.replace(range, replacement)
28
63
  end
29
64
  end
30
65
  end
@@ -46,7 +46,7 @@ module Rubocop
46
46
  end
47
47
 
48
48
  def called_with_dot?(node)
49
- !!node.loc.dot
49
+ node.loc.dot
50
50
  end
51
51
 
52
52
  def check(node)
@@ -57,11 +57,11 @@ module Rubocop
57
57
  with_space = range_with_surrounding_space(op)
58
58
  if op.is?('**')
59
59
  unless with_space.is?('**')
60
- add_offence(with_space, op, 'Space around operator ** detected.')
60
+ add_offense(with_space, op, 'Space around operator ** detected.')
61
61
  end
62
62
  elsif with_space.source !~ /^\s.*\s$/
63
- add_offence(with_space, op,
64
- 'Surrounding space missing for operator' +
63
+ add_offense(with_space, op,
64
+ 'Surrounding space missing for operator' \
65
65
  " '#{op.source}'.")
66
66
  end
67
67
  end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module Style
6
+ # Checks that block braces have or don't have a space before the opening
7
+ # brace depending on configuration.
8
+ class SpaceBeforeBlockBraces < Cop
9
+ include ConfigurableEnforcedStyle
10
+
11
+ def on_block(node)
12
+ return if node.loc.begin.is?('do') # No braces.
13
+
14
+ # If braces are on separate lines, and the Blocks cop is enabled,
15
+ # those braces will be changed to do..end by the user or by
16
+ # auto-correct, so reporting space issues is not useful, and it
17
+ # creates auto-correct conflicts.
18
+ if config.for_cop('Blocks')['Enabled'] && Util.block_length(node) > 0
19
+ return
20
+ end
21
+
22
+ left_brace = node.loc.begin
23
+ space_plus_brace = range_with_surrounding_space(left_brace)
24
+ used_style =
25
+ space_plus_brace.source.start_with?('{') ? :no_space : :space
26
+
27
+ case used_style
28
+ when style then correct_style_detected
29
+ when :space then space_detected(left_brace, space_plus_brace)
30
+ else space_missing(left_brace)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def space_missing(left_brace)
37
+ add_offense(left_brace, left_brace,
38
+ 'Space missing to the left of {.') do
39
+ opposite_style_detected
40
+ end
41
+ end
42
+
43
+ def space_detected(left_brace, space_plus_brace)
44
+ space = Parser::Source::Range.new(left_brace.source_buffer,
45
+ space_plus_brace.begin_pos,
46
+ left_brace.begin_pos)
47
+ add_offense(space, space, 'Space detected to the left of {.') do
48
+ opposite_style_detected
49
+ end
50
+ end
51
+
52
+ def autocorrect(range)
53
+ @corrections << lambda do |corrector|
54
+ case range.source
55
+ when /\s/ then corrector.remove(range)
56
+ else corrector.insert_before(range, ' ')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -12,7 +12,7 @@ module Rubocop
12
12
  kw = node.loc.keyword
13
13
  b = kw.begin_pos
14
14
  left_of_kw = Parser::Source::Range.new(kw.source_buffer, b - 1, b)
15
- add_offence(node, left_of_kw) unless left_of_kw.is?(' ')
15
+ add_offense(node, left_of_kw) unless left_of_kw.is?(' ')
16
16
  end
17
17
  end
18
18
 
@@ -3,12 +3,11 @@
3
3
  module Rubocop
4
4
  module Cop
5
5
  module Style
6
- # Checks that block braces have or don't have surrounding space depending
7
- # on configuration. For blocks taking parameters, it checks that the left
8
- # brace has or doesn't have trailing space depending on configuration.
9
- # Also checks that the left brace is preceded by a space and this is not
10
- # configurable.
11
- class SpaceAroundBlockBraces < Cop
6
+ # Checks that block braces have or don't have surrounding space inside
7
+ # them on configuration. For blocks taking parameters, it checks that the
8
+ # left brace has or doesn't have trailing space depending on
9
+ # configuration.
10
+ class SpaceInsideBlockBraces < Cop
12
11
  include ConfigurableEnforcedStyle
13
12
  include SurroundingSpace
14
13
 
@@ -25,25 +24,17 @@ module Rubocop
25
24
 
26
25
  left_brace, right_brace = node.loc.begin, node.loc.end
27
26
 
28
- check_outside(left_brace)
29
27
  check_inside(node, left_brace, right_brace)
30
28
  end
31
29
 
32
30
  private
33
31
 
34
- def check_outside(left_brace)
35
- if range_with_surrounding_space(left_brace).source.start_with?('{')
36
- add_offence(left_brace, left_brace,
37
- 'Space missing to the left of {.')
38
- end
39
- end
40
-
41
32
  def check_inside(node, left_brace, right_brace)
42
33
  sb = node.loc.expression.source_buffer
43
34
 
44
35
  if left_brace.end_pos == right_brace.begin_pos
45
36
  if style_for_empty_braces == :space
46
- offence(sb, left_brace.begin_pos, right_brace.end_pos,
37
+ offense(sb, left_brace.begin_pos, right_brace.end_pos,
47
38
  'Space missing inside empty braces.')
48
39
  end
49
40
  else
@@ -54,7 +45,7 @@ module Rubocop
54
45
  if inner =~ /\S/
55
46
  braces_with_contents_inside(node, inner, sb)
56
47
  elsif style_for_empty_braces == :no_space
57
- offence(sb, range.begin_pos, range.end_pos,
48
+ offense(sb, range.begin_pos, range.end_pos,
58
49
  'Space inside empty braces detected.')
59
50
  end
60
51
  end
@@ -84,7 +75,7 @@ module Rubocop
84
75
  if pipe
85
76
  if left_brace.end_pos == pipe.begin_pos &&
86
77
  cop_config['SpaceBeforeBlockParameters']
87
- offence(sb, left_brace.begin_pos, pipe.end_pos,
78
+ offense(sb, left_brace.begin_pos, pipe.end_pos,
88
79
  'Space between { and | missing.')
89
80
  end
90
81
  else
@@ -99,7 +90,7 @@ module Rubocop
99
90
  def space_inside_left_brace(left_brace, pipe, sb)
100
91
  if pipe
101
92
  unless cop_config['SpaceBeforeBlockParameters']
102
- offence(sb, left_brace.end_pos, pipe.begin_pos,
93
+ offense(sb, left_brace.end_pos, pipe.begin_pos,
103
94
  'Space between { and | detected.')
104
95
  end
105
96
  else
@@ -116,24 +107,24 @@ module Rubocop
116
107
  end
117
108
 
118
109
  def no_space(sb, begin_pos, end_pos, msg)
119
- if style == :space_inside_braces
120
- offence(sb, begin_pos, end_pos, msg) { opposite_style_detected }
110
+ if style == :space
111
+ offense(sb, begin_pos, end_pos, msg) { opposite_style_detected }
121
112
  else
122
113
  correct_style_detected
123
114
  end
124
115
  end
125
116
 
126
117
  def space(sb, begin_pos, end_pos, msg)
127
- if style == :no_space_inside_braces
128
- offence(sb, begin_pos, end_pos, msg) { opposite_style_detected }
118
+ if style == :no_space
119
+ offense(sb, begin_pos, end_pos, msg) { opposite_style_detected }
129
120
  else
130
121
  correct_style_detected
131
122
  end
132
123
  end
133
124
 
134
- def offence(sb, begin_pos, end_pos, msg)
125
+ def offense(sb, begin_pos, end_pos, msg)
135
126
  range = Parser::Source::Range.new(sb, begin_pos, end_pos)
136
- add_offence(range, range, msg) { yield if block_given? }
127
+ add_offense(range, range, msg) { yield if block_given? }
137
128
  end
138
129
 
139
130
  def style_for_empty_braces
@@ -28,7 +28,7 @@ module Rubocop
28
28
  private
29
29
 
30
30
  def check(t1, t2)
31
- # No offence if line break inside.
31
+ # No offense if line break inside.
32
32
  return if t1.pos.line < t2.pos.line
33
33
 
34
34
  is_empty_braces = t1.text == '{' && t2.text == '}'
@@ -37,10 +37,10 @@ module Rubocop
37
37
  else
38
38
  style == :space
39
39
  end
40
- if offence?(t1, t2, expect_space)
40
+ if offense?(t1, t2, expect_space)
41
41
  brace = (t1.text == '{' ? t1 : t2).pos
42
42
  range = expect_space ? brace : space_range(brace)
43
- add_offence(range, range, message(brace, is_empty_braces,
43
+ add_offense(range, range, message(brace, is_empty_braces,
44
44
  expect_space)) do
45
45
  opposite_style_detected
46
46
  end
@@ -49,7 +49,7 @@ module Rubocop
49
49
  end
50
50
  end
51
51
 
52
- def offence?(t1, t2, expect_space)
52
+ def offense?(t1, t2, expect_space)
53
53
  has_space = space_between?(t1, t2)
54
54
  expect_space ? !has_space : has_space
55
55
  end
@@ -61,15 +61,22 @@ module Rubocop
61
61
  brace.source
62
62
  end
63
63
  problem = expect_space ? 'missing' : 'detected'
64
- sprintf(MSG, "#{inside_what} #{problem}")
64
+ format(MSG, "#{inside_what} #{problem}")
65
65
  end
66
66
 
67
67
  def autocorrect(range)
68
68
  @corrections << lambda do |corrector|
69
+ # It is possible that BracesAroundHashParameters will remove the
70
+ # braces while this cop inserts spaces. This can lead to unwanted
71
+ # changes to the inspected code. If we replace the brace with a
72
+ # brace plus space (rather than just inserting a space), then any
73
+ # removal of the same brace will give us a clobbering error. This
74
+ # in turn will make RuboCop fall back on cop-by-cop
75
+ # auto-correction. Problem solved.
69
76
  case range.source
70
77
  when /\s/ then corrector.remove(range)
71
- when '{' then corrector.insert_after(range, ' ')
72
- else corrector.insert_before(range, ' ')
78
+ when '{' then corrector.replace(range, '{ ')
79
+ else corrector.replace(range, ' }')
73
80
  end
74
81
  end
75
82
  end