rubocop 1.46.0 → 1.52.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/config/default.yml +83 -11
  4. data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
  5. data/lib/rubocop/cli/command/execute_runner.rb +7 -2
  6. data/lib/rubocop/cli.rb +6 -6
  7. data/lib/rubocop/comment_config.rb +2 -0
  8. data/lib/rubocop/config.rb +7 -3
  9. data/lib/rubocop/config_loader.rb +8 -8
  10. data/lib/rubocop/config_obsoletion.rb +2 -2
  11. data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
  12. data/lib/rubocop/cop/base.rb +6 -2
  13. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  14. data/lib/rubocop/cop/cop.rb +2 -2
  15. data/lib/rubocop/cop/corrector.rb +1 -1
  16. data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -3
  17. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
  18. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
  19. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  20. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
  21. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -1
  22. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  23. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  24. data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
  25. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
  26. data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
  27. data/lib/rubocop/cop/internal_affairs/cop_description.rb +37 -13
  28. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
  29. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
  30. data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
  31. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +3 -3
  32. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  33. data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +1 -1
  34. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
  35. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
  36. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
  37. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  38. data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
  39. data/lib/rubocop/cop/layout/class_structure.rb +6 -3
  40. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -2
  41. data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
  42. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
  43. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  44. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
  45. data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
  46. data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
  47. data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
  48. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
  49. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
  50. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
  51. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
  52. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -4
  53. data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
  54. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  55. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  56. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
  57. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
  58. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
  59. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
  60. data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
  61. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
  62. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
  63. data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
  64. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
  65. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +3 -1
  66. data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
  67. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
  68. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  69. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
  70. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  71. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  72. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  73. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
  74. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  75. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
  76. data/lib/rubocop/cop/lint/else_layout.rb +1 -1
  77. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  78. data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
  79. data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
  80. data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -4
  81. data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
  82. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
  83. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  84. data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
  85. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
  86. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
  87. data/lib/rubocop/cop/lint/missing_super.rb +34 -2
  88. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  89. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
  90. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
  91. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
  92. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
  93. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  94. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  95. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -4
  96. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
  97. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
  98. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  99. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
  100. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  101. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
  102. data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
  103. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
  104. data/lib/rubocop/cop/lint/script_permission.rb +1 -1
  105. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
  106. data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -12
  107. data/lib/rubocop/cop/lint/syntax.rb +4 -0
  108. data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
  109. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
  110. data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
  111. data/lib/rubocop/cop/lint/useless_access_modifier.rb +9 -1
  112. data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
  113. data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
  114. data/lib/rubocop/cop/lint/useless_rescue.rb +4 -1
  115. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  116. data/lib/rubocop/cop/lint/void.rb +69 -9
  117. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  118. data/lib/rubocop/cop/metrics/class_length.rb +1 -0
  119. data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
  120. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
  121. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
  122. data/lib/rubocop/cop/migration/department_name.rb +1 -1
  123. data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
  124. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
  125. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  126. data/lib/rubocop/cop/mixin/comments_help.rb +9 -5
  127. data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
  128. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
  129. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -2
  130. data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
  131. data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
  132. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  133. data/lib/rubocop/cop/mixin/range_help.rb +1 -6
  134. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  135. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  136. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  137. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  138. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  139. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
  140. data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
  141. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +22 -7
  142. data/lib/rubocop/cop/naming/method_name.rb +3 -3
  143. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  144. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +12 -4
  145. data/lib/rubocop/cop/naming/variable_name.rb +6 -1
  146. data/lib/rubocop/cop/registry.rb +3 -1
  147. data/lib/rubocop/cop/style/accessor_grouping.rb +32 -7
  148. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
  149. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  150. data/lib/rubocop/cop/style/attr.rb +11 -1
  151. data/lib/rubocop/cop/style/begin_block.rb +1 -2
  152. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
  153. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  154. data/lib/rubocop/cop/style/block_delimiters.rb +11 -2
  155. data/lib/rubocop/cop/style/case_like_if.rb +20 -3
  156. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  157. data/lib/rubocop/cop/style/class_equality_comparison.rb +51 -40
  158. data/lib/rubocop/cop/style/collection_compact.rb +20 -7
  159. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  160. data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
  161. data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
  162. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  163. data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
  164. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
  165. data/lib/rubocop/cop/style/copyright.rb +6 -3
  166. data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
  167. data/lib/rubocop/cop/style/dir.rb +1 -1
  168. data/lib/rubocop/cop/style/dir_empty.rb +54 -0
  169. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
  170. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
  171. data/lib/rubocop/cop/style/documentation.rb +11 -5
  172. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  173. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  174. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  175. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  176. data/lib/rubocop/cop/style/eval_with_location.rb +8 -8
  177. data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
  178. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  179. data/lib/rubocop/cop/style/file_empty.rb +71 -0
  180. data/lib/rubocop/cop/style/file_read.rb +3 -3
  181. data/lib/rubocop/cop/style/file_write.rb +1 -1
  182. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  183. data/lib/rubocop/cop/style/guard_clause.rb +3 -1
  184. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
  185. data/lib/rubocop/cop/style/hash_except.rb +23 -12
  186. data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
  187. data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
  188. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  189. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  190. data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
  191. data/lib/rubocop/cop/style/if_unless_modifier.rb +111 -15
  192. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
  193. data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
  194. data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
  195. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
  196. data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
  197. data/lib/rubocop/cop/style/map_to_set.rb +4 -1
  198. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -9
  199. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
  200. data/lib/rubocop/cop/style/min_max.rb +3 -3
  201. data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
  202. data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
  203. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
  204. data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
  205. data/lib/rubocop/cop/style/negated_if_else_condition.rb +12 -7
  206. data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
  207. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  208. data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
  209. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
  210. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  211. data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
  212. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  213. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
  214. data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
  215. data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
  216. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  217. data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
  218. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  219. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  220. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
  221. data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
  222. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
  223. data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
  224. data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
  225. data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
  226. data/lib/rubocop/cop/style/require_order.rb +12 -8
  227. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
  228. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
  229. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  230. data/lib/rubocop/cop/style/select_by_regexp.rb +15 -5
  231. data/lib/rubocop/cop/style/semicolon.rb +12 -1
  232. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  233. data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -4
  234. data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
  235. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  236. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  237. data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
  238. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
  239. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  240. data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
  241. data/lib/rubocop/cop/style/unpack_first.rb +3 -3
  242. data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
  243. data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
  244. data/lib/rubocop/cop/team.rb +2 -2
  245. data/lib/rubocop/cop/util.rb +1 -1
  246. data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
  247. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  248. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  249. data/lib/rubocop/cop/variable_force.rb +1 -0
  250. data/lib/rubocop/cops_documentation_generator.rb +10 -3
  251. data/lib/rubocop/directive_comment.rb +3 -3
  252. data/lib/rubocop/ext/comment.rb +18 -0
  253. data/lib/rubocop/ext/regexp_node.rb +1 -1
  254. data/lib/rubocop/ext/regexp_parser.rb +1 -1
  255. data/lib/rubocop/formatter/junit_formatter.rb +4 -1
  256. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  257. data/lib/rubocop/options.rb +4 -1
  258. data/lib/rubocop/result_cache.rb +2 -2
  259. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  260. data/lib/rubocop/rspec/support.rb +1 -0
  261. data/lib/rubocop/server/cache.rb +1 -1
  262. data/lib/rubocop/server/client_command/exec.rb +2 -1
  263. data/lib/rubocop/server/core.rb +1 -1
  264. data/lib/rubocop/server/helper.rb +1 -1
  265. data/lib/rubocop/server/server_command/exec.rb +1 -1
  266. data/lib/rubocop/target_ruby.rb +3 -2
  267. data/lib/rubocop/version.rb +10 -6
  268. data/lib/rubocop.rb +13 -0
  269. metadata +23 -8
@@ -6,49 +6,40 @@ module RuboCop
6
6
  # Checks for a line break before the first element in a
7
7
  # multi-line array.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
9
+ # @example
10
10
  #
11
- # # bad
12
- # [ :a,
13
- # :b]
11
+ # # bad
12
+ # [ :a,
13
+ # :b]
14
14
  #
15
- # # bad
16
- # [ :a, {
17
- # :b => :c
18
- # }]
15
+ # # good
16
+ # [
17
+ # :a,
18
+ # :b]
19
19
  #
20
- # # good
21
- # [:a, :b]
20
+ # # good
21
+ # [:a, :b]
22
22
  #
23
- # # good
24
- # [
25
- # :a,
26
- # :b]
23
+ # @example AllowMultilineFinalElement: false (default)
27
24
  #
28
- # # good
29
- # [
30
- # :a, {
31
- # :b => :c
32
- # }]
25
+ # # bad
26
+ # [ :a, {
27
+ # :b => :c
28
+ # }]
33
29
  #
34
- # @example AllowMultilineFinalElement: true
30
+ # # good
31
+ # [
32
+ # :a, {
33
+ # :b => :c
34
+ # }]
35
35
  #
36
- # # bad
37
- # [ :a,
38
- # :b]
39
- #
40
- # # good
41
- # [ :a, {
42
- # :b => :c
43
- # }]
36
+ # @example AllowMultilineFinalElement: true
44
37
  #
45
- # # good
46
- # [
47
- # :a,
48
- # :b]
38
+ # # good
39
+ # [:a, {
40
+ # :b => :c
41
+ # }]
49
42
  #
50
- # # good
51
- # [:a, :b]
52
43
  class FirstArrayElementLineBreak < Base
53
44
  include FirstElementLineBreak
54
45
  extend AutoCorrector
@@ -6,17 +6,12 @@ module RuboCop
6
6
  # Checks for a line break before the first element in a
7
7
  # multi-line hash.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
9
+ # @example
10
10
  #
11
11
  # # bad
12
12
  # { a: 1,
13
13
  # b: 2}
14
14
  #
15
- # # bad
16
- # { a: 1, b: {
17
- # c: 3
18
- # }}
19
- #
20
15
  # # good
21
16
  # {
22
17
  # a: 1,
@@ -28,11 +23,14 @@ module RuboCop
28
23
  # c: 3
29
24
  # }}
30
25
  #
31
- # @example AllowMultilineFinalElement: true
26
+ # @example AllowMultilineFinalElement: false (default)
32
27
  #
33
28
  # # bad
34
- # { a: 1,
35
- # b: 2}
29
+ # { a: 1, b: {
30
+ # c: 3
31
+ # }}
32
+ #
33
+ # @example AllowMultilineFinalElement: true
36
34
  #
37
35
  # # bad
38
36
  # { a: 1,
@@ -45,16 +43,6 @@ module RuboCop
45
43
  # c: 3
46
44
  # }}
47
45
  #
48
- # # good
49
- # {
50
- # a: 1,
51
- # b: 2 }
52
- #
53
- # # good
54
- # {
55
- # a: 1, b: {
56
- # c: 3
57
- # }}
58
46
  class FirstHashElementLineBreak < Base
59
47
  include FirstElementLineBreak
60
48
  extend AutoCorrector
@@ -6,73 +6,63 @@ module RuboCop
6
6
  # Checks for a line break before the first argument in a
7
7
  # multi-line method call.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
10
- #
11
- # # bad
12
- # method(foo, bar,
13
- # baz)
14
- #
15
- # # bad
16
- # method(foo, bar, {
17
- # baz: "a",
18
- # qux: "b",
19
- # })
9
+ # @example
20
10
  #
21
- # # good
22
- # method(
23
- # foo, bar,
24
- # baz)
11
+ # # bad
12
+ # method(foo, bar,
13
+ # baz)
25
14
  #
26
- # # good
27
- # method(
28
- # foo, bar, {
29
- # baz: "a",
30
- # qux: "b",
31
- # })
15
+ # # good
16
+ # method(
17
+ # foo, bar,
18
+ # baz)
32
19
  #
33
20
  # # ignored
34
21
  # method foo, bar,
35
22
  # baz
36
23
  #
37
- # @example AllowMultilineFinalElement: true
24
+ # @example AllowMultilineFinalElement: false (default)
25
+ #
26
+ # # bad
27
+ # method(foo, bar, {
28
+ # baz: "a",
29
+ # qux: "b",
30
+ # })
38
31
  #
39
- # # bad
40
- # method(foo, bar,
41
- # baz)
32
+ # # good
33
+ # method(
34
+ # foo, bar, {
35
+ # baz: "a",
36
+ # qux: "b",
37
+ # })
42
38
  #
43
- # # bad
44
- # method(foo,
45
- # bar,
46
- # {
47
- # baz: "a",
48
- # qux: "b",
49
- # }
50
- # )
39
+ # @example AllowMultilineFinalElement: true
51
40
  #
52
- # # good
53
- # method(foo, bar, {
41
+ # # bad
42
+ # method(foo,
43
+ # bar,
44
+ # {
54
45
  # baz: "a",
55
46
  # qux: "b",
56
- # })
47
+ # }
48
+ # )
57
49
  #
58
- # # good
59
- # method(
60
- # foo, bar,
61
- # baz)
50
+ # # good
51
+ # method(foo, bar, {
52
+ # baz: "a",
53
+ # qux: "b",
54
+ # })
62
55
  #
63
- # # good
64
- # method(
65
- # foo,
66
- # bar,
67
- # {
68
- # baz: "a",
69
- # qux: "b",
70
- # }
71
- # )
56
+ # # good
57
+ # method(
58
+ # foo,
59
+ # bar,
60
+ # {
61
+ # baz: "a",
62
+ # qux: "b",
63
+ # }
64
+ # )
72
65
  #
73
- # # ignored
74
- # method foo, bar,
75
- # baz
76
66
  class FirstMethodArgumentLineBreak < Base
77
67
  include FirstElementLineBreak
78
68
  extend AutoCorrector
@@ -6,69 +6,52 @@ module RuboCop
6
6
  # Checks for a line break before the first parameter in a
7
7
  # multi-line method parameter definition.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
10
- #
11
- # # bad
12
- # def method(foo, bar,
13
- # baz)
14
- # do_something
15
- # end
16
- #
17
- # # bad
18
- # def method(foo, bar, baz = {
19
- # :a => "b",
20
- # })
21
- # do_something
22
- # end
9
+ # @example
23
10
  #
24
- # # good
25
- # def method(
26
- # foo, bar,
27
- # baz)
28
- # do_something
29
- # end
11
+ # # bad
12
+ # def method(foo, bar,
13
+ # baz)
14
+ # do_something
15
+ # end
30
16
  #
31
- # # good
32
- # def method(
33
- # foo, bar, baz = {
34
- # :a => "b",
35
- # })
36
- # do_something
37
- # end
17
+ # # good
18
+ # def method(
19
+ # foo, bar,
20
+ # baz)
21
+ # do_something
22
+ # end
38
23
  #
39
- # # ignored
40
- # def method foo,
41
- # bar
42
- # do_something
43
- # end
24
+ # # ignored
25
+ # def method foo,
26
+ # bar
27
+ # do_something
28
+ # end
44
29
  #
45
- # @example AllowMultilineFinalElement: true
30
+ # @example AllowMultilineFinalElement: false (default)
46
31
  #
47
- # # bad
48
- # def method(foo, bar,
49
- # baz)
50
- # do_something
51
- # end
32
+ # # bad
33
+ # def method(foo, bar, baz = {
34
+ # :a => "b",
35
+ # })
36
+ # do_something
37
+ # end
52
38
  #
53
- # # good
54
- # def method(foo, bar, baz = {
55
- # :a => "b",
56
- # })
57
- # do_something
58
- # end
39
+ # # good
40
+ # def method(
41
+ # foo, bar, baz = {
42
+ # :a => "b",
43
+ # })
44
+ # do_something
45
+ # end
59
46
  #
60
- # # good
61
- # def method(
62
- # foo, bar,
63
- # baz)
64
- # do_something
65
- # end
47
+ # @example AllowMultilineFinalElement: true
66
48
  #
67
- # # ignored
68
- # def method foo,
69
- # bar
70
- # do_something
71
- # end
49
+ # # good
50
+ # def method(foo, bar, baz = {
51
+ # :a => "b",
52
+ # })
53
+ # do_something
54
+ # end
72
55
  #
73
56
  class FirstMethodParameterLineBreak < Base
74
57
  include FirstElementLineBreak
@@ -67,7 +67,7 @@ module RuboCop
67
67
 
68
68
  outermost_send = outermost_send_on_same_line(heredoc_arg)
69
69
  return unless outermost_send
70
- return if end_keyword_before_closing_parentesis?(node)
70
+ return if end_keyword_before_closing_parenthesis?(node)
71
71
  return if subsequent_closing_parentheses_in_same_line?(outermost_send)
72
72
  return if exist_argument_between_heredoc_end_and_closing_parentheses?(node)
73
73
 
@@ -159,7 +159,7 @@ module RuboCop
159
159
 
160
160
  # Closing parenthesis helpers.
161
161
 
162
- def end_keyword_before_closing_parentesis?(parenthesized_send_node)
162
+ def end_keyword_before_closing_parenthesis?(parenthesized_send_node)
163
163
  parenthesized_send_node.ancestors.any? do |ancestor|
164
164
  ancestor.loc.respond_to?(:end) && ancestor.loc.end&.source == 'end'
165
165
  end
@@ -228,9 +228,9 @@ module RuboCop
228
228
  end
229
229
 
230
230
  def find_most_bottom_of_heredoc_end(arguments)
231
- arguments.map do |argument|
231
+ arguments.filter_map do |argument|
232
232
  argument.loc.heredoc_end.end_pos if argument.loc.respond_to?(:heredoc_end)
233
- end.compact.max
233
+ end.max
234
234
  end
235
235
 
236
236
  # Internal trailing comma helpers.
@@ -115,7 +115,7 @@ module RuboCop
115
115
  end
116
116
 
117
117
  def adjust_minus(corrector, node)
118
- heredoc_beginning = node.loc.expression.source
118
+ heredoc_beginning = node.source
119
119
  corrected = heredoc_beginning.sub(/<<-?/, '<<~')
120
120
  corrector.replace(node, corrected)
121
121
  end
@@ -139,7 +139,7 @@ module RuboCop
139
139
  end
140
140
 
141
141
  def base_indent_level(node)
142
- base_line_num = node.loc.expression.line
142
+ base_line_num = node.source_range.line
143
143
  base_line = processed_source.lines[base_line_num - 1]
144
144
  indent_level(base_line)
145
145
  end
@@ -34,7 +34,7 @@ module RuboCop
34
34
  private
35
35
 
36
36
  def first_token
37
- processed_source.find_token { |t| !t.text.start_with?('#') }
37
+ processed_source.tokens.find { |t| !t.text.start_with?('#') }
38
38
  end
39
39
 
40
40
  def space_before(token)
@@ -63,7 +63,7 @@ module RuboCop
63
63
  next if gemfile_ruby_comment?(comment)
64
64
 
65
65
  add_offense(comment) do |corrector|
66
- expr = comment.loc.expression
66
+ expr = comment.source_range
67
67
 
68
68
  corrector.insert_after(hash_mark(expr), ' ')
69
69
  end
@@ -51,12 +51,11 @@ module RuboCop
51
51
  private_constant :LINE_1_ENDING, :LINE_2_BEGINNING,
52
52
  :LEADING_STYLE_OFFENSE, :TRAILING_STYLE_OFFENSE
53
53
 
54
- # rubocop:disable Metrics/AbcSize
55
54
  def on_dstr(node)
56
55
  # Quick check if we possibly have line continuations.
57
56
  return unless node.source.include?('\\')
58
57
 
59
- end_of_first_line = node.loc.expression.begin_pos - node.loc.expression.column
58
+ end_of_first_line = node.source_range.begin_pos - node.source_range.column
60
59
 
61
60
  raw_lines(node).each_cons(2) do |raw_line_one, raw_line_two|
62
61
  end_of_first_line += raw_line_one.length
@@ -70,7 +69,6 @@ module RuboCop
70
69
  end
71
70
  end
72
71
  end
73
- # rubocop:enable Metrics/AbcSize
74
72
 
75
73
  private
76
74
 
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Ensures that each item in a multi-line array
7
7
  # starts on a separate line.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
9
+ # @example
10
10
  #
11
11
  # # bad
12
12
  # [
@@ -14,11 +14,6 @@ module RuboCop
14
14
  # c
15
15
  # ]
16
16
  #
17
- # # bad
18
- # [ a, b, foo(
19
- # bar
20
- # )]
21
- #
22
17
  # # good
23
18
  # [
24
19
  # a,
@@ -35,34 +30,20 @@ module RuboCop
35
30
  # )
36
31
  # ]
37
32
  #
38
- # @example AllowMultilineFinalElement: true
33
+ # @example AllowMultilineFinalElement: false (default)
39
34
  #
40
35
  # # bad
41
- # [
42
- # a, b,
43
- # c
44
- # ]
45
- #
46
- # # good
47
- # [ a, b, foo(
36
+ # [a, b, foo(
48
37
  # bar
49
38
  # )]
50
39
  #
51
- # # good
52
- # [
53
- # a,
54
- # b,
55
- # c
56
- # ]
40
+ # @example AllowMultilineFinalElement: true
57
41
  #
58
42
  # # good
59
- # [
60
- # a,
61
- # b,
62
- # foo(
63
- # bar
64
- # )
65
- # ]
43
+ # [a, b, foo(
44
+ # bar
45
+ # )]
46
+ #
66
47
  class MultilineArrayLineBreaks < Base
67
48
  include MultilineElementLineBreaks
68
49
  extend AutoCorrector
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Ensures that each key in a multi-line hash
7
7
  # starts on a separate line.
8
8
  #
9
- # @example AllowMultilineFinalElement: false (default)
9
+ # @example
10
10
  #
11
11
  # # bad
12
12
  # {
@@ -14,11 +14,6 @@ module RuboCop
14
14
  # c: 3
15
15
  # }
16
16
  #
17
- # # bad
18
- # { a: 1, b: {
19
- # c: 3,
20
- # }}
21
- #
22
17
  # # good
23
18
  # {
24
19
  # a: 1,
@@ -34,34 +29,20 @@ module RuboCop
34
29
  # }
35
30
  # }
36
31
  #
37
- # @example AllowMultilineFinalElement: true
32
+ # @example AllowMultilineFinalElement: false (default)
38
33
  #
39
34
  # # bad
40
- # {
41
- # a: 1, b: 2,
42
- # c: 3
43
- # }
44
- #
45
- # # good
46
35
  # { a: 1, b: {
47
36
  # c: 3,
48
37
  # }}
49
38
  #
50
- # # good
51
- # {
52
- # a: 1,
53
- # b: 2,
54
- # c: 3
55
- # }
56
- #
39
+ # @example AllowMultilineFinalElement: true
57
40
  #
58
41
  # # good
59
- # {
60
- # a: 1,
61
- # b: {
62
- # c: 3,
63
- # }
64
- # }
42
+ # { a: 1, b: {
43
+ # c: 3,
44
+ # }}
45
+ #
65
46
  class MultilineHashKeyLineBreaks < Base
66
47
  include MultilineElementLineBreaks
67
48
  extend AutoCorrector
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # NOTE: This cop does not move the first argument, if you want that to
10
10
  # be on a separate line, see `Layout/FirstMethodArgumentLineBreak`.
11
11
  #
12
- # @example AllowMultilineFinalElement: false (default)
12
+ # @example
13
13
  #
14
14
  # # bad
15
15
  # foo(a, b,
@@ -31,6 +31,8 @@ module RuboCop
31
31
  # # good
32
32
  # foo(a, b, c)
33
33
  #
34
+ # @example AllowMultilineFinalElement: false (default)
35
+ #
34
36
  # # good
35
37
  # foo(
36
38
  # a,
@@ -42,26 +44,6 @@ module RuboCop
42
44
  #
43
45
  # @example AllowMultilineFinalElement: true
44
46
  #
45
- # # bad
46
- # foo(a, b,
47
- # c
48
- # )
49
- #
50
- # # good
51
- # foo(a, b, {
52
- # foo: "bar",
53
- # })
54
- #
55
- # # good
56
- # foo(
57
- # a,
58
- # b,
59
- # c
60
- # )
61
- #
62
- # # good
63
- # foo(a, b, c)
64
- #
65
47
  # # good
66
48
  # foo(
67
49
  # a,
@@ -70,6 +52,7 @@ module RuboCop
70
52
  # foo: "bar",
71
53
  # }
72
54
  # )
55
+ #
73
56
  class MultilineMethodArgumentLineBreaks < Base
74
57
  include MultilineElementLineBreaks
75
58
  extend AutoCorrector
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # NOTE: This cop does not move the first argument, if you want that to
10
10
  # be on a separate line, see `Layout/FirstMethodParameterLineBreak`.
11
11
  #
12
- # @example AllowMultilineFinalElement: false (default)
12
+ # @example
13
13
  #
14
14
  # # bad
15
15
  # def foo(a, b,
@@ -17,12 +17,6 @@ module RuboCop
17
17
  # )
18
18
  # end
19
19
  #
20
- # # bad
21
- # def foo(a, b = {
22
- # foo: "bar",
23
- # })
24
- # end
25
- #
26
20
  # # good
27
21
  # def foo(
28
22
  # a,
@@ -44,40 +38,22 @@ module RuboCop
44
38
  # def foo(a, b, c)
45
39
  # end
46
40
  #
47
- # @example AllowMultilineFinalElement: true
41
+ # @example AllowMultilineFinalElement: false (default)
48
42
  #
49
43
  # # bad
50
- # def foo(a, b,
51
- # c
52
- # )
53
- # end
54
- #
55
- # # good
56
44
  # def foo(a, b = {
57
45
  # foo: "bar",
58
46
  # })
59
47
  # end
60
48
  #
61
- # # good
62
- # def foo(
63
- # a,
64
- # b,
65
- # c
66
- # )
67
- # end
49
+ # @example AllowMultilineFinalElement: true
68
50
  #
69
51
  # # good
70
- # def foo(
71
- # a,
72
- # b = {
73
- # foo: "bar",
74
- # }
75
- # )
52
+ # def foo(a, b = {
53
+ # foo: "bar",
54
+ # })
76
55
  # end
77
56
  #
78
- # # good
79
- # def foo(a, b, c)
80
- # end
81
57
  class MultilineMethodParameterLineBreaks < Base
82
58
  include MultilineElementLineBreaks
83
59
  extend AutoCorrector