rubocop 0.43.0 → 0.44.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 (430) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/bin/rubocop +0 -1
  4. data/config/default.yml +31 -0
  5. data/config/disabled.yml +6 -6
  6. data/config/enabled.yml +182 -140
  7. data/lib/rubocop.rb +7 -2
  8. data/lib/rubocop/ast_node.rb +0 -1
  9. data/lib/rubocop/ast_node/builder.rb +0 -1
  10. data/lib/rubocop/ast_node/sexp.rb +0 -1
  11. data/lib/rubocop/ast_node/traversal.rb +0 -1
  12. data/lib/rubocop/cached_data.rb +3 -20
  13. data/lib/rubocop/cli.rb +0 -1
  14. data/lib/rubocop/comment_config.rb +0 -1
  15. data/lib/rubocop/config.rb +0 -1
  16. data/lib/rubocop/config_loader.rb +1 -2
  17. data/lib/rubocop/config_loader_resolver.rb +0 -1
  18. data/lib/rubocop/config_store.rb +0 -1
  19. data/lib/rubocop/cop/autocorrect_logic.rb +0 -1
  20. data/lib/rubocop/cop/commissioner.rb +0 -1
  21. data/lib/rubocop/cop/cop.rb +15 -5
  22. data/lib/rubocop/cop/corrector.rb +0 -1
  23. data/lib/rubocop/cop/force.rb +0 -1
  24. data/lib/rubocop/cop/ignored_node.rb +0 -1
  25. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -1
  26. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -1
  27. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
  28. data/lib/rubocop/cop/lint/block_alignment.rb +0 -1
  29. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -1
  30. data/lib/rubocop/cop/lint/condition_position.rb +0 -1
  31. data/lib/rubocop/cop/lint/debugger.rb +0 -1
  32. data/lib/rubocop/cop/lint/def_end_alignment.rb +0 -1
  33. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +0 -1
  34. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -1
  35. data/lib/rubocop/cop/lint/duplicated_key.rb +0 -1
  36. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -1
  37. data/lib/rubocop/cop/lint/else_layout.rb +0 -1
  38. data/lib/rubocop/cop/lint/empty_ensure.rb +0 -1
  39. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -1
  40. data/lib/rubocop/cop/lint/end_alignment.rb +0 -1
  41. data/lib/rubocop/cop/lint/end_in_method.rb +0 -1
  42. data/lib/rubocop/cop/lint/ensure_return.rb +0 -1
  43. data/lib/rubocop/cop/lint/eval.rb +0 -1
  44. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -1
  45. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -1
  46. data/lib/rubocop/cop/lint/handle_exceptions.rb +0 -1
  47. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +0 -1
  48. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -1
  49. data/lib/rubocop/cop/lint/inherit_exception.rb +0 -1
  50. data/lib/rubocop/cop/lint/invalid_character_literal.rb +0 -1
  51. data/lib/rubocop/cop/lint/literal_in_condition.rb +0 -1
  52. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -1
  53. data/lib/rubocop/cop/lint/loop.rb +0 -1
  54. data/lib/rubocop/cop/lint/nested_method_definition.rb +0 -1
  55. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -1
  56. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +0 -1
  57. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +0 -1
  58. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -1
  59. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -1
  60. data/lib/rubocop/cop/lint/rand_one.rb +0 -1
  61. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -1
  62. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -1
  63. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -2
  64. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +0 -1
  65. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +0 -1
  66. data/lib/rubocop/cop/lint/syntax.rb +0 -1
  67. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +0 -1
  68. data/lib/rubocop/cop/lint/unified_integer.rb +0 -1
  69. data/lib/rubocop/cop/lint/unneeded_disable.rb +0 -1
  70. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +15 -2
  71. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -1
  72. data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -27
  73. data/lib/rubocop/cop/lint/unused_method_argument.rb +0 -1
  74. data/lib/rubocop/cop/lint/useless_access_modifier.rb +0 -1
  75. data/lib/rubocop/cop/lint/useless_assignment.rb +0 -1
  76. data/lib/rubocop/cop/lint/useless_comparison.rb +0 -1
  77. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -1
  78. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -1
  79. data/lib/rubocop/cop/lint/void.rb +0 -1
  80. data/lib/rubocop/cop/metrics/abc_size.rb +1 -2
  81. data/lib/rubocop/cop/metrics/block_length.rb +26 -0
  82. data/lib/rubocop/cop/metrics/block_nesting.rb +0 -1
  83. data/lib/rubocop/cop/metrics/class_length.rb +0 -1
  84. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +0 -1
  85. data/lib/rubocop/cop/metrics/line_length.rb +45 -8
  86. data/lib/rubocop/cop/metrics/method_length.rb +5 -10
  87. data/lib/rubocop/cop/metrics/module_length.rb +0 -1
  88. data/lib/rubocop/cop/metrics/parameter_lists.rb +0 -1
  89. data/lib/rubocop/cop/metrics/perceived_complexity.rb +0 -1
  90. data/lib/rubocop/cop/mixin/access_modifier_node.rb +0 -1
  91. data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -1
  92. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +0 -1
  93. data/lib/rubocop/cop/mixin/array_syntax.rb +0 -1
  94. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -1
  95. data/lib/rubocop/cop/mixin/check_assignment.rb +0 -1
  96. data/lib/rubocop/cop/mixin/classish_length.rb +0 -1
  97. data/lib/rubocop/cop/mixin/code_length.rb +1 -2
  98. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +0 -1
  99. data/lib/rubocop/cop/mixin/configurable_max.rb +0 -1
  100. data/lib/rubocop/cop/mixin/configurable_naming.rb +0 -1
  101. data/lib/rubocop/cop/mixin/configurable_numbering.rb +2 -2
  102. data/lib/rubocop/cop/mixin/def_node.rb +0 -1
  103. data/lib/rubocop/cop/mixin/documentation_comment.rb +0 -1
  104. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +41 -16
  105. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +0 -1
  106. data/lib/rubocop/cop/mixin/first_element_line_break.rb +0 -1
  107. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +0 -1
  108. data/lib/rubocop/cop/mixin/hash_node.rb +0 -1
  109. data/lib/rubocop/cop/mixin/if_node.rb +0 -1
  110. data/lib/rubocop/cop/mixin/integer_node.rb +0 -1
  111. data/lib/rubocop/cop/mixin/match_range.rb +0 -1
  112. data/lib/rubocop/cop/mixin/method_complexity.rb +0 -1
  113. data/lib/rubocop/cop/mixin/method_preference.rb +0 -1
  114. data/lib/rubocop/cop/mixin/min_body_length.rb +0 -1
  115. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +0 -1
  116. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +0 -1
  117. data/lib/rubocop/cop/mixin/negative_conditional.rb +0 -1
  118. data/lib/rubocop/cop/mixin/on_method_def.rb +0 -1
  119. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +0 -1
  120. data/lib/rubocop/cop/mixin/parentheses.rb +0 -1
  121. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +0 -1
  122. data/lib/rubocop/cop/mixin/percent_literal.rb +0 -1
  123. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +0 -1
  124. data/lib/rubocop/cop/mixin/safe_assignment.rb +0 -1
  125. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -1
  126. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +0 -1
  127. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +0 -1
  128. data/lib/rubocop/cop/mixin/space_inside.rb +0 -1
  129. data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -1
  130. data/lib/rubocop/cop/mixin/string_help.rb +0 -1
  131. data/lib/rubocop/cop/mixin/string_literals_help.rb +0 -1
  132. data/lib/rubocop/cop/mixin/surrounding_space.rb +0 -1
  133. data/lib/rubocop/cop/mixin/too_many_lines.rb +25 -0
  134. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -2
  135. data/lib/rubocop/cop/mixin/unused_argument.rb +0 -1
  136. data/lib/rubocop/cop/offense.rb +0 -1
  137. data/lib/rubocop/cop/performance/case_when_splat.rb +17 -8
  138. data/lib/rubocop/cop/performance/casecmp.rb +0 -1
  139. data/lib/rubocop/cop/performance/count.rb +0 -1
  140. data/lib/rubocop/cop/performance/detect.rb +0 -1
  141. data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -1
  142. data/lib/rubocop/cop/performance/end_with.rb +0 -1
  143. data/lib/rubocop/cop/performance/fixed_size.rb +0 -1
  144. data/lib/rubocop/cop/performance/flat_map.rb +0 -1
  145. data/lib/rubocop/cop/performance/{hash_each.rb → hash_each_methods.rb} +0 -1
  146. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +0 -1
  147. data/lib/rubocop/cop/performance/range_include.rb +0 -1
  148. data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -1
  149. data/lib/rubocop/cop/performance/redundant_match.rb +0 -1
  150. data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
  151. data/lib/rubocop/cop/performance/redundant_sort_by.rb +0 -1
  152. data/lib/rubocop/cop/performance/reverse_each.rb +0 -1
  153. data/lib/rubocop/cop/performance/sample.rb +1 -2
  154. data/lib/rubocop/cop/performance/size.rb +0 -1
  155. data/lib/rubocop/cop/performance/sort_with_block.rb +0 -1
  156. data/lib/rubocop/cop/performance/start_with.rb +0 -1
  157. data/lib/rubocop/cop/performance/string_replacement.rb +0 -1
  158. data/lib/rubocop/cop/performance/times_map.rb +0 -1
  159. data/lib/rubocop/cop/rails/action_filter.rb +2 -3
  160. data/lib/rubocop/cop/rails/date.rb +0 -1
  161. data/lib/rubocop/cop/rails/delegate.rb +0 -1
  162. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +62 -0
  163. data/lib/rubocop/cop/rails/dynamic_find_by.rb +77 -0
  164. data/lib/rubocop/cop/rails/exit.rb +0 -1
  165. data/lib/rubocop/cop/rails/find_by.rb +0 -1
  166. data/lib/rubocop/cop/rails/find_each.rb +0 -1
  167. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +0 -1
  168. data/lib/rubocop/cop/rails/http_positional_arguments.rb +89 -0
  169. data/lib/rubocop/cop/rails/not_null_column.rb +1 -2
  170. data/lib/rubocop/cop/rails/output.rb +0 -1
  171. data/lib/rubocop/cop/rails/output_safety.rb +1 -2
  172. data/lib/rubocop/cop/rails/pluralization_grammar.rb +0 -1
  173. data/lib/rubocop/cop/rails/read_write_attribute.rb +0 -1
  174. data/lib/rubocop/cop/rails/request_referer.rb +0 -1
  175. data/lib/rubocop/cop/rails/safe_navigation.rb +0 -1
  176. data/lib/rubocop/cop/rails/save_bang.rb +12 -3
  177. data/lib/rubocop/cop/rails/scope_args.rb +0 -1
  178. data/lib/rubocop/cop/rails/time_zone.rb +0 -1
  179. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +1 -2
  180. data/lib/rubocop/cop/rails/validation.rb +0 -1
  181. data/lib/rubocop/cop/security/json_load.rb +11 -3
  182. data/lib/rubocop/cop/severity.rb +0 -1
  183. data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -1
  184. data/lib/rubocop/cop/style/accessor_method_name.rb +0 -1
  185. data/lib/rubocop/cop/style/alias.rb +0 -1
  186. data/lib/rubocop/cop/style/align_array.rb +0 -1
  187. data/lib/rubocop/cop/style/align_hash.rb +0 -1
  188. data/lib/rubocop/cop/style/align_parameters.rb +0 -1
  189. data/lib/rubocop/cop/style/and_or.rb +0 -1
  190. data/lib/rubocop/cop/style/array_join.rb +0 -1
  191. data/lib/rubocop/cop/style/ascii_comments.rb +0 -1
  192. data/lib/rubocop/cop/style/ascii_identifiers.rb +0 -1
  193. data/lib/rubocop/cop/style/attr.rb +0 -1
  194. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +0 -1
  195. data/lib/rubocop/cop/style/bare_percent_literals.rb +0 -1
  196. data/lib/rubocop/cop/style/begin_block.rb +0 -1
  197. data/lib/rubocop/cop/style/block_comments.rb +0 -1
  198. data/lib/rubocop/cop/style/block_delimiters.rb +0 -1
  199. data/lib/rubocop/cop/style/block_end_newline.rb +0 -1
  200. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -1
  201. data/lib/rubocop/cop/style/case_equality.rb +0 -1
  202. data/lib/rubocop/cop/style/case_indentation.rb +0 -1
  203. data/lib/rubocop/cop/style/character_literal.rb +0 -1
  204. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +0 -1
  205. data/lib/rubocop/cop/style/class_and_module_children.rb +0 -1
  206. data/lib/rubocop/cop/style/class_check.rb +0 -1
  207. data/lib/rubocop/cop/style/class_methods.rb +0 -1
  208. data/lib/rubocop/cop/style/class_vars.rb +0 -1
  209. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +0 -1
  210. data/lib/rubocop/cop/style/collection_methods.rb +0 -1
  211. data/lib/rubocop/cop/style/colon_method_call.rb +0 -1
  212. data/lib/rubocop/cop/style/command_literal.rb +0 -1
  213. data/lib/rubocop/cop/style/comment_annotation.rb +0 -1
  214. data/lib/rubocop/cop/style/comment_indentation.rb +0 -1
  215. data/lib/rubocop/cop/style/conditional_assignment.rb +0 -1
  216. data/lib/rubocop/cop/style/constant_name.rb +0 -1
  217. data/lib/rubocop/cop/style/copyright.rb +0 -1
  218. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -1
  219. data/lib/rubocop/cop/style/documentation.rb +0 -1
  220. data/lib/rubocop/cop/style/documentation_method.rb +0 -1
  221. data/lib/rubocop/cop/style/dot_position.rb +0 -1
  222. data/lib/rubocop/cop/style/double_negation.rb +0 -1
  223. data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
  224. data/lib/rubocop/cop/style/each_with_object.rb +0 -1
  225. data/lib/rubocop/cop/style/else_alignment.rb +0 -1
  226. data/lib/rubocop/cop/style/empty_case_condition.rb +0 -1
  227. data/lib/rubocop/cop/style/empty_else.rb +7 -6
  228. data/lib/rubocop/cop/style/empty_line_between_defs.rb +0 -1
  229. data/lib/rubocop/cop/style/empty_lines.rb +0 -1
  230. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +15 -8
  231. data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +0 -1
  232. data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +0 -1
  233. data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +0 -1
  234. data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +0 -1
  235. data/lib/rubocop/cop/style/empty_literal.rb +0 -1
  236. data/lib/rubocop/cop/style/encoding.rb +0 -1
  237. data/lib/rubocop/cop/style/end_block.rb +0 -1
  238. data/lib/rubocop/cop/style/end_of_line.rb +0 -1
  239. data/lib/rubocop/cop/style/even_odd.rb +0 -1
  240. data/lib/rubocop/cop/style/extra_spacing.rb +5 -4
  241. data/lib/rubocop/cop/style/file_name.rb +0 -1
  242. data/lib/rubocop/cop/style/first_array_element_line_break.rb +0 -1
  243. data/lib/rubocop/cop/style/first_hash_element_line_break.rb +0 -1
  244. data/lib/rubocop/cop/style/first_method_argument_line_break.rb +0 -1
  245. data/lib/rubocop/cop/style/first_method_parameter_line_break.rb +0 -1
  246. data/lib/rubocop/cop/style/first_parameter_indentation.rb +0 -1
  247. data/lib/rubocop/cop/style/flip_flop.rb +0 -1
  248. data/lib/rubocop/cop/style/for.rb +0 -1
  249. data/lib/rubocop/cop/style/format_string.rb +0 -1
  250. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +0 -1
  251. data/lib/rubocop/cop/style/global_vars.rb +0 -1
  252. data/lib/rubocop/cop/style/guard_clause.rb +2 -4
  253. data/lib/rubocop/cop/style/hash_syntax.rb +0 -1
  254. data/lib/rubocop/cop/style/identical_conditional_branches.rb +0 -1
  255. data/lib/rubocop/cop/style/if_inside_else.rb +0 -1
  256. data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -1
  257. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +0 -1
  258. data/lib/rubocop/cop/style/if_with_semicolon.rb +0 -1
  259. data/lib/rubocop/cop/style/implicit_runtime_error.rb +0 -1
  260. data/lib/rubocop/cop/style/indent_array.rb +0 -1
  261. data/lib/rubocop/cop/style/indent_assignment.rb +0 -1
  262. data/lib/rubocop/cop/style/indent_hash.rb +0 -1
  263. data/lib/rubocop/cop/style/indentation_consistency.rb +0 -1
  264. data/lib/rubocop/cop/style/indentation_width.rb +0 -1
  265. data/lib/rubocop/cop/style/infinite_loop.rb +0 -1
  266. data/lib/rubocop/cop/style/initial_indentation.rb +0 -1
  267. data/lib/rubocop/cop/style/inline_comment.rb +0 -1
  268. data/lib/rubocop/cop/style/lambda.rb +0 -1
  269. data/lib/rubocop/cop/style/lambda_call.rb +0 -1
  270. data/lib/rubocop/cop/style/leading_comment_space.rb +0 -1
  271. data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -2
  272. data/lib/rubocop/cop/style/method_call_parentheses.rb +0 -1
  273. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +0 -1
  274. data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -1
  275. data/lib/rubocop/cop/style/method_missing.rb +0 -1
  276. data/lib/rubocop/cop/style/method_name.rb +0 -1
  277. data/lib/rubocop/cop/style/missing_else.rb +0 -1
  278. data/lib/rubocop/cop/style/module_function.rb +0 -1
  279. data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +0 -1
  280. data/lib/rubocop/cop/style/multiline_assignment_layout.rb +0 -1
  281. data/lib/rubocop/cop/style/multiline_block_chain.rb +0 -1
  282. data/lib/rubocop/cop/style/multiline_block_layout.rb +0 -1
  283. data/lib/rubocop/cop/style/multiline_hash_brace_layout.rb +0 -1
  284. data/lib/rubocop/cop/style/multiline_if_then.rb +0 -1
  285. data/lib/rubocop/cop/style/multiline_memoization.rb +44 -0
  286. data/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb +0 -1
  287. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +0 -1
  288. data/lib/rubocop/cop/style/multiline_method_definition_brace_layout.rb +0 -1
  289. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +0 -1
  290. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +0 -1
  291. data/lib/rubocop/cop/style/mutable_constant.rb +0 -1
  292. data/lib/rubocop/cop/style/negated_if.rb +0 -1
  293. data/lib/rubocop/cop/style/negated_while.rb +0 -1
  294. data/lib/rubocop/cop/style/nested_modifier.rb +0 -1
  295. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +0 -1
  296. data/lib/rubocop/cop/style/nested_ternary_operator.rb +0 -1
  297. data/lib/rubocop/cop/style/next.rb +0 -1
  298. data/lib/rubocop/cop/style/nil_comparison.rb +0 -1
  299. data/lib/rubocop/cop/style/non_nil_check.rb +18 -2
  300. data/lib/rubocop/cop/style/not.rb +0 -1
  301. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -5
  302. data/lib/rubocop/cop/style/numeric_literals.rb +0 -1
  303. data/lib/rubocop/cop/style/numeric_predicate.rb +0 -1
  304. data/lib/rubocop/cop/style/one_line_conditional.rb +0 -1
  305. data/lib/rubocop/cop/style/op_method.rb +0 -1
  306. data/lib/rubocop/cop/style/option_hash.rb +0 -1
  307. data/lib/rubocop/cop/style/optional_arguments.rb +0 -1
  308. data/lib/rubocop/cop/style/parallel_assignment.rb +13 -2
  309. data/lib/rubocop/cop/style/parentheses_around_condition.rb +0 -1
  310. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +0 -1
  311. data/lib/rubocop/cop/style/percent_q_literals.rb +0 -1
  312. data/lib/rubocop/cop/style/perl_backrefs.rb +0 -1
  313. data/lib/rubocop/cop/style/predicate_name.rb +0 -1
  314. data/lib/rubocop/cop/style/preferred_hash_methods.rb +44 -6
  315. data/lib/rubocop/cop/style/proc.rb +0 -1
  316. data/lib/rubocop/cop/style/raise_args.rb +13 -14
  317. data/lib/rubocop/cop/style/redundant_begin.rb +0 -1
  318. data/lib/rubocop/cop/style/redundant_exception.rb +0 -1
  319. data/lib/rubocop/cop/style/redundant_freeze.rb +0 -1
  320. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
  321. data/lib/rubocop/cop/style/redundant_return.rb +37 -9
  322. data/lib/rubocop/cop/style/redundant_self.rb +0 -1
  323. data/lib/rubocop/cop/style/regexp_literal.rb +0 -1
  324. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +0 -1
  325. data/lib/rubocop/cop/style/rescue_modifier.rb +0 -1
  326. data/lib/rubocop/cop/style/safe_navigation.rb +51 -39
  327. data/lib/rubocop/cop/style/self_assignment.rb +0 -1
  328. data/lib/rubocop/cop/style/semicolon.rb +0 -1
  329. data/lib/rubocop/cop/style/send.rb +0 -1
  330. data/lib/rubocop/cop/style/signal_exception.rb +0 -1
  331. data/lib/rubocop/cop/style/single_line_block_params.rb +0 -1
  332. data/lib/rubocop/cop/style/single_line_methods.rb +0 -1
  333. data/lib/rubocop/cop/style/space_after_colon.rb +0 -1
  334. data/lib/rubocop/cop/style/space_after_comma.rb +0 -1
  335. data/lib/rubocop/cop/style/space_after_method_name.rb +0 -1
  336. data/lib/rubocop/cop/style/space_after_not.rb +0 -1
  337. data/lib/rubocop/cop/style/space_after_semicolon.rb +0 -1
  338. data/lib/rubocop/cop/style/space_around_block_parameters.rb +0 -1
  339. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +0 -1
  340. data/lib/rubocop/cop/style/space_around_keyword.rb +0 -1
  341. data/lib/rubocop/cop/style/space_around_operators.rb +0 -1
  342. data/lib/rubocop/cop/style/space_before_block_braces.rb +0 -1
  343. data/lib/rubocop/cop/style/space_before_comma.rb +0 -1
  344. data/lib/rubocop/cop/style/space_before_comment.rb +0 -1
  345. data/lib/rubocop/cop/style/space_before_first_arg.rb +0 -1
  346. data/lib/rubocop/cop/style/space_before_semicolon.rb +0 -1
  347. data/lib/rubocop/cop/style/space_inside_array_percent_literal.rb +0 -1
  348. data/lib/rubocop/cop/style/space_inside_block_braces.rb +0 -1
  349. data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -1
  350. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +0 -1
  351. data/lib/rubocop/cop/style/space_inside_parens.rb +0 -1
  352. data/lib/rubocop/cop/style/space_inside_percent_literal_delimiters.rb +0 -1
  353. data/lib/rubocop/cop/style/space_inside_range_literal.rb +0 -1
  354. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +0 -1
  355. data/lib/rubocop/cop/style/special_global_vars.rb +0 -1
  356. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +0 -1
  357. data/lib/rubocop/cop/style/string_literals.rb +0 -1
  358. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +0 -1
  359. data/lib/rubocop/cop/style/string_methods.rb +0 -1
  360. data/lib/rubocop/cop/style/struct_inheritance.rb +0 -1
  361. data/lib/rubocop/cop/style/symbol_array.rb +0 -1
  362. data/lib/rubocop/cop/style/symbol_literal.rb +0 -1
  363. data/lib/rubocop/cop/style/symbol_proc.rb +0 -1
  364. data/lib/rubocop/cop/style/tab.rb +0 -1
  365. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
  366. data/lib/rubocop/cop/style/trailing_blank_lines.rb +0 -1
  367. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -1
  368. data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +0 -1
  369. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +0 -1
  370. data/lib/rubocop/cop/style/trailing_whitespace.rb +0 -1
  371. data/lib/rubocop/cop/style/trivial_accessors.rb +0 -1
  372. data/lib/rubocop/cop/style/unless_else.rb +0 -1
  373. data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -2
  374. data/lib/rubocop/cop/style/unneeded_interpolation.rb +0 -1
  375. data/lib/rubocop/cop/style/unneeded_percent_q.rb +0 -1
  376. data/lib/rubocop/cop/style/variable_interpolation.rb +0 -1
  377. data/lib/rubocop/cop/style/variable_name.rb +0 -1
  378. data/lib/rubocop/cop/style/variable_number.rb +0 -1
  379. data/lib/rubocop/cop/style/when_then.rb +0 -1
  380. data/lib/rubocop/cop/style/while_until_do.rb +0 -1
  381. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  382. data/lib/rubocop/cop/style/word_array.rb +0 -1
  383. data/lib/rubocop/cop/style/zero_length_predicate.rb +0 -1
  384. data/lib/rubocop/cop/team.rb +1 -2
  385. data/lib/rubocop/cop/util.rb +11 -6
  386. data/lib/rubocop/cop/variable_force.rb +0 -1
  387. data/lib/rubocop/cop/variable_force/assignment.rb +0 -1
  388. data/lib/rubocop/cop/variable_force/locatable.rb +0 -1
  389. data/lib/rubocop/cop/variable_force/reference.rb +0 -1
  390. data/lib/rubocop/cop/variable_force/scope.rb +0 -1
  391. data/lib/rubocop/cop/variable_force/variable.rb +0 -1
  392. data/lib/rubocop/cop/variable_force/variable_table.rb +0 -1
  393. data/lib/rubocop/error.rb +0 -1
  394. data/lib/rubocop/formatter/base_formatter.rb +0 -1
  395. data/lib/rubocop/formatter/clang_style_formatter.rb +0 -1
  396. data/lib/rubocop/formatter/colorizable.rb +0 -1
  397. data/lib/rubocop/formatter/disabled_config_formatter.rb +0 -1
  398. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -1
  399. data/lib/rubocop/formatter/emacs_style_formatter.rb +0 -1
  400. data/lib/rubocop/formatter/file_list_formatter.rb +0 -1
  401. data/lib/rubocop/formatter/formatter_set.rb +0 -1
  402. data/lib/rubocop/formatter/fuubar_style_formatter.rb +0 -1
  403. data/lib/rubocop/formatter/html_formatter.rb +2 -3
  404. data/lib/rubocop/formatter/json_formatter.rb +0 -1
  405. data/lib/rubocop/formatter/offense_count_formatter.rb +0 -1
  406. data/lib/rubocop/formatter/progress_formatter.rb +0 -1
  407. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -1
  408. data/lib/rubocop/formatter/text_util.rb +0 -1
  409. data/lib/rubocop/formatter/worst_offenders_formatter.rb +0 -1
  410. data/lib/rubocop/name_similarity.rb +0 -1
  411. data/lib/rubocop/node_pattern.rb +0 -1
  412. data/lib/rubocop/options.rb +0 -1
  413. data/lib/rubocop/path_util.rb +0 -1
  414. data/lib/rubocop/processed_source.rb +3 -4
  415. data/lib/rubocop/rake_task.rb +0 -1
  416. data/lib/rubocop/remote_config.rb +0 -1
  417. data/lib/rubocop/result_cache.rb +3 -4
  418. data/lib/rubocop/rspec/cop_helper.rb +0 -1
  419. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -1
  420. data/lib/rubocop/rspec/shared_contexts.rb +0 -1
  421. data/lib/rubocop/rspec/shared_examples.rb +0 -1
  422. data/lib/rubocop/rspec/support.rb +0 -1
  423. data/lib/rubocop/runner.rb +0 -1
  424. data/lib/rubocop/string_interpreter.rb +0 -1
  425. data/lib/rubocop/string_util.rb +0 -1
  426. data/lib/rubocop/target_finder.rb +0 -1
  427. data/lib/rubocop/token.rb +0 -1
  428. data/lib/rubocop/version.rb +1 -2
  429. data/lib/rubocop/warning.rb +0 -1
  430. metadata +9 -3
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
3
+ require 'pry'
4
4
  module RuboCop
5
5
  module Cop
6
6
  module Performance
@@ -82,7 +82,7 @@ module RuboCop
82
82
  *conditions, _body = *node
83
83
 
84
84
  lambda do |corrector|
85
- if needs_reorder?(conditions)
85
+ if needs_reorder?(node)
86
86
  reorder_condition(corrector, node, replacement(conditions))
87
87
  else
88
88
  inline_fix_branch(corrector, node, conditions,
@@ -94,8 +94,10 @@ module RuboCop
94
94
  private
95
95
 
96
96
  def replacement(conditions)
97
- new_condition = conditions.map(&:source)
98
- new_condition.join(', ')
97
+ ordered_conditions = conditions.partition { |cond| !cond.splat_type? }
98
+ ordered_conditions.flatten!
99
+ ordered_conditions.map!(&:source)
100
+ ordered_conditions.join(', ')
99
101
  end
100
102
 
101
103
  def inline_fix_branch(corrector, _node, conditions, new_condition)
@@ -107,6 +109,8 @@ module RuboCop
107
109
  def reorder_condition(corrector, node, new_condition)
108
110
  *_conditions, body = *node
109
111
  _case_branch, *when_branches, _else_branch = *node.parent
112
+ return if when_branches.size == 1 # Can't reorder one branch
113
+
110
114
  corrector.remove(when_branch_range(node, when_branches))
111
115
 
112
116
  correction = if same_line?(node, body)
@@ -159,10 +163,15 @@ module RuboCop
159
163
  !condition.splat_type?
160
164
  end
161
165
 
162
- def needs_reorder?(conditions)
163
- conditions.any? do |condition|
164
- variable, = *condition
165
- condition.splat_type? && !(variable && variable.array_type?)
166
+ def needs_reorder?(node)
167
+ _case_condition, *when_branches, _else_branch = *node.parent
168
+ current_index = when_branches.index { |branch| branch == node }
169
+ when_branches[(current_index + 1)..-1].any? do |branch|
170
+ *conditions, _ = *branch
171
+ conditions.none? do |condition|
172
+ variable, = *condition
173
+ condition.splat_type? && !(variable && variable.array_type?)
174
+ end
166
175
  end
167
176
  end
168
177
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -45,6 +44,7 @@ module RuboCop
45
44
 
46
45
  def each_redundant_merge(node)
47
46
  redundant_merge(node) do |receiver, pairs|
47
+ next unless receiver
48
48
  next if node.value_used? &&
49
49
  !EachWithObjectInspector.new(node, receiver).value_used?
50
50
  next if pairs.size > 1 && !receiver.pure?
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -92,7 +91,7 @@ module RuboCop
92
91
  def range_size(range_node)
93
92
  vals = *range_node
94
93
  return :unknown unless vals.all?(&:int_type?)
95
- low, high = *vals.map(&:to_a).map(&:first)
94
+ low, high = *vals.map { |val| val.to_a.first }
96
95
  return :unknown unless low.zero? && high >= 0
97
96
  case range_node.type
98
97
  when :erange then high - low
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,12 +1,11 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
5
4
  module Cop
6
5
  module Rails
7
- # This cop enforces the consistent use of action filters methods.
6
+ # This cop enforces the consistent use of action filter methods.
8
7
  #
9
- # The cop is configurable and the enforce the use of older
8
+ # The cop is configurable and can enforce the use of the older
10
9
  # something_filter methods or the newer something_action methods.
11
10
  class ActionFilter < Cop
12
11
  include ConfigurableEnforcedStyle
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ # This cop looks for delegations that pass :allow_blank as an option
7
+ # instead of :allow_nil. :allow_blank is not a valid option to pass
8
+ # to ActiveSupport#delegate.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # delegate :foo, to: :bar, allow_blank: true
13
+ #
14
+ # # good
15
+ # delegate :foo, to: :bar, allow_nil: true
16
+ class DelegateAllowBlank < Cop
17
+ MSG = '`allow_blank` is not a valid option, use `allow_nil`.'.freeze
18
+
19
+ def_node_matcher :delegate, <<-PATTERN
20
+ (send _ :delegate _ $hash)
21
+ PATTERN
22
+
23
+ def_node_matcher :delegate_options, <<-PATTERN
24
+ (hash $...)
25
+ PATTERN
26
+
27
+ def_node_matcher :allow_blank?, <<-PATTERN
28
+ (pair $(sym :allow_blank) true)
29
+ PATTERN
30
+
31
+ def on_send(node)
32
+ offending_node = allow_blank_option(node)
33
+ return unless offending_node
34
+
35
+ allow_blank = offending_node.children.first
36
+ add_offense(node, allow_blank.source_range, MSG)
37
+ end
38
+
39
+ def autocorrect(node)
40
+ offending_node = allow_blank_option(node)
41
+ return unless offending_node
42
+
43
+ allow_blank = offending_node.children.first
44
+ lambda do |corrector|
45
+ corrector.replace(allow_blank.source_range, 'allow_nil')
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def allow_blank_option(node)
52
+ options_hash = delegate(node)
53
+ return unless options_hash
54
+ options = delegate_options(options_hash)
55
+ return unless options
56
+
57
+ options.detect { |opt| allow_blank?(opt) }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ # This cop checks dynamic `find_by_*` methods.
7
+ # Use `find_by` instead of dynamic method.
8
+ # See. https://github.com/bbatsov/rails-style-guide#find_by
9
+ #
10
+ # @example
11
+ # # bad
12
+ # User.find_by_name(name)
13
+ #
14
+ # # bad
15
+ # User.find_by_name_and_email(name)
16
+ #
17
+ # # bad
18
+ # User.find_by_email!(name)
19
+ #
20
+ # # good
21
+ # User.find_by(name: name)
22
+ #
23
+ # # good
24
+ # User.find_by(name: name, email: email)
25
+ #
26
+ # # good
27
+ # User.find_by!(email: email)
28
+ class DynamicFindBy < Cop
29
+ MSG = 'Use `%s` instead of dynamic `%s`.'.freeze
30
+ METHOD_PATTERN = /^find_by_(.+?)(!)?$/
31
+
32
+ def on_send(node)
33
+ _receiver, method, _args = *node
34
+ method_name = method.to_s
35
+ return if whitelist.include?(method_name)
36
+ static_name = static_method_name(method_name)
37
+ return unless static_name
38
+
39
+ add_offense(node, :expression, format(MSG, static_name, method))
40
+ end
41
+
42
+ def autocorrect(node)
43
+ _receiver, method, *args = *node
44
+ static_name = static_method_name(method.to_s)
45
+ keywords = column_keywords(method)
46
+ return if keywords.size != args.size
47
+
48
+ lambda do |corrector|
49
+ corrector.replace(node.loc.selector, static_name)
50
+ keywords.each.with_index do |keyword, idx|
51
+ corrector.insert_before(args[idx].loc.expression, keyword)
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def whitelist
59
+ cop_config['Whitelist']
60
+ end
61
+
62
+ def column_keywords(method)
63
+ keyword_string = method.to_s[METHOD_PATTERN, 1]
64
+ keyword_string.split('_and_').map { |keyword| "#{keyword}: " }
65
+ end
66
+
67
+ # Returns static method name.
68
+ # If code isn't wrong, returns nil
69
+ def static_method_name(method_name)
70
+ match = METHOD_PATTERN.match(method_name)
71
+ return nil unless match
72
+ match[2] ? 'find_by!' : 'find_by'
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ # This cop is used to identify usages of http methods
7
+ # like `get`, `post`, `put`, `path` without the usage of keyword arguments
8
+ # in your tests and change them to use keyword arguments.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # get :new, { user_id: 1}
13
+ #
14
+ # # good
15
+ # get :new, params: { user_id: 1 }
16
+ class HttpPositionalArguments < Cop
17
+ MSG = 'Use keyword arguments instead of ' \
18
+ 'positional arguments for http call: `%s`.'.freeze
19
+ KEYWORD_ARGS = [:headers, :env, :params, :body, :flash, :as].freeze
20
+ HTTP_METHODS = [:get, :post, :put, :patch, :delete, :head].freeze
21
+
22
+ def on_send(node)
23
+ receiver, http_method, http_path, data = *node
24
+ # if the first word on the line is not an http method, then skip
25
+ return unless HTTP_METHODS.include?(http_method)
26
+ # if the data is nil then we don't need to add keyword arguments
27
+ # because there is no data to put in params or headers, so skip
28
+ return if data.nil?
29
+ return unless needs_conversion?(data)
30
+ # ensures this is the first method on the line
31
+ # there is an edge case here where sometimes the http method is
32
+ # wrapped into another method, but its just safer to skip those
33
+ # cases and process manually
34
+ return unless receiver.nil?
35
+ # a http_method without a path?, must be something else
36
+ return if http_path.nil?
37
+ add_offense(node, node.loc.selector, format(MSG, node.method_name))
38
+ end
39
+
40
+ # @return [Boolean] true if the line needs to be converted
41
+ def needs_conversion?(data)
42
+ # if the line has already been converted to use keyword args
43
+ # then skip
44
+ # ie. get :new, params: { user_id: 1 } (looking for keyword arg)
45
+ value = data.descendants.find do |d|
46
+ KEYWORD_ARGS.include?(d.children.first) if d.type == :sym
47
+ end
48
+ value.nil?
49
+ end
50
+
51
+ def convert_hash_data(data, type)
52
+ # empty hash or no hash return empty string
53
+ return '' if data.nil? || data.children.count < 1
54
+ hash_data = if data.type == :send
55
+ # user supplies an object,
56
+ # no need to surround with braces
57
+ data.source
58
+ else
59
+ format('{ %s }', data.children.map(&:source).join(', '))
60
+ end
61
+ format(', %s: %s', type, hash_data)
62
+ end
63
+
64
+ # given a pre Rails 5 method: get :new, user_id: @user.id, {}
65
+ #
66
+ # @return lambda of auto correct procedure
67
+ # the result should look like:
68
+ # get :new, params: { user_id: @user.id }, headers: {}
69
+ # the http_method is the method use to call the controller
70
+ # the controller node can be a symbol, method, object or string
71
+ # that represents the path/action on the Rails controller
72
+ # the data is the http parameters and environment sent in
73
+ # the Rails 5 http call
74
+ def autocorrect(node)
75
+ _receiver, http_method, http_path, *data = *node
76
+ controller_action = http_path.source
77
+ params = convert_hash_data(data.first, 'params')
78
+ headers = convert_hash_data(data.last, 'headers') if data.count > 1
79
+ # the range of the text to replace, which is the whole line
80
+ code_to_replace = node.loc.expression
81
+ # what to replace with
82
+ new_code = format('%s %s%s%s', http_method, controller_action,
83
+ params, headers)
84
+ ->(corrector) { corrector.replace(code_to_replace, new_code) }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end