rubocop 0.66.0 → 1.25.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (861) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +70 -43
  4. data/assets/output.html.erb +1 -1
  5. data/config/default.yml +1936 -1212
  6. data/config/obsoletion.yml +200 -0
  7. data/exe/rubocop +2 -4
  8. data/lib/rubocop/ast_aliases.rb +8 -0
  9. data/lib/rubocop/cached_data.rb +6 -6
  10. data/lib/rubocop/cli/command/auto_genenerate_config.rb +132 -0
  11. data/lib/rubocop/cli/command/base.rb +35 -0
  12. data/lib/rubocop/cli/command/execute_runner.rb +100 -0
  13. data/lib/rubocop/cli/command/init_dotfile.rb +44 -0
  14. data/lib/rubocop/cli/command/show_cops.rb +74 -0
  15. data/lib/rubocop/cli/command/show_docs_url.rb +48 -0
  16. data/lib/rubocop/cli/command/suggest_extensions.rb +81 -0
  17. data/lib/rubocop/cli/command/version.rb +18 -0
  18. data/lib/rubocop/cli/command.rb +22 -0
  19. data/lib/rubocop/cli/environment.rb +22 -0
  20. data/lib/rubocop/cli.rb +45 -200
  21. data/lib/rubocop/comment_config.rb +56 -99
  22. data/lib/rubocop/config.rb +92 -510
  23. data/lib/rubocop/config_loader.rb +150 -85
  24. data/lib/rubocop/config_loader_resolver.rb +129 -46
  25. data/lib/rubocop/config_obsoletion/changed_enforced_styles.rb +33 -0
  26. data/lib/rubocop/config_obsoletion/changed_parameter.rb +21 -0
  27. data/lib/rubocop/config_obsoletion/cop_rule.rb +33 -0
  28. data/lib/rubocop/config_obsoletion/extracted_cop.rb +44 -0
  29. data/lib/rubocop/config_obsoletion/parameter_rule.rb +44 -0
  30. data/lib/rubocop/config_obsoletion/removed_cop.rb +41 -0
  31. data/lib/rubocop/config_obsoletion/renamed_cop.rb +34 -0
  32. data/lib/rubocop/config_obsoletion/rule.rb +41 -0
  33. data/lib/rubocop/config_obsoletion/split_cop.rb +27 -0
  34. data/lib/rubocop/config_obsoletion.rb +103 -0
  35. data/lib/rubocop/config_regeneration.rb +33 -0
  36. data/lib/rubocop/config_store.rb +31 -7
  37. data/lib/rubocop/config_validator.rb +255 -0
  38. data/lib/rubocop/cop/autocorrect_logic.rb +78 -6
  39. data/lib/rubocop/cop/badge.rb +16 -32
  40. data/lib/rubocop/cop/base.rb +450 -0
  41. data/lib/rubocop/cop/bundler/duplicated_gem.rb +31 -7
  42. data/lib/rubocop/cop/bundler/gem_comment.rb +122 -15
  43. data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
  44. data/lib/rubocop/cop/bundler/gem_version.rb +133 -0
  45. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +47 -30
  46. data/lib/rubocop/cop/bundler/ordered_gems.rb +7 -18
  47. data/lib/rubocop/cop/commissioner.rb +103 -53
  48. data/lib/rubocop/cop/cop.rb +93 -191
  49. data/lib/rubocop/cop/corrector.rb +68 -122
  50. data/lib/rubocop/cop/correctors/alignment_corrector.rb +48 -32
  51. data/lib/rubocop/cop/correctors/condition_corrector.rb +3 -6
  52. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -6
  53. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +9 -10
  54. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +2 -3
  55. data/lib/rubocop/cop/correctors/if_then_corrector.rb +55 -0
  56. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +11 -11
  57. data/lib/rubocop/cop/correctors/line_break_corrector.rb +9 -12
  58. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +37 -8
  59. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +11 -12
  60. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +6 -9
  61. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +11 -22
  62. data/lib/rubocop/cop/correctors/punctuation_corrector.rb +8 -10
  63. data/lib/rubocop/cop/correctors/require_library_corrector.rb +23 -0
  64. data/lib/rubocop/cop/correctors/space_corrector.rb +2 -5
  65. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +6 -8
  66. data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +17 -8
  67. data/lib/rubocop/cop/documentation.rb +39 -0
  68. data/lib/rubocop/cop/exclude_limit.rb +26 -0
  69. data/lib/rubocop/cop/force.rb +2 -1
  70. data/lib/rubocop/cop/gemspec/date_assignment.rb +49 -0
  71. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +8 -16
  72. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +8 -22
  73. data/lib/rubocop/cop/gemspec/require_mfa.rb +144 -0
  74. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +74 -32
  75. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +50 -0
  76. data/lib/rubocop/cop/generator/configuration_injector.rb +15 -11
  77. data/lib/rubocop/cop/generator/require_file_injector.rb +3 -6
  78. data/lib/rubocop/cop/generator.rb +43 -41
  79. data/lib/rubocop/cop/ignored_node.rb +1 -3
  80. data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +68 -0
  81. data/lib/rubocop/cop/internal_affairs/example_description.rb +92 -0
  82. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +34 -0
  83. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +60 -0
  84. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +50 -0
  85. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +15 -17
  86. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
  87. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +13 -16
  88. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +14 -12
  89. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +62 -0
  90. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +65 -0
  91. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +15 -23
  92. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +14 -11
  93. data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +47 -0
  94. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +148 -0
  95. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +73 -0
  96. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +9 -9
  97. data/lib/rubocop/cop/internal_affairs.rb +12 -1
  98. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +20 -29
  99. data/lib/rubocop/cop/layout/argument_alignment.rb +137 -0
  100. data/lib/rubocop/cop/layout/array_alignment.rb +84 -0
  101. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +17 -7
  102. data/lib/rubocop/cop/layout/begin_end_alignment.rb +74 -0
  103. data/lib/rubocop/cop/layout/block_alignment.rb +43 -51
  104. data/lib/rubocop/cop/layout/block_end_newline.rb +9 -12
  105. data/lib/rubocop/cop/layout/case_indentation.rb +72 -30
  106. data/lib/rubocop/cop/layout/class_structure.rb +67 -78
  107. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +8 -10
  108. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +28 -34
  109. data/lib/rubocop/cop/layout/comment_indentation.rb +61 -39
  110. data/lib/rubocop/cop/layout/condition_position.rb +17 -9
  111. data/lib/rubocop/cop/layout/def_end_alignment.rb +10 -11
  112. data/lib/rubocop/cop/layout/dot_position.rb +64 -26
  113. data/lib/rubocop/cop/layout/else_alignment.rb +30 -8
  114. data/lib/rubocop/cop/layout/empty_comment.rb +34 -43
  115. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +74 -35
  116. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +16 -16
  117. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +136 -0
  118. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +161 -39
  119. data/lib/rubocop/cop/layout/empty_lines.rb +8 -13
  120. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +98 -38
  121. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +14 -10
  122. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +118 -0
  123. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +3 -6
  124. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +5 -6
  125. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +8 -14
  126. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +16 -19
  127. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -6
  128. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -8
  129. data/lib/rubocop/cop/layout/end_alignment.rb +25 -24
  130. data/lib/rubocop/cop/layout/end_of_line.rb +18 -13
  131. data/lib/rubocop/cop/layout/extra_spacing.rb +39 -103
  132. data/lib/rubocop/cop/layout/first_argument_indentation.rb +276 -0
  133. data/lib/rubocop/cop/layout/{indent_array.rb → first_array_element_indentation.rb} +30 -24
  134. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -8
  135. data/lib/rubocop/cop/layout/{indent_hash.rb → first_hash_element_indentation.rb} +42 -26
  136. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +3 -7
  137. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +7 -13
  138. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +3 -7
  139. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +53 -196
  140. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +139 -60
  141. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +305 -0
  142. data/lib/rubocop/cop/layout/heredoc_indentation.rb +165 -0
  143. data/lib/rubocop/cop/layout/indentation_consistency.rb +23 -19
  144. data/lib/rubocop/cop/layout/indentation_style.rb +110 -0
  145. data/lib/rubocop/cop/layout/indentation_width.rb +66 -47
  146. data/lib/rubocop/cop/layout/initial_indentation.rb +8 -12
  147. data/lib/rubocop/cop/layout/leading_comment_space.rb +74 -13
  148. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +7 -12
  149. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +141 -0
  150. data/lib/rubocop/cop/layout/line_length.rb +269 -0
  151. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +8 -11
  152. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +35 -0
  153. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +40 -18
  154. data/lib/rubocop/cop/layout/multiline_block_layout.rb +68 -33
  155. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +8 -15
  156. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +46 -0
  157. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +50 -0
  158. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +8 -11
  159. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +34 -25
  160. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +8 -11
  161. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +26 -12
  162. data/lib/rubocop/cop/layout/parameter_alignment.rb +119 -0
  163. data/lib/rubocop/cop/layout/redundant_line_break.rb +140 -0
  164. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +75 -39
  165. data/lib/rubocop/cop/layout/single_line_block_chain.rb +64 -0
  166. data/lib/rubocop/cop/layout/space_after_colon.rb +12 -10
  167. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -5
  168. data/lib/rubocop/cop/layout/space_after_method_name.rb +8 -11
  169. data/lib/rubocop/cop/layout/space_after_not.rb +11 -12
  170. data/lib/rubocop/cop/layout/space_after_semicolon.rb +2 -5
  171. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +50 -53
  172. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +21 -24
  173. data/lib/rubocop/cop/layout/space_around_keyword.rb +69 -33
  174. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +98 -0
  175. data/lib/rubocop/cop/layout/space_around_operators.rb +148 -53
  176. data/lib/rubocop/cop/layout/space_before_block_braces.rb +55 -22
  177. data/lib/rubocop/cop/layout/space_before_brackets.rb +66 -0
  178. data/lib/rubocop/cop/layout/space_before_comma.rb +3 -5
  179. data/lib/rubocop/cop/layout/space_before_comment.rb +11 -12
  180. data/lib/rubocop/cop/layout/space_before_first_arg.rb +21 -15
  181. data/lib/rubocop/cop/layout/space_before_semicolon.rb +2 -5
  182. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +23 -39
  183. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +39 -45
  184. data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +6 -16
  185. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +53 -39
  186. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +23 -49
  187. data/lib/rubocop/cop/layout/space_inside_parens.rb +96 -33
  188. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +6 -11
  189. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +10 -19
  190. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +20 -32
  191. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +25 -42
  192. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +11 -16
  193. data/lib/rubocop/cop/layout/trailing_whitespace.rb +79 -16
  194. data/lib/rubocop/cop/legacy/corrections_proxy.rb +43 -0
  195. data/lib/rubocop/cop/legacy/corrector.rb +27 -0
  196. data/lib/rubocop/cop/lint/ambiguous_assignment.rb +54 -0
  197. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +22 -10
  198. data/lib/rubocop/cop/lint/ambiguous_operator.rb +59 -11
  199. data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +111 -0
  200. data/lib/rubocop/cop/lint/ambiguous_range.rb +105 -0
  201. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +44 -7
  202. data/lib/rubocop/cop/lint/assignment_in_condition.rb +28 -13
  203. data/lib/rubocop/cop/lint/big_decimal_new.rb +12 -12
  204. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +68 -0
  205. data/lib/rubocop/cop/lint/boolean_symbol.rb +29 -4
  206. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -2
  207. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +100 -0
  208. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  209. data/lib/rubocop/cop/lint/debugger.rb +61 -25
  210. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +98 -47
  211. data/lib/rubocop/cop/lint/deprecated_constants.rb +81 -0
  212. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +154 -0
  213. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +34 -5
  214. data/lib/rubocop/cop/lint/duplicate_branch.rb +155 -0
  215. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +4 -14
  216. data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
  217. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +3 -5
  218. data/lib/rubocop/cop/lint/duplicate_methods.rb +28 -31
  219. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +77 -0
  220. data/lib/rubocop/cop/lint/duplicate_require.rb +47 -0
  221. data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +47 -0
  222. data/lib/rubocop/cop/lint/each_with_object_argument.rb +6 -4
  223. data/lib/rubocop/cop/lint/else_layout.rb +38 -10
  224. data/lib/rubocop/cop/lint/empty_block.rb +98 -0
  225. data/lib/rubocop/cop/lint/empty_class.rb +93 -0
  226. data/lib/rubocop/cop/lint/empty_conditional_body.rb +67 -0
  227. data/lib/rubocop/cop/lint/empty_ensure.rb +6 -8
  228. data/lib/rubocop/cop/lint/empty_expression.rb +3 -3
  229. data/lib/rubocop/cop/lint/empty_file.rb +48 -0
  230. data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
  231. data/lib/rubocop/cop/lint/empty_interpolation.rb +8 -11
  232. data/lib/rubocop/cop/lint/empty_when.rb +32 -9
  233. data/lib/rubocop/cop/lint/ensure_return.rb +30 -17
  234. data/lib/rubocop/cop/lint/erb_new_arguments.rb +65 -10
  235. data/lib/rubocop/cop/lint/flip_flop.rb +10 -4
  236. data/lib/rubocop/cop/lint/float_comparison.rb +93 -0
  237. data/lib/rubocop/cop/lint/float_out_of_range.rb +3 -4
  238. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +63 -59
  239. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +47 -0
  240. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +154 -0
  241. data/lib/rubocop/cop/lint/identity_comparison.rb +51 -0
  242. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +12 -12
  243. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +72 -0
  244. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +18 -24
  245. data/lib/rubocop/cop/lint/inherit_exception.rb +33 -8
  246. data/lib/rubocop/cop/lint/interpolation_check.rb +26 -8
  247. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +44 -0
  248. data/lib/rubocop/cop/lint/literal_as_condition.rb +38 -17
  249. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +65 -20
  250. data/lib/rubocop/cop/lint/loop.rb +32 -9
  251. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +36 -24
  252. data/lib/rubocop/cop/lint/missing_super.rb +101 -0
  253. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +36 -0
  254. data/lib/rubocop/cop/lint/multiple_comparison.rb +48 -0
  255. data/lib/rubocop/cop/lint/nested_method_definition.rb +24 -28
  256. data/lib/rubocop/cop/lint/nested_percent_literal.rb +18 -6
  257. data/lib/rubocop/cop/lint/next_without_accumulator.rb +4 -3
  258. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -0
  259. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +173 -0
  260. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +17 -16
  261. data/lib/rubocop/cop/lint/number_conversion.rb +122 -12
  262. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +47 -0
  263. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +41 -0
  264. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +12 -15
  265. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +113 -0
  266. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +36 -14
  267. data/lib/rubocop/cop/lint/percent_string_array.rb +17 -12
  268. data/lib/rubocop/cop/lint/percent_symbol_array.rb +13 -14
  269. data/lib/rubocop/cop/lint/raise_exception.rb +91 -0
  270. data/lib/rubocop/cop/lint/rand_one.rb +6 -5
  271. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +290 -0
  272. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +133 -0
  273. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +50 -0
  274. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +11 -12
  275. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
  276. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +88 -46
  277. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +14 -21
  278. data/lib/rubocop/cop/lint/redundant_with_index.rb +17 -22
  279. data/lib/rubocop/cop/lint/redundant_with_object.rb +17 -22
  280. data/lib/rubocop/cop/lint/regexp_as_condition.rb +5 -3
  281. data/lib/rubocop/cop/lint/require_parentheses.rb +4 -6
  282. data/lib/rubocop/cop/lint/require_relative_self_path.rb +50 -0
  283. data/lib/rubocop/cop/lint/rescue_exception.rb +3 -4
  284. data/lib/rubocop/cop/lint/rescue_type.rb +11 -17
  285. data/lib/rubocop/cop/lint/return_in_void_context.rb +5 -8
  286. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +13 -20
  287. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +16 -18
  288. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +13 -5
  289. data/lib/rubocop/cop/lint/script_permission.rb +12 -9
  290. data/lib/rubocop/cop/lint/self_assignment.rb +78 -0
  291. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +83 -0
  292. data/lib/rubocop/cop/lint/shadowed_argument.rb +9 -15
  293. data/lib/rubocop/cop/lint/shadowed_exception.rb +19 -31
  294. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +22 -8
  295. data/lib/rubocop/cop/lint/struct_new_override.rb +59 -0
  296. data/lib/rubocop/cop/lint/suppressed_exception.rb +132 -0
  297. data/lib/rubocop/cop/lint/symbol_conversion.rb +178 -0
  298. data/lib/rubocop/cop/lint/syntax.rb +11 -30
  299. data/lib/rubocop/cop/lint/to_enum_arguments.rb +89 -0
  300. data/lib/rubocop/cop/lint/to_json.rb +25 -14
  301. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +34 -0
  302. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +55 -0
  303. data/lib/rubocop/cop/lint/triple_quotes.rb +71 -0
  304. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +31 -13
  305. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +90 -0
  306. data/lib/rubocop/cop/lint/unified_integer.rb +7 -8
  307. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +204 -0
  308. data/lib/rubocop/cop/lint/unreachable_code.rb +7 -9
  309. data/lib/rubocop/cop/lint/unreachable_loop.rb +196 -0
  310. data/lib/rubocop/cop/lint/unused_block_argument.rb +40 -17
  311. data/lib/rubocop/cop/lint/unused_method_argument.rb +65 -17
  312. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +7 -4
  313. data/lib/rubocop/cop/lint/uri_regexp.rb +12 -47
  314. data/lib/rubocop/cop/lint/useless_access_modifier.rb +101 -51
  315. data/lib/rubocop/cop/lint/useless_assignment.rb +13 -21
  316. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +10 -11
  317. data/lib/rubocop/cop/lint/useless_method_definition.rb +69 -0
  318. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +117 -0
  319. data/lib/rubocop/cop/lint/useless_setter_call.rb +21 -13
  320. data/lib/rubocop/cop/lint/useless_times.rb +110 -0
  321. data/lib/rubocop/cop/lint/void.rb +20 -50
  322. data/lib/rubocop/cop/message_annotator.rb +21 -10
  323. data/lib/rubocop/cop/metrics/abc_size.rb +33 -3
  324. data/lib/rubocop/cop/metrics/block_length.rb +43 -12
  325. data/lib/rubocop/cop/metrics/block_nesting.rb +5 -10
  326. data/lib/rubocop/cop/metrics/class_length.rb +40 -11
  327. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +29 -6
  328. data/lib/rubocop/cop/metrics/method_length.rb +35 -6
  329. data/lib/rubocop/cop/metrics/module_length.rb +30 -10
  330. data/lib/rubocop/cop/metrics/parameter_lists.rb +79 -13
  331. data/lib/rubocop/cop/metrics/perceived_complexity.rb +8 -11
  332. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +96 -18
  333. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +160 -0
  334. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  335. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +143 -0
  336. data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +42 -0
  337. data/lib/rubocop/cop/migration/department_name.rb +81 -0
  338. data/lib/rubocop/cop/mixin/alignment.rb +20 -13
  339. data/lib/rubocop/cop/mixin/allowed_identifiers.rb +18 -0
  340. data/lib/rubocop/cop/mixin/allowed_methods.rb +21 -0
  341. data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -29
  342. data/lib/rubocop/cop/mixin/array_min_size.rb +2 -4
  343. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  344. data/lib/rubocop/cop/mixin/check_assignment.rb +1 -1
  345. data/lib/rubocop/cop/mixin/check_line_breakable.rb +223 -0
  346. data/lib/rubocop/cop/mixin/code_length.rb +30 -9
  347. data/lib/rubocop/cop/mixin/comments_help.rb +42 -0
  348. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +7 -5
  349. data/lib/rubocop/cop/mixin/configurable_formatting.rb +4 -11
  350. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
  351. data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
  352. data/lib/rubocop/cop/mixin/configurable_numbering.rb +4 -3
  353. data/lib/rubocop/cop/mixin/def_node.rb +4 -6
  354. data/lib/rubocop/cop/mixin/documentation_comment.rb +9 -11
  355. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +15 -15
  356. data/lib/rubocop/cop/mixin/empty_parameter.rb +3 -2
  357. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +18 -5
  358. data/lib/rubocop/cop/mixin/enforce_superclass.rb +24 -11
  359. data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -3
  360. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +43 -13
  361. data/lib/rubocop/cop/mixin/gem_declaration.rb +13 -0
  362. data/lib/rubocop/cop/mixin/gemspec_help.rb +30 -0
  363. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +25 -12
  364. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +82 -0
  365. data/lib/rubocop/cop/mixin/hash_transform_method.rb +188 -0
  366. data/lib/rubocop/cop/mixin/heredoc.rb +5 -0
  367. data/lib/rubocop/cop/mixin/ignored_methods.rb +36 -3
  368. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  369. data/lib/rubocop/cop/mixin/interpolation.rb +25 -0
  370. data/lib/rubocop/cop/mixin/line_length_help.rb +90 -0
  371. data/lib/rubocop/cop/mixin/match_range.rb +2 -5
  372. data/lib/rubocop/cop/mixin/method_complexity.rb +29 -8
  373. data/lib/rubocop/cop/mixin/method_preference.rb +1 -2
  374. data/lib/rubocop/cop/mixin/min_body_length.rb +1 -1
  375. data/lib/rubocop/cop/mixin/{array_hash_indentation.rb → multiline_element_indentation.rb} +8 -6
  376. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +33 -0
  377. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +18 -47
  378. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +15 -15
  379. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -4
  380. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -6
  381. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +16 -6
  382. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  383. data/lib/rubocop/cop/mixin/percent_array.rb +31 -15
  384. data/lib/rubocop/cop/mixin/percent_literal.rb +0 -6
  385. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +94 -5
  386. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +6 -9
  387. data/lib/rubocop/cop/mixin/range_help.rb +25 -14
  388. data/lib/rubocop/cop/mixin/rational_literal.rb +19 -0
  389. data/lib/rubocop/cop/mixin/require_library.rb +59 -0
  390. data/lib/rubocop/cop/mixin/rescue_node.rb +13 -8
  391. data/lib/rubocop/cop/mixin/safe_assignment.rb +6 -2
  392. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +7 -8
  393. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +8 -8
  394. data/lib/rubocop/cop/mixin/statement_modifier.rb +49 -23
  395. data/lib/rubocop/cop/mixin/string_help.rb +4 -1
  396. data/lib/rubocop/cop/mixin/string_literals_help.rb +3 -5
  397. data/lib/rubocop/cop/mixin/surrounding_space.rb +22 -36
  398. data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
  399. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  400. data/lib/rubocop/cop/mixin/trailing_body.rb +2 -3
  401. data/lib/rubocop/cop/mixin/trailing_comma.rb +27 -34
  402. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +31 -33
  403. data/lib/rubocop/cop/mixin/unused_argument.rb +5 -9
  404. data/lib/rubocop/cop/mixin/visibility_help.rb +37 -0
  405. data/lib/rubocop/cop/naming/accessor_method_name.rb +21 -5
  406. data/lib/rubocop/cop/naming/ascii_identifiers.rb +29 -11
  407. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +18 -8
  408. data/lib/rubocop/cop/naming/block_forwarding.rb +121 -0
  409. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +4 -4
  410. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +14 -4
  411. data/lib/rubocop/cop/naming/constant_name.rb +12 -9
  412. data/lib/rubocop/cop/naming/file_name.rb +81 -39
  413. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +13 -7
  414. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +9 -9
  415. data/lib/rubocop/cop/naming/inclusive_language.rb +266 -0
  416. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +136 -27
  417. data/lib/rubocop/cop/naming/method_name.rb +42 -3
  418. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
  419. data/lib/rubocop/cop/naming/predicate_name.rb +14 -17
  420. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +163 -0
  421. data/lib/rubocop/cop/naming/variable_name.rb +5 -2
  422. data/lib/rubocop/cop/naming/variable_number.rb +94 -9
  423. data/lib/rubocop/cop/offense.rb +64 -19
  424. data/lib/rubocop/cop/registry.rb +122 -25
  425. data/lib/rubocop/cop/security/eval.rb +6 -4
  426. data/lib/rubocop/cop/security/io_methods.rb +49 -0
  427. data/lib/rubocop/cop/security/json_load.rb +18 -17
  428. data/lib/rubocop/cop/security/marshal_load.rb +6 -6
  429. data/lib/rubocop/cop/security/open.rb +30 -12
  430. data/lib/rubocop/cop/security/yaml_load.rb +14 -8
  431. data/lib/rubocop/cop/severity.rb +4 -14
  432. data/lib/rubocop/cop/style/access_modifier_declarations.rb +37 -12
  433. data/lib/rubocop/cop/style/accessor_grouping.rb +150 -0
  434. data/lib/rubocop/cop/style/alias.rb +52 -45
  435. data/lib/rubocop/cop/style/and_or.rb +36 -24
  436. data/lib/rubocop/cop/style/arguments_forwarding.rb +154 -0
  437. data/lib/rubocop/cop/style/array_coercion.rb +87 -0
  438. data/lib/rubocop/cop/style/array_join.rb +10 -10
  439. data/lib/rubocop/cop/style/ascii_comments.rb +7 -11
  440. data/lib/rubocop/cop/style/attr.rb +22 -14
  441. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +10 -13
  442. data/lib/rubocop/cop/style/bare_percent_literals.rb +13 -15
  443. data/lib/rubocop/cop/style/begin_block.rb +3 -3
  444. data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +60 -0
  445. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +125 -0
  446. data/lib/rubocop/cop/style/block_comments.rb +24 -20
  447. data/lib/rubocop/cop/style/block_delimiters.rb +145 -30
  448. data/lib/rubocop/cop/style/case_equality.rb +54 -6
  449. data/lib/rubocop/cop/style/case_like_if.rb +263 -0
  450. data/lib/rubocop/cop/style/character_literal.rb +20 -16
  451. data/lib/rubocop/cop/style/class_and_module_children.rb +84 -44
  452. data/lib/rubocop/cop/style/class_check.rb +7 -12
  453. data/lib/rubocop/cop/style/class_equality_comparison.rb +67 -0
  454. data/lib/rubocop/cop/style/class_methods.rb +16 -30
  455. data/lib/rubocop/cop/style/class_methods_definitions.rb +157 -0
  456. data/lib/rubocop/cop/style/class_vars.rb +23 -7
  457. data/lib/rubocop/cop/style/collection_compact.rb +111 -0
  458. data/lib/rubocop/cop/style/collection_methods.rb +32 -21
  459. data/lib/rubocop/cop/style/colon_method_call.rb +9 -11
  460. data/lib/rubocop/cop/style/colon_method_definition.rb +7 -7
  461. data/lib/rubocop/cop/style/combinable_loops.rb +93 -0
  462. data/lib/rubocop/cop/style/command_literal.rb +24 -30
  463. data/lib/rubocop/cop/style/comment_annotation.rb +68 -35
  464. data/lib/rubocop/cop/style/commented_keyword.rb +39 -34
  465. data/lib/rubocop/cop/style/conditional_assignment.rb +123 -155
  466. data/lib/rubocop/cop/style/constant_visibility.rb +46 -6
  467. data/lib/rubocop/cop/style/copyright.rb +28 -27
  468. data/lib/rubocop/cop/style/date_time.rb +26 -10
  469. data/lib/rubocop/cop/style/def_with_parentheses.rb +9 -12
  470. data/lib/rubocop/cop/style/dir.rb +12 -13
  471. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +87 -0
  472. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +169 -0
  473. data/lib/rubocop/cop/style/documentation.rb +113 -28
  474. data/lib/rubocop/cop/style/documentation_method.rb +48 -3
  475. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +46 -0
  476. data/lib/rubocop/cop/style/double_negation.rb +76 -11
  477. data/lib/rubocop/cop/style/each_for_simple_loop.rb +8 -11
  478. data/lib/rubocop/cop/style/each_with_object.rb +21 -23
  479. data/lib/rubocop/cop/style/empty_block_parameter.rb +10 -11
  480. data/lib/rubocop/cop/style/empty_case_condition.rb +33 -27
  481. data/lib/rubocop/cop/style/empty_else.rb +16 -24
  482. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +10 -11
  483. data/lib/rubocop/cop/style/empty_literal.rb +48 -33
  484. data/lib/rubocop/cop/style/empty_method.rb +15 -26
  485. data/lib/rubocop/cop/style/encoding.rb +30 -23
  486. data/lib/rubocop/cop/style/end_block.rb +7 -4
  487. data/lib/rubocop/cop/style/endless_method.rb +101 -0
  488. data/lib/rubocop/cop/style/eval_with_location.rb +146 -57
  489. data/lib/rubocop/cop/style/even_odd.rb +12 -14
  490. data/lib/rubocop/cop/style/expand_path_arguments.rb +34 -32
  491. data/lib/rubocop/cop/style/explicit_block_argument.rb +149 -0
  492. data/lib/rubocop/cop/style/exponential_notation.rb +116 -0
  493. data/lib/rubocop/cop/style/file_read.rb +112 -0
  494. data/lib/rubocop/cop/style/file_write.rb +124 -0
  495. data/lib/rubocop/cop/style/float_division.rb +151 -0
  496. data/lib/rubocop/cop/style/for.rb +9 -15
  497. data/lib/rubocop/cop/style/format_string.rb +58 -48
  498. data/lib/rubocop/cop/style/format_string_token.rb +85 -77
  499. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +118 -83
  500. data/lib/rubocop/cop/style/global_std_stream.rb +70 -0
  501. data/lib/rubocop/cop/style/global_vars.rb +3 -3
  502. data/lib/rubocop/cop/style/guard_clause.rb +65 -16
  503. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +99 -0
  504. data/lib/rubocop/cop/style/hash_conversion.rb +134 -0
  505. data/lib/rubocop/cop/style/hash_each_methods.rb +108 -0
  506. data/lib/rubocop/cop/style/hash_except.rb +97 -0
  507. data/lib/rubocop/cop/style/hash_like_case.rb +77 -0
  508. data/lib/rubocop/cop/style/hash_syntax.rb +91 -50
  509. data/lib/rubocop/cop/style/hash_transform_keys.rb +90 -0
  510. data/lib/rubocop/cop/style/hash_transform_values.rb +90 -0
  511. data/lib/rubocop/cop/style/identical_conditional_branches.rb +92 -12
  512. data/lib/rubocop/cop/style/if_inside_else.rb +109 -4
  513. data/lib/rubocop/cop/style/if_unless_modifier.rb +148 -41
  514. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -4
  515. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +136 -0
  516. data/lib/rubocop/cop/style/if_with_semicolon.rb +52 -4
  517. data/lib/rubocop/cop/style/implicit_runtime_error.rb +4 -2
  518. data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
  519. data/lib/rubocop/cop/style/infinite_loop.rb +33 -30
  520. data/lib/rubocop/cop/style/inline_comment.rb +5 -5
  521. data/lib/rubocop/cop/style/inverse_methods.rb +71 -46
  522. data/lib/rubocop/cop/style/ip_addresses.rb +8 -9
  523. data/lib/rubocop/cop/style/keyword_parameters_order.rb +75 -0
  524. data/lib/rubocop/cop/style/lambda.rb +21 -25
  525. data/lib/rubocop/cop/style/lambda_call.rb +18 -35
  526. data/lib/rubocop/cop/style/line_end_concatenation.rb +50 -37
  527. data/lib/rubocop/cop/style/map_to_hash.rb +68 -0
  528. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +210 -0
  529. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +44 -0
  530. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +95 -222
  531. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +19 -12
  532. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +15 -8
  533. data/lib/rubocop/cop/style/method_def_parentheses.rb +42 -27
  534. data/lib/rubocop/cop/style/min_max.rb +12 -16
  535. data/lib/rubocop/cop/style/missing_else.rb +21 -26
  536. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +11 -5
  537. data/lib/rubocop/cop/style/mixin_grouping.rb +34 -49
  538. data/lib/rubocop/cop/style/mixin_usage.rb +15 -23
  539. data/lib/rubocop/cop/style/module_function.rb +76 -33
  540. data/lib/rubocop/cop/style/multiline_block_chain.rb +15 -7
  541. data/lib/rubocop/cop/style/multiline_if_modifier.rb +5 -12
  542. data/lib/rubocop/cop/style/multiline_if_then.rb +6 -12
  543. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
  544. data/lib/rubocop/cop/style/multiline_memoization.rb +16 -14
  545. data/lib/rubocop/cop/style/multiline_method_signature.rb +34 -4
  546. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +32 -11
  547. data/lib/rubocop/cop/style/multiline_when_then.rb +66 -0
  548. data/lib/rubocop/cop/style/multiple_comparison.rb +77 -12
  549. data/lib/rubocop/cop/style/mutable_constant.rb +120 -47
  550. data/lib/rubocop/cop/style/negated_if.rb +11 -12
  551. data/lib/rubocop/cop/style/negated_if_else_condition.rb +128 -0
  552. data/lib/rubocop/cop/style/negated_unless.rb +88 -0
  553. data/lib/rubocop/cop/style/negated_while.rb +7 -15
  554. data/lib/rubocop/cop/style/nested_modifier.rb +34 -23
  555. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +26 -23
  556. data/lib/rubocop/cop/style/nested_ternary_operator.rb +30 -4
  557. data/lib/rubocop/cop/style/next.rb +42 -51
  558. data/lib/rubocop/cop/style/nil_comparison.rb +21 -13
  559. data/lib/rubocop/cop/style/nil_lambda.rb +70 -0
  560. data/lib/rubocop/cop/style/non_nil_check.rb +76 -42
  561. data/lib/rubocop/cop/style/not.rb +23 -29
  562. data/lib/rubocop/cop/style/numbered_parameters.rb +46 -0
  563. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +50 -0
  564. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +11 -16
  565. data/lib/rubocop/cop/style/numeric_literals.rb +36 -32
  566. data/lib/rubocop/cop/style/numeric_predicate.rb +27 -37
  567. data/lib/rubocop/cop/style/one_line_conditional.rb +61 -34
  568. data/lib/rubocop/cop/style/open_struct_use.rb +69 -0
  569. data/lib/rubocop/cop/style/option_hash.rb +8 -9
  570. data/lib/rubocop/cop/style/optional_arguments.rb +8 -10
  571. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +63 -0
  572. data/lib/rubocop/cop/style/or_assignment.rb +23 -16
  573. data/lib/rubocop/cop/style/parallel_assignment.rb +30 -27
  574. data/lib/rubocop/cop/style/parentheses_around_condition.rb +34 -9
  575. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +22 -30
  576. data/lib/rubocop/cop/style/percent_q_literals.rb +12 -15
  577. data/lib/rubocop/cop/style/perl_backrefs.rb +84 -16
  578. data/lib/rubocop/cop/style/preferred_hash_methods.rb +22 -23
  579. data/lib/rubocop/cop/style/proc.rb +9 -9
  580. data/lib/rubocop/cop/style/quoted_symbols.rb +124 -0
  581. data/lib/rubocop/cop/style/raise_args.rb +41 -37
  582. data/lib/rubocop/cop/style/random_with_offset.rb +70 -78
  583. data/lib/rubocop/cop/style/redundant_argument.rb +95 -0
  584. data/lib/rubocop/cop/style/redundant_assignment.rb +106 -0
  585. data/lib/rubocop/cop/style/redundant_begin.rb +101 -14
  586. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +7 -11
  587. data/lib/rubocop/cop/style/redundant_condition.rb +136 -0
  588. data/lib/rubocop/cop/style/redundant_conditional.rb +16 -17
  589. data/lib/rubocop/cop/style/redundant_exception.rb +25 -20
  590. data/lib/rubocop/cop/style/redundant_fetch_block.rb +119 -0
  591. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +61 -0
  592. data/lib/rubocop/cop/style/redundant_freeze.rb +17 -15
  593. data/lib/rubocop/cop/style/redundant_interpolation.rb +117 -0
  594. data/lib/rubocop/cop/style/redundant_parentheses.rb +71 -49
  595. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +22 -26
  596. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +108 -0
  597. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +118 -0
  598. data/lib/rubocop/cop/style/redundant_return.rb +64 -62
  599. data/lib/rubocop/cop/style/redundant_self.rb +71 -24
  600. data/lib/rubocop/cop/style/redundant_self_assignment.rb +119 -0
  601. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +83 -0
  602. data/lib/rubocop/cop/{performance/unneeded_sort.rb → style/redundant_sort.rb} +67 -39
  603. data/lib/rubocop/cop/{performance → style}/redundant_sort_by.rb +9 -12
  604. data/lib/rubocop/cop/style/regexp_literal.rb +27 -33
  605. data/lib/rubocop/cop/style/rescue_modifier.rb +64 -13
  606. data/lib/rubocop/cop/style/rescue_standard_error.rb +27 -25
  607. data/lib/rubocop/cop/style/return_nil.rb +17 -11
  608. data/lib/rubocop/cop/style/safe_navigation.rb +78 -44
  609. data/lib/rubocop/cop/{performance → style}/sample.rb +22 -22
  610. data/lib/rubocop/cop/style/select_by_regexp.rb +139 -0
  611. data/lib/rubocop/cop/style/self_assignment.rb +27 -23
  612. data/lib/rubocop/cop/style/semicolon.rb +50 -31
  613. data/lib/rubocop/cop/style/send.rb +5 -7
  614. data/lib/rubocop/cop/style/signal_exception.rb +33 -28
  615. data/lib/rubocop/cop/style/single_argument_dig.rb +60 -0
  616. data/lib/rubocop/cop/style/single_line_block_params.rb +38 -14
  617. data/lib/rubocop/cop/style/single_line_methods.rb +90 -21
  618. data/lib/rubocop/cop/style/slicing_with_range.rb +51 -0
  619. data/lib/rubocop/cop/style/sole_nested_conditional.rb +182 -0
  620. data/lib/rubocop/cop/style/special_global_vars.rb +52 -62
  621. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +19 -26
  622. data/lib/rubocop/cop/style/static_class.rb +97 -0
  623. data/lib/rubocop/cop/style/stderr_puts.rb +15 -14
  624. data/lib/rubocop/cop/style/string_chars.rb +41 -0
  625. data/lib/rubocop/cop/style/string_concatenation.rb +173 -0
  626. data/lib/rubocop/cop/style/string_hash_keys.rb +16 -10
  627. data/lib/rubocop/cop/style/string_literals.rb +20 -16
  628. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +5 -3
  629. data/lib/rubocop/cop/style/string_methods.rb +8 -18
  630. data/lib/rubocop/cop/style/strip.rb +42 -0
  631. data/lib/rubocop/cop/style/struct_inheritance.rb +49 -9
  632. data/lib/rubocop/cop/style/swap_values.rb +112 -0
  633. data/lib/rubocop/cop/style/symbol_array.rb +15 -26
  634. data/lib/rubocop/cop/style/symbol_literal.rb +6 -10
  635. data/lib/rubocop/cop/style/symbol_proc.rb +81 -57
  636. data/lib/rubocop/cop/style/ternary_parentheses.rb +77 -39
  637. data/lib/rubocop/cop/style/top_level_method_definition.rb +83 -0
  638. data/lib/rubocop/cop/style/trailing_body_on_class.rb +4 -7
  639. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +10 -9
  640. data/lib/rubocop/cop/style/trailing_body_on_module.rb +4 -7
  641. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +39 -25
  642. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +43 -5
  643. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +105 -0
  644. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +46 -5
  645. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +12 -40
  646. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +24 -33
  647. data/lib/rubocop/cop/style/trivial_accessors.rb +105 -44
  648. data/lib/rubocop/cop/style/unless_else.rb +8 -13
  649. data/lib/rubocop/cop/style/unless_logical_operators.rb +105 -0
  650. data/lib/rubocop/cop/style/unpack_first.rb +7 -13
  651. data/lib/rubocop/cop/style/variable_interpolation.rb +12 -25
  652. data/lib/rubocop/cop/style/when_then.rb +7 -7
  653. data/lib/rubocop/cop/style/while_until_do.rb +7 -17
  654. data/lib/rubocop/cop/style/while_until_modifier.rb +17 -25
  655. data/lib/rubocop/cop/style/word_array.rb +27 -28
  656. data/lib/rubocop/cop/style/yoda_condition.rb +63 -31
  657. data/lib/rubocop/cop/style/zero_length_predicate.rb +38 -30
  658. data/lib/rubocop/cop/team.rb +160 -91
  659. data/lib/rubocop/cop/util.rb +71 -33
  660. data/lib/rubocop/cop/utils/format_string.rb +133 -0
  661. data/lib/rubocop/cop/variable_force/assignment.rb +2 -2
  662. data/lib/rubocop/cop/variable_force/branch.rb +18 -9
  663. data/lib/rubocop/cop/variable_force/reference.rb +1 -3
  664. data/lib/rubocop/cop/variable_force/scope.rb +9 -12
  665. data/lib/rubocop/cop/variable_force/variable.rb +22 -12
  666. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  667. data/lib/rubocop/cop/variable_force.rb +22 -32
  668. data/lib/rubocop/cops_documentation_generator.rb +282 -0
  669. data/lib/rubocop/core_ext/string.rb +2 -26
  670. data/lib/rubocop/directive_comment.rb +144 -0
  671. data/lib/rubocop/error.rb +24 -0
  672. data/lib/rubocop/ext/processed_source.rb +18 -0
  673. data/lib/rubocop/ext/regexp_node.rb +87 -0
  674. data/lib/rubocop/ext/regexp_parser.rb +92 -0
  675. data/lib/rubocop/file_finder.rb +12 -18
  676. data/lib/rubocop/formatter/auto_gen_config_formatter.rb +2 -1
  677. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  678. data/lib/rubocop/formatter/clang_style_formatter.rb +13 -8
  679. data/lib/rubocop/formatter/disabled_config_formatter.rb +55 -27
  680. data/lib/rubocop/formatter/emacs_style_formatter.rb +24 -9
  681. data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
  682. data/lib/rubocop/formatter/formatter_set.rb +20 -19
  683. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  684. data/lib/rubocop/formatter/git_hub_actions_formatter.rb +44 -0
  685. data/lib/rubocop/formatter/html_formatter.rb +16 -17
  686. data/lib/rubocop/formatter/json_formatter.rb +20 -20
  687. data/lib/rubocop/formatter/junit_formatter.rb +93 -0
  688. data/lib/rubocop/formatter/offense_count_formatter.rb +2 -2
  689. data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
  690. data/lib/rubocop/formatter/progress_formatter.rb +4 -5
  691. data/lib/rubocop/formatter/quiet_formatter.rb +1 -1
  692. data/lib/rubocop/formatter/simple_text_formatter.rb +61 -16
  693. data/lib/rubocop/formatter/tap_formatter.rb +23 -8
  694. data/lib/rubocop/formatter/worst_offenders_formatter.rb +2 -2
  695. data/lib/rubocop/lockfile.rb +40 -0
  696. data/lib/rubocop/magic_comment.rb +80 -18
  697. data/lib/rubocop/name_similarity.rb +18 -10
  698. data/lib/rubocop/options.rb +301 -222
  699. data/lib/rubocop/path_util.rb +20 -22
  700. data/lib/rubocop/platform.rb +1 -1
  701. data/lib/rubocop/rake_task.rb +14 -12
  702. data/lib/rubocop/remote_config.rb +18 -14
  703. data/lib/rubocop/result_cache.rb +71 -36
  704. data/lib/rubocop/rspec/cop_helper.rb +11 -36
  705. data/lib/rubocop/rspec/expect_offense.rb +139 -43
  706. data/lib/rubocop/rspec/parallel_formatter.rb +90 -0
  707. data/lib/rubocop/rspec/shared_contexts.rb +86 -45
  708. data/lib/rubocop/rspec/support.rb +1 -1
  709. data/lib/rubocop/runner.rb +147 -85
  710. data/lib/rubocop/string_interpreter.rb +10 -7
  711. data/lib/rubocop/target_finder.rb +72 -53
  712. data/lib/rubocop/target_ruby.rb +264 -0
  713. data/lib/rubocop/util.rb +16 -0
  714. data/lib/rubocop/version.rb +71 -7
  715. data/lib/rubocop/yaml_duplication_checker.rb +10 -3
  716. data/lib/rubocop.rb +241 -169
  717. metadata +301 -216
  718. data/bin/console +0 -9
  719. data/bin/setup +0 -7
  720. data/lib/rubocop/ast/builder.rb +0 -75
  721. data/lib/rubocop/ast/node/and_node.rb +0 -29
  722. data/lib/rubocop/ast/node/args_node.rb +0 -29
  723. data/lib/rubocop/ast/node/array_node.rb +0 -57
  724. data/lib/rubocop/ast/node/block_node.rb +0 -115
  725. data/lib/rubocop/ast/node/break_node.rb +0 -17
  726. data/lib/rubocop/ast/node/case_node.rb +0 -56
  727. data/lib/rubocop/ast/node/def_node.rb +0 -71
  728. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  729. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  730. data/lib/rubocop/ast/node/for_node.rb +0 -53
  731. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  732. data/lib/rubocop/ast/node/if_node.rb +0 -175
  733. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  734. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  735. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  736. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  737. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  738. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  739. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -251
  740. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  741. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  742. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  743. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  744. data/lib/rubocop/ast/node/or_node.rb +0 -29
  745. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  746. data/lib/rubocop/ast/node/range_node.rb +0 -11
  747. data/lib/rubocop/ast/node/regexp_node.rb +0 -35
  748. data/lib/rubocop/ast/node/resbody_node.rb +0 -17
  749. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  750. data/lib/rubocop/ast/node/send_node.rb +0 -13
  751. data/lib/rubocop/ast/node/str_node.rb +0 -16
  752. data/lib/rubocop/ast/node/super_node.rb +0 -21
  753. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  754. data/lib/rubocop/ast/node/until_node.rb +0 -35
  755. data/lib/rubocop/ast/node/when_node.rb +0 -53
  756. data/lib/rubocop/ast/node/while_node.rb +0 -35
  757. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  758. data/lib/rubocop/ast/node.rb +0 -642
  759. data/lib/rubocop/ast/sexp.rb +0 -16
  760. data/lib/rubocop/ast/traversal.rb +0 -183
  761. data/lib/rubocop/cop/layout/align_array.rb +0 -39
  762. data/lib/rubocop/cop/layout/align_parameters.rb +0 -94
  763. data/lib/rubocop/cop/layout/indent_heredoc.rb +0 -294
  764. data/lib/rubocop/cop/layout/tab.rb +0 -87
  765. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  766. data/lib/rubocop/cop/lint/handle_exceptions.rb +0 -56
  767. data/lib/rubocop/cop/lint/multiple_compare.rb +0 -48
  768. data/lib/rubocop/cop/lint/unneeded_cop_disable_directive.rb +0 -263
  769. data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +0 -116
  770. data/lib/rubocop/cop/lint/useless_comparison.rb +0 -28
  771. data/lib/rubocop/cop/metrics/line_length.rb +0 -204
  772. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
  773. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +0 -37
  774. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -22
  775. data/lib/rubocop/cop/mixin/target_rails_version.rb +0 -16
  776. data/lib/rubocop/cop/mixin/too_many_lines.rb +0 -39
  777. data/lib/rubocop/cop/performance/caller.rb +0 -69
  778. data/lib/rubocop/cop/performance/case_when_splat.rb +0 -177
  779. data/lib/rubocop/cop/performance/casecmp.rb +0 -108
  780. data/lib/rubocop/cop/performance/chain_array_allocation.rb +0 -78
  781. data/lib/rubocop/cop/performance/compare_with_block.rb +0 -122
  782. data/lib/rubocop/cop/performance/count.rb +0 -102
  783. data/lib/rubocop/cop/performance/detect.rb +0 -110
  784. data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -94
  785. data/lib/rubocop/cop/performance/end_with.rb +0 -56
  786. data/lib/rubocop/cop/performance/fixed_size.rb +0 -97
  787. data/lib/rubocop/cop/performance/flat_map.rb +0 -78
  788. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +0 -99
  789. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +0 -46
  790. data/lib/rubocop/cop/performance/open_struct.rb +0 -46
  791. data/lib/rubocop/cop/performance/range_include.rb +0 -50
  792. data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -93
  793. data/lib/rubocop/cop/performance/redundant_match.rb +0 -56
  794. data/lib/rubocop/cop/performance/redundant_merge.rb +0 -183
  795. data/lib/rubocop/cop/performance/regexp_match.rb +0 -265
  796. data/lib/rubocop/cop/performance/reverse_each.rb +0 -42
  797. data/lib/rubocop/cop/performance/size.rb +0 -77
  798. data/lib/rubocop/cop/performance/start_with.rb +0 -59
  799. data/lib/rubocop/cop/performance/string_replacement.rb +0 -173
  800. data/lib/rubocop/cop/performance/times_map.rb +0 -71
  801. data/lib/rubocop/cop/performance/unfreeze_string.rb +0 -50
  802. data/lib/rubocop/cop/performance/uri_default_parser.rb +0 -47
  803. data/lib/rubocop/cop/rails/action_filter.rb +0 -117
  804. data/lib/rubocop/cop/rails/active_record_aliases.rb +0 -48
  805. data/lib/rubocop/cop/rails/active_support_aliases.rb +0 -69
  806. data/lib/rubocop/cop/rails/application_job.rb +0 -40
  807. data/lib/rubocop/cop/rails/application_record.rb +0 -40
  808. data/lib/rubocop/cop/rails/assert_not.rb +0 -44
  809. data/lib/rubocop/cop/rails/belongs_to.rb +0 -120
  810. data/lib/rubocop/cop/rails/blank.rb +0 -158
  811. data/lib/rubocop/cop/rails/bulk_change_table.rb +0 -289
  812. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +0 -91
  813. data/lib/rubocop/cop/rails/date.rb +0 -156
  814. data/lib/rubocop/cop/rails/delegate.rb +0 -135
  815. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +0 -51
  816. data/lib/rubocop/cop/rails/dynamic_find_by.rb +0 -91
  817. data/lib/rubocop/cop/rails/enum_uniqueness.rb +0 -45
  818. data/lib/rubocop/cop/rails/environment_comparison.rb +0 -66
  819. data/lib/rubocop/cop/rails/exit.rb +0 -67
  820. data/lib/rubocop/cop/rails/file_path.rb +0 -108
  821. data/lib/rubocop/cop/rails/find_by.rb +0 -55
  822. data/lib/rubocop/cop/rails/find_each.rb +0 -52
  823. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +0 -25
  824. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +0 -106
  825. data/lib/rubocop/cop/rails/http_positional_arguments.rb +0 -117
  826. data/lib/rubocop/cop/rails/http_status.rb +0 -186
  827. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +0 -94
  828. data/lib/rubocop/cop/rails/inverse_of.rb +0 -246
  829. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +0 -149
  830. data/lib/rubocop/cop/rails/link_to_blank.rb +0 -90
  831. data/lib/rubocop/cop/rails/not_null_column.rb +0 -67
  832. data/lib/rubocop/cop/rails/output.rb +0 -49
  833. data/lib/rubocop/cop/rails/output_safety.rb +0 -99
  834. data/lib/rubocop/cop/rails/pluralization_grammar.rb +0 -107
  835. data/lib/rubocop/cop/rails/presence.rb +0 -124
  836. data/lib/rubocop/cop/rails/present.rb +0 -149
  837. data/lib/rubocop/cop/rails/read_write_attribute.rb +0 -74
  838. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +0 -135
  839. data/lib/rubocop/cop/rails/reflection_class_name.rb +0 -38
  840. data/lib/rubocop/cop/rails/refute_methods.rb +0 -76
  841. data/lib/rubocop/cop/rails/relative_date_constant.rb +0 -93
  842. data/lib/rubocop/cop/rails/request_referer.rb +0 -56
  843. data/lib/rubocop/cop/rails/reversible_migration.rb +0 -286
  844. data/lib/rubocop/cop/rails/safe_navigation.rb +0 -91
  845. data/lib/rubocop/cop/rails/save_bang.rb +0 -316
  846. data/lib/rubocop/cop/rails/scope_args.rb +0 -29
  847. data/lib/rubocop/cop/rails/skips_model_validations.rb +0 -88
  848. data/lib/rubocop/cop/rails/time_zone.rb +0 -231
  849. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +0 -105
  850. data/lib/rubocop/cop/rails/unknown_env.rb +0 -63
  851. data/lib/rubocop/cop/rails/validation.rb +0 -106
  852. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -190
  853. data/lib/rubocop/cop/style/method_missing_super.rb +0 -34
  854. data/lib/rubocop/cop/style/unneeded_condition.rb +0 -112
  855. data/lib/rubocop/cop/style/unneeded_interpolation.rb +0 -98
  856. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
  857. data/lib/rubocop/node_pattern.rb +0 -584
  858. data/lib/rubocop/processed_source.rb +0 -210
  859. data/lib/rubocop/rspec/shared_examples.rb +0 -59
  860. data/lib/rubocop/string_util.rb +0 -14
  861. data/lib/rubocop/token.rb +0 -114
@@ -59,8 +59,10 @@ module RuboCop
59
59
  # ERB.new(str, nil, '-', '@output_buffer')
60
60
  # end
61
61
  #
62
- class ErbNewArguments < Cop
62
+ class ErbNewArguments < Base
63
+ include RangeHelp
63
64
  extend TargetRubyVersion
65
+ extend AutoCorrector
64
66
 
65
67
  minimum_target_ruby_version 2.6
66
68
 
@@ -76,30 +78,83 @@ module RuboCop
76
78
  '`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
77
79
  ].freeze
78
80
 
79
- def_node_matcher :erb_new_with_non_keyword_arguments, <<-PATTERN
81
+ RESTRICT_ON_SEND = %i[new].freeze
82
+
83
+ # @!method erb_new_with_non_keyword_arguments(node)
84
+ def_node_matcher :erb_new_with_non_keyword_arguments, <<~PATTERN
80
85
  (send
81
86
  (const {nil? cbase} :ERB) :new $...)
82
87
  PATTERN
83
88
 
84
89
  def on_send(node)
85
90
  erb_new_with_non_keyword_arguments(node) do |arguments|
86
- return if correct_arguments?(arguments)
91
+ return if arguments.empty? || correct_arguments?(arguments)
87
92
 
88
- 1.upto(3) do |i|
89
- next if !arguments[i] || arguments[i].hash_type?
93
+ arguments[1..3].each_with_index do |argument, i|
94
+ next if !argument || argument.hash_type?
90
95
 
91
- message = format(MESSAGES[i - 1], arg_value: arguments[i].source)
96
+ message = format(MESSAGES[i], arg_value: argument.source)
92
97
 
93
98
  add_offense(
94
- node, location: arguments[i].source_range, message: message
95
- )
99
+ argument.source_range, message: message
100
+ ) do |corrector|
101
+ autocorrect(corrector, node)
102
+ end
96
103
  end
97
104
  end
98
105
  end
99
106
 
107
+ private
108
+
109
+ def autocorrect(corrector, node)
110
+ str_arg = node.arguments[0].source
111
+
112
+ kwargs = build_kwargs(node)
113
+ overridden_kwargs = override_by_legacy_args(kwargs, node)
114
+
115
+ good_arguments = [str_arg, overridden_kwargs].flatten.compact.join(', ')
116
+
117
+ corrector.replace(arguments_range(node), good_arguments)
118
+ end
119
+
100
120
  def correct_arguments?(arguments)
101
- arguments.size == 1 ||
102
- arguments.size == 2 && arguments[1].hash_type?
121
+ arguments.size == 1 || (arguments.size == 2 && arguments[1].hash_type?)
122
+ end
123
+
124
+ def build_kwargs(node)
125
+ return [nil, nil] unless node.arguments.last.hash_type?
126
+
127
+ trim_mode_arg, eoutvar_arg = nil
128
+
129
+ node.arguments.last.pairs.each do |pair|
130
+ case pair.key.source
131
+ when 'trim_mode'
132
+ trim_mode_arg = "trim_mode: #{pair.value.source}"
133
+ when 'eoutvar'
134
+ eoutvar_arg = "eoutvar: #{pair.value.source}"
135
+ end
136
+ end
137
+
138
+ [trim_mode_arg, eoutvar_arg]
139
+ end
140
+
141
+ def override_by_legacy_args(kwargs, node)
142
+ arguments = node.arguments
143
+ overridden_kwargs = kwargs.dup
144
+
145
+ overridden_kwargs[0] = "trim_mode: #{arguments[2].source}" if arguments[2]
146
+
147
+ if arguments[3] && !arguments[3].hash_type?
148
+ overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
149
+ end
150
+
151
+ overridden_kwargs
152
+ end
153
+
154
+ def arguments_range(node)
155
+ arguments = node.arguments
156
+
157
+ range_between(arguments.first.source_range.begin_pos, arguments.last.source_range.end_pos)
103
158
  end
104
159
  end
105
160
  end
@@ -3,8 +3,14 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This cop looks for uses of flip-flop operator.
7
- # flip-flop operator is deprecated since Ruby 2.6.0.
6
+ # This cop looks for uses of flip-flop operator
7
+ # based on the Ruby Style Guide.
8
+ #
9
+ # Here is the history of flip-flops in Ruby.
10
+ # flip-flop operator is deprecated in Ruby 2.6.0 and
11
+ # the deprecation has been reverted by Ruby 2.7.0 and
12
+ # backported to Ruby 2.6.
13
+ # See: https://bugs.ruby-lang.org/issues/5400
8
14
  #
9
15
  # @example
10
16
  # # bad
@@ -16,8 +22,8 @@ module RuboCop
16
22
  # (1..20).each do |x|
17
23
  # puts x if (x >= 5) && (x <= 10)
18
24
  # end
19
- class FlipFlop < Cop
20
- MSG = 'Avoid the use of flip-flop operators.'.freeze
25
+ class FlipFlop < Base
26
+ MSG = 'Avoid the use of flip-flop operators.'
21
27
 
22
28
  def on_iflipflop(node)
23
29
  add_offense(node)
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # This cop checks for the presence of precise comparison of floating point numbers.
7
+ #
8
+ # Floating point values are inherently inaccurate, and comparing them for exact equality
9
+ # is almost never the desired semantics. Comparison via the `==/!=` operators checks
10
+ # floating-point value representation to be exactly the same, which is very unlikely
11
+ # if you perform any arithmetic operations involving precision loss.
12
+ #
13
+ # @example
14
+ # # bad
15
+ # x == 0.1
16
+ # x != 0.1
17
+ #
18
+ # # good - using BigDecimal
19
+ # x.to_d == 0.1.to_d
20
+ #
21
+ # # good
22
+ # (x - 0.1).abs < Float::EPSILON
23
+ #
24
+ # # good
25
+ # tolerance = 0.0001
26
+ # (x - 0.1).abs < tolerance
27
+ #
28
+ # # Or some other epsilon based type of comparison:
29
+ # # https://www.embeddeduse.com/2019/08/26/qt-compare-two-floats/
30
+ #
31
+ class FloatComparison < Base
32
+ MSG = 'Avoid (in)equality comparisons of floats as they are unreliable.'
33
+
34
+ EQUALITY_METHODS = %i[== != eql? equal?].freeze
35
+ FLOAT_RETURNING_METHODS = %i[to_f Float fdiv].freeze
36
+ FLOAT_INSTANCE_METHODS = %i[@- abs magnitude modulo next_float prev_float quo].to_set.freeze
37
+
38
+ RESTRICT_ON_SEND = EQUALITY_METHODS
39
+
40
+ def on_send(node)
41
+ lhs, _method, rhs = *node
42
+ add_offense(node) if float?(lhs) || float?(rhs)
43
+ end
44
+
45
+ private
46
+
47
+ def float?(node)
48
+ return false unless node
49
+
50
+ case node.type
51
+ when :float
52
+ true
53
+ when :send
54
+ check_send(node)
55
+ when :begin
56
+ float?(node.children.first)
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ # rubocop:disable Metrics/PerceivedComplexity
63
+ def check_send(node)
64
+ if node.arithmetic_operation?
65
+ lhs, _operation, rhs = *node
66
+ float?(lhs) || float?(rhs)
67
+ elsif FLOAT_RETURNING_METHODS.include?(node.method_name)
68
+ true
69
+ elsif node.receiver&.float_type?
70
+ if FLOAT_INSTANCE_METHODS.include?(node.method_name)
71
+ true
72
+ else
73
+ check_numeric_returning_method(node)
74
+ end
75
+ end
76
+ end
77
+ # rubocop:enable Metrics/PerceivedComplexity
78
+
79
+ def check_numeric_returning_method(node)
80
+ return false unless node.receiver
81
+
82
+ case node.method_name
83
+ when :angle, :arg, :phase
84
+ Float(node.receiver.source).negative?
85
+ when :ceil, :floor, :round, :truncate
86
+ precision = node.first_argument
87
+ precision&.int_type? && Integer(precision.source).positive?
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -18,14 +18,13 @@ module RuboCop
18
18
  # # good
19
19
  #
20
20
  # float = 42.9
21
- class FloatOutOfRange < Cop
22
- MSG = 'Float out of range.'.freeze
21
+ class FloatOutOfRange < Base
22
+ MSG = 'Float out of range.'
23
23
 
24
24
  def on_float(node)
25
25
  value, = *node
26
26
 
27
- return unless value.infinite? ||
28
- value.zero? && node.source =~ /[1-9]/
27
+ return unless value.infinite? || (value.zero? && /[1-9]/.match?(node.source))
29
28
 
30
29
  add_offense(node)
31
30
  end
@@ -7,6 +7,10 @@ module RuboCop
7
7
  # expected fields for format/sprintf/#% and what is actually
8
8
  # passed as arguments.
9
9
  #
10
+ # In addition it checks whether different formats are used in the same
11
+ # format string. Do not mix numbered, unnumbered, and named formats in
12
+ # the same format string.
13
+ #
10
14
  # @example
11
15
  #
12
16
  # # bad
@@ -18,33 +22,60 @@ module RuboCop
18
22
  # # good
19
23
  #
20
24
  # format('A value: %s and another: %i', a_value, another)
21
- class FormatParameterMismatch < Cop
25
+ #
26
+ # @example
27
+ #
28
+ # # bad
29
+ #
30
+ # format('Unnumbered format: %s and numbered: %2$s', a_value, another)
31
+ #
32
+ # @example
33
+ #
34
+ # # good
35
+ #
36
+ # format('Numbered format: %1$s and numbered %2$s', a_value, another)
37
+ class FormatParameterMismatch < Base
22
38
  # http://rubular.com/r/CvpbxkcTzy
23
39
  MSG = "Number of arguments (%<arg_num>i) to `%<method>s` doesn't " \
24
- 'match the number of fields (%<field_num>i).'.freeze
25
- FIELD_REGEX =
26
- /(%(([\s#+-0\*]*)(\d*)?(\.\d+)?[bBdiouxXeEfgGaAcps]|%))/.freeze
27
- NAMED_FIELD_REGEX = /%\{[_a-zA-Z][_a-zA-Z]+\}/.freeze
28
- KERNEL = 'Kernel'.freeze
29
- SHOVEL = '<<'.freeze
30
- PERCENT = '%'.freeze
31
- PERCENT_PERCENT = '%%'.freeze
32
- DIGIT_DOLLAR_FLAG = /%(\d+)\$/.freeze
40
+ 'match the number of fields (%<field_num>i).'
41
+ MSG_INVALID = 'Format string is invalid because formatting sequence types ' \
42
+ '(numbered, named or unnumbered) are mixed.'
43
+
44
+ KERNEL = 'Kernel'
45
+ SHOVEL = '<<'
33
46
  STRING_TYPES = %i[str dstr].freeze
34
- NAMED_INTERPOLATION = /%(?:<\w+>|\{\w+\})/.freeze
47
+ RESTRICT_ON_SEND = %i[format sprintf %].freeze
35
48
 
36
49
  def on_send(node)
50
+ return unless format_string?(node)
51
+
52
+ if invalid_format_string?(node)
53
+ add_offense(node.loc.selector, message: MSG_INVALID)
54
+ return
55
+ end
56
+
37
57
  return unless offending_node?(node)
38
58
 
39
- add_offense(node, location: :selector)
59
+ add_offense(node.loc.selector, message: message(node))
40
60
  end
41
61
 
42
62
  private
43
63
 
64
+ def format_string?(node)
65
+ called_on_string?(node) && method_with_format_args?(node)
66
+ end
67
+
68
+ def invalid_format_string?(node)
69
+ string = if sprintf?(node) || format?(node)
70
+ node.first_argument.source
71
+ else
72
+ node.receiver.source
73
+ end
74
+ !RuboCop::Cop::Utils::FormatString.new(string).valid?
75
+ end
76
+
44
77
  def offending_node?(node)
45
- return false unless called_on_string?(node)
46
- return false unless method_with_format_args?(node)
47
- return false if named_mode?(node) || splat_args?(node)
78
+ return false if splat_args?(node)
48
79
 
49
80
  num_of_format_args, num_of_expected_fields = count_matches(node)
50
81
 
@@ -54,36 +85,23 @@ module RuboCop
54
85
  end
55
86
 
56
87
  def matched_arguments_count?(expected, passed)
57
- if passed < 0
88
+ if passed.negative?
58
89
  expected < passed.abs
59
90
  else
60
91
  expected != passed
61
92
  end
62
93
  end
63
94
 
64
- def called_on_string?(node)
65
- receiver_node, _method, format_string, = *node
66
- if receiver_node.nil? || receiver_node.const_type?
67
- format_string && format_string.str_type?
68
- else
69
- receiver_node.str_type?
70
- end
71
- end
95
+ # @!method called_on_string?(node)
96
+ def_node_matcher :called_on_string?, <<~PATTERN
97
+ {(send {nil? const_type?} _ (str _) ...)
98
+ (send (str ...) ...)}
99
+ PATTERN
72
100
 
73
101
  def method_with_format_args?(node)
74
102
  sprintf?(node) || format?(node) || percent?(node)
75
103
  end
76
104
 
77
- def named_mode?(node)
78
- relevant_node = if sprintf?(node) || format?(node)
79
- node.first_argument
80
- elsif percent?(node)
81
- node.receiver
82
- end
83
-
84
- !relevant_node.source.scan(NAMED_FIELD_REGEX).empty?
85
- end
86
-
87
105
  def splat_args?(node)
88
106
  return false if percent?(node)
89
107
 
@@ -122,8 +140,7 @@ module RuboCop
122
140
  end
123
141
 
124
142
  def format_method?(name, node)
125
- return false if node.const_receiver? &&
126
- !node.receiver.loc.name.is?(KERNEL)
143
+ return false if node.const_receiver? && !node.receiver.loc.name.is?(KERNEL)
127
144
  return false unless node.method?(name)
128
145
 
129
146
  node.arguments.size > 1 && node.first_argument.str_type?
@@ -131,28 +148,17 @@ module RuboCop
131
148
 
132
149
  def expected_fields_count(node)
133
150
  return :unknown unless node.str_type?
134
- return 1 if node.source =~ NAMED_INTERPOLATION
135
151
 
136
- max_digit_dollar_num = max_digit_dollar_num(node)
137
- return max_digit_dollar_num if max_digit_dollar_num &&
138
- max_digit_dollar_num.nonzero?
152
+ format_string = RuboCop::Cop::Utils::FormatString.new(node.source)
153
+ return 1 if format_string.named_interpolation?
139
154
 
140
- node
141
- .source
142
- .scan(FIELD_REGEX)
143
- .reject { |x| x.first == PERCENT_PERCENT }
144
- .reduce(0) { |acc, elem| acc + arguments_count(elem[2]) }
145
- end
146
-
147
- def max_digit_dollar_num(node)
148
- node.source.scan(DIGIT_DOLLAR_FLAG).map do |digit_dollar_num|
149
- digit_dollar_num.first.to_i
150
- end.max
151
- end
155
+ max_digit_dollar_num = format_string.max_digit_dollar_num
156
+ return max_digit_dollar_num if max_digit_dollar_num&.nonzero?
152
157
 
153
- # number of arguments required for the format sequence
154
- def arguments_count(format)
155
- format.scan('*').count + 1
158
+ format_string
159
+ .format_sequences
160
+ .reject(&:percent?)
161
+ .reduce(0) { |acc, seq| acc + seq.arity }
156
162
  end
157
163
 
158
164
  def format?(node)
@@ -167,11 +173,9 @@ module RuboCop
167
173
  receiver = node.receiver
168
174
 
169
175
  percent = node.method?(:%) &&
170
- (STRING_TYPES.include?(receiver.type) ||
171
- node.first_argument.array_type?)
176
+ (STRING_TYPES.include?(receiver.type) || node.first_argument.array_type?)
172
177
 
173
- return false if percent && STRING_TYPES.include?(receiver.type) &&
174
- heredoc?(node)
178
+ return false if percent && STRING_TYPES.include?(receiver.type) && heredoc?(node)
175
179
 
176
180
  percent
177
181
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # Prefer using `Hash#compare_by_identity` rather than using `object_id`
7
+ # for hash keys.
8
+ #
9
+ # This cop looks for hashes being keyed by objects' `object_id`, using
10
+ # one of these methods: `key?`, `has_key?`, `fetch`, `[]` and `[]=`.
11
+ #
12
+ # @safety
13
+ # This cop is unsafe. Although unlikely, the hash could store both object
14
+ # ids and other values that need be compared by value, and thus
15
+ # could be a false positive.
16
+ #
17
+ # Furthermore, this cop cannot guarantee that the receiver of one of the
18
+ # methods (`key?`, etc.) is actually a hash.
19
+ #
20
+ # @example
21
+ # # bad
22
+ # hash = {}
23
+ # hash[foo.object_id] = :bar
24
+ # hash.key?(baz.object_id)
25
+ #
26
+ # # good
27
+ # hash = {}.compare_by_identity
28
+ # hash[foo] = :bar
29
+ # hash.key?(baz)
30
+ #
31
+ class HashCompareByIdentity < Base
32
+ RESTRICT_ON_SEND = %i[key? has_key? fetch [] []=].freeze
33
+
34
+ MSG = 'Use `Hash#compare_by_identity` instead of using `object_id` for keys.'
35
+
36
+ # @!method id_as_hash_key?(node)
37
+ def_node_matcher :id_as_hash_key?, <<~PATTERN
38
+ (send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ add_offense(node) if id_as_hash_key?(node)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # This cop checks for the ordering of a method call where
7
+ # the receiver of the call is a HEREDOC.
8
+ #
9
+ # @example
10
+ # # bad
11
+ #
12
+ # <<-SQL
13
+ # bar
14
+ # SQL
15
+ # .strip_indent
16
+ #
17
+ # <<-SQL
18
+ # bar
19
+ # SQL
20
+ # .strip_indent
21
+ # .trim
22
+ #
23
+ # # good
24
+ #
25
+ # <<~SQL
26
+ # bar
27
+ # SQL
28
+ #
29
+ # <<~SQL.trim
30
+ # bar
31
+ # SQL
32
+ #
33
+ class HeredocMethodCallPosition < Base
34
+ include RangeHelp
35
+ extend AutoCorrector
36
+
37
+ MSG = 'Put a method call with a HEREDOC receiver on the same line as the HEREDOC opening.'
38
+
39
+ def on_send(node)
40
+ heredoc = heredoc_node_descendent_receiver(node)
41
+ return unless heredoc
42
+ return if correctly_positioned?(node, heredoc)
43
+
44
+ add_offense(call_after_heredoc_range(heredoc)) do |corrector|
45
+ autocorrect(corrector, node, heredoc)
46
+ end
47
+ end
48
+ alias on_csend on_send
49
+
50
+ private
51
+
52
+ def autocorrect(corrector, node, heredoc)
53
+ call_range = call_range_to_safely_reposition(node, heredoc)
54
+ return if call_range.nil?
55
+
56
+ call_source = call_range.source.strip
57
+ corrector.remove(call_range)
58
+ corrector.insert_after(heredoc_begin_line_range(node), call_source)
59
+ end
60
+
61
+ def heredoc_node_descendent_receiver(node)
62
+ while send_node?(node)
63
+ return node.receiver if heredoc_node?(node.receiver)
64
+
65
+ node = node.receiver
66
+ end
67
+ end
68
+
69
+ def send_node?(node)
70
+ return nil unless node
71
+
72
+ node.call_type?
73
+ end
74
+
75
+ def heredoc_node?(node)
76
+ node.respond_to?(:heredoc?) && node.heredoc?
77
+ end
78
+
79
+ def call_after_heredoc_range(heredoc)
80
+ pos = heredoc_end_pos(heredoc)
81
+ range_between(pos + 1, pos + 2)
82
+ end
83
+
84
+ def correctly_positioned?(node, heredoc)
85
+ heredoc_end_pos(heredoc) > call_end_pos(node)
86
+ end
87
+
88
+ def calls_on_multiple_lines?(node, _heredoc)
89
+ last_line = node.last_line
90
+ while send_node?(node)
91
+ return true unless last_line == node.last_line
92
+ return true unless all_on_same_line?(node.arguments)
93
+
94
+ node = node.receiver
95
+ end
96
+ false
97
+ end
98
+
99
+ def all_on_same_line?(nodes)
100
+ return true if nodes.empty?
101
+
102
+ nodes.first.first_line == nodes.last.last_line
103
+ end
104
+
105
+ def heredoc_end_pos(heredoc)
106
+ heredoc.location.heredoc_end.end_pos
107
+ end
108
+
109
+ def call_end_pos(node)
110
+ node.source_range.end_pos
111
+ end
112
+
113
+ def heredoc_begin_line_range(heredoc)
114
+ pos = heredoc.source_range.begin_pos
115
+ range_by_whole_lines(range_between(pos, pos))
116
+ end
117
+
118
+ def call_line_range(node)
119
+ pos = node.source_range.end_pos
120
+ range_by_whole_lines(range_between(pos, pos))
121
+ end
122
+
123
+ # Returns nil if no range can be safely repositioned.
124
+ def call_range_to_safely_reposition(node, heredoc)
125
+ return nil if calls_on_multiple_lines?(node, heredoc)
126
+
127
+ heredoc_end_pos = heredoc_end_pos(heredoc)
128
+ call_end_pos = call_end_pos(node)
129
+
130
+ call_range = range_between(heredoc_end_pos, call_end_pos)
131
+ call_line_range = call_line_range(node)
132
+
133
+ call_source = call_range.source.strip
134
+ call_line_source = call_line_range.source.strip
135
+
136
+ return call_range if call_source == call_line_source
137
+
138
+ if trailing_comma?(call_source, call_line_source)
139
+ # If there's some on the last line other than the call, e.g.
140
+ # a trailing comma, then we leave the "\n" following the
141
+ # heredoc_end in place.
142
+ return range_between(heredoc_end_pos, call_end_pos + 1)
143
+ end
144
+
145
+ nil
146
+ end
147
+
148
+ def trailing_comma?(call_source, call_line_source)
149
+ "#{call_source}," == call_line_source
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ #
7
+ # Prefer `equal?` over `==` when comparing `object_id`.
8
+ #
9
+ # `Object#equal?` is provided to compare objects for identity, and in contrast
10
+ # `Object#==` is provided for the purpose of doing value comparison.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # foo.object_id == bar.object_id
15
+ #
16
+ # # good
17
+ # foo.equal?(bar)
18
+ #
19
+ class IdentityComparison < Base
20
+ extend AutoCorrector
21
+
22
+ MSG = 'Use `equal?` instead `==` when comparing `object_id`.'
23
+ RESTRICT_ON_SEND = %i[==].freeze
24
+
25
+ def on_send(node)
26
+ return unless compare_between_object_id_by_double_equal?(node)
27
+
28
+ add_offense(node) do |corrector|
29
+ receiver = node.receiver.receiver
30
+ argument = node.first_argument.receiver
31
+ return unless receiver && argument
32
+
33
+ replacement = "#{receiver.source}.equal?(#{argument.source})"
34
+
35
+ corrector.replace(node, replacement)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def compare_between_object_id_by_double_equal?(node)
42
+ object_id_method?(node.receiver) && object_id_method?(node.first_argument)
43
+ end
44
+
45
+ def object_id_method?(node)
46
+ node.send_type? && node.method?(:object_id)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end