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 cop checks whether the rescue and ensure keywords are aligned
7
7
  # properly.
8
8
  #
@@ -2,10 +2,10 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for colon (:) not followed by some kind of space.
7
7
  # N.B. this cop does not handle spaces after a ternary operator, which are
8
- # instead handled by Style/SpaceAroundOperators.
8
+ # instead handled by Layout/SpaceAroundOperators.
9
9
  class SpaceAfterColon < Cop
10
10
  MSG = 'Space missing after colon.'.freeze
11
11
 
@@ -2,13 +2,13 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for comma (,) not followed by some kind of space.
7
7
  class SpaceAfterComma < Cop
8
8
  include SpaceAfterPunctuation
9
9
 
10
10
  def space_style_before_rcurly
11
- cfg = config.for_cop('Style/SpaceInsideHashLiteralBraces')
11
+ cfg = config.for_cop('Layout/SpaceInsideHashLiteralBraces')
12
12
  cfg['EnforcedStyle'] || 'space'
13
13
  end
14
14
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for space between a method name and a left parenthesis in defs.
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 cop checks for space after `!`.
7
7
  #
8
8
  # @example
@@ -2,13 +2,13 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for semicolon (;) not followed by some kind of space.
7
7
  class SpaceAfterSemicolon < Cop
8
8
  include SpaceAfterPunctuation
9
9
 
10
10
  def space_style_before_rcurly
11
- cfg = config.for_cop('Style/SpaceInsideBlockBraces')
11
+ cfg = config.for_cop('Layout/SpaceInsideBlockBraces')
12
12
  cfg['EnforcedStyle'] || 'space'
13
13
  end
14
14
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks the spacing inside and after block parameters pipes.
7
7
  #
8
8
  # @example
@@ -16,15 +16,17 @@ module RuboCop
16
16
  include ConfigurableEnforcedStyle
17
17
 
18
18
  def on_block(node)
19
- _method, args, body = *node
19
+ return unless node.arguments?
20
+
21
+ args = node.arguments
22
+
20
23
  opening_pipe = args.loc.begin
21
24
  closing_pipe = args.loc.end
22
- return unless !args.children.empty? && opening_pipe
23
25
 
24
26
  check_inside_pipes(args.children, opening_pipe, closing_pipe)
25
27
 
26
- if body
27
- check_space(closing_pipe.end_pos, body.source_range.begin_pos,
28
+ if node.body
29
+ check_space(closing_pipe.end_pos, node.body.source_range.begin_pos,
28
30
  closing_pipe, 'after closing `|`')
29
31
  end
30
32
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks that the equals signs in parameter default assignments
7
7
  # have or don't have surrounding space depending on configuration.
8
8
  class SpaceAroundEqualsInParameterDefault < Cop
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks the spacing around the keywords.
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
  # Checks that operators have space around them, except for **
7
7
  # which should not have surrounding space.
8
8
  class SpaceAroundOperators < Cop
@@ -10,6 +10,10 @@ module RuboCop
10
10
 
11
11
  IRREGULAR_METHODS = %i[[] ! []=].freeze
12
12
 
13
+ def self.autocorrect_incompatible_with
14
+ [Style::SelfAssignment]
15
+ end
16
+
13
17
  def on_pair(node)
14
18
  return unless node.hash_rocket?
15
19
 
@@ -129,7 +133,7 @@ module RuboCop
129
133
  end
130
134
 
131
135
  def align_hash_cop_config
132
- config.for_cop('Style/AlignHash')
136
+ config.for_cop('Layout/AlignHash')
133
137
  end
134
138
 
135
139
  def hash_table_style?
@@ -2,14 +2,18 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks that block braces have or don't have a space before the opening
7
7
  # brace depending on configuration.
8
8
  class SpaceBeforeBlockBraces < Cop
9
9
  include ConfigurableEnforcedStyle
10
10
 
11
+ def self.autocorrect_incompatible_with
12
+ [Style::SymbolProc]
13
+ end
14
+
11
15
  def on_block(node)
12
- return if node.loc.begin.is?('do') # No braces.
16
+ return if node.keywords?
13
17
 
14
18
  left_brace = node.loc.begin
15
19
  space_plus_brace = range_with_surrounding_space(left_brace)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for comma (,) preceded by space.
7
7
  class SpaceBeforeComma < Cop
8
8
  include SpaceBeforePunctuation
@@ -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 missing space between a token and a comment on the
7
7
  # same line.
8
8
  class SpaceBeforeComment < Cop
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks that exactly one space is used between a method name and the
7
7
  # first argument for method calls without parentheses.
8
8
  #
@@ -14,10 +14,12 @@ module RuboCop
14
14
  # @bad
15
15
  # something x
16
16
  # something y, z
17
+ # something'hello'
17
18
  #
18
19
  # @good
19
20
  # something x
20
21
  # something y, z
22
+ # something 'hello'
21
23
  #
22
24
  class SpaceBeforeFirstArg < Cop
23
25
  include PrecedingFollowingAlignment
@@ -34,7 +36,7 @@ module RuboCop
34
36
  space = range_between(first_arg_with_space.begin_pos,
35
37
  first_arg.begin_pos)
36
38
 
37
- add_offense(space, space) if space.length > 1
39
+ add_offense(space, space) if space.length != 1
38
40
  end
39
41
 
40
42
  def autocorrect(range)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for semicolon (;) preceded by space.
7
7
  class SpaceBeforeSemicolon < Cop
8
8
  include SpaceBeforePunctuation
@@ -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 spaces between -> and opening parameter
7
7
  # brace in lambda literals.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for unnecessary additional spaces inside array percent literals
7
7
  # (i.e. %i/%w).
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks that block braces have or don't have surrounding space inside
7
7
  # them on configuration. For blocks taking parameters, it checks that the
8
8
  # left brace has or doesn't have trailing space depending on
@@ -12,7 +12,7 @@ module RuboCop
12
12
  include SurroundingSpace
13
13
 
14
14
  def on_block(node)
15
- return if node.loc.begin.is?('do') # No braces.
15
+ return if node.keywords?
16
16
 
17
17
  left_brace = node.loc.begin
18
18
  right_brace = node.loc.end
@@ -46,8 +46,7 @@ module RuboCop
46
46
  end
47
47
 
48
48
  def braces_with_contents_inside(node, inner)
49
- _method, args, _body = *node
50
- args_delimiter = args.loc.begin # Can be ( | or nil.
49
+ args_delimiter = node.arguments.loc.begin # Can be ( | or nil.
51
50
 
52
51
  check_left_brace(inner, node.loc.begin, args_delimiter)
53
52
  check_right_brace(inner, node.loc.end, block_length(node))
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for spaces inside square brackets.
7
7
  class SpaceInsideBrackets < Cop
8
8
  include SpaceInside
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks that braces used for hash literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  class SpaceInsideHashLiteralBraces < Cop
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for spaces inside ordinary round parentheses.
7
7
  class SpaceInsideParens < Cop
8
8
  include SpaceInside
@@ -2,18 +2,19 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for unnecessary additional spaces inside the delimiters of
7
7
  # %i/%w/%x literals.
8
8
  #
9
9
  # @example
10
- # @good
10
+ #
11
+ # # good
11
12
  # %i(foo bar baz)
12
13
  #
13
- # @bad
14
+ # # bad
14
15
  # %w( foo bar baz )
15
16
  #
16
- # @bad
17
+ # # bad
17
18
  # %x( ls -l )
18
19
  class SpaceInsidePercentLiteralDelimiters < Cop
19
20
  include MatchRange
@@ -27,11 +28,11 @@ module RuboCop
27
28
  process(node, '%i', '%I', '%w', '%W')
28
29
  end
29
30
 
30
- def on_percent_literal(node)
31
- add_offenses_for_unnecessary_spaces(node)
31
+ def on_xstr(node)
32
+ process(node, '%x')
32
33
  end
33
34
 
34
- def on_xstr(node)
35
+ def on_percent_literal(node)
35
36
  add_offenses_for_unnecessary_spaces(node)
36
37
  end
37
38
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # Checks for spaces inside range literals.
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 cop checks for whitespace within string interpolations.
7
7
  #
8
8
  # @example
@@ -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 tabs inside the source code.
9
9
  class Tab < Cop
10
10
  MSG = 'Tab detected.'.freeze
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop looks for trailing blank lines and a final newline in the
7
7
  # source code.
8
8
  class TrailingBlankLines < Cop
@@ -2,14 +2,14 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Style
5
+ module Layout
6
6
  # This cop looks for trailing whitespace in the source code.
7
7
  class TrailingWhitespace < Cop
8
8
  MSG = 'Trailing whitespace detected.'.freeze
9
9
 
10
10
  def investigate(processed_source)
11
11
  processed_source.lines.each_with_index do |line, index|
12
- next unless line =~ /.*[ \t]+$/
12
+ next unless line.end_with?(' ', "\t")
13
13
 
14
14
  range = source_range(processed_source.buffer,
15
15
  index + 1,
@@ -30,7 +30,7 @@ module RuboCop
30
30
 
31
31
  def on_send(node)
32
32
  return if node.parenthesized? || allowed_method?(node)
33
- return if lambda_argument?(node.first_argument)
33
+ return if lambda_argument?(node.last_argument)
34
34
 
35
35
  return unless method_with_block?(node.last_argument)
36
36
  last_param = node.last_argument.children.first
@@ -33,10 +33,10 @@ module RuboCop
33
33
  hash[:operator] = key
34
34
  end
35
35
 
36
- MSG_FORMAT = 'Ambiguous %{actual} operator. Parenthesize the method ' \
37
- "arguments if it's surely a %{actual} operator, or add " \
38
- 'a whitespace to the right of the `%{operator}` if it ' \
39
- 'should be a %{possible}.'.freeze
36
+ MSG_FORMAT = 'Ambiguous %<actual>s operator. Parenthesize the method ' \
37
+ "arguments if it's surely a %<actual>s operator, or add " \
38
+ 'a whitespace to the right of the `%<operator>s` if it ' \
39
+ 'should be a %<possible>s.'.freeze
40
40
 
41
41
  private
42
42
 
@@ -63,21 +63,6 @@ module RuboCop
63
63
  format(MSG, node.source)
64
64
  end
65
65
 
66
- def autocorrect(node)
67
- lambda do |corrector|
68
- if pry_rescue?(node)
69
- block = node.parent
70
- body = block.children[2] # (block <send> <parameters> <body>)
71
- corrector.replace(block.source_range, body.source)
72
- else
73
- range = node.source_range
74
- range = range_with_surrounding_space(range, :left, false)
75
- range = range_with_surrounding_space(range, :right, true)
76
- corrector.remove(range)
77
- end
78
- end
79
- end
80
-
81
66
  def binding_irb?(node)
82
67
  target_ruby_version >= 2.4 && binding_irb_call?(node)
83
68
  end