rubocop 0.48.1 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/config/default.yml +397 -357
  4. data/config/disabled.yml +29 -29
  5. data/config/enabled.yml +366 -326
  6. data/lib/rubocop.rb +85 -70
  7. data/lib/rubocop/ast/builder.rb +4 -1
  8. data/lib/rubocop/ast/node.rb +2 -2
  9. data/lib/rubocop/ast/node/and_node.rb +1 -1
  10. data/lib/rubocop/ast/node/args_node.rb +24 -0
  11. data/lib/rubocop/ast/node/block_node.rb +107 -0
  12. data/lib/rubocop/ast/node/case_node.rb +1 -1
  13. data/lib/rubocop/ast/node/ensure_node.rb +1 -1
  14. data/lib/rubocop/ast/node/for_node.rb +1 -1
  15. data/lib/rubocop/ast/node/if_node.rb +1 -1
  16. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +74 -0
  17. data/lib/rubocop/ast/node/or_node.rb +1 -1
  18. data/lib/rubocop/ast/node/pair_node.rb +1 -1
  19. data/lib/rubocop/ast/node/resbody_node.rb +1 -1
  20. data/lib/rubocop/ast/node/send_node.rb +36 -57
  21. data/lib/rubocop/ast/node/super_node.rb +42 -0
  22. data/lib/rubocop/ast/node/until_node.rb +1 -1
  23. data/lib/rubocop/ast/node/when_node.rb +1 -1
  24. data/lib/rubocop/ast/node/while_node.rb +1 -1
  25. data/lib/rubocop/cli.rb +10 -0
  26. data/lib/rubocop/config.rb +23 -7
  27. data/lib/rubocop/config_loader.rb +19 -3
  28. data/lib/rubocop/cop/badge.rb +1 -1
  29. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
  30. data/lib/rubocop/cop/commissioner.rb +1 -1
  31. data/lib/rubocop/cop/cop.rb +10 -0
  32. data/lib/rubocop/cop/{style → layout}/access_modifier_indentation.rb +33 -3
  33. data/lib/rubocop/cop/{style → layout}/align_array.rb +16 -1
  34. data/lib/rubocop/cop/{style → layout}/align_hash.rb +1 -1
  35. data/lib/rubocop/cop/{style → layout}/align_parameters.rb +29 -1
  36. data/lib/rubocop/cop/{style → layout}/block_end_newline.rb +10 -5
  37. data/lib/rubocop/cop/{style → layout}/case_indentation.rb +64 -1
  38. data/lib/rubocop/cop/{style → layout}/closing_parenthesis_indentation.rb +2 -2
  39. data/lib/rubocop/cop/{style → layout}/comment_indentation.rb +1 -1
  40. data/lib/rubocop/cop/{style → layout}/dot_position.rb +1 -1
  41. data/lib/rubocop/cop/{style → layout}/else_alignment.rb +1 -1
  42. data/lib/rubocop/cop/{style → layout}/empty_line_after_magic_comment.rb +1 -1
  43. data/lib/rubocop/cop/{style → layout}/empty_line_between_defs.rb +1 -1
  44. data/lib/rubocop/cop/{style → layout}/empty_lines.rb +1 -1
  45. data/lib/rubocop/cop/{style → layout}/empty_lines_around_access_modifier.rb +2 -7
  46. data/lib/rubocop/cop/{style → layout}/empty_lines_around_begin_body.rb +1 -1
  47. data/lib/rubocop/cop/{style → layout}/empty_lines_around_block_body.rb +2 -4
  48. data/lib/rubocop/cop/{style → layout}/empty_lines_around_class_body.rb +1 -1
  49. data/lib/rubocop/cop/{style → layout}/empty_lines_around_exception_handling_keywords.rb +1 -1
  50. data/lib/rubocop/cop/{style → layout}/empty_lines_around_method_body.rb +1 -1
  51. data/lib/rubocop/cop/{style → layout}/empty_lines_around_module_body.rb +1 -1
  52. data/lib/rubocop/cop/{style → layout}/end_of_line.rb +1 -1
  53. data/lib/rubocop/cop/{style → layout}/extra_spacing.rb +1 -1
  54. data/lib/rubocop/cop/{style → layout}/first_array_element_line_break.rb +1 -1
  55. data/lib/rubocop/cop/{style → layout}/first_hash_element_line_break.rb +1 -1
  56. data/lib/rubocop/cop/{style → layout}/first_method_argument_line_break.rb +1 -1
  57. data/lib/rubocop/cop/{style → layout}/first_method_parameter_line_break.rb +1 -1
  58. data/lib/rubocop/cop/{style → layout}/first_parameter_indentation.rb +1 -1
  59. data/lib/rubocop/cop/{style → layout}/indent_array.rb +1 -1
  60. data/lib/rubocop/cop/{style → layout}/indent_assignment.rb +1 -1
  61. data/lib/rubocop/cop/{style → layout}/indent_hash.rb +2 -2
  62. data/lib/rubocop/cop/{style → layout}/indent_heredoc.rb +3 -3
  63. data/lib/rubocop/cop/{style → layout}/indentation_consistency.rb +1 -1
  64. data/lib/rubocop/cop/{style → layout}/indentation_width.rb +10 -12
  65. data/lib/rubocop/cop/{style → layout}/initial_indentation.rb +1 -1
  66. data/lib/rubocop/cop/{style → layout}/leading_comment_space.rb +1 -1
  67. data/lib/rubocop/cop/{style → layout}/multiline_array_brace_layout.rb +1 -1
  68. data/lib/rubocop/cop/{style → layout}/multiline_assignment_layout.rb +1 -1
  69. data/lib/rubocop/cop/{style → layout}/multiline_block_layout.rb +21 -36
  70. data/lib/rubocop/cop/{style → layout}/multiline_hash_brace_layout.rb +5 -1
  71. data/lib/rubocop/cop/{style → layout}/multiline_method_call_brace_layout.rb +1 -1
  72. data/lib/rubocop/cop/{style → layout}/multiline_method_call_indentation.rb +3 -3
  73. data/lib/rubocop/cop/{style → layout}/multiline_method_definition_brace_layout.rb +1 -1
  74. data/lib/rubocop/cop/{style → layout}/multiline_operation_indentation.rb +6 -5
  75. data/lib/rubocop/cop/{style → layout}/rescue_ensure_alignment.rb +1 -1
  76. data/lib/rubocop/cop/{style → layout}/space_after_colon.rb +2 -2
  77. data/lib/rubocop/cop/{style → layout}/space_after_comma.rb +2 -2
  78. data/lib/rubocop/cop/{style → layout}/space_after_method_name.rb +1 -1
  79. data/lib/rubocop/cop/{style → layout}/space_after_not.rb +1 -1
  80. data/lib/rubocop/cop/{style → layout}/space_after_semicolon.rb +2 -2
  81. data/lib/rubocop/cop/{style → layout}/space_around_block_parameters.rb +7 -5
  82. data/lib/rubocop/cop/{style → layout}/space_around_equals_in_parameter_default.rb +1 -1
  83. data/lib/rubocop/cop/{style → layout}/space_around_keyword.rb +1 -1
  84. data/lib/rubocop/cop/{style → layout}/space_around_operators.rb +6 -2
  85. data/lib/rubocop/cop/{style → layout}/space_before_block_braces.rb +6 -2
  86. data/lib/rubocop/cop/{style → layout}/space_before_comma.rb +1 -1
  87. data/lib/rubocop/cop/{style → layout}/space_before_comment.rb +1 -1
  88. data/lib/rubocop/cop/{style → layout}/space_before_first_arg.rb +4 -2
  89. data/lib/rubocop/cop/{style → layout}/space_before_semicolon.rb +1 -1
  90. data/lib/rubocop/cop/{style → layout}/space_in_lambda_literal.rb +1 -1
  91. data/lib/rubocop/cop/{style → layout}/space_inside_array_percent_literal.rb +1 -1
  92. data/lib/rubocop/cop/{style → layout}/space_inside_block_braces.rb +3 -4
  93. data/lib/rubocop/cop/{style → layout}/space_inside_brackets.rb +1 -1
  94. data/lib/rubocop/cop/{style → layout}/space_inside_hash_literal_braces.rb +1 -1
  95. data/lib/rubocop/cop/{style → layout}/space_inside_parens.rb +1 -1
  96. data/lib/rubocop/cop/{style → layout}/space_inside_percent_literal_delimiters.rb +8 -7
  97. data/lib/rubocop/cop/{style → layout}/space_inside_range_literal.rb +1 -1
  98. data/lib/rubocop/cop/{style → layout}/space_inside_string_interpolation.rb +1 -1
  99. data/lib/rubocop/cop/{style → layout}/tab.rb +1 -1
  100. data/lib/rubocop/cop/{style → layout}/trailing_blank_lines.rb +1 -1
  101. data/lib/rubocop/cop/{style → layout}/trailing_whitespace.rb +2 -2
  102. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  103. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -4
  104. data/lib/rubocop/cop/lint/debugger.rb +0 -15
  105. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -1
  106. data/lib/rubocop/cop/lint/rescue_type.rb +81 -0
  107. data/lib/rubocop/cop/lint/script_permission.rb +42 -0
  108. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
  109. data/lib/rubocop/cop/message_annotator.rb +23 -13
  110. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  111. data/lib/rubocop/cop/mixin/array_min_size.rb +59 -0
  112. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +10 -11
  113. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  114. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  115. data/lib/rubocop/cop/mixin/enforce_superclass.rb +36 -0
  116. data/lib/rubocop/cop/mixin/hash_alignment.rb +1 -1
  117. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +7 -3
  118. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  119. data/lib/rubocop/cop/performance/caller.rb +41 -0
  120. data/lib/rubocop/cop/performance/compare_with_block.rb +60 -14
  121. data/lib/rubocop/cop/performance/double_start_end_with.rb +2 -2
  122. data/lib/rubocop/cop/performance/redundant_merge.rb +2 -0
  123. data/lib/rubocop/cop/rails/action_filter.rb +1 -3
  124. data/lib/rubocop/cop/rails/application_job.rb +32 -0
  125. data/lib/rubocop/cop/rails/application_record.rb +32 -0
  126. data/lib/rubocop/cop/rails/blank.rb +9 -3
  127. data/lib/rubocop/cop/rails/output_safety.rb +59 -15
  128. data/lib/rubocop/cop/rails/present.rb +9 -3
  129. data/lib/rubocop/cop/rails/relative_date_constant.rb +35 -4
  130. data/lib/rubocop/cop/rails/reversible_migration.rb +82 -18
  131. data/lib/rubocop/cop/rails/save_bang.rb +7 -2
  132. data/lib/rubocop/cop/rails/skips_model_validations.rb +7 -0
  133. data/lib/rubocop/cop/registry.rb +4 -3
  134. data/lib/rubocop/cop/security/eval.rb +9 -3
  135. data/lib/rubocop/cop/style/and_or.rb +1 -1
  136. data/lib/rubocop/cop/style/block_delimiters.rb +11 -17
  137. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
  138. data/lib/rubocop/cop/style/collection_methods.rb +1 -3
  139. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  140. data/lib/rubocop/cop/style/copyright.rb +2 -2
  141. data/lib/rubocop/cop/style/documentation_method.rb +1 -1
  142. data/lib/rubocop/cop/style/each_for_simple_loop.rb +2 -1
  143. data/lib/rubocop/cop/style/each_with_object.rb +10 -6
  144. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  145. data/lib/rubocop/cop/style/for.rb +4 -5
  146. data/lib/rubocop/cop/style/format_string.rb +49 -0
  147. data/lib/rubocop/cop/style/format_string_token.rb +141 -0
  148. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  149. data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -2
  150. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -1
  151. data/lib/rubocop/cop/style/inverse_methods.rb +10 -1
  152. data/lib/rubocop/cop/style/lambda.rb +9 -9
  153. data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -0
  154. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -3
  155. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -2
  156. data/lib/rubocop/cop/style/method_name.rb +8 -2
  157. data/lib/rubocop/cop/style/mixin_grouping.rb +41 -3
  158. data/lib/rubocop/cop/style/multiline_block_chain.rb +7 -11
  159. data/lib/rubocop/cop/style/multiple_comparison.rb +77 -0
  160. data/lib/rubocop/cop/style/next.rb +11 -22
  161. data/lib/rubocop/cop/style/parallel_assignment.rb +10 -19
  162. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -2
  163. data/lib/rubocop/cop/style/self_assignment.rb +4 -0
  164. data/lib/rubocop/cop/style/single_line_block_params.rb +23 -17
  165. data/lib/rubocop/cop/style/symbol_array.rb +24 -13
  166. data/lib/rubocop/cop/style/symbol_proc.rb +4 -0
  167. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  168. data/lib/rubocop/cop/style/unneeded_interpolation.rb +4 -0
  169. data/lib/rubocop/cop/style/word_array.rb +33 -53
  170. data/lib/rubocop/cop/style/yoda_condition.rb +78 -0
  171. data/lib/rubocop/cop/team.rb +1 -14
  172. data/lib/rubocop/cop/util.rb +16 -0
  173. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -11
  174. data/lib/rubocop/node_pattern.rb +52 -52
  175. data/lib/rubocop/options.rb +25 -0
  176. data/lib/rubocop/path_util.rb +17 -1
  177. data/lib/rubocop/result_cache.rb +8 -7
  178. data/lib/rubocop/rspec/expect_offense.rb +167 -0
  179. data/lib/rubocop/rspec/shared_examples.rb +0 -8
  180. data/lib/rubocop/rspec/support.rb +1 -0
  181. data/lib/rubocop/runner.rb +12 -2
  182. data/lib/rubocop/target_finder.rb +5 -0
  183. data/lib/rubocop/version.rb +1 -1
  184. metadata +101 -72
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks if empty lines exist around the bodies of `begin`
7
7
  # sections. This cop doesn't check empty lines at `begin` body
8
8
  # beginning/end and around method definition body.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks if empty lines exist around the bodies of methods.
7
7
  #
8
8
  # @example
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks if empty lines around the bodies of modules match
7
7
  # the configuration.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks for Windows-style line endings in the source code.
7
7
  class EndOfLine < Cop
8
8
  include ConfigurableEnforcedStyle
@@ -4,7 +4,7 @@ require 'set'
4
4
 
5
5
  module RuboCop
6
6
  module Cop
7
- module Style
7
+ module Layout
8
8
  # This cop checks for extra/unnecessary whitespace.
9
9
  #
10
10
  # @example
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks for a line break before the first element in a
7
7
  # multi-line array.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks for a line break before the first element in a
7
7
  # multi-line hash.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks for a line break before the first argument in a
7
7
  # multi-line method call.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks for a line break before the first parameter in a
7
7
  # multi-line method parameter definition.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks the indentation of the first parameter in a method call.
7
7
  # Parameters after the first one are checked by Style/AlignParameters, not
8
8
  # by this cop.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks the indentation of the first element in an array literal
7
7
  # where the opening bracket and the first element are on separate lines.
8
8
  # The other elements' indentations are handled by the AlignArray cop.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks the indentation of the first line of the
7
7
  # right-hand-side of a multi-line assignment.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks the indentation of the first key in a hash literal
7
7
  # where the opening brace and the first key are on separate lines. The
8
8
  # other keys' indentations are handled by the AlignHash cop.
@@ -102,7 +102,7 @@ module RuboCop
102
102
  def separator_style?(first_pair)
103
103
  separator = first_pair.loc.operator
104
104
  key = "Enforced#{separator.is?(':') ? 'Colon' : 'HashRocket'}Style"
105
- config.for_cop('Style/AlignHash')[key] == 'separator'
105
+ config.for_cop('Layout/AlignHash')[key] == 'separator'
106
106
  end
107
107
 
108
108
  def check_based_on_longest_key(pairs, left_brace, left_parenthesis)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks the indentation of the here document bodies. The bodies
7
7
  # are indented one step.
8
8
  # In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you
@@ -105,8 +105,8 @@ module RuboCop
105
105
  if heredoc_indent_type(node) == '~'
106
106
  corrector.replace(node.loc.heredoc_body, indented_body(node))
107
107
  else
108
- heredoc_begenning = node.loc.expression.source
109
- corrected = heredoc_begenning.sub(/<<-?/, '<<~')
108
+ heredoc_beginning = node.loc.expression.source
109
+ corrected = heredoc_beginning.sub(/<<-?/, '<<~')
110
110
  corrector.replace(node.loc.expression, corrected)
111
111
  end
112
112
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks for inconsistent indentation.
7
7
  #
8
8
  # @example
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks for indentation that doesn't use the specified number
7
7
  # of spaces.
8
8
  #
@@ -45,7 +45,7 @@ module RuboCop
45
45
  # end
46
46
  # end
47
47
  # end
48
- class IndentationWidth < Cop # rubocop:disable Metrics/ClassLength
48
+ class IndentationWidth < Cop
49
49
  include EndKeywordAlignment
50
50
  include AutocorrectAlignment
51
51
  include OnMethodDef
@@ -75,17 +75,15 @@ module RuboCop
75
75
  end
76
76
 
77
77
  def on_block(node)
78
- _method, _args, body = *node
79
- # Check body against end/} indentation. Checking against variable
80
- # assignments, etc, would be more difficult. The end/} must be at the
81
- # beginning of its line.
82
- loc = node.loc
83
- return unless begins_its_line?(loc.end)
84
-
85
- check_indentation(loc.end, body)
78
+ end_loc = node.loc.end
79
+
80
+ return unless begins_its_line?(end_loc)
81
+
82
+ check_indentation(end_loc, node.body)
83
+
86
84
  return unless indentation_consistency_style == 'rails'
87
85
 
88
- check_members(loc.end, [body])
86
+ check_members(end_loc, [node.body])
89
87
  end
90
88
 
91
89
  def on_module(node)
@@ -173,7 +171,7 @@ module RuboCop
173
171
  end
174
172
 
175
173
  def indentation_consistency_style
176
- config.for_cop('Style/IndentationConsistency')['EnforcedStyle']
174
+ config.for_cop('Layout/IndentationConsistency')['EnforcedStyle']
177
175
  end
178
176
 
179
177
  def check_assignment(node, rhs)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cops checks for indentation of the first non-blank non-comment
7
7
  # line in a file.
8
8
  class InitialIndentation < Cop
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks whether comments have a leading space
7
7
  # after the # denoting the start of the comment. The
8
8
  # leading space is not required for some RDoc special syntax,
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks that the closing brace in an array literal is either
7
7
  # on the same line as the last array element, or a new line.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks whether the multiline assignments have a newline
7
7
  # after the assignment operator.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks whether the multiline do end blocks have a newline
7
7
  # after the start of the block. Additionally, it checks whether the block
8
8
  # arguments, if any, are on the same line as the start of the block.
@@ -42,32 +42,22 @@ module RuboCop
42
42
  'block start.'.freeze
43
43
 
44
44
  def on_block(node)
45
- return if oneliner?(node)
45
+ return if node.single_line?
46
46
 
47
- # A block node has three children: the block start,
48
- # the arguments, and the expression. We care if the block start
49
- # with arguments and the expression start on the same line.
50
- _block_start, args, last_expression = node.children
51
- do_loc = node.loc.begin # Actually it's either do or {.
52
-
53
- if args_on_different_line?(do_loc.line, args)
54
- add_offense_for_expression(node, args, ARG_MSG)
47
+ unless args_on_beginning_line?(node)
48
+ add_offense_for_expression(node, node.arguments, ARG_MSG)
55
49
  end
56
50
 
57
- return unless last_expression
58
- expression_loc = last_expression.loc
59
- return unless do_loc.line == expression_loc.line
60
- add_offense_for_expression(node, last_expression, MSG)
61
- end
51
+ return unless node.body && node.loc.begin.line == node.body.loc.line
62
52
 
63
- def oneliner?(node)
64
- node.loc.begin.line == node.loc.end.line
53
+ add_offense_for_expression(node, node.body, MSG)
65
54
  end
66
55
 
67
- def args_on_different_line?(do_line, args)
68
- return false if args.children.empty?
56
+ private
69
57
 
70
- do_line != args.loc.last_line
58
+ def args_on_beginning_line?(node)
59
+ !node.arguments? ||
60
+ node.loc.begin.line == node.arguments.loc.last_line
71
61
  end
72
62
 
73
63
  def add_offense_for_expression(node, expr, msg)
@@ -79,31 +69,26 @@ module RuboCop
79
69
 
80
70
  def autocorrect(node)
81
71
  lambda do |corrector|
82
- _method, args, block_body = *node
83
- unless arguments_on_different_line?(node, args)
84
- autocorrect_arguments(corrector, node, args)
85
- expr_before_body = args.source_range.end
72
+ unless args_on_beginning_line?(node)
73
+ autocorrect_arguments(corrector, node)
74
+ expr_before_body = node.arguments.source_range.end
86
75
  end
87
76
 
88
- return unless block_body
77
+ return unless node.body
89
78
 
90
79
  expr_before_body ||= node.loc.begin
91
- if expr_before_body.line == block_body.loc.line
92
- autocorrect_body(corrector, node, block_body)
80
+
81
+ if expr_before_body.line == node.body.loc.line
82
+ autocorrect_body(corrector, node, node.body)
93
83
  end
94
84
  end
95
85
  end
96
86
 
97
- def arguments_on_different_line?(node, args)
98
- args.children.empty? || args.loc.last_line == node.loc.line
99
- end
100
-
101
- def autocorrect_arguments(corrector, node, args)
102
- end_pos =
103
- range_with_surrounding_space(args.source_range, :right, false)
104
- .end_pos
87
+ def autocorrect_arguments(corrector, node)
88
+ end_pos = range_with_surrounding_space(node.arguments.source_range,
89
+ :right, false).end_pos
105
90
  range = range_between(node.loc.begin.end.begin_pos, end_pos)
106
- corrector.replace(range, " |#{block_arg_string(args)}|")
91
+ corrector.replace(range, " |#{block_arg_string(node.arguments)}|")
107
92
  end
108
93
 
109
94
  def autocorrect_body(corrector, node, block_body)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks that the closing brace in a hash literal is either
7
7
  # on the same line as the last hash element, or a new line.
8
8
  #
@@ -72,6 +72,10 @@ module RuboCop
72
72
  ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
73
73
  'line as the last hash element.'.freeze
74
74
 
75
+ def self.autocorrect_incompatible_with
76
+ [Style::BracesAroundHashParameters]
77
+ end
78
+
75
79
  def on_hash(node)
76
80
  check_brace_layout(node)
77
81
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks that the closing brace in a method call is either
7
7
  # on the same line as the last method argument, or a new line.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks the indentation of the method name part in method calls
7
7
  # that span more than one line.
8
8
  #
@@ -56,7 +56,7 @@ module RuboCop
56
56
  return unless style == :aligned && cop_config['IndentationWidth']
57
57
 
58
58
  raise ValidationError,
59
- 'The `Style/MultilineMethodCallIndentation`' \
59
+ 'The `Layout/MultilineMethodCallIndentation`' \
60
60
  ' cop only accepts an `IndentationWidth` ' \
61
61
  'configuration parameter when ' \
62
62
  '`EnforcedStyle` is `indented`.'
@@ -188,7 +188,7 @@ module RuboCop
188
188
  end
189
189
 
190
190
  def semantic_alignment_node(node)
191
- return if argument_in_method_call(node)
191
+ return if argument_in_method_call(node, :with_parentheses)
192
192
 
193
193
  # descend to root of method chain
194
194
  node = node.receiver while node.receiver
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks that the closing brace in a method definition is either
7
7
  # on the same line as the last method parameter, or a new line.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop checks the indentation of the right hand side operand in
7
7
  # binary operations that span more than one line.
8
8
  #
@@ -28,7 +28,7 @@ module RuboCop
28
28
  def validate_config
29
29
  return unless style == :aligned && cop_config['IndentationWidth']
30
30
 
31
- raise ValidationError, 'The `Style/MultilineOperationIndentation`' \
31
+ raise ValidationError, 'The `Layout/MultilineOperationIndentation`' \
32
32
  ' cop only accepts an `IndentationWidth` ' \
33
33
  'configuration parameter when ' \
34
34
  '`EnforcedStyle` is `indented`.'
@@ -67,9 +67,10 @@ module RuboCop
67
67
  return true if begins_its_line?(assignment_rhs.source_range)
68
68
  end
69
69
 
70
- given_style == :aligned && (kw_node_with_special_indentation(node) ||
71
- assignment_node ||
72
- argument_in_method_call(node))
70
+ given_style == :aligned &&
71
+ (kw_node_with_special_indentation(node) ||
72
+ assignment_node ||
73
+ argument_in_method_call(node, :with_or_without_parentheses))
73
74
  end
74
75
 
75
76
  def message(node, lhs, rhs)