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
@@ -6,55 +6,64 @@ module RuboCop
6
6
  # refer to two or more cops under different departments
7
7
  class AmbiguousCopName < RuboCop::Error
8
8
  MSG = 'Ambiguous cop name `%<name>s` used in %<origin>s needs ' \
9
- 'department qualifier. Did you mean %<options>s?'.freeze
9
+ 'department qualifier. Did you mean %<options>s?'
10
10
 
11
11
  def initialize(name, origin, badges)
12
12
  super(
13
- format(
14
- MSG,
15
- name: name,
16
- origin: origin,
17
- options: badges.to_a.join(' or ')
18
- )
13
+ format(MSG, name: name, origin: origin, options: badges.to_a.join(' or '))
19
14
  )
20
15
  end
21
16
  end
22
17
 
23
18
  # Registry that tracks all cops by their badge and department.
24
19
  class Registry
25
- def initialize(cops = [])
20
+ include Enumerable
21
+
22
+ attr_reader :options
23
+
24
+ def initialize(cops = [], options = {})
26
25
  @registry = {}
27
26
  @departments = {}
28
27
  @cops_by_cop_name = Hash.new { |hash, key| hash[key] = [] }
29
28
 
30
- cops.each { |cop| enlist(cop) }
29
+ @enrollment_queue = cops
30
+ @options = options
31
31
  end
32
32
 
33
33
  def enlist(cop)
34
- @registry[cop.badge] = cop
35
- @departments[cop.department] ||= []
36
- @departments[cop.department] << cop
37
- @cops_by_cop_name[cop.cop_name] << cop
34
+ @enrollment_queue << cop
35
+ end
36
+
37
+ def dismiss(cop)
38
+ raise "Cop #{cop} could not be dismissed" unless @enrollment_queue.delete(cop)
38
39
  end
39
40
 
40
41
  # @return [Array<Symbol>] list of departments for current cops.
41
42
  def departments
43
+ clear_enrollment_queue
42
44
  @departments.keys
43
45
  end
44
46
 
45
47
  # @return [Registry] Cops for that specific department.
46
48
  def with_department(department)
49
+ clear_enrollment_queue
47
50
  with(@departments.fetch(department, []))
48
51
  end
49
52
 
50
53
  # @return [Registry] Cops not for a specific department.
51
54
  def without_department(department)
55
+ clear_enrollment_queue
52
56
  without_department = @departments.dup
53
57
  without_department.delete(department)
54
58
 
55
59
  with(without_department.values.flatten)
56
60
  end
57
61
 
62
+ # @return [Boolean] Checks if given name is department
63
+ def department?(name)
64
+ departments.include? name.to_sym
65
+ end
66
+
58
67
  def contains_cop_matching?(names)
59
68
  cops.any? { |cop| cop.match?(names) }
60
69
  end
@@ -65,17 +74,17 @@ module RuboCop
65
74
  #
66
75
  # cops = RuboCop::Cop::Cop.all
67
76
  # cops.
68
- # qualified_cop_name('Layout/IndentArray') # => 'Layout/IndentArray'
77
+ # qualified_cop_name('Layout/EndOfLine') # => 'Layout/EndOfLine'
69
78
  #
70
79
  # @example fixes incorrect namespaces
71
80
  #
72
81
  # cops = RuboCop::Cop::Cop.all
73
- # cops.qualified_cop_name('Lint/IndentArray') # => 'Layout/IndentArray'
82
+ # cops.qualified_cop_name('Lint/EndOfLine') # => 'Layout/EndOfLine'
74
83
  #
75
84
  # @example namespaces bare cop identifiers
76
85
  #
77
86
  # cops = RuboCop::Cop::Cop.all
78
- # cops.qualified_cop_name('IndentArray') # => 'Layout/IndentArray'
87
+ # cops.qualified_cop_name('EndOfLine') # => 'Layout/EndOfLine'
79
88
  #
80
89
  # @example passes back unrecognized cop names
81
90
  #
@@ -91,8 +100,9 @@ module RuboCop
91
100
  # @note Emits a warning if the provided name has an incorrect namespace
92
101
  #
93
102
  # @return [String] Qualified cop name
94
- def qualified_cop_name(name, path)
103
+ def qualified_cop_name(name, path, warn: true)
95
104
  badge = Badge.parse(name)
105
+ print_warning(name, path) if warn && department_missing?(badge, name)
96
106
  return name if registered?(badge)
97
107
 
98
108
  potential_badges = qualify_badge(badge)
@@ -104,44 +114,79 @@ module RuboCop
104
114
  end
105
115
  end
106
116
 
117
+ def department_missing?(badge, name)
118
+ !badge.qualified? && unqualified_cop_names.include?(name)
119
+ end
120
+
121
+ def print_warning(name, path)
122
+ message = "#{path}: Warning: no department given for #{name}."
123
+ if path.end_with?('.rb')
124
+ message += ' Run `rubocop -a --only Migration/DepartmentName` to fix.'
125
+ end
126
+ warn message
127
+ end
128
+
129
+ def unqualified_cop_names
130
+ clear_enrollment_queue
131
+ @unqualified_cop_names ||=
132
+ Set.new(@cops_by_cop_name.keys.map { |qn| File.basename(qn) }) <<
133
+ 'RedundantCopDisableDirective'
134
+ end
135
+
107
136
  # @return [Hash{String => Array<Class>}]
108
137
  def to_h
138
+ clear_enrollment_queue
109
139
  @cops_by_cop_name
110
140
  end
111
141
 
112
142
  def cops
143
+ clear_enrollment_queue
113
144
  @registry.values
114
145
  end
115
146
 
116
147
  def length
148
+ clear_enrollment_queue
117
149
  @registry.size
118
150
  end
119
151
 
120
- def enabled(config, only, only_safe = false)
121
- select do |cop|
122
- only.include?(cop.cop_name) || enabled?(cop, config, only_safe)
123
- end
152
+ def enabled(config, only = [], only_safe: false)
153
+ select { |cop| only.include?(cop.cop_name) || enabled?(cop, config, only_safe) }
124
154
  end
125
155
 
126
156
  def enabled?(cop, config, only_safe)
127
157
  cfg = config.for_cop(cop)
158
+
159
+ cop_enabled = cfg.fetch('Enabled') == true || enabled_pending_cop?(cfg, config)
160
+
128
161
  if only_safe
129
- cfg.fetch('Enabled') && cfg.fetch('Safe', true)
162
+ cop_enabled && cfg.fetch('Safe', true)
130
163
  else
131
- cfg.fetch('Enabled')
164
+ cop_enabled
132
165
  end
133
166
  end
134
167
 
168
+ def enabled_pending_cop?(cop_cfg, config)
169
+ return false if @options[:disable_pending_cops]
170
+
171
+ cop_cfg.fetch('Enabled') == 'pending' &&
172
+ (@options[:enable_pending_cops] || config.enabled_new_cops?)
173
+ end
174
+
135
175
  def names
136
176
  cops.map(&:cop_name)
137
177
  end
138
178
 
179
+ def names_for_department(department)
180
+ cops.select { |cop| cop.department == department.to_sym }.map(&:cop_name)
181
+ end
182
+
139
183
  def ==(other)
140
184
  cops == other.cops
141
185
  end
142
186
 
143
187
  def sort!
144
- @registry = Hash[@registry.sort_by { |badge, _| badge.cop_name }]
188
+ clear_enrollment_queue
189
+ @registry = @registry.sort_by { |badge, _| badge.cop_name }.to_h
145
190
 
146
191
  self
147
192
  end
@@ -157,16 +202,67 @@ module RuboCop
157
202
  # @param [String] cop_name
158
203
  # @return [Class, nil]
159
204
  def find_by_cop_name(cop_name)
160
- @cops_by_cop_name[cop_name].first
205
+ to_h[cop_name].first
206
+ end
207
+
208
+ def freeze
209
+ clear_enrollment_queue
210
+ unqualified_cop_names # build cache
211
+ super
212
+ end
213
+
214
+ @global = new
215
+
216
+ class << self
217
+ attr_reader :global
218
+ end
219
+
220
+ def self.all
221
+ global.without_department(:Test).cops
222
+ end
223
+
224
+ def self.qualified_cop_name(name, origin)
225
+ global.qualified_cop_name(name, origin)
226
+ end
227
+
228
+ # Changes momentarily the global registry
229
+ # Intended for testing purposes
230
+ def self.with_temporary_global(temp_global = global.dup)
231
+ previous = @global
232
+ @global = temp_global
233
+ yield
234
+ ensure
235
+ @global = previous
236
+ end
237
+
238
+ def self.reset!
239
+ @global = new
161
240
  end
162
241
 
163
242
  private
164
243
 
244
+ def initialize_copy(reg)
245
+ initialize(reg.cops, reg.options)
246
+ end
247
+
248
+ def clear_enrollment_queue
249
+ return if @enrollment_queue.empty?
250
+
251
+ @enrollment_queue.each do |cop|
252
+ @registry[cop.badge] = cop
253
+ @departments[cop.department] ||= []
254
+ @departments[cop.department] << cop
255
+ @cops_by_cop_name[cop.cop_name] << cop
256
+ end
257
+ @enrollment_queue = []
258
+ end
259
+
165
260
  def with(cops)
166
261
  self.class.new(cops)
167
262
  end
168
263
 
169
264
  def qualify_badge(badge)
265
+ clear_enrollment_queue
170
266
  @departments
171
267
  .map { |department, _| badge.with_department(department) }
172
268
  .select { |potential_badge| registered?(potential_badge) }
@@ -183,6 +279,7 @@ module RuboCop
183
279
  end
184
280
 
185
281
  def registered?(badge)
282
+ clear_enrollment_queue
186
283
  @registry.key?(badge)
187
284
  end
188
285
  end
@@ -11,10 +11,12 @@ module RuboCop
11
11
  #
12
12
  # eval(something)
13
13
  # binding.eval(something)
14
- class Eval < Cop
15
- MSG = 'The use of `eval` is a serious security risk.'.freeze
14
+ class Eval < Base
15
+ MSG = 'The use of `eval` is a serious security risk.'
16
+ RESTRICT_ON_SEND = %i[eval].freeze
16
17
 
17
- def_node_matcher :eval?, <<-PATTERN
18
+ # @!method eval?(node)
19
+ def_node_matcher :eval?, <<~PATTERN
18
20
  (send {nil? (send nil? :binding)} :eval $!str ...)
19
21
  PATTERN
20
22
 
@@ -22,7 +24,7 @@ module RuboCop
22
24
  eval?(node) do |code|
23
25
  return if code.dstr_type? && code.recursive_literal?
24
26
 
25
- add_offense(node, location: :selector)
27
+ add_offense(node.loc.selector)
26
28
  end
27
29
  end
28
30
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Security
6
+ # Checks for the first argument to `IO.read`, `IO.binread`, `IO.write`, `IO.binwrite`,
7
+ # `IO.foreach`, and `IO.readlines`.
8
+ #
9
+ # If argument starts with a pipe character (`'|'`) and the receiver is the `IO` class,
10
+ # a subprocess is created in the same way as `Kernel#open`, and its output is returned.
11
+ # `Kernel#open` may allow unintentional command injection, which is the reason these
12
+ # `IO` methods are a security risk.
13
+ # Consider to use `File.read` to disable the behavior of subprocess invocation.
14
+ #
15
+ # @safety
16
+ # This cop is unsafe because false positive will occur if the variable passed as
17
+ # the first argument is a command that is not a file path.
18
+ #
19
+ # @example
20
+ #
21
+ # # bad
22
+ # IO.read(path)
23
+ # IO.read('path')
24
+ #
25
+ # # good
26
+ # File.read(path)
27
+ # File.read('path')
28
+ # IO.read('| command') # Allow intentional command invocation.
29
+ #
30
+ class IoMethods < Base
31
+ extend AutoCorrector
32
+
33
+ MSG = '`File.%<method_name>s` is safer than `IO.%<method_name>s`.'
34
+ RESTRICT_ON_SEND = %i[read binread write binwrite foreach readlines].freeze
35
+
36
+ def on_send(node)
37
+ return unless (receiver = node.receiver) && receiver.source == 'IO'
38
+
39
+ argument = node.first_argument
40
+ return if argument.respond_to?(:value) && argument.value.strip.start_with?('|')
41
+
42
+ add_offense(node, message: format(MSG, method_name: node.method_name)) do |corrector|
43
+ corrector.replace(receiver, 'File')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -6,13 +6,14 @@ module RuboCop
6
6
  # This cop checks for the use of JSON class methods which have potential
7
7
  # security issues.
8
8
  #
9
- # Autocorrect is disabled by default because it's potentially dangerous.
10
- # If using a stream, like `JSON.load(open('file'))`, it will need to call
11
- # `#read` manually, like `JSON.parse(open('file').read)`.
12
- # If reading single values (rather than proper JSON objects), like
13
- # `JSON.load('false')`, it will need to pass the `quirks_mode: true`
14
- # option, like `JSON.parse('false', quirks_mode: true)`.
15
- # Other similar issues may apply.
9
+ # @safety
10
+ # This cop's autocorrection is unsafe because it's potentially dangerous.
11
+ # If using a stream, like `JSON.load(open('file'))`, it will need to call
12
+ # `#read` manually, like `JSON.parse(open('file').read)`.
13
+ # If reading single values (rather than proper JSON objects), like
14
+ # `JSON.load('false')`, it will need to pass the `quirks_mode: true`
15
+ # option, like `JSON.parse('false', quirks_mode: true)`.
16
+ # Other similar issues may apply.
16
17
  #
17
18
  # @example
18
19
  # # bad
@@ -22,24 +23,24 @@ module RuboCop
22
23
  # # good
23
24
  # JSON.parse("{}")
24
25
  #
25
- class JSONLoad < Cop
26
- MSG = 'Prefer `JSON.parse` over `JSON.%<method>s`.'.freeze
26
+ class JSONLoad < Base
27
+ extend AutoCorrector
27
28
 
28
- def_node_matcher :json_load, <<-PATTERN
29
+ MSG = 'Prefer `JSON.parse` over `JSON.%<method>s`.'
30
+ RESTRICT_ON_SEND = %i[load restore].freeze
31
+
32
+ # @!method json_load(node)
33
+ def_node_matcher :json_load, <<~PATTERN
29
34
  (send (const {nil? cbase} :JSON) ${:load :restore} ...)
30
35
  PATTERN
31
36
 
32
37
  def on_send(node)
33
38
  json_load(node) do |method|
34
- add_offense(node,
35
- location: :selector,
36
- message: format(MSG, method: method))
39
+ add_offense(node.loc.selector, message: format(MSG, method: method)) do |corrector|
40
+ corrector.replace(node.loc.selector, 'parse')
41
+ end
37
42
  end
38
43
  end
39
-
40
- def autocorrect(node)
41
- ->(corrector) { corrector.replace(node.loc.selector, 'parse') }
42
- end
43
44
  end
44
45
  end
45
46
  end
@@ -18,19 +18,19 @@ module RuboCop
18
18
  # # okish - deep copy hack
19
19
  # Marshal.load(Marshal.dump({}))
20
20
  #
21
- class MarshalLoad < Cop
22
- MSG = 'Avoid using `Marshal.%<method>s`.'.freeze
21
+ class MarshalLoad < Base
22
+ MSG = 'Avoid using `Marshal.%<method>s`.'
23
+ RESTRICT_ON_SEND = %i[load restore].freeze
23
24
 
24
- def_node_matcher :marshal_load, <<-PATTERN
25
+ # @!method marshal_load(node)
26
+ def_node_matcher :marshal_load, <<~PATTERN
25
27
  (send (const {nil? cbase} :Marshal) ${:load :restore}
26
28
  !(send (const {nil? cbase} :Marshal) :dump ...))
27
29
  PATTERN
28
30
 
29
31
  def on_send(node)
30
32
  marshal_load(node) do |method|
31
- add_offense(node,
32
- location: :selector,
33
- message: format(MSG, method: method))
33
+ add_offense(node.loc.selector, message: format(MSG, method: method))
34
34
  end
35
35
  end
36
36
  end
@@ -3,34 +3,52 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Security
6
- # This cop checks for the use of `Kernel#open`.
6
+ # This cop checks for the use of `Kernel#open` and `URI.open` with dynamic
7
+ # data.
7
8
  #
8
- # `Kernel#open` enables not only file access but also process invocation
9
- # by prefixing a pipe symbol (e.g., `open("| ls")`). So, it may lead to
10
- # a serious security risk by using variable input to the argument of
11
- # `Kernel#open`. It would be better to use `File.open`, `IO.popen` or
12
- # `URI#open` explicitly.
9
+ # `Kernel#open` and `URI.open` enable not only file access but also process
10
+ # invocation by prefixing a pipe symbol (e.g., `open("| ls")`).
11
+ # So, it may lead to a serious security risk by using variable input to
12
+ # the argument of `Kernel#open` and `URI.open`. It would be better to use
13
+ # `File.open`, `IO.popen` or `URI.parse#open` explicitly.
14
+ #
15
+ # NOTE: `open` and `URI.open` with literal strings are not flagged by this
16
+ # cop.
17
+ #
18
+ # @safety
19
+ # This cop could register false positives if `open` is redefined
20
+ # in a class and then used without a receiver in that class.
13
21
  #
14
22
  # @example
15
23
  # # bad
16
24
  # open(something)
25
+ # open("| #{something}")
26
+ # URI.open(something)
17
27
  #
18
28
  # # good
19
29
  # File.open(something)
20
30
  # IO.popen(something)
21
31
  # URI.parse(something).open
22
- class Open < Cop
23
- MSG = 'The use of `Kernel#open` is a serious security risk.'.freeze
32
+ #
33
+ # # good (literal strings)
34
+ # open("foo.text")
35
+ # open("| foo")
36
+ # URI.open("http://example.com")
37
+ class Open < Base
38
+ MSG = 'The use of `%<receiver>sopen` is a serious security risk.'
39
+ RESTRICT_ON_SEND = %i[open].freeze
24
40
 
25
- def_node_matcher :open?, <<-PATTERN
26
- (send nil? :open $!str ...)
41
+ # @!method open?(node)
42
+ def_node_matcher :open?, <<~PATTERN
43
+ (send ${nil? (const {nil? cbase} :URI)} :open $!str ...)
27
44
  PATTERN
28
45
 
29
46
  def on_send(node)
30
- open?(node) do |code|
47
+ open?(node) do |receiver, code|
31
48
  return if safe?(code)
32
49
 
33
- add_offense(node, location: :selector)
50
+ message = format(MSG, receiver: receiver ? "#{receiver.source}." : 'Kernel#')
51
+ add_offense(node.loc.selector, message: message)
34
52
  end
35
53
  end
36
54
 
@@ -7,6 +7,10 @@ module RuboCop
7
7
  # potential security issues leading to remote code execution when
8
8
  # loading from an untrusted source.
9
9
  #
10
+ # @safety
11
+ # The behaviour of the code might change depending on what was
12
+ # in the YAML payload, since `YAML.safe_load` is more restrictive.
13
+ #
10
14
  # @example
11
15
  # # bad
12
16
  # YAML.load("--- foo")
@@ -15,22 +19,24 @@ module RuboCop
15
19
  # YAML.safe_load("--- foo")
16
20
  # YAML.dump("foo")
17
21
  #
18
- class YAMLLoad < Cop
19
- MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'.freeze
22
+ class YAMLLoad < Base
23
+ extend AutoCorrector
24
+
25
+ MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'
26
+ RESTRICT_ON_SEND = %i[load].freeze
20
27
 
21
- def_node_matcher :yaml_load, <<-PATTERN
28
+ # @!method yaml_load(node)
29
+ def_node_matcher :yaml_load, <<~PATTERN
22
30
  (send (const {nil? cbase} :YAML) :load ...)
23
31
  PATTERN
24
32
 
25
33
  def on_send(node)
26
34
  yaml_load(node) do
27
- add_offense(node, location: :selector)
35
+ add_offense(node.loc.selector) do |corrector|
36
+ corrector.replace(node.loc.selector, 'safe_load')
37
+ end
28
38
  end
29
39
  end
30
-
31
- def autocorrect(node)
32
- ->(corrector) { corrector.replace(node.loc.selector, 'safe_load') }
33
- end
34
40
  end
35
41
  end
36
42
  end
@@ -6,11 +6,10 @@ module RuboCop
6
6
  class Severity
7
7
  include Comparable
8
8
 
9
- # @api private
10
- NAMES = %i[refactor convention warning error fatal].freeze
9
+ NAMES = %i[info refactor convention warning error fatal].freeze
11
10
 
12
11
  # @api private
13
- CODE_TABLE = { R: :refactor, C: :convention,
12
+ CODE_TABLE = { I: :info, R: :refactor, C: :convention,
14
13
  W: :warning, E: :error, F: :fatal }.freeze
15
14
 
16
15
  # @api public
@@ -19,10 +18,9 @@ module RuboCop
19
18
  #
20
19
  # @return [Symbol]
21
20
  # severity.
22
- # any of `:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
21
+ # any of `:info`, `:refactor`, `:convention`, `:warning`, `:error` or `:fatal`.
23
22
  attr_reader :name
24
23
 
25
- # @api private
26
24
  def self.name_from_code(code)
27
25
  name = code.to_sym
28
26
  CODE_TABLE[name] || name
@@ -31,30 +29,24 @@ module RuboCop
31
29
  # @api private
32
30
  def initialize(name_or_code)
33
31
  name = Severity.name_from_code(name_or_code)
34
- unless NAMES.include?(name)
35
- raise ArgumentError, "Unknown severity: #{name}"
36
- end
32
+ raise ArgumentError, "Unknown severity: #{name}" unless NAMES.include?(name)
37
33
 
38
34
  @name = name.freeze
39
35
  freeze
40
36
  end
41
37
 
42
- # @api private
43
38
  def to_s
44
39
  @name.to_s
45
40
  end
46
41
 
47
- # @api private
48
42
  def code
49
43
  @name.to_s[0].upcase
50
44
  end
51
45
 
52
- # @api private
53
46
  def level
54
47
  NAMES.index(name) + 1
55
48
  end
56
49
 
57
- # @api private
58
50
  def ==(other)
59
51
  @name == if other.is_a?(Symbol)
60
52
  other
@@ -63,12 +55,10 @@ module RuboCop
63
55
  end
64
56
  end
65
57
 
66
- # @api private
67
58
  def hash
68
59
  @name.hash
69
60
  end
70
61
 
71
- # @api private
72
62
  def <=>(other)
73
63
  level <=> other.level
74
64
  end