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,51 +6,33 @@ module RuboCop
6
6
  module SurroundingSpace
7
7
  include RangeHelp
8
8
 
9
- NO_SPACE_COMMAND = 'Do not use'.freeze
10
- SPACE_COMMAND = 'Use'.freeze
9
+ NO_SPACE_COMMAND = 'Do not use'
10
+ SPACE_COMMAND = 'Use'
11
+
12
+ SINGLE_SPACE_REGEXP = /[ \t]/.freeze
11
13
 
12
14
  private
13
15
 
14
16
  def side_space_range(range:, side:)
15
- buffer = @processed_source.buffer
17
+ buffer = processed_source.buffer
16
18
  src = buffer.source
17
19
 
18
20
  begin_pos = range.begin_pos
19
21
  end_pos = range.end_pos
20
22
  if side == :left
23
+ end_pos = begin_pos
21
24
  begin_pos = reposition(src, begin_pos, -1)
22
- end_pos -= 1
23
25
  end
24
26
  if side == :right
25
- begin_pos += 1
27
+ begin_pos = end_pos
26
28
  end_pos = reposition(src, end_pos, 1)
27
29
  end
28
30
  Parser::Source::Range.new(buffer, begin_pos, end_pos)
29
31
  end
30
32
 
31
- def index_of_first_token(node)
32
- range = node.source_range
33
- token_table[range.line][range.column]
34
- end
35
-
36
- def index_of_last_token(node)
37
- range = node.source_range
38
- table_row = token_table[range.last_line]
39
- (0...range.last_column).reverse_each do |c|
40
- ix = table_row[c]
41
- return ix if ix
42
- end
43
- end
44
-
45
- def token_table
46
- @token_table ||= begin
47
- table = {}
48
- @processed_source.tokens.each_with_index do |t, ix|
49
- table[t.line] ||= {}
50
- table[t.line][t.column] = ix
51
- end
52
- table
53
- end
33
+ def on_new_investigation
34
+ @token_table = nil
35
+ super
54
36
  end
55
37
 
56
38
  def no_space_offenses(node, # rubocop:disable Metrics/ParameterLists
@@ -85,22 +67,25 @@ module RuboCop
85
67
  return false unless token
86
68
 
87
69
  if side == :left
88
- String(token.space_after?) == ' '
70
+ SINGLE_SPACE_REGEXP.match?(String(token.space_after?))
89
71
  else
90
- String(token.space_before?) == ' '
72
+ SINGLE_SPACE_REGEXP.match?(String(token.space_before?))
91
73
  end
92
74
  end
93
75
 
94
76
  def reposition(src, pos, step)
95
77
  offset = step == -1 ? -1 : 0
96
- pos += step while src[pos + offset] =~ /[ \t]/
97
- pos < 0 ? 0 : pos
78
+ pos += step while SINGLE_SPACE_REGEXP.match?(src[pos + offset])
79
+ pos.negative? ? 0 : pos
98
80
  end
99
81
 
100
82
  def space_offense(node, token, side, message, command)
101
83
  range = side_space_range(range: token.pos, side: side)
102
- add_offense(node, location: range,
103
- message: format(message, command: command))
84
+ add_offense(range, message: format(message, command: command)) do |corrector|
85
+ autocorrect(corrector, node) unless ignored_node?(node)
86
+
87
+ ignore_node(node)
88
+ end
104
89
  end
105
90
 
106
91
  def empty_offenses(node, left, right, message)
@@ -114,8 +99,9 @@ module RuboCop
114
99
  end
115
100
 
116
101
  def empty_offense(node, range, message, command)
117
- add_offense(node, location: range,
118
- message: format(message, command: command))
102
+ add_offense(range, message: format(message, command: command)) do |corrector|
103
+ autocorrect(corrector, node)
104
+ end
119
105
  end
120
106
 
121
107
  def empty_brackets?(left_bracket_token, right_bracket_token)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Classes that include this module just implement functions for working
6
+ # with symbol nodes.
7
+ module SymbolHelp
8
+ def hash_key?(node)
9
+ node.parent&.pair_type? && node == node.parent.child_nodes.first
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,12 +4,16 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for checking target ruby version.
6
6
  module TargetRubyVersion
7
+ def required_minimum_ruby_version
8
+ @minimum_target_ruby_version
9
+ end
10
+
7
11
  def minimum_target_ruby_version(version)
8
12
  @minimum_target_ruby_version = version
9
13
  end
10
14
 
11
15
  def support_target_ruby_version?(version)
12
- @minimum_target_ruby_version <= version
16
+ required_minimum_ruby_version <= version
13
17
  end
14
18
  end
15
19
  end
@@ -6,12 +6,11 @@ module RuboCop
6
6
  module TrailingBody
7
7
  def trailing_body?(node)
8
8
  body = node.to_a.reverse[0]
9
- body && node.multiline? &&
10
- body_on_first_line?(node, body)
9
+ body && node.multiline? && body_on_first_line?(node, body)
11
10
  end
12
11
 
13
12
  def body_on_first_line?(node, body)
14
- node.source_range.first_line == body.source_range.first_line
13
+ same_line?(node, body)
15
14
  end
16
15
 
17
16
  def first_part_of(body)
@@ -8,7 +8,7 @@ module RuboCop
8
8
  include ConfigurableEnforcedStyle
9
9
  include RangeHelp
10
10
 
11
- MSG = '%<command>s comma after the last %<unit>s.'.freeze
11
+ MSG = '%<command>s comma after the last %<unit>s.'
12
12
 
13
13
  private
14
14
 
@@ -18,20 +18,22 @@ module RuboCop
18
18
 
19
19
  def check(node, items, kind, begin_pos, end_pos)
20
20
  after_last_item = range_between(begin_pos, end_pos)
21
-
22
- # If there is any heredoc in items, then match the comma succeeding
23
- # any whitespace (except newlines), otherwise allow for newlines
24
- comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
25
- comma_offset = after_last_item.source =~ comma_regex &&
26
- after_last_item.source.index(',')
21
+ comma_offset = comma_offset(items, after_last_item)
27
22
 
28
23
  if comma_offset && !inside_comment?(after_last_item, comma_offset)
29
24
  check_comma(node, kind, after_last_item.begin_pos + comma_offset)
30
25
  elsif should_have_comma?(style, node)
31
- put_comma(node, items, kind)
26
+ put_comma(items, kind)
32
27
  end
33
28
  end
34
29
 
30
+ def comma_offset(items, range)
31
+ # If there is any heredoc in items, then match the comma succeeding
32
+ # any whitespace (except newlines), otherwise allow for newlines
33
+ comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
34
+ comma_regex.match?(range.source) && range.source.index(',')
35
+ end
36
+
35
37
  def check_comma(node, kind, comma_pos)
36
38
  return if should_have_comma?(style, node)
37
39
 
@@ -72,10 +74,8 @@ module RuboCop
72
74
  end
73
75
 
74
76
  def inside_comment?(range, comma_offset)
75
- processed_source.comments.any? do |comment|
76
- comment_offset = comment.loc.expression.begin_pos - range.begin_pos
77
- comment_offset >= 0 && comment_offset < comma_offset
78
- end
77
+ comment = processed_source.comment_at_line(range.line)
78
+ comment && comment.loc.expression.begin_pos < range.begin_pos + comma_offset
79
79
  end
80
80
 
81
81
  # Returns true if the node has round/square/curly brackets.
@@ -91,9 +91,11 @@ module RuboCop
91
91
  end
92
92
 
93
93
  def method_name_and_arguments_on_same_line?(node)
94
- %i[send csend].include?(node.type) &&
95
- node.loc.selector.line == node.arguments.last.last_line &&
96
- node.last_line == node.arguments.last.last_line
94
+ return false unless node.call_type?
95
+
96
+ line = node.loc.selector.nil? ? node.loc.line : node.loc.selector.line
97
+
98
+ line == node.last_argument.last_line && node.last_line == node.last_argument.last_line
97
99
  end
98
100
 
99
101
  # A single argument with the closing bracket on the same line as the end
@@ -130,30 +132,28 @@ module RuboCop
130
132
 
131
133
  def avoid_comma(kind, comma_begin_pos, extra_info)
132
134
  range = range_between(comma_begin_pos, comma_begin_pos + 1)
133
- article = kind =~ /array/ ? 'an' : 'a'
135
+ article = /array/.match?(kind) ? 'an' : 'a'
134
136
  msg = format(
135
137
  MSG,
136
138
  command: 'Avoid',
137
139
  unit: format(kind, article: article) + extra_info.to_s
138
140
  )
139
141
 
140
- add_offense(range, location: range, message: msg)
142
+ add_offense(range, message: msg) do |corrector|
143
+ PunctuationCorrector.swap_comma(corrector, range)
144
+ end
141
145
  end
142
146
 
143
- def put_comma(node, items, kind)
144
- return if avoid_autocorrect?(elements(node))
145
-
147
+ def put_comma(items, kind)
146
148
  last_item = items.last
147
149
  return if last_item.block_pass_type?
148
150
 
149
151
  range = autocorrect_range(last_item)
150
- msg = format(
151
- MSG,
152
- command: 'Put a',
153
- unit: format(kind, article: 'a multiline')
154
- )
152
+ msg = format(MSG, command: 'Put a', unit: format(kind, article: 'a multiline'))
155
153
 
156
- add_offense(range, location: range, message: msg)
154
+ add_offense(range, message: msg) do |corrector|
155
+ PunctuationCorrector.swap_comma(corrector, range)
156
+ end
157
157
  end
158
158
 
159
159
  def autocorrect_range(item)
@@ -164,11 +164,6 @@ module RuboCop
164
164
  range_between(expr.begin_pos + ix, expr.end_pos)
165
165
  end
166
166
 
167
- # By default, there's no reason to avoid auto-correct.
168
- def avoid_autocorrect?(_nodes)
169
- false
170
- end
171
-
172
167
  def any_heredoc?(items)
173
168
  items.any? { |item| heredoc?(item) }
174
169
  end
@@ -186,9 +181,7 @@ module RuboCop
186
181
  # ...
187
182
  # SOURCE
188
183
  # })
189
- if node.pair_type? || node.hash_type?
190
- return heredoc?(node.children.last)
191
- end
184
+ return heredoc?(node.children.last) if node.pair_type? || node.hash_type?
192
185
 
193
186
  false
194
187
  end
@@ -4,20 +4,29 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality shared by Uncommunicative cops
6
6
  module UncommunicativeName
7
- CASE_MSG = 'Only use lowercase characters for %<name_type>s.'.freeze
8
- NUM_MSG = 'Do not end %<name_type>s with a number.'.freeze
9
- LENGTH_MSG = '%<name_type>s must be at least %<min>s ' \
10
- 'characters long.'.freeze
11
- FORBIDDEN_MSG = 'Do not use %<name>s as a name for a ' \
12
- '%<name_type>s.'.freeze
7
+ CASE_MSG = 'Only use lowercase characters for %<name_type>s.'
8
+ NUM_MSG = 'Do not end %<name_type>s with a number.'
9
+ LENGTH_MSG = '%<name_type>s must be at least %<min>s characters long.'
10
+ FORBIDDEN_MSG = 'Do not use %<name>s as a name for a %<name_type>s.'
13
11
 
14
12
  def check(node, args)
15
13
  args.each do |arg|
16
- name = arg.children.first.to_s
17
- next if (arg.restarg_type? || arg.kwrestarg_type?) && name.empty?
14
+ # Argument names might be "_" or prefixed with "_" to indicate they
15
+ # are unused. Trim away this prefix and only analyse the basename.
16
+ name_child = arg.children.first
17
+ next if name_child.nil?
18
+
19
+ full_name = name_child.to_s
20
+ next if full_name == '_'
21
+
22
+ name = full_name.gsub(/\A(_+)/, '')
18
23
  next if allowed_names.include?(name)
19
24
 
20
- range = arg_range(arg, name.size)
25
+ length = full_name.size
26
+ length += 1 if arg.restarg_type?
27
+ length += 2 if arg.kwrestarg_type?
28
+
29
+ range = arg_range(arg, length)
21
30
  issue_offenses(node, range, name)
22
31
  end
23
32
  end
@@ -34,37 +43,32 @@ module RuboCop
34
43
  end
35
44
 
36
45
  def case_offense(node, range)
37
- add_offense(node, location: range,
38
- message: format(CASE_MSG, name_type: name_type(node)))
46
+ add_offense(range, message: format(CASE_MSG, name_type: name_type(node)))
39
47
  end
40
48
 
41
49
  def uppercase?(name)
42
- name =~ /[[:upper:]]/
50
+ /[[:upper:]]/.match?(name)
43
51
  end
44
52
 
45
53
  def name_type(node)
46
- @name_type ||= begin
47
- case node.type
48
- when :block then 'block parameter'
49
- when :def, :defs then 'method parameter'
50
- end
51
- end
54
+ @name_type ||= case node.type
55
+ when :block then 'block parameter'
56
+ when :def, :defs then 'method parameter'
57
+ end
52
58
  end
53
59
 
54
60
  def num_offense(node, range)
55
- add_offense(node, location: range,
56
- message: format(NUM_MSG, name_type: name_type(node)))
61
+ add_offense(range, message: format(NUM_MSG, name_type: name_type(node)))
57
62
  end
58
63
 
59
64
  def ends_with_num?(name)
60
- name[-1] =~ /\d/
65
+ /\d/.match?(name[-1])
61
66
  end
62
67
 
63
68
  def length_offense(node, range)
64
- add_offense(node, location: range,
65
- message: format(LENGTH_MSG,
66
- name_type: name_type(node).capitalize,
67
- min: min_length))
69
+ message = format(LENGTH_MSG, name_type: name_type(node).capitalize, min: min_length)
70
+
71
+ add_offense(range, message: message)
68
72
  end
69
73
 
70
74
  def long_enough?(name)
@@ -73,17 +77,11 @@ module RuboCop
73
77
 
74
78
  def arg_range(arg, length)
75
79
  begin_pos = arg.source_range.begin_pos
76
- Parser::Source::Range.new(processed_source.buffer,
77
- begin_pos,
78
- begin_pos + length)
80
+ Parser::Source::Range.new(processed_source.buffer, begin_pos, begin_pos + length)
79
81
  end
80
82
 
81
83
  def forbidden_offense(node, range, name)
82
- add_offense(
83
- node,
84
- location: range,
85
- message: format(FORBIDDEN_MSG, name: name, name_type: name_type(node))
86
- )
84
+ add_offense(range, message: format(FORBIDDEN_MSG, name: name, name_type: name_type(node)))
87
85
  end
88
86
 
89
87
  def allowed_names
@@ -7,14 +7,8 @@ module RuboCop
7
7
  module UnusedArgument
8
8
  extend NodePattern::Macros
9
9
 
10
- def join_force?(force_class)
11
- force_class == VariableForce
12
- end
13
-
14
10
  def after_leaving_scope(scope, _variable_table)
15
- scope.variables.each_value do |variable|
16
- check_argument(variable)
17
- end
11
+ scope.variables.each_value { |variable| check_argument(variable) }
18
12
  end
19
13
 
20
14
  private
@@ -24,8 +18,10 @@ module RuboCop
24
18
  return if variable.referenced?
25
19
 
26
20
  message = message(variable)
27
- add_offense(variable.declaration_node, location: :name,
28
- message: message)
21
+
22
+ add_offense(variable.declaration_node.loc.name, message: message) do |corrector|
23
+ autocorrect(corrector, variable.declaration_node)
24
+ end
29
25
  end
30
26
  end
31
27
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Help methods for determining node visibility.
6
+ module VisibilityHelp
7
+ extend NodePattern::Macros
8
+
9
+ VISIBILITY_SCOPES = %i[private protected public].freeze
10
+
11
+ private
12
+
13
+ def node_visibility(node)
14
+ scope = find_visibility_start(node)
15
+ scope&.method_name || :public
16
+ end
17
+
18
+ def find_visibility_start(node)
19
+ node.left_siblings.reverse.find { |sibling| visibility_block?(sibling) }
20
+ end
21
+
22
+ # Navigate to find the last protected method
23
+ def find_visibility_end(node)
24
+ possible_visibilities = VISIBILITY_SCOPES - [node_visibility(node)]
25
+ right = node.right_siblings
26
+ right.find do |child_node|
27
+ possible_visibilities.include?(node_visibility(child_node))
28
+ end || right.last
29
+ end
30
+
31
+ # @!method visibility_block?(node)
32
+ def_node_matcher :visibility_block?, <<~PATTERN
33
+ (send nil? { :private :protected :public })
34
+ PATTERN
35
+ end
36
+ end
37
+ end
@@ -3,7 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Naming
6
- # This cop makes sure that accessor methods are named properly.
6
+ # This cop makes sure that accessor methods are named properly. Applies
7
+ # to both instance and class methods.
8
+ #
9
+ # NOTE: Offenses are only registered for methods with the expected
10
+ # arity. Getters (`get_attribute`) must have no arguments to be
11
+ # registered, and setters (`set_attribute(value)`) must have exactly
12
+ # one.
7
13
  #
8
14
  # @example
9
15
  # # bad
@@ -21,14 +27,24 @@ module RuboCop
21
27
  # # good
22
28
  # def attribute
23
29
  # end
24
- class AccessorMethodName < Cop
25
- MSG_READER = 'Do not prefix reader method names with `get_`.'.freeze
26
- MSG_WRITER = 'Do not prefix writer method names with `set_`.'.freeze
30
+ #
31
+ # # accepted, incorrect arity for getter
32
+ # def get_value(attr)
33
+ # end
34
+ #
35
+ # # accepted, incorrect arity for setter
36
+ # def set_value
37
+ # end
38
+ class AccessorMethodName < Base
39
+ MSG_READER = 'Do not prefix reader method names with `get_`.'
40
+ MSG_WRITER = 'Do not prefix writer method names with `set_`.'
27
41
 
28
42
  def on_def(node)
29
43
  return unless bad_reader_name?(node) || bad_writer_name?(node)
30
44
 
31
- add_offense(node, location: :name)
45
+ message = message(node)
46
+
47
+ add_offense(node.loc.name, message: message)
32
48
  end
33
49
  alias on_defs on_def
34
50
 
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Style/AsciiComments
4
-
5
3
  module RuboCop
6
4
  module Cop
7
5
  module Naming
8
- # This cop checks for non-ascii characters in identifier names.
6
+ # This cop checks for non-ascii characters in identifier and constant names.
7
+ # Identifiers are always checked and whether constants are checked
8
+ # can be controlled using AsciiConstants config.
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -36,27 +36,46 @@ module RuboCop
36
36
  # # good
37
37
  # params[:width_gteq]
38
38
  #
39
- class AsciiIdentifiers < Cop
39
+ # @example AsciiConstants: true (default)
40
+ # # bad
41
+ # class Foö
42
+ # end
43
+ #
44
+ # FOÖ = "foo"
45
+ #
46
+ # @example AsciiConstants: false
47
+ # # good
48
+ # class Foö
49
+ # end
50
+ #
51
+ # FOÖ = "foo"
52
+ #
53
+ class AsciiIdentifiers < Base
40
54
  include RangeHelp
41
55
 
42
- MSG = 'Use only ascii symbols in identifiers.'.freeze
56
+ IDENTIFIER_MSG = 'Use only ascii symbols in identifiers.'
57
+ CONSTANT_MSG = 'Use only ascii symbols in constants.'
43
58
 
44
- def investigate(processed_source)
59
+ def on_new_investigation
45
60
  processed_source.each_token do |token|
46
- next unless token.type == :tIDENTIFIER && !token.text.ascii_only?
61
+ next if !should_check?(token) || token.text.ascii_only?
47
62
 
48
- add_offense(token, location: first_offense_range(token))
63
+ message = token.type == :tIDENTIFIER ? IDENTIFIER_MSG : CONSTANT_MSG
64
+ add_offense(first_offense_range(token), message: message)
49
65
  end
50
66
  end
51
67
 
52
68
  private
53
69
 
70
+ def should_check?(token)
71
+ token.type == :tIDENTIFIER || (token.type == :tCONSTANT && cop_config['AsciiConstants'])
72
+ end
73
+
54
74
  def first_offense_range(identifier)
55
75
  expression = identifier.pos
56
76
  first_offense = first_non_ascii_chars(identifier.text)
57
77
 
58
- start_position = expression.begin_pos +
59
- identifier.text.index(first_offense)
78
+ start_position = expression.begin_pos + identifier.text.index(first_offense)
60
79
  end_position = start_position + first_offense.length
61
80
 
62
81
  range_between(start_position, end_position)
@@ -69,4 +88,3 @@ module RuboCop
69
88
  end
70
89
  end
71
90
  end
72
- # rubocop:enable Style/AsciiComments
@@ -13,29 +13,39 @@ module RuboCop
13
13
  #
14
14
  # # good
15
15
  # def +(other); end
16
- class BinaryOperatorParameterName < Cop
17
- MSG = 'When defining the `%<opr>s` operator, ' \
18
- 'name its argument `other`.'.freeze
16
+ class BinaryOperatorParameterName < Base
17
+ extend AutoCorrector
18
+
19
+ MSG = 'When defining the `%<opr>s` operator, name its argument `other`.'
19
20
 
20
21
  OP_LIKE_METHODS = %i[eql? equal?].freeze
21
- BLACKLISTED = %i[+@ -@ [] []= << === `].freeze
22
+ EXCLUDED = %i[+@ -@ [] []= << === ` =~].freeze
22
23
 
23
- def_node_matcher :op_method_candidate?, <<-PATTERN
24
+ # @!method op_method_candidate?(node)
25
+ def_node_matcher :op_method_candidate?, <<~PATTERN
24
26
  (def [#op_method? $_] (args $(arg [!:other !:_other])) _)
25
27
  PATTERN
26
28
 
27
29
  def on_def(node)
28
30
  op_method_candidate?(node) do |name, arg|
29
- add_offense(arg, message: format(MSG, opr: name))
31
+ add_offense(arg, message: format(MSG, opr: name)) do |corrector|
32
+ corrector.replace(arg, 'other')
33
+ node.each_descendant(:lvar, :lvasgn) do |lvar|
34
+ lvar_location = lvar.loc.name
35
+ next unless lvar_location.source == arg.source
36
+
37
+ corrector.replace(lvar_location, 'other')
38
+ end
39
+ end
30
40
  end
31
41
  end
32
42
 
33
43
  private
34
44
 
35
45
  def op_method?(name)
36
- return false if BLACKLISTED.include?(name)
46
+ return false if EXCLUDED.include?(name)
37
47
 
38
- name !~ /\A\w/ || OP_LIKE_METHODS.include?(name)
48
+ !/\A[[:word:]]/.match?(name) || OP_LIKE_METHODS.include?(name)
39
49
  end
40
50
  end
41
51
  end