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
@@ -14,7 +14,7 @@ module RuboCop
14
14
  #
15
15
  # @example Usage
16
16
  #
17
- # expect_offense(<<-RUBY.strip_indent)
17
+ # expect_offense(<<~RUBY)
18
18
  # a do
19
19
  # b
20
20
  # end.c
@@ -23,7 +23,7 @@ module RuboCop
23
23
  #
24
24
  # @example Equivalent assertion without `expect_offense`
25
25
  #
26
- # inspect_source(<<-RUBY.strip_indent)
26
+ # inspect_source(<<~RUBY)
27
27
  # a do
28
28
  # b
29
29
  # end.c
@@ -43,12 +43,12 @@ module RuboCop
43
43
  #
44
44
  # @example `expect_offense` and `expect_correction`
45
45
  #
46
- # expect_offense(<<-RUBY.strip_indent)
46
+ # expect_offense(<<~RUBY)
47
47
  # x % 2 == 0
48
48
  # ^^^^^^^^^^ Replace with `Integer#even?`.
49
49
  # RUBY
50
50
  #
51
- # expect_correction(<<-RUBY.strip_indent)
51
+ # expect_correction(<<~RUBY)
52
52
  # x.even?
53
53
  # RUBY
54
54
  #
@@ -63,7 +63,7 @@ module RuboCop
63
63
  #
64
64
  # @example `expect_offense` and `expect_no_corrections`
65
65
  #
66
- # expect_offense(<<-RUBY.strip_indent)
66
+ # expect_offense(<<~RUBY)
67
67
  # a do
68
68
  # b
69
69
  # end.c
@@ -71,73 +71,147 @@ module RuboCop
71
71
  # RUBY
72
72
  #
73
73
  # expect_no_corrections
74
+ #
75
+ # If your code has variables of different lengths, you can use `%{foo}`,
76
+ # `^{foo}`, and `_{foo}` to format your template; you can also abbreviate
77
+ # offense messages with `[...]`:
78
+ #
79
+ # %w[raise fail].each do |keyword|
80
+ # expect_offense(<<~RUBY, keyword: keyword)
81
+ # %{keyword}(RuntimeError, msg)
82
+ # ^{keyword}^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument [...]
83
+ # RUBY
84
+ #
85
+ # %w[has_one has_many].each do |type|
86
+ # expect_offense(<<~RUBY, type: type)
87
+ # class Book
88
+ # %{type} :chapter, foreign_key: 'book_id'
89
+ # _{type} ^^^^^^^^^^^^^^^^^^^^^^ Specifying the default [...]
90
+ # end
91
+ # RUBY
92
+ # end
93
+ #
94
+ # If you need to specify an offense on a blank line, use the empty `^{}` marker:
95
+ #
96
+ # @example `^{}` empty line offense
97
+ #
98
+ # expect_offense(<<~RUBY)
99
+ #
100
+ # ^{} Missing frozen string literal comment.
101
+ # puts 1
102
+ # RUBY
74
103
  module ExpectOffense
75
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
76
- def expect_offense(source, file = nil)
77
- RuboCop::Formatter::DisabledConfigFormatter
78
- .config_to_allow_offenses = {}
79
- RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
80
- cop.instance_variable_get(:@options)[:auto_correct] = true
104
+ def format_offense(source, **replacements)
105
+ replacements.each do |keyword, value|
106
+ value = value.to_s
107
+ source = source.gsub("%{#{keyword}}", value)
108
+ .gsub("^{#{keyword}}", '^' * value.size)
109
+ .gsub("_{#{keyword}}", ' ' * value.size)
110
+ end
111
+ source
112
+ end
81
113
 
82
- expected_annotations = AnnotatedSource.parse(source)
114
+ def expect_offense(source, file = nil, severity: nil, chomp: false, **replacements)
115
+ expected_annotations = parse_annotations(source, **replacements)
116
+ source = expected_annotations.plain_source
117
+ source = source.chomp if chomp
83
118
 
84
- if expected_annotations.plain_source == source
85
- raise 'Use `expect_no_offenses` to assert that no offenses are found'
86
- end
119
+ @processed_source = parse_processed_source(source, file)
120
+ @offenses = _investigate(cop, @processed_source)
121
+ actual_annotations = expected_annotations.with_offense_annotations(@offenses)
122
+
123
+ expect(actual_annotations).to eq(expected_annotations), ''
124
+ expect(@offenses.map(&:severity).uniq).to eq([severity]) if severity
87
125
 
88
- @processed_source = parse_source(expected_annotations.plain_source,
89
- file)
126
+ @offenses
127
+ end
90
128
 
91
- unless @processed_source.valid_syntax?
92
- raise 'Error parsing example code'
129
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
130
+ def expect_correction(correction, loop: true, source: nil)
131
+ if source
132
+ expected_annotations = parse_annotations(source, raise_error: false)
133
+ @processed_source = parse_processed_source(expected_annotations.plain_source)
134
+ _investigate(cop, @processed_source)
93
135
  end
94
136
 
95
- _investigate(cop, @processed_source)
96
- actual_annotations =
97
- expected_annotations.with_offense_annotations(cop.offenses)
137
+ raise '`expect_correction` must follow `expect_offense`' unless @processed_source
98
138
 
99
- expect(actual_annotations.to_s).to eq(expected_annotations.to_s)
100
- end
101
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
139
+ source = @processed_source.raw_source
140
+
141
+ iteration = 0
142
+ new_source = loop do
143
+ iteration += 1
144
+
145
+ corrected_source = @last_corrector.rewrite
102
146
 
103
- def expect_correction(correction)
104
- unless @processed_source
105
- raise '`expect_correction` must follow `expect_offense`'
147
+ break corrected_source unless loop
148
+ break corrected_source if @last_corrector.empty?
149
+ break corrected_source if corrected_source == @processed_source.buffer.source
150
+
151
+ if iteration > RuboCop::Runner::MAX_ITERATIONS
152
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
153
+ end
154
+
155
+ # Prepare for next loop
156
+ @processed_source = parse_source(corrected_source, @processed_source.path)
157
+ _investigate(cop, @processed_source)
106
158
  end
107
159
 
108
- corrector =
109
- RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
110
- new_source = corrector.rewrite
160
+ raise 'Use `expect_no_corrections` if the code will not change' if new_source == source
111
161
 
112
162
  expect(new_source).to eq(correction)
113
163
  end
164
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
114
165
 
115
166
  def expect_no_corrections
116
- unless @processed_source
117
- raise '`expect_no_corrections` must follow `expect_offense`'
118
- end
167
+ raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
119
168
 
120
- return if cop.corrections.empty?
169
+ return if @last_corrector.empty?
121
170
 
122
171
  # In order to print a nice diff, e.g. what source got corrected to,
123
172
  # we need to run the actual corrections
124
173
 
125
- corrector =
126
- RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
127
- new_source = corrector.rewrite
174
+ new_source = @last_corrector.rewrite
128
175
 
129
176
  expect(new_source).to eq(@processed_source.buffer.source)
130
177
  end
131
178
 
132
179
  def expect_no_offenses(source, file = nil)
133
- inspect_source(source, file)
180
+ offenses = inspect_source(source, file)
181
+
182
+ expected_annotations = AnnotatedSource.parse(source)
183
+ actual_annotations = expected_annotations.with_offense_annotations(offenses)
184
+ expect(actual_annotations.to_s).to eq(source)
185
+ end
186
+
187
+ def parse_annotations(source, raise_error: true, **replacements)
188
+ set_formatter_options
189
+
190
+ source = format_offense(source, **replacements)
191
+ annotations = AnnotatedSource.parse(source)
192
+ return annotations unless raise_error && annotations.plain_source == source
193
+
194
+ raise 'Use `expect_no_offenses` to assert that no offenses are found'
195
+ end
196
+
197
+ def parse_processed_source(source, file = nil)
198
+ processed_source = parse_source(source, file)
199
+ return processed_source if processed_source.valid_syntax?
200
+
201
+ raise 'Error parsing example code: ' \
202
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
203
+ end
134
204
 
135
- expect(cop.offenses).to be_empty
205
+ def set_formatter_options
206
+ RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
207
+ RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
208
+ cop.instance_variable_get(:@options)[:auto_correct] = true
136
209
  end
137
210
 
138
211
  # Parsed representation of code annotated with the `^^^ Message` style
139
212
  class AnnotatedSource
140
- ANNOTATION_PATTERN = /\A\s*\^+ /.freeze
213
+ ANNOTATION_PATTERN = /\A\s*(\^+|\^{}) /.freeze
214
+ ABBREV = "[...]\n"
141
215
 
142
216
  # @param annotated_source [String] string passed to the matchers
143
217
  #
@@ -150,12 +224,13 @@ module RuboCop
150
224
  annotations = []
151
225
 
152
226
  annotated_source.each_line do |source_line|
153
- if source_line =~ ANNOTATION_PATTERN
227
+ if ANNOTATION_PATTERN.match?(source_line)
154
228
  annotations << [source.size, source_line]
155
229
  else
156
230
  source << source_line
157
231
  end
158
232
  end
233
+ annotations.each { |a| a[0] = 1 } if source.empty?
159
234
 
160
235
  new(source, annotations)
161
236
  end
@@ -171,6 +246,25 @@ module RuboCop
171
246
  @annotations = annotations.sort.freeze
172
247
  end
173
248
 
249
+ def ==(other)
250
+ other.is_a?(self.class) && other.lines == lines && match_annotations?(other)
251
+ end
252
+
253
+ # Dirty hack: expectations with [...] are rewritten when they match
254
+ # This way the diff is clean.
255
+ def match_annotations?(other)
256
+ annotations.zip(other.annotations) do |(_actual_line, actual_annotation),
257
+ (_expected_line, expected_annotation)|
258
+ if expected_annotation&.end_with?(ABBREV) &&
259
+ actual_annotation.start_with?(expected_annotation[0...-ABBREV.length])
260
+
261
+ expected_annotation.replace(actual_annotation)
262
+ end
263
+ end
264
+
265
+ annotations == other.annotations
266
+ end
267
+
174
268
  # Construct annotated source string (like what we parse)
175
269
  #
176
270
  # Reconstruct a deterministic annotated source string. This is
@@ -203,6 +297,7 @@ module RuboCop
203
297
 
204
298
  reconstructed.join
205
299
  end
300
+ alias inspect to_s
206
301
 
207
302
  # Return the plain source code without annotations
208
303
  #
@@ -221,6 +316,7 @@ module RuboCop
221
316
  offenses.map do |offense|
222
317
  indent = ' ' * offense.column
223
318
  carets = '^' * offense.column_length
319
+ carets = '^{}' if offense.column_length.zero?
224
320
 
225
321
  [offense.line, "#{indent}#{carets} #{offense.message}\n"]
226
322
  end
@@ -228,7 +324,7 @@ module RuboCop
228
324
  self.class.new(lines, offense_annotations)
229
325
  end
230
326
 
231
- private
327
+ protected
232
328
 
233
329
  attr_reader :lines, :annotations
234
330
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Support.require_rspec_core 'formatters/base_text_formatter'
4
+ RSpec::Support.require_rspec_core 'formatters/console_codes'
5
+
6
+ module RuboCop
7
+ module RSpec
8
+ # RSpec formatter for use with running `rake spec` in parallel. This formatter
9
+ # removes much of the noise from RSpec so that only the important information
10
+ # will be surfaced by test-queue.
11
+ # It also adds metadata to the output in order to more easily find the text
12
+ # needed for outputting after the parallel run completes.
13
+ class ParallelFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
14
+ ::RSpec::Core::Formatters.register self, :dump_pending, :dump_failures, :dump_summary
15
+
16
+ # Don't show pending tests
17
+ def dump_pending(*); end
18
+
19
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
20
+ # output goes where in the final parallelized output, and should not be
21
+ # removed!
22
+ def dump_failures(notification)
23
+ return if notification.failure_notifications.empty?
24
+
25
+ output.puts '# FAILURES BEGIN'
26
+ notification.failure_notifications.each do |failure|
27
+ output.puts failure.fully_formatted('*', colorizer)
28
+ end
29
+ output.puts
30
+ output.puts '# FAILURES END'
31
+ end
32
+
33
+ def dump_summary(summary)
34
+ output_summary(summary)
35
+ output_rerun_commands(summary)
36
+ end
37
+
38
+ private
39
+
40
+ def colorizer
41
+ @colorizer ||= ::RSpec::Core::Formatters::ConsoleCodes
42
+ end
43
+
44
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
45
+ # output goes where in the final parallelized output, and should not be
46
+ # removed!
47
+ def output_summary(summary)
48
+ output.puts '# SUMMARY BEGIN'
49
+ output.puts colorize_summary(summary)
50
+ output.puts '# SUMMARY END'
51
+ end
52
+
53
+ def colorize_summary(summary)
54
+ totals = totals(summary)
55
+
56
+ if summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
57
+ colorizer.wrap(totals, ::RSpec.configuration.failure_color)
58
+ else
59
+ colorizer.wrap(totals, ::RSpec.configuration.success_color)
60
+ end
61
+ end
62
+
63
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
64
+ # output goes where in the final parallelized output, and should not be
65
+ # removed!
66
+ def output_rerun_commands(summary)
67
+ output.puts '# RERUN BEGIN'
68
+ output.puts summary.colorized_rerun_commands.lines[3..-1].join
69
+ output.puts '# RERUN END'
70
+ end
71
+
72
+ def totals(summary)
73
+ output = pluralize(summary.example_count, 'example')
74
+ output += ", #{summary.pending_count} pending" if summary.pending_count.positive?
75
+ output += ", #{pluralize(summary.failure_count, 'failure')}"
76
+
77
+ if summary.errors_outside_of_examples_count.positive?
78
+ error_count = pluralize(summary.errors_outside_of_examples_count, 'error')
79
+ output += ", #{error_count} occurred outside of examples"
80
+ end
81
+
82
+ output
83
+ end
84
+
85
+ def pluralize(*args)
86
+ ::RSpec::Core::Formatters::Helpers.pluralize(*args)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,33 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tmpdir'
4
- require 'fileutils'
5
4
 
6
5
  RSpec.shared_context 'isolated environment', :isolated_environment do
7
6
  around do |example|
8
7
  Dir.mktmpdir do |tmpdir|
9
8
  original_home = ENV['HOME']
9
+ original_xdg_config_home = ENV['XDG_CONFIG_HOME']
10
10
 
11
11
  # Make sure to expand all symlinks in the path first. Otherwise we may
12
12
  # get mismatched pathnames when loading config files later on.
13
13
  tmpdir = File.realpath(tmpdir)
14
14
 
15
+ virtual_home = File.expand_path(File.join(tmpdir, 'home'))
16
+ Dir.mkdir(virtual_home)
17
+ ENV['HOME'] = virtual_home
18
+ ENV.delete('XDG_CONFIG_HOME')
19
+
20
+ base_dir = example.metadata[:project_inside_home] ? virtual_home : tmpdir
21
+ root = example.metadata[:root]
22
+ working_dir = root ? File.join(base_dir, 'work', root) : File.join(base_dir, 'work')
23
+
15
24
  # Make upwards search for .rubocop.yml files stop at this directory.
16
- RuboCop::FileFinder.root_level = tmpdir
25
+ RuboCop::FileFinder.root_level = working_dir
17
26
 
18
27
  begin
19
- virtual_home = File.expand_path(File.join(tmpdir, 'home'))
20
- Dir.mkdir(virtual_home)
21
- ENV['HOME'] = virtual_home
28
+ FileUtils.mkdir_p(working_dir)
22
29
 
23
- working_dir = File.join(tmpdir, 'work')
24
- Dir.mkdir(working_dir)
25
-
26
- RuboCop::PathUtil.chdir(working_dir) do
27
- example.run
28
- end
30
+ Dir.chdir(working_dir) { example.run }
29
31
  ensure
30
32
  ENV['HOME'] = original_home
33
+ ENV['XDG_CONFIG_HOME'] = original_xdg_config_home
31
34
 
32
35
  RuboCop::FileFinder.root_level = nil
33
36
  end
@@ -35,40 +38,82 @@ RSpec.shared_context 'isolated environment', :isolated_environment do
35
38
  end
36
39
  end
37
40
 
38
- # `cop_config` must be declared with #let.
39
- RSpec.shared_context 'config', :config do
40
- let(:config) do
41
- # Module#<
42
- unless described_class < RuboCop::Cop::Cop
43
- raise '`config` must be used in `describe SomeCopClass do .. end`'
44
- end
41
+ RSpec.shared_context 'maintain registry', :restore_registry do
42
+ around(:each) { |example| RuboCop::Cop::Registry.with_temporary_global { example.run } }
43
+
44
+ def stub_cop_class(name, inherit: RuboCop::Cop::Base, &block)
45
+ klass = Class.new(inherit, &block)
46
+ stub_const(name, klass)
47
+ klass
48
+ end
49
+ end
45
50
 
46
- hash = { 'AllCops' => { 'TargetRubyVersion' => ruby_version } }
47
- hash['Rails'] = { 'Enabled' => true } if enabled_rails
48
- hash['AllCops']['TargetRailsVersion'] = rails_version if rails_version
49
- if respond_to?(:cop_config)
50
- cop_name = described_class.cop_name
51
- hash[cop_name] = RuboCop::ConfigLoader
52
- .default_configuration[cop_name]
53
- .merge(cop_config)
51
+ # This context assumes nothing and defines `cop`, among others.
52
+ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
53
+ ### Meant to be overridden at will
54
+
55
+ let(:cop_class) do
56
+ unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
57
+ raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
58
+ 'or RuboCop::Cop::Cop for legacy)'
54
59
  end
60
+ described_class
61
+ end
62
+
63
+ let(:cop_config) { {} }
64
+
65
+ let(:other_cops) { {} }
66
+
67
+ let(:cop_options) { {} }
68
+
69
+ ### Utilities
70
+
71
+ def source_range(range, buffer: source_buffer)
72
+ Parser::Source::Range.new(buffer, range.begin,
73
+ range.exclude_end? ? range.end : range.end + 1)
74
+ end
75
+
76
+ ### Useful intermediary steps (less likely to be overridden)
77
+
78
+ let(:processed_source) { parse_source(source, 'test') }
79
+
80
+ let(:source_buffer) { processed_source.buffer }
55
81
 
56
- hash = other_cops.merge hash if respond_to?(:other_cops)
82
+ let(:all_cops_config) do
83
+ rails = { 'TargetRubyVersion' => ruby_version }
84
+ rails['TargetRailsVersion'] = rails_version if rails_version
85
+ rails
86
+ end
87
+
88
+ let(:cur_cop_config) do
89
+ RuboCop::ConfigLoader
90
+ .default_configuration.for_cop(cop_class)
91
+ .merge({
92
+ 'Enabled' => true, # in case it is 'pending'
93
+ 'AutoCorrect' => true # in case defaults set it to false
94
+ })
95
+ .merge(cop_config)
96
+ end
97
+
98
+ let(:config) do
99
+ hash = { 'AllCops' => all_cops_config, cop_class.cop_name => cur_cop_config }.merge!(other_cops)
57
100
 
58
101
  RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
59
102
  end
60
- end
61
103
 
62
- RSpec.shared_context 'ruby 2.2', :ruby22 do
63
- let(:ruby_version) { 2.2 }
104
+ let(:cop) { cop_class.new(config, cop_options) }
64
105
  end
65
106
 
66
- RSpec.shared_context 'ruby 2.3', :ruby23 do
67
- let(:ruby_version) { 2.3 }
68
- end
107
+ RSpec.shared_context 'mock console output' do
108
+ before do
109
+ $stdout = StringIO.new
110
+ $stderr = StringIO.new
111
+ end
69
112
 
70
- RSpec.shared_context 'ruby 2.4', :ruby24 do
71
- let(:ruby_version) { 2.4 }
113
+ after do
114
+ $stdout = STDOUT
115
+ $stderr = STDERR
116
+ end
72
117
  end
73
118
 
74
119
  RSpec.shared_context 'ruby 2.5', :ruby25 do
@@ -79,18 +124,14 @@ RSpec.shared_context 'ruby 2.6', :ruby26 do
79
124
  let(:ruby_version) { 2.6 }
80
125
  end
81
126
 
82
- RSpec.shared_context 'with Rails', :enabled_rails do
83
- let(:enabled_rails) { true }
84
- end
85
-
86
- RSpec.shared_context 'with Rails 3', :rails3 do
87
- let(:rails_version) { 3.0 }
127
+ RSpec.shared_context 'ruby 2.7', :ruby27 do
128
+ let(:ruby_version) { 2.7 }
88
129
  end
89
130
 
90
- RSpec.shared_context 'with Rails 4', :rails4 do
91
- let(:rails_version) { 4.0 }
131
+ RSpec.shared_context 'ruby 3.0', :ruby30 do
132
+ let(:ruby_version) { 3.0 }
92
133
  end
93
134
 
94
- RSpec.shared_context 'with Rails 5', :rails5 do
95
- let(:rails_version) { 5.0 }
135
+ RSpec.shared_context 'ruby 3.1', :ruby31 do
136
+ let(:ruby_version) { 3.1 }
96
137
  end
@@ -5,8 +5,8 @@
5
5
  require_relative 'cop_helper'
6
6
  require_relative 'host_environment_simulation_helper'
7
7
  require_relative 'shared_contexts'
8
- require_relative 'shared_examples'
9
8
  require_relative 'expect_offense'
9
+ require_relative 'parallel_formatter'
10
10
 
11
11
  RSpec.configure do |config|
12
12
  config.include CopHelper