rubocop 0.75.1 → 0.76.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +52 -53
  4. data/lib/rubocop.rb +10 -9
  5. data/lib/rubocop/ast/builder.rb +1 -0
  6. data/lib/rubocop/ast/node.rb +4 -0
  7. data/lib/rubocop/ast/node/return_node.rb +24 -0
  8. data/lib/rubocop/cli.rb +7 -4
  9. data/lib/rubocop/comment_config.rb +2 -2
  10. data/lib/rubocop/config.rb +7 -0
  11. data/lib/rubocop/config_loader.rb +1 -1
  12. data/lib/rubocop/config_loader_resolver.rb +2 -1
  13. data/lib/rubocop/config_obsoletion.rb +9 -0
  14. data/lib/rubocop/config_validator.rb +24 -15
  15. data/lib/rubocop/cop/commissioner.rb +15 -7
  16. data/lib/rubocop/cop/cop.rb +10 -6
  17. data/lib/rubocop/cop/corrector.rb +8 -7
  18. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  19. data/lib/rubocop/cop/layout/align_hash.rb +6 -2
  20. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  21. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  22. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  23. data/lib/rubocop/cop/layout/indent_first_argument.rb +9 -7
  24. data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
  25. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  26. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  27. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  28. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  29. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  30. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  31. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  32. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  33. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +23 -23
  34. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
  35. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  36. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +5 -5
  37. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  38. data/lib/rubocop/cop/lint/void.rb +4 -4
  39. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  40. data/lib/rubocop/cop/metrics/line_length.rb +1 -4
  41. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  42. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  43. data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
  44. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
  45. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  46. data/lib/rubocop/cop/registry.rb +1 -1
  47. data/lib/rubocop/cop/style/attr.rb +2 -2
  48. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
  49. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  50. data/lib/rubocop/cop/style/copyright.rb +11 -7
  51. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  52. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  53. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  54. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  55. data/lib/rubocop/cop/style/format_string.rb +10 -7
  56. data/lib/rubocop/cop/style/format_string_token.rb +2 -0
  57. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
  58. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  59. data/lib/rubocop/cop/style/if_unless_modifier.rb +9 -2
  60. data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
  61. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  62. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  63. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  64. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
  65. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  66. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  67. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  68. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  69. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  70. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  71. data/lib/rubocop/cop/style/redundant_return.rb +25 -21
  72. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
  73. data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
  74. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  75. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  76. data/lib/rubocop/cop/util.rb +1 -1
  77. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  78. data/lib/rubocop/cop/variable_force.rb +7 -5
  79. data/lib/rubocop/node_pattern.rb +3 -1
  80. data/lib/rubocop/options.rb +12 -6
  81. data/lib/rubocop/result_cache.rb +1 -1
  82. data/lib/rubocop/runner.rb +32 -27
  83. data/lib/rubocop/target_finder.rb +12 -6
  84. data/lib/rubocop/version.rb +1 -1
  85. metadata +12 -11
@@ -147,16 +147,16 @@ module RuboCop
147
147
  end
148
148
 
149
149
  def remove_braces_with_whitespace(corrector, node, space)
150
+ loc = node.loc
151
+
150
152
  if node.multiline?
151
153
  remove_braces_with_range(corrector,
152
- left_whole_line_range(node.loc.begin),
153
- right_whole_line_range(node.loc.end))
154
+ left_whole_line_range(loc.begin),
155
+ right_whole_line_range(loc.end))
154
156
  else
155
- right_brace_and_space = right_brace_and_space(node.loc.end, space)
156
- left_brace_and_space = left_brace_and_space(node.loc.begin, space)
157
157
  remove_braces_with_range(corrector,
158
- left_brace_and_space,
159
- right_brace_and_space)
158
+ left_brace_and_space(loc.begin, space),
159
+ right_brace_and_space(loc.end, space))
160
160
  end
161
161
  end
162
162
 
@@ -49,10 +49,10 @@ module RuboCop
49
49
  next unless annotation?(comment) &&
50
50
  !correct_annotation?(first_word, colon, space, note)
51
51
 
52
- length = concat_length(first_word, colon, space)
53
52
  add_offense(
54
53
  comment,
55
- location: annotation_range(comment, margin, length),
54
+ location: annotation_range(comment, margin,
55
+ first_word, colon, space),
56
56
  message: format(note ? MSG : MISSING_NOTE, keyword: first_word)
57
57
  )
58
58
  end
@@ -62,8 +62,7 @@ module RuboCop
62
62
  margin, first_word, colon, space, note = split_comment(comment)
63
63
  return if note.nil?
64
64
 
65
- length = concat_length(first_word, colon, space)
66
- range = annotation_range(comment, margin, length)
65
+ range = annotation_range(comment, margin, first_word, colon, space)
67
66
 
68
67
  ->(corrector) { corrector.replace(range, "#{first_word.upcase}: ") }
69
68
  end
@@ -79,8 +78,9 @@ module RuboCop
79
78
  !comment_line?(comment.loc.expression.source_line)
80
79
  end
81
80
 
82
- def annotation_range(comment, margin, length)
81
+ def annotation_range(comment, margin, first_word, colon, space)
83
82
  start = comment.loc.expression.begin_pos + margin.length
83
+ length = concat_length(first_word, colon, space)
84
84
  range_between(start, start + length)
85
85
  end
86
86
 
@@ -33,13 +33,7 @@ module RuboCop
33
33
  end
34
34
 
35
35
  def autocorrect(token)
36
- raise Warning, AUTOCORRECT_EMPTY_WARNING if autocorrect_notice.empty?
37
-
38
- regex = Regexp.new(notice)
39
- unless autocorrect_notice =~ regex
40
- raise Warning, "AutocorrectNotice '#{autocorrect_notice}' must " \
41
- "match Notice /#{notice}/"
42
- end
36
+ verify_autocorrect_notice!
43
37
 
44
38
  lambda do |corrector|
45
39
  range = token.nil? ? range_between(0, 0) : token.pos
@@ -57,6 +51,16 @@ module RuboCop
57
51
  cop_config['AutocorrectNotice']
58
52
  end
59
53
 
54
+ def verify_autocorrect_notice!
55
+ raise Warning, AUTOCORRECT_EMPTY_WARNING if autocorrect_notice.empty?
56
+
57
+ regex = Regexp.new(notice)
58
+ return if autocorrect_notice =~ regex
59
+
60
+ raise Warning, "AutocorrectNotice '#{autocorrect_notice}' must " \
61
+ "match Notice /#{notice}/"
62
+ end
63
+
60
64
  def insert_notice_before(processed_source)
61
65
  token_index = 0
62
66
  token_index += 1 if shebang_token?(processed_source, token_index)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Lint/UnneededCopDisableDirective
3
+ # rubocop:disable Lint/RedundantCopDisableDirective
4
4
  # rubocop:disable Style/DoubleCopDisableDirective
5
5
 
6
6
  module RuboCop
@@ -26,7 +26,7 @@ module RuboCop
26
26
  #
27
27
  class DoubleCopDisableDirective < Cop
28
28
  # rubocop:enable Style/For, Style/DoubleCopDisableDirective
29
- # rubocop:enable Lint/UnneededCopDisableDirective, Metrics/AbcSize
29
+ # rubocop:enable Lint/RedundantCopDisableDirective, Metrics/AbcSize
30
30
  MSG = 'More than one disable comment on one line.'
31
31
 
32
32
  def investigate(processed_source)
@@ -84,8 +84,8 @@ module RuboCop
84
84
 
85
85
  next unless conditions.size > 1
86
86
 
87
- range = range_between(conditions.first.loc.expression.begin_pos,
88
- conditions.last.loc.expression.end_pos)
87
+ range = range_between(conditions.first.source_range.begin_pos,
88
+ conditions.last.source_range.end_pos)
89
89
 
90
90
  corrector.replace(range, conditions.map(&:source).join(' || '))
91
91
  end
@@ -84,8 +84,8 @@ module RuboCop
84
84
  # to rewrite the arguments to wrap them in parenthesis.
85
85
  args = node.parent.arguments
86
86
 
87
- range_between(args[0].loc.expression.begin_pos - 1,
88
- args[-1].loc.expression.end_pos)
87
+ range_between(args[0].source_range.begin_pos - 1,
88
+ args[-1].source_range.end_pos)
89
89
  else
90
90
  node.source_range
91
91
  end
@@ -73,11 +73,11 @@ module RuboCop
73
73
  end
74
74
 
75
75
  def corrected(node)
76
- has_parentheses = parentheses?(node.arguments)
77
-
78
- arguments = node.arguments? ? node.arguments.source : ''
79
- extra_space = node.arguments? && !has_parentheses ? ' ' : ''
80
- scope = node.receiver ? "#{node.receiver.source}." : ''
76
+ if node.arguments?
77
+ arguments = node.arguments.source
78
+ extra_space = ' ' unless parentheses?(node.arguments)
79
+ end
80
+ scope = node.receiver ? "#{node.receiver.source}." : ''
81
81
 
82
82
  signature = [scope, node.method_name, extra_space, arguments].join
83
83
 
@@ -94,10 +94,12 @@ module RuboCop
94
94
  private
95
95
 
96
96
  def autocorrect_from_percent(corrector, node)
97
- args = if %i[array hash].include?(node.first_argument.type)
98
- node.first_argument.children.map(&:source).join(', ')
97
+ percent_rhs = node.first_argument
98
+ args = case percent_rhs.type
99
+ when :array, :hash
100
+ percent_rhs.children.map(&:source).join(', ')
99
101
  else
100
- node.first_argument.source
102
+ percent_rhs.source
101
103
  end
102
104
 
103
105
  corrected = "#{style}(#{node.receiver.source}, #{args})"
@@ -106,14 +108,15 @@ module RuboCop
106
108
  end
107
109
 
108
110
  def autocorrect_to_percent(corrector, node)
109
- format = node.first_argument.source
111
+ format_arg, *param_args = node.arguments
112
+ format = format_arg.source
110
113
 
111
- args = if node.arguments.size == 2
112
- arg = node.arguments.last
114
+ args = if param_args.one?
115
+ arg = param_args.last
113
116
 
114
117
  arg.hash_type? ? "{ #{arg.source} }" : arg.source
115
118
  else
116
- "[#{node.arguments[1..-1].map(&:source).join(', ')}]"
119
+ "[#{param_args.map(&:source).join(', ')}]"
117
120
  end
118
121
 
119
122
  corrector.replace(node.loc.expression, "#{format} % #{args}")
@@ -104,6 +104,8 @@ module RuboCop
104
104
  format_string = RuboCop::Cop::Utils::FormatString.new(contents.source)
105
105
 
106
106
  format_string.format_sequences.each do |seq|
107
+ next if seq.percent?
108
+
107
109
  detected_style = seq.style
108
110
  token = contents.begin.adjust(
109
111
  begin_pos: seq.begin_pos,
@@ -11,6 +11,9 @@ module RuboCop
11
11
  # encoding comment. The frozen string literal comment is only valid in
12
12
  # Ruby 2.3+.
13
13
  #
14
+ # Note that the cop will ignore files where the comment exists but is set
15
+ # to `false` instead of `true`.
16
+ #
14
17
  # @example EnforcedStyle: always (default)
15
18
  # # The `always` style will always add the frozen string literal comment
16
19
  # # to a file, regardless of the Ruby version or if `freeze` or `<<` are
@@ -27,6 +30,13 @@ module RuboCop
27
30
  # # ...
28
31
  # end
29
32
  #
33
+ # # good
34
+ # # frozen_string_literal: false
35
+ #
36
+ # module Bar
37
+ # # ...
38
+ # end
39
+ #
30
40
  # @example EnforcedStyle: never
31
41
  # # The `never` will enforce that the frozen string literal comment does
32
42
  # # not exist in a file.
@@ -168,10 +168,10 @@ module RuboCop
168
168
  end
169
169
 
170
170
  def autocorrect_ruby19(corrector, pair_node)
171
- key = pair_node.key
171
+ key = pair_node.key.source_range
172
172
  op = pair_node.loc.operator
173
173
 
174
- range = range_between(key.source_range.begin_pos, op.end_pos)
174
+ range = key.join(op)
175
175
  range = range_with_surrounding_space(range: range, side: :right)
176
176
 
177
177
  space = argument_without_space?(pair_node.parent) ? ' ' : ''
@@ -70,8 +70,15 @@ module RuboCop
70
70
  return false unless max_line_length
71
71
 
72
72
  range = node.source_range
73
- range.first_line == range.last_line &&
74
- range.last_column > max_line_length
73
+ return false unless range.first_line == range.last_line
74
+ return false unless line_length_enabled_at_line?(range.first_line)
75
+
76
+ range.last_column > max_line_length
77
+ end
78
+
79
+ def line_length_enabled_at_line?(line)
80
+ processed_source.comment_config
81
+ .cop_enabled_at_line?('Metrics/LineLength', line)
75
82
  end
76
83
 
77
84
  def named_capture_in_condition?(node)
@@ -97,12 +97,13 @@ module RuboCop
97
97
  end
98
98
 
99
99
  def modifier_replacement(node)
100
+ body = node.body
100
101
  if node.single_line?
101
- 'loop { ' + node.body.source + ' }'
102
+ 'loop { ' + body.source + ' }'
102
103
  else
103
- indentation = node.body.loc.expression.source_line[LEADING_SPACE]
104
+ indentation = body.source_range.source_line[LEADING_SPACE]
104
105
 
105
- ['loop do', node.body.source.gsub(/^/, configured_indent),
106
+ ['loop do', body.source.gsub(/^/, configured_indent),
106
107
  'end'].join("\n#{indentation}")
107
108
  end
108
109
  end
@@ -94,20 +94,25 @@ module RuboCop
94
94
  end
95
95
 
96
96
  def autocorrect(node)
97
+ if node.block_type?
98
+ correct_inverse_block(node)
99
+ elsif node.send_type?
100
+ correct_inverse_method(node)
101
+ end
102
+ end
103
+
104
+ def correct_inverse_method(node)
97
105
  method_call, _lhs, method, _rhs = inverse_candidate?(node)
106
+ return unless method_call && method
98
107
 
99
- if method_call && method
100
- lambda do |corrector|
101
- corrector.remove(not_to_receiver(node, method_call))
102
- corrector.replace(method_call.loc.selector,
103
- inverse_methods[method].to_s)
108
+ lambda do |corrector|
109
+ corrector.remove(not_to_receiver(node, method_call))
110
+ corrector.replace(method_call.loc.selector,
111
+ inverse_methods[method].to_s)
104
112
 
105
- if EQUALITY_METHODS.include?(method)
106
- corrector.remove(end_parentheses(node, method_call))
107
- end
113
+ if EQUALITY_METHODS.include?(method)
114
+ corrector.remove(end_parentheses(node, method_call))
108
115
  end
109
- else
110
- correct_inverse_block(node)
111
116
  end
112
117
  end
113
118
 
@@ -122,18 +127,19 @@ module RuboCop
122
127
  end
123
128
 
124
129
  def correct_inverse_selector(block, corrector)
125
- selector = block.loc.selector.source
130
+ selector_loc = block.loc.selector
131
+ selector = selector_loc.source
126
132
 
127
133
  if NEGATED_EQUALITY_METHODS.include?(selector.to_sym)
128
134
  selector[0] = '='
129
- corrector.replace(block.loc.selector, selector)
135
+ corrector.replace(selector_loc, selector)
130
136
  else
131
137
  if block.loc.dot
132
138
  range = dot_range(block.loc)
133
139
  corrector.remove(range)
134
140
  end
135
141
 
136
- corrector.remove(block.loc.selector)
142
+ corrector.remove(selector_loc)
137
143
  end
138
144
  end
139
145
 
@@ -26,13 +26,14 @@ module RuboCop
26
26
  'those strings.'
27
27
  CONCAT_TOKEN_TYPES = %i[tPLUS tLSHFT].freeze
28
28
  SIMPLE_STRING_TOKEN_TYPE = :tSTRING
29
- COMPLEX_STRING_EDGE_TOKEN_TYPES = %i[tSTRING_BEG tSTRING_END].freeze
29
+ COMPLEX_STRING_BEGIN_TOKEN = :tSTRING_BEG
30
+ COMPLEX_STRING_END_TOKEN = :tSTRING_END
30
31
  HIGH_PRECEDENCE_OP_TOKEN_TYPES = %i[tSTAR2 tPERCENT tDOT
31
32
  tLBRACK2].freeze
32
33
  QUOTE_DELIMITERS = %w[' "].freeze
33
34
 
34
35
  def self.autocorrect_incompatible_with
35
- [Style::UnneededInterpolation]
36
+ [Style::RedundantInterpolation]
36
37
  end
37
38
 
38
39
  def investigate(processed_source)
@@ -59,9 +60,7 @@ module RuboCop
59
60
  def check_token_set(index)
60
61
  predecessor, operator, successor = processed_source.tokens[index, 3]
61
62
 
62
- return unless eligible_successor?(successor) &&
63
- eligible_operator?(operator) &&
64
- eligible_predecessor?(predecessor)
63
+ return unless eligible_token_set?(predecessor, operator, successor)
65
64
 
66
65
  return if operator.line == successor.line
67
66
 
@@ -72,6 +71,12 @@ module RuboCop
72
71
  add_offense(operator.pos, location: operator.pos)
73
72
  end
74
73
 
74
+ def eligible_token_set?(predecessor, operator, successor)
75
+ eligible_successor?(successor) &&
76
+ eligible_operator?(operator) &&
77
+ eligible_predecessor?(predecessor)
78
+ end
79
+
75
80
  def eligible_successor?(successor)
76
81
  successor && standard_string_literal?(successor)
77
82
  end
@@ -91,13 +96,12 @@ module RuboCop
91
96
 
92
97
  def token_after_last_string(successor, base_index)
93
98
  index = base_index + 3
94
- begin_token, end_token = COMPLEX_STRING_EDGE_TOKEN_TYPES
95
- if successor.type == begin_token
99
+ if successor.type == COMPLEX_STRING_BEGIN_TOKEN
96
100
  ends_to_find = 1
97
101
  while ends_to_find.positive?
98
102
  case processed_source.tokens[index].type
99
- when begin_token then ends_to_find += 1
100
- when end_token then ends_to_find -= 1
103
+ when COMPLEX_STRING_BEGIN_TOKEN then ends_to_find += 1
104
+ when COMPLEX_STRING_END_TOKEN then ends_to_find -= 1
101
105
  end
102
106
  index += 1
103
107
  end
@@ -109,7 +113,7 @@ module RuboCop
109
113
  case token.type
110
114
  when SIMPLE_STRING_TOKEN_TYPE
111
115
  true
112
- when *COMPLEX_STRING_EDGE_TOKEN_TYPES
116
+ when COMPLEX_STRING_BEGIN_TOKEN, COMPLEX_STRING_END_TOKEN
113
117
  QUOTE_DELIMITERS.include?(token.text)
114
118
  else
115
119
  false
@@ -113,22 +113,30 @@ module RuboCop
113
113
  lambda do |corrector|
114
114
  if node.args_type?
115
115
  # offense is registered on args node when parentheses are unwanted
116
- corrector.replace(node.loc.begin, ' ')
117
- corrector.remove(node.loc.end)
116
+ correct_arguments(node, corrector)
118
117
  else
119
- args_expr = node.arguments.source_range
120
- args_with_space = range_with_surrounding_space(range: args_expr,
121
- side: :left)
122
- just_space = range_between(args_with_space.begin_pos,
123
- args_expr.begin_pos)
124
- corrector.replace(just_space, '(')
125
- corrector.insert_after(args_expr, ')')
118
+ correct_definition(node, corrector)
126
119
  end
127
120
  end
128
121
  end
129
122
 
130
123
  private
131
124
 
125
+ def correct_arguments(arg_node, corrector)
126
+ corrector.replace(arg_node.loc.begin, ' ')
127
+ corrector.remove(arg_node.loc.end)
128
+ end
129
+
130
+ def correct_definition(def_node, corrector)
131
+ arguments_range = def_node.arguments.source_range
132
+ args_with_space = range_with_surrounding_space(range: arguments_range,
133
+ side: :left)
134
+ leading_space = range_between(args_with_space.begin_pos,
135
+ arguments_range.begin_pos)
136
+ corrector.replace(leading_space, '(')
137
+ corrector.insert_after(arguments_range, ')')
138
+ end
139
+
132
140
  def require_parentheses?(args)
133
141
  style == :require_parentheses ||
134
142
  (style == :require_no_parentheses_except_multiline &&
@@ -44,7 +44,7 @@ module RuboCop
44
44
  lambda do |corrector|
45
45
  corrector.remove(
46
46
  range_with_surrounding_space(
47
- range: node.loc.begin, side: :left
47
+ range: node.loc.begin, side: :left, newlines: false
48
48
  )
49
49
  )
50
50
  end
@@ -49,11 +49,13 @@ module RuboCop
49
49
  node.parent.condition.source_range.end_pos)
50
50
 
51
51
  lambda do |corrector|
52
- corrector.replace(range, new_expression(node.parent, node))
52
+ corrector.replace(range, new_expression(node))
53
53
  end
54
54
  end
55
55
 
56
- def new_expression(outer_node, inner_node)
56
+ def new_expression(inner_node)
57
+ outer_node = inner_node.parent
58
+
57
59
  operator = replacement_operator(outer_node.keyword)
58
60
  lh_operand = left_hand_operand(outer_node, operator)
59
61
  rh_operand = right_hand_operand(inner_node, outer_node.keyword)