rubocop 0.72.0 → 0.73.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +13 -0
  4. data/lib/rubocop.rb +2 -0
  5. data/lib/rubocop/ast/node.rb +8 -8
  6. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
  7. data/lib/rubocop/ast/traversal.rb +3 -3
  8. data/lib/rubocop/cop/autocorrect_logic.rb +71 -1
  9. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  10. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  11. data/lib/rubocop/cop/commissioner.rb +3 -9
  12. data/lib/rubocop/cop/cop.rb +36 -6
  13. data/lib/rubocop/cop/corrector.rb +2 -3
  14. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +2 -2
  15. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  16. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  17. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  18. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  19. data/lib/rubocop/cop/generator.rb +1 -1
  20. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -2
  21. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  22. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -2
  23. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
  24. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -2
  25. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
  26. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  27. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  28. data/lib/rubocop/cop/layout/indent_first_argument.rb +1 -1
  29. data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -2
  30. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  31. data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -0
  32. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +18 -4
  33. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +14 -2
  34. data/lib/rubocop/cop/layout/tab.rb +10 -22
  35. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -1
  36. data/lib/rubocop/cop/lint/debugger.rb +3 -3
  37. data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -3
  38. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  39. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  40. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  41. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  42. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  43. data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
  44. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
  45. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  46. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  47. data/lib/rubocop/cop/lint/number_conversion.rb +2 -2
  48. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  49. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  50. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
  51. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -5
  52. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  53. data/lib/rubocop/cop/lint/unified_integer.rb +1 -1
  54. data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -1
  55. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
  56. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  57. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
  58. data/lib/rubocop/cop/lint/uri_regexp.rb +2 -2
  59. data/lib/rubocop/cop/lint/useless_access_modifier.rb +6 -6
  60. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  61. data/lib/rubocop/cop/metrics/class_length.rb +1 -1
  62. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  63. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  64. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  65. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -1
  66. data/lib/rubocop/cop/mixin/enforce_superclass.rb +4 -4
  67. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  68. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
  69. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  70. data/lib/rubocop/cop/naming/constant_name.rb +2 -2
  71. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  72. data/lib/rubocop/cop/security/eval.rb +1 -1
  73. data/lib/rubocop/cop/security/json_load.rb +1 -1
  74. data/lib/rubocop/cop/security/marshal_load.rb +1 -1
  75. data/lib/rubocop/cop/security/open.rb +1 -1
  76. data/lib/rubocop/cop/security/yaml_load.rb +1 -1
  77. data/lib/rubocop/cop/style/alias.rb +1 -1
  78. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  79. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  80. data/lib/rubocop/cop/style/constant_visibility.rb +1 -1
  81. data/lib/rubocop/cop/style/date_time.rb +3 -3
  82. data/lib/rubocop/cop/style/dir.rb +1 -1
  83. data/lib/rubocop/cop/style/documentation_method.rb +1 -1
  84. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +49 -0
  85. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  86. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  87. data/lib/rubocop/cop/style/eval_with_location.rb +2 -2
  88. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  89. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  90. data/lib/rubocop/cop/style/float_division.rb +4 -4
  91. data/lib/rubocop/cop/style/format_string.rb +7 -7
  92. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  93. data/lib/rubocop/cop/style/inverse_methods.rb +2 -2
  94. data/lib/rubocop/cop/style/min_max.rb +1 -1
  95. data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
  96. data/lib/rubocop/cop/style/multiline_when_then.rb +55 -0
  97. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
  98. data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
  99. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -3
  100. data/lib/rubocop/cop/style/option_hash.rb +1 -1
  101. data/lib/rubocop/cop/style/or_assignment.rb +2 -2
  102. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  103. data/lib/rubocop/cop/style/random_with_offset.rb +6 -6
  104. data/lib/rubocop/cop/style/redundant_conditional.rb +2 -2
  105. data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
  106. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  107. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
  108. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
  109. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
  110. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  111. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  112. data/lib/rubocop/cop/style/sample.rb +1 -1
  113. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  114. data/lib/rubocop/cop/style/string_hash_keys.rb +2 -2
  115. data/lib/rubocop/cop/style/strip.rb +1 -1
  116. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
  117. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  118. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  119. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  120. data/lib/rubocop/cop/style/unneeded_sort.rb +1 -1
  121. data/lib/rubocop/cop/style/unpack_first.rb +1 -1
  122. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -5
  123. data/lib/rubocop/cop/team.rb +15 -14
  124. data/lib/rubocop/error.rb +23 -0
  125. data/lib/rubocop/node_pattern.rb +2 -2
  126. data/lib/rubocop/options.rb +17 -0
  127. data/lib/rubocop/rspec/shared_contexts.rb +12 -0
  128. data/lib/rubocop/target_finder.rb +6 -4
  129. data/lib/rubocop/version.rb +1 -1
  130. metadata +4 -2
@@ -22,7 +22,7 @@ module RuboCop
22
22
  class Open < Cop
23
23
  MSG = 'The use of `Kernel#open` is a serious security risk.'
24
24
 
25
- def_node_matcher :open?, <<-PATTERN
25
+ def_node_matcher :open?, <<~PATTERN
26
26
  (send nil? :open $!str ...)
27
27
  PATTERN
28
28
 
@@ -18,7 +18,7 @@ module RuboCop
18
18
  class YAMLLoad < Cop
19
19
  MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'
20
20
 
21
- def_node_matcher :yaml_load, <<-PATTERN
21
+ def_node_matcher :yaml_load, <<~PATTERN
22
22
  (send (const {nil? cbase} :YAML) :load ...)
23
23
  PATTERN
24
24
 
@@ -138,7 +138,7 @@ module RuboCop
138
138
  end
139
139
  end
140
140
 
141
- def_node_matcher :identifier, <<-PATTERN
141
+ def_node_matcher :identifier, <<~PATTERN
142
142
  (sym $_)
143
143
  PATTERN
144
144
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  class ColonMethodCall < Cop
21
21
  MSG = 'Do not use `::` for method calls.'
22
22
 
23
- def_node_matcher :java_type_node?, <<-PATTERN
23
+ def_node_matcher :java_type_node?, <<~PATTERN
24
24
  (send
25
25
  (const nil? :Java) _)
26
26
  PATTERN
@@ -223,7 +223,7 @@ module RuboCop
223
223
 
224
224
  # The shovel operator `<<` does not have its own type. It is a `send`
225
225
  # type.
226
- def_node_matcher :assignment_type?, <<-PATTERN
226
+ def_node_matcher :assignment_type?, <<~PATTERN
227
227
  {
228
228
  #{ASSIGNMENT_TYPES.join(' ')}
229
229
  (send _recv {:[]= :<< :=~ :!~ :<=> #end_with_eq?} ...)
@@ -57,7 +57,7 @@ module RuboCop
57
57
  end
58
58
  end
59
59
 
60
- def_node_matcher :visibility_declaration_for?, <<-PATTERN
60
+ def_node_matcher :visibility_declaration_for?, <<~PATTERN
61
61
  (send nil? {:public_constant :private_constant} ({sym str} %1))
62
62
  PATTERN
63
63
  end
@@ -45,15 +45,15 @@ module RuboCop
45
45
  CLASS_MSG = 'Prefer Time over DateTime.'
46
46
  COERCION_MSG = 'Do not use #to_datetime.'
47
47
 
48
- def_node_matcher :date_time?, <<-PATTERN
48
+ def_node_matcher :date_time?, <<~PATTERN
49
49
  (send (const {nil? (cbase)} :DateTime) ...)
50
50
  PATTERN
51
51
 
52
- def_node_matcher :historic_date?, <<-PATTERN
52
+ def_node_matcher :historic_date?, <<~PATTERN
53
53
  (send _ _ _ (const (const nil? :Date) _))
54
54
  PATTERN
55
55
 
56
- def_node_matcher :to_datetime?, <<-PATTERN
56
+ def_node_matcher :to_datetime?, <<~PATTERN
57
57
  (send _ :to_datetime)
58
58
  PATTERN
59
59
 
@@ -20,7 +20,7 @@ module RuboCop
20
20
  MSG = 'Use `__dir__` to get an absolute path to the current ' \
21
21
  "file's directory."
22
22
 
23
- def_node_matcher :dir_replacement?, <<-PATTERN
23
+ def_node_matcher :dir_replacement?, <<~PATTERN
24
24
  {(send (const nil? :File) :expand_path (send (const nil? :File) :dirname #file_keyword?))
25
25
  (send (const nil? :File) :dirname (send (const nil? :File) :realpath #file_keyword?))}
26
26
  PATTERN
@@ -53,7 +53,7 @@ module RuboCop
53
53
 
54
54
  MSG = 'Missing method documentation comment.'
55
55
 
56
- def_node_matcher :module_function_node?, <<-PATTERN
56
+ def_node_matcher :module_function_node?, <<~PATTERN
57
57
  (send nil? :module_function ...)
58
58
  PATTERN
59
59
 
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Lint/UnneededCopDisableDirective
4
+ # rubocop:disable Style/DoubleCopDisableDirective
5
+
6
+ module RuboCop
7
+ module Cop
8
+ module Style
9
+ # Detects double disable comments on one line. This is mostly to catch
10
+ # automatically generated comments that need to be regenerated.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # def f # rubocop:disable Style/For # rubocop:disable Metrics/AbcSize
15
+ # end
16
+ #
17
+ # # good
18
+ # # rubocop:disable Metrics/AbcSize
19
+ # def f # rubocop:disable Style/For
20
+ # end
21
+ # # rubocop:enable Metrics/AbcSize
22
+ #
23
+ # # if both fit on one line
24
+ # def f # rubocop:disable Style/For, Metrics/AbcSize
25
+ # end
26
+ #
27
+ class DoubleCopDisableDirective < Cop
28
+ # rubocop:enable Style/For, Style/DoubleCopDisableDirective
29
+ # rubocop:enable Lint/UnneededCopDisableDirective, Metrics/AbcSize
30
+ MSG = 'More than one disable comment on one line.'
31
+
32
+ def investigate(processed_source)
33
+ processed_source.comments.each do |comment|
34
+ next unless comment.text.scan('# rubocop:disable').size > 1
35
+
36
+ add_offense(comment)
37
+ end
38
+ end
39
+
40
+ def autocorrect(comment)
41
+ lambda do |corrector|
42
+ corrector.replace(comment.loc.expression,
43
+ comment.text[/# rubocop:disable \S+/])
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -49,7 +49,7 @@ module RuboCop
49
49
 
50
50
  private
51
51
 
52
- def_node_matcher :offending_each_range, <<-PATTERN
52
+ def_node_matcher :offending_each_range, <<~PATTERN
53
53
  (block (send (begin (${irange erange} (int $_) (int $_))) :each) (args) ...)
54
54
  PATTERN
55
55
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  MSG = 'Use `each_with_object` instead of `%<method>s`.'
23
23
  METHODS = %i[inject reduce].freeze
24
24
 
25
- def_node_matcher :each_with_object_candidate?, <<-PATTERN
25
+ def_node_matcher :each_with_object_candidate?, <<~PATTERN
26
26
  (block $(send _ {:inject :reduce} _) $_ $_)
27
27
  PATTERN
28
28
 
@@ -37,7 +37,7 @@ module RuboCop
37
37
  MSG_INCORRECT_LINE = 'Use `%<expected>s` instead of `%<actual>s`, ' \
38
38
  'as they are used by backtraces.'
39
39
 
40
- def_node_matcher :eval_without_location?, <<-PATTERN
40
+ def_node_matcher :eval_without_location?, <<~PATTERN
41
41
  {
42
42
  (send nil? :eval ${str dstr})
43
43
  (send nil? :eval ${str dstr} _)
@@ -53,7 +53,7 @@ module RuboCop
53
53
  }
54
54
  PATTERN
55
55
 
56
- def_node_matcher :line_with_offset?, <<-PATTERN
56
+ def_node_matcher :line_with_offset?, <<~PATTERN
57
57
  {
58
58
  (send #special_line_keyword? %1 (int %2))
59
59
  (send (int %2) %1 #special_line_keyword?)
@@ -18,7 +18,7 @@ module RuboCop
18
18
  class EvenOdd < Cop
19
19
  MSG = 'Replace with `Integer#%<method>s?`.'
20
20
 
21
- def_node_matcher :even_odd_candidate?, <<-PATTERN
21
+ def_node_matcher :even_odd_candidate?, <<~PATTERN
22
22
  (send
23
23
  {(send $_ :% (int 2))
24
24
  (begin (send $_ :% (int 2)))}
@@ -51,21 +51,21 @@ module RuboCop
51
51
  'instead of ' \
52
52
  '`Pathname.new(__FILE__).parent.expand_path`.'
53
53
 
54
- def_node_matcher :file_expand_path, <<-PATTERN
54
+ def_node_matcher :file_expand_path, <<~PATTERN
55
55
  (send
56
56
  (const nil? :File) :expand_path
57
57
  $_
58
58
  $_)
59
59
  PATTERN
60
60
 
61
- def_node_matcher :pathname_parent_expand_path, <<-PATTERN
61
+ def_node_matcher :pathname_parent_expand_path, <<~PATTERN
62
62
  (send
63
63
  (send
64
64
  (send nil? :Pathname
65
65
  $_) :parent) :expand_path)
66
66
  PATTERN
67
67
 
68
- def_node_matcher :pathname_new_parent_expand_path, <<-PATTERN
68
+ def_node_matcher :pathname_new_parent_expand_path, <<~PATTERN
69
69
  (send
70
70
  (send
71
71
  (send
@@ -42,16 +42,16 @@ module RuboCop
42
42
  class FloatDivision < Cop
43
43
  include ConfigurableEnforcedStyle
44
44
 
45
- def_node_matcher :right_coerce?, <<-PATTERN
45
+ def_node_matcher :right_coerce?, <<~PATTERN
46
46
  (send _ :/ (send _ :to_f))
47
47
  PATTERN
48
- def_node_matcher :left_coerce?, <<-PATTERN
48
+ def_node_matcher :left_coerce?, <<~PATTERN
49
49
  (send (send _ :to_f) :/ _)
50
50
  PATTERN
51
- def_node_matcher :both_coerce?, <<-PATTERN
51
+ def_node_matcher :both_coerce?, <<~PATTERN
52
52
  (send (send _ :to_f) :/ (send _ :to_f))
53
53
  PATTERN
54
- def_node_matcher :any_coerce?, <<-PATTERN
54
+ def_node_matcher :any_coerce?, <<~PATTERN
55
55
  {(send _ :/ (send _ :to_f)) (send (send _ :to_f) :/ _)}
56
56
  PATTERN
57
57
 
@@ -40,15 +40,15 @@ module RuboCop
40
40
 
41
41
  MSG = 'Favor `%<prefer>s` over `%<current>s`.'
42
42
 
43
- def_node_matcher :formatter, <<-PATTERN
44
- {
45
- (send nil? ${:sprintf :format} _ _ ...)
46
- (send {str dstr} $:% ... )
47
- (send !nil? $:% {array hash})
48
- }
43
+ def_node_matcher :formatter, <<~PATTERN
44
+ {
45
+ (send nil? ${:sprintf :format} _ _ ...)
46
+ (send {str dstr} $:% ... )
47
+ (send !nil? $:% {array hash})
48
+ }
49
49
  PATTERN
50
50
 
51
- def_node_matcher :variable_argument?, <<-PATTERN
51
+ def_node_matcher :variable_argument?, <<~PATTERN
52
52
  (send {str dstr} :% {send_type? lvar_type?})
53
53
  PATTERN
54
54
 
@@ -118,9 +118,9 @@ module RuboCop
118
118
 
119
119
  def alternative_style
120
120
  case style
121
- when :hash_rockets then
121
+ when :hash_rockets
122
122
  :ruby19
123
- when :ruby19, :ruby19_no_mixed_keys then
123
+ when :ruby19, :ruby19_no_mixed_keys
124
124
  :hash_rockets
125
125
  end
126
126
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
  [Style::Not]
48
48
  end
49
49
 
50
- def_node_matcher :inverse_candidate?, <<-PATTERN
50
+ def_node_matcher :inverse_candidate?, <<~PATTERN
51
51
  {
52
52
  (send $(send $(...) $_ $...) :!)
53
53
  (send (block $(send $(...) $_) $...) :!)
@@ -55,7 +55,7 @@ module RuboCop
55
55
  }
56
56
  PATTERN
57
57
 
58
- def_node_matcher :inverse_block?, <<-PATTERN
58
+ def_node_matcher :inverse_block?, <<~PATTERN
59
59
  (block $(send (...) $_) ... { $(send ... :!)
60
60
  $(send (...) {:!= :!~} ...)
61
61
  (begin ... $(send ... :!))
@@ -38,7 +38,7 @@ module RuboCop
38
38
 
39
39
  private
40
40
 
41
- def_node_matcher :min_max_candidate, <<-PATTERN
41
+ def_node_matcher :min_max_candidate, <<~PATTERN
42
42
  ({array return} (send [$_receiver !nil?] :min) (send [$_receiver !nil?] :max))
43
43
  PATTERN
44
44
 
@@ -44,7 +44,7 @@ module RuboCop
44
44
  MSG = '`%<statement>s` is used at the top level. Use inside `class` ' \
45
45
  'or `module`.'
46
46
 
47
- def_node_matcher :include_statement, <<-PATTERN
47
+ def_node_matcher :include_statement, <<~PATTERN
48
48
  (send nil? ${:include :extend :prepend}
49
49
  const)
50
50
  PATTERN
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop checks uses of the `then` keyword
7
+ # in multi-line when statements.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # case foo
12
+ # when bar then
13
+ # end
14
+ #
15
+ # # good
16
+ # case foo
17
+ # when bar
18
+ # end
19
+ #
20
+ # # good
21
+ # case foo
22
+ # when bar then do_something
23
+ # end
24
+ #
25
+ class MultilineWhenThen < Cop
26
+ include RangeHelp
27
+
28
+ MSG = 'Do not use `then` for multiline `when` statement.'
29
+
30
+ def on_when(node)
31
+ # Without `then`, there's no offense
32
+ return unless node.then?
33
+
34
+ # Single line usage of `then` is not an offense
35
+ return if !node.children.last.nil? && !node.multiline? && node.then?
36
+
37
+ # With more than one statements after then, there's not offense
38
+ return if node.children.last&.begin_type?
39
+
40
+ add_offense(node, location: :begin)
41
+ end
42
+
43
+ def autocorrect(node)
44
+ lambda do |corrector|
45
+ corrector.remove(
46
+ range_with_surrounding_space(
47
+ range: node.loc.begin, side: :left
48
+ )
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -30,7 +30,7 @@ module RuboCop
30
30
  private
31
31
 
32
32
  def_node_matcher :simple_double_comparison?, '(send $lvar :== $lvar)'
33
- def_node_matcher :simple_comparison?, <<-PATTERN
33
+ def_node_matcher :simple_comparison?, <<~PATTERN
34
34
  {(send $lvar :== _)
35
35
  (send _ :== $lvar)}
36
36
  PATTERN
@@ -143,13 +143,13 @@ module RuboCop
143
143
  end
144
144
  end
145
145
 
146
- def_node_matcher :splat_value, <<-PATTERN
146
+ def_node_matcher :splat_value, <<~PATTERN
147
147
  (array (splat $_))
148
148
  PATTERN
149
149
 
150
150
  # Some of these patterns may not actually return an immutable object,
151
151
  # but we want to consider them immutable for this cop.
152
- def_node_matcher :operation_produces_immutable_object?, <<-PATTERN
152
+ def_node_matcher :operation_produces_immutable_object?, <<~PATTERN
153
153
  {
154
154
  (const _ _)
155
155
  (send (const nil? :Struct) :new ...)
@@ -165,7 +165,7 @@ module RuboCop
165
165
  }
166
166
  PATTERN
167
167
 
168
- def_node_matcher :range_enclosed_in_parentheses?, <<-PATTERN
168
+ def_node_matcher :range_enclosed_in_parentheses?, <<~PATTERN
169
169
  (begin ({irange erange} _ _))
170
170
  PATTERN
171
171
  end
@@ -120,15 +120,15 @@ module RuboCop
120
120
  end
121
121
  end
122
122
 
123
- def_node_matcher :predicate, <<-PATTERN
123
+ def_node_matcher :predicate, <<~PATTERN
124
124
  (send $(...) ${:zero? :positive? :negative?})
125
125
  PATTERN
126
126
 
127
- def_node_matcher :comparison, <<-PATTERN
127
+ def_node_matcher :comparison, <<~PATTERN
128
128
  (send [$(...) !gvar_type?] ${:== :> :<} (int 0))
129
129
  PATTERN
130
130
 
131
- def_node_matcher :inverted_comparison, <<-PATTERN
131
+ def_node_matcher :inverted_comparison, <<~PATTERN
132
132
  (send (int 0) ${:== :> :<} [$(...) !gvar_type?])
133
133
  PATTERN
134
134
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  class OptionHash < Cop
23
23
  MSG = 'Prefer keyword arguments to options hashes.'
24
24
 
25
- def_node_matcher :option_hash, <<-PATTERN
25
+ def_node_matcher :option_hash, <<~PATTERN
26
26
  (args ... $(optarg [#suspicious_name? _] (hash)))
27
27
  PATTERN
28
28
 
@@ -29,7 +29,7 @@ module RuboCop
29
29
  class OrAssignment < Cop
30
30
  MSG = 'Use the double pipe equals operator `||=` instead.'
31
31
 
32
- def_node_matcher :ternary_assignment?, <<-PATTERN
32
+ def_node_matcher :ternary_assignment?, <<~PATTERN
33
33
  ({lvasgn ivasgn cvasgn gvasgn} _var
34
34
  (if
35
35
  ({lvar ivar cvar gvar} _var)
@@ -37,7 +37,7 @@ module RuboCop
37
37
  _))
38
38
  PATTERN
39
39
 
40
- def_node_matcher :unless_assignment?, <<-PATTERN
40
+ def_node_matcher :unless_assignment?, <<~PATTERN
41
41
  (if
42
42
  ({lvar ivar cvar gvar} _var) nil?
43
43
  ({lvasgn ivasgn cvasgn gvasgn} _var