rubocop 1.65.0 → 1.65.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/cop/cop.rb +2 -2
  3. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  4. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  5. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  6. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  7. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  8. data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
  9. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  10. data/lib/rubocop/cop/lint/debugger.rb +0 -4
  11. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  12. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +0 -4
  13. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  14. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  15. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  16. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  17. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  18. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  19. data/lib/rubocop/cop/lint/empty_when.rb +0 -2
  20. data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
  21. data/lib/rubocop/cop/lint/float_comparison.rb +3 -1
  22. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  23. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  24. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -5
  25. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  26. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  27. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  28. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
  29. data/lib/rubocop/cop/lint/loop.rb +6 -12
  30. data/lib/rubocop/cop/lint/nested_method_definition.rb +0 -6
  31. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  32. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  33. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  34. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  35. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  36. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  37. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  38. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  39. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  40. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  41. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  42. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
  43. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  44. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  45. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -5
  46. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -5
  47. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  48. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  49. data/lib/rubocop/cop/naming/predicate_name.rb +52 -26
  50. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  51. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  52. data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
  53. data/lib/rubocop/cop/style/eval_with_location.rb +12 -11
  54. data/lib/rubocop/cop/style/file_read.rb +2 -5
  55. data/lib/rubocop/cop/style/file_write.rb +2 -5
  56. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  57. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +0 -1
  58. data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
  59. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  60. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  61. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  62. data/lib/rubocop/cop/style/redundant_condition.rb +0 -1
  63. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  64. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  65. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  66. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  67. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -1
  68. data/lib/rubocop/cop/variable_force.rb +13 -1
  69. data/lib/rubocop/core_ext/string.rb +2 -6
  70. data/lib/rubocop/ext/regexp_node.rb +9 -31
  71. data/lib/rubocop/options.rb +3 -1
  72. data/lib/rubocop/version.rb +1 -1
  73. data/lib/rubocop.rb +5 -0
  74. metadata +7 -7
@@ -9,16 +9,12 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # rand 1
14
13
  # Kernel.rand(-1)
15
14
  # rand 1.0
16
15
  # rand(-1.0)
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # 0 # just use 0 instead
23
19
  class RandOne < Base
24
20
  MSG = '`%<method>s` always returns `0`. Perhaps you meant `rand(2)` or `rand`?'
@@ -14,14 +14,16 @@ module RuboCop
14
14
  #
15
15
  # When comment enables all cops at once `rubocop:enable all`
16
16
  # that cop checks whether any cop was actually enabled.
17
+ #
17
18
  # @example
19
+ #
18
20
  # # bad
19
21
  # foo = 1
20
22
  # # rubocop:enable Layout/LineLength
21
23
  #
22
24
  # # good
23
25
  # foo = 1
24
- # @example
26
+ #
25
27
  # # bad
26
28
  # # rubocop:disable Style/StringLiterals
27
29
  # foo = "1"
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # Checks for unneeded usages of splat expansion
6
+ # Checks for unneeded usages of splat expansion.
7
7
  #
8
8
  # @example
9
9
  #
@@ -9,16 +9,12 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # "result is #{something.to_s}"
14
13
  # print something.to_s
15
14
  # puts something.to_s
16
15
  # warn something.to_s
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # "result is #{something}"
23
19
  # print something
24
20
  # puts something
@@ -15,15 +15,11 @@ module RuboCop
15
15
  # @example
16
16
  #
17
17
  # # bad
18
- #
19
18
  # if day.is? :tuesday && month == :jan
20
19
  # # ...
21
20
  # end
22
21
  #
23
- # @example
24
- #
25
22
  # # good
26
- #
27
23
  # if day.is?(:tuesday) && month == :jan
28
24
  # # ...
29
25
  # end
@@ -8,17 +8,13 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # begin
13
12
  # do_something
14
13
  # rescue Exception
15
14
  # handle_exception
16
15
  # end
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # begin
23
19
  # do_something
24
20
  # rescue ArgumentError
@@ -19,8 +19,6 @@ module RuboCop
19
19
  # return 42
20
20
  # end
21
21
  #
22
- # @example
23
- #
24
22
  # # good
25
23
  # def initialize
26
24
  # foo
@@ -12,15 +12,11 @@ module RuboCop
12
12
  # @example
13
13
  #
14
14
  # # bad
15
- #
16
15
  # x&.foo.bar
17
16
  # x&.foo + bar
18
17
  # x&.foo[bar]
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # x&.foo&.bar
25
21
  # x&.foo || bar
26
22
  class SafeNavigationChain < Base
@@ -12,17 +12,16 @@ module RuboCop
12
12
  # because `Ractor` should not access outer variables.
13
13
  # eg. following style is encouraged:
14
14
  #
15
- # [source,ruby]
16
- # ----
17
- # worker_id, pipe = env
18
- # Ractor.new(worker_id, pipe) do |worker_id, pipe|
19
- # end
20
- # ----
15
+ # [source,ruby]
16
+ # ----
17
+ # worker_id, pipe = env
18
+ # Ractor.new(worker_id, pipe) do |worker_id, pipe|
19
+ # end
20
+ # ----
21
21
  #
22
22
  # @example
23
23
  #
24
24
  # # bad
25
- #
26
25
  # def some_method
27
26
  # foo = 1
28
27
  #
@@ -31,10 +30,7 @@ module RuboCop
31
30
  # end
32
31
  # end
33
32
  #
34
- # @example
35
- #
36
33
  # # good
37
- #
38
34
  # def some_method
39
35
  # foo = 1
40
36
  #
@@ -8,14 +8,10 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # 1.is_a?(Fixnum)
13
12
  # 1.is_a?(Bignum)
14
13
  #
15
- # @example
16
- #
17
14
  # # good
18
- #
19
15
  # 1.is_a?(Integer)
20
16
  class UnifiedInteger < Base
21
17
  extend AutoCorrector
@@ -10,14 +10,12 @@ module RuboCop
10
10
  # @example
11
11
  #
12
12
  # # bad
13
- #
14
13
  # def some_method
15
14
  # return
16
15
  # do_something
17
16
  # end
18
17
  #
19
18
  # # bad
20
- #
21
19
  # def some_method
22
20
  # if cond
23
21
  # return
@@ -27,10 +25,7 @@ module RuboCop
27
25
  # do_something
28
26
  # end
29
27
  #
30
- # @example
31
- #
32
28
  # # good
33
- #
34
29
  # def some_method
35
30
  # do_something
36
31
  # end
@@ -28,16 +28,12 @@ module RuboCop
28
28
  # @example
29
29
  #
30
30
  # # bad
31
- #
32
31
  # def some_method
33
32
  # some_var = 1
34
33
  # do_something
35
34
  # end
36
35
  #
37
- # @example
38
- #
39
36
  # # good
40
- #
41
37
  # def some_method
42
38
  # some_var = 1
43
39
  # do_something(some_var)
@@ -61,7 +57,7 @@ module RuboCop
61
57
  def check_for_unused_assignments(variable)
62
58
  return if variable.should_be_unused?
63
59
 
64
- variable.assignments.each do |assignment|
60
+ variable.assignments.reverse_each do |assignment|
65
61
  next if assignment.used? || part_of_ignored_node?(assignment.node)
66
62
 
67
63
  message = message_for_useless_assignment(assignment)
@@ -10,17 +10,13 @@ module RuboCop
10
10
  # @example
11
11
  #
12
12
  # # bad
13
- #
14
13
  # begin
15
14
  # do_something
16
15
  # else
17
16
  # do_something_else # This will never be run.
18
17
  # end
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # begin
25
21
  # do_something
26
22
  # rescue
@@ -17,16 +17,12 @@ module RuboCop
17
17
  # @example
18
18
  #
19
19
  # # bad
20
- #
21
20
  # def something
22
21
  # x = Something.new
23
22
  # x.attr = 5
24
23
  # end
25
24
  #
26
- # @example
27
- #
28
25
  # # good
29
- #
30
26
  # def something
31
27
  # x = Something.new
32
28
  # x.attr = 5
@@ -3,59 +3,75 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Naming
6
- # Checks that predicate methods names end with a question mark and
6
+ # Checks that predicate method names end with a question mark and
7
7
  # do not start with a forbidden prefix.
8
8
  #
9
- # A method is determined to be a predicate method if its name starts
10
- # with one of the prefixes defined in the `NamePrefix` configuration.
11
- # You can change what prefixes are considered by changing this option.
12
- # Any method name that starts with one of these prefixes is required by
13
- # the cop to end with a `?`. Other methods can be allowed by adding to
14
- # the `AllowedMethods` configuration.
9
+ # A method is determined to be a predicate method if its name starts with
10
+ # one of the prefixes listed in the `NamePrefix` configuration. The list
11
+ # defaults to `is_`, `has_`, and `have_` but may be overridden.
15
12
  #
16
- # NOTE: The `is_a?` method is allowed by default.
13
+ # Predicate methods must end with a question mark.
17
14
  #
18
- # If `ForbiddenPrefixes` is set, methods that start with the configured
19
- # prefixes will not be allowed and will be removed by autocorrection.
15
+ # When `ForbiddenPrefixes` is also set (as it is by default), predicate
16
+ # methods which begin with a forbidden prefix are not allowed, even if
17
+ # they end with a `?`. These methods should be changed to remove the
18
+ # prefix.
20
19
  #
21
- # In other words, if `ForbiddenPrefixes` is empty, a method named `is_foo`
22
- # will register an offense only due to the lack of question mark (and will be
23
- # autocorrected to `is_foo?`). If `ForbiddenPrefixes` contains `is_`,
24
- # `is_foo` will register an offense both because the ? is missing and because of
25
- # the `is_` prefix, and will be corrected to `foo?`.
26
- #
27
- # NOTE: `ForbiddenPrefixes` is only applied to prefixes in `NamePrefix`;
28
- # a prefix in the former but not the latter will not be considered by
29
- # this cop.
30
- #
31
- # @example
20
+ # @example NamePrefix: ['is_', 'has_', 'have_'] (default)
32
21
  # # bad
33
22
  # def is_even(value)
34
23
  # end
35
24
  #
36
- # def is_even?(value)
25
+ # # When ForbiddenPrefixes: ['is_', 'has_', 'have_'] (default)
26
+ # # good
27
+ # def even?(value)
37
28
  # end
38
29
  #
30
+ # # When ForbiddenPrefixes: []
39
31
  # # good
40
- # def even?(value)
32
+ # def is_even?(value)
41
33
  # end
42
34
  #
35
+ # @example NamePrefix: ['seems_to_be_']
43
36
  # # bad
44
- # def has_value
37
+ # def seems_to_be_even(value)
45
38
  # end
46
39
  #
47
- # def has_value?
40
+ # # When ForbiddenPrefixes: ['seems_to_be_']
41
+ # # good
42
+ # def even?(value)
48
43
  # end
49
44
  #
45
+ # # When ForbiddenPrefixes: []
50
46
  # # good
51
- # def value?
47
+ # def seems_to_be_even?(value)
52
48
  # end
53
49
  #
54
50
  # @example AllowedMethods: ['is_a?'] (default)
51
+ # # Despite starting with the `is_` prefix, this method is allowed
55
52
  # # good
56
53
  # def is_a?(value)
57
54
  # end
58
55
  #
56
+ # @example AllowedMethods: ['is_even?']
57
+ # # good
58
+ # def is_even?(value)
59
+ # end
60
+ #
61
+ # @example MethodDefinitionMacros: ['define_method', 'define_singleton_method'] (default)
62
+ # # bad
63
+ # define_method(:is_even) { |value| }
64
+ #
65
+ # # good
66
+ # define_method(:even?) { |value| }
67
+ #
68
+ # @example MethodDefinitionMacros: ['def_node_matcher']
69
+ # # bad
70
+ # def_node_matcher(:is_even) { |value| }
71
+ #
72
+ # # good
73
+ # # def_node_matcher(:even?) { |value| }
74
+ #
59
75
  class PredicateName < Base
60
76
  include AllowedMethods
61
77
 
@@ -93,6 +109,16 @@ module RuboCop
93
109
  end
94
110
  alias on_defs on_def
95
111
 
112
+ def validate_config
113
+ forbidden_prefixes.each do |forbidden_prefix|
114
+ next if predicate_prefixes.include?(forbidden_prefix)
115
+
116
+ raise ValidationError, <<~MSG.chomp
117
+ The `Naming/PredicateName` cop is misconfigured. Prefix #{forbidden_prefix} must be included in NamePrefix because it is included in ForbiddenPrefixes.
118
+ MSG
119
+ end
120
+ end
121
+
96
122
  private
97
123
 
98
124
  def allowed_method_name?(method_name, prefix)
@@ -113,13 +113,21 @@ module RuboCop
113
113
  end
114
114
  end
115
115
 
116
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
116
117
  def correct_node(corrector, node, offending_name, preferred_name)
117
118
  return unless node
118
119
 
119
120
  node.each_node(:lvar, :lvasgn, :masgn) do |child_node|
120
121
  next unless variable_name_matches?(child_node, offending_name)
121
122
 
122
- corrector.replace(child_node, preferred_name) if child_node.lvar_type?
123
+ if child_node.lvar_type?
124
+ parent_node = child_node.parent
125
+ if parent_node.respond_to?(:value_omission?) && parent_node.value_omission?
126
+ corrector.insert_after(parent_node.loc.operator, " #{preferred_name}")
127
+ else
128
+ corrector.replace(child_node, preferred_name)
129
+ end
130
+ end
123
131
 
124
132
  if child_node.masgn_type? || child_node.lvasgn_type?
125
133
  correct_reassignment(corrector, child_node, offending_name, preferred_name)
@@ -127,6 +135,7 @@ module RuboCop
127
135
  end
128
136
  end
129
137
  end
138
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
130
139
 
131
140
  # If the exception variable is reassigned, that assignment needs to be corrected.
132
141
  # Further `lvar` nodes will not be corrected though since they now refer to a
@@ -28,8 +28,6 @@ module RuboCop
28
28
  # # good (without parentheses it's a syntax error)
29
29
  # def foo() do_something end
30
30
  #
31
- # @example
32
- #
33
31
  # # bad
34
32
  # def Baz.foo()
35
33
  # do_something
@@ -16,7 +16,6 @@ module RuboCop
16
16
  # # good
17
17
  # 5.times { }
18
18
  #
19
- # @example
20
19
  # # bad
21
20
  # (0...10).each {}
22
21
  #
@@ -17,6 +17,18 @@ module RuboCop
17
17
  # will not attempt to automatically add a binding, or add filename and
18
18
  # line values.
19
19
  #
20
+ # NOTE: This cop works only when a string literal is given as a code string.
21
+ # No offense is reported if a string variable is given as below:
22
+ #
23
+ # [source,ruby]
24
+ # ----
25
+ # code = <<-RUBY
26
+ # def do_something
27
+ # end
28
+ # RUBY
29
+ # eval code # not checked.
30
+ # ----
31
+ #
20
32
  # @example
21
33
  # # bad
22
34
  # eval <<-RUBY
@@ -42,17 +54,6 @@ module RuboCop
42
54
  # end
43
55
  # RUBY
44
56
  #
45
- # This cop works only when a string literal is given as a code string.
46
- # No offense is reported if a string variable is given as below:
47
- #
48
- # @example
49
- # # not checked
50
- # code = <<-RUBY
51
- # def do_something
52
- # end
53
- # RUBY
54
- # eval code
55
- #
56
57
  class EvalWithLocation < Base
57
58
  extend AutoCorrector
58
59
 
@@ -6,8 +6,7 @@ module RuboCop
6
6
  # Favor `File.(bin)read` convenience methods.
7
7
  #
8
8
  # @example
9
- # ## text mode
10
- # # bad
9
+ # # bad - text mode
11
10
  # File.open(filename).read
12
11
  # File.open(filename, &:read)
13
12
  # File.open(filename) { |f| f.read }
@@ -23,9 +22,7 @@ module RuboCop
23
22
  # # good
24
23
  # File.read(filename)
25
24
  #
26
- # @example
27
- # ## binary mode
28
- # # bad
25
+ # # bad - binary mode
29
26
  # File.open(filename, 'rb').read
30
27
  # File.open(filename, 'rb', &:read)
31
28
  # File.open(filename, 'rb') do |f|
@@ -17,8 +17,7 @@ module RuboCop
17
17
  # ----
18
18
  #
19
19
  # @example
20
- # ## text mode
21
- # # bad
20
+ # # bad - text mode
22
21
  # File.open(filename, 'w').write(content)
23
22
  # File.open(filename, 'w') do |f|
24
23
  # f.write(content)
@@ -27,9 +26,7 @@ module RuboCop
27
26
  # # good
28
27
  # File.write(filename, content)
29
28
  #
30
- # @example
31
- # ## binary mode
32
- # # bad
29
+ # # bad - binary mode
33
30
  # File.open(filename, 'wb').write(content)
34
31
  # File.open(filename, 'wb') do |f|
35
32
  # f.write(content)
@@ -44,7 +44,9 @@ module RuboCop
44
44
  PATTERN
45
45
 
46
46
  def on_const(node)
47
- const_name = node.children[1]
47
+ return if namespaced?(node)
48
+
49
+ const_name = node.short_name
48
50
  return unless STD_STREAMS.include?(const_name)
49
51
 
50
52
  gvar_name = gvar_name(const_name).to_sym
@@ -61,6 +63,10 @@ module RuboCop
61
63
  format(MSG, gvar_name: gvar_name(const_name), const_name: const_name)
62
64
  end
63
65
 
66
+ def namespaced?(node)
67
+ !node.namespace.nil? && (node.relative? || !node.namespace.cbase_type?)
68
+ end
69
+
64
70
  def gvar_name(const_name)
65
71
  "$#{const_name.to_s.downcase}"
66
72
  end
@@ -44,7 +44,6 @@ module RuboCop
44
44
  # # good
45
45
  # foo == bar
46
46
  #
47
- # @example
48
47
  # # bad
49
48
  # if foo.do_something?
50
49
  # true
@@ -72,8 +72,8 @@ module RuboCop
72
72
 
73
73
  private
74
74
 
75
- def invertible?(node)
76
- case node.type
75
+ def invertible?(node) # rubocop:disable Metrics/CyclomaticComplexity
76
+ case node&.type
77
77
  when :begin
78
78
  invertible?(node.children.first)
79
79
  when :send
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # Enforces the presence (default) or absence of parentheses in
7
- # method calls containing parameters.
7
+ # method calls containing arguments.
8
8
  #
9
9
  # In the default style (require_parentheses), macro methods are allowed.
10
10
  # Additional methods can be added to the `AllowedMethods` or
@@ -168,10 +168,6 @@ module RuboCop
168
168
  config.for_cop('Style/UnlessElse')
169
169
  end
170
170
 
171
- def empty_else_cop_enabled?
172
- empty_else_config.fetch('Enabled')
173
- end
174
-
175
171
  def empty_else_style
176
172
  return unless empty_else_config.key?('EnforcedStyle')
177
173
 
@@ -54,10 +54,6 @@ module RuboCop
54
54
 
55
55
  same_line?(when_node, when_node.body)
56
56
  end
57
-
58
- def accept_node_type?(node)
59
- node&.array_type? || node&.hash_type?
60
- end
61
57
  end
62
58
  end
63
59
  end
@@ -12,7 +12,6 @@ module RuboCop
12
12
  # # good
13
13
  # a = b || c
14
14
  #
15
- # @example
16
15
  # # bad
17
16
  # if b
18
17
  # b
@@ -95,30 +95,14 @@ module RuboCop
95
95
  delimiters.include?(char)
96
96
  end
97
97
 
98
- if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
99
- def each_escape(node)
100
- node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
101
- yield(expr.text[1], expr.ts, !char_class_depth.zero?) if expr.type == :escape
102
-
103
- if expr.type == :set
104
- char_class_depth + (event == :enter ? 1 : -1)
105
- else
106
- char_class_depth
107
- end
108
- end
109
- end
110
- # Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
111
- # It's for compatibility with regexp_parser 1.8 and will never be maintained.
112
- else
113
- def each_escape(node)
114
- node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
115
- yield(expr.text[1], expr.start_index, !char_class_depth.zero?) if expr.type == :escape
116
-
117
- if expr.type == :set
118
- char_class_depth + (event == :enter ? 1 : -1)
119
- else
120
- char_class_depth
121
- end
98
+ def each_escape(node)
99
+ node.parsed_tree&.traverse&.reduce(0) do |char_class_depth, (event, expr)|
100
+ yield(expr.text[1], expr.ts, !char_class_depth.zero?) if expr.type == :escape
101
+
102
+ if expr.type == :set
103
+ char_class_depth + (event == :enter ? 1 : -1)
104
+ else
105
+ char_class_depth
122
106
  end
123
107
  end
124
108
  end