rubocop 1.71.2 → 1.74.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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/config/default.yml +86 -15
  4. data/config/internal_affairs.yml +20 -0
  5. data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
  6. data/lib/rubocop/comment_config.rb +1 -1
  7. data/lib/rubocop/config.rb +4 -0
  8. data/lib/rubocop/config_loader.rb +44 -9
  9. data/lib/rubocop/config_loader_resolver.rb +24 -9
  10. data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
  11. data/lib/rubocop/config_obsoletion.rb +1 -1
  12. data/lib/rubocop/config_validator.rb +1 -1
  13. data/lib/rubocop/cop/internal_affairs/example_description.rb +7 -3
  14. data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
  15. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -1
  16. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +91 -0
  17. data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
  18. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +7 -1
  19. data/lib/rubocop/cop/internal_affairs.rb +2 -16
  20. data/lib/rubocop/cop/layout/block_alignment.rb +2 -0
  21. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +4 -4
  22. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  23. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  24. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +26 -1
  25. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
  26. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  27. data/lib/rubocop/cop/layout/line_length.rb +3 -3
  28. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  29. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
  30. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
  31. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -14
  32. data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
  33. data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
  34. data/lib/rubocop/cop/lint/float_comparison.rb +1 -6
  35. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  36. data/lib/rubocop/cop/lint/literal_as_condition.rb +103 -9
  37. data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
  38. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  39. data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
  40. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +258 -0
  41. data/lib/rubocop/cop/lint/return_in_void_context.rb +4 -11
  42. data/lib/rubocop/cop/lint/shared_mutable_default.rb +12 -1
  43. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
  44. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +71 -0
  45. data/lib/rubocop/cop/lint/void.rb +6 -0
  46. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
  47. data/lib/rubocop/cop/mixin/alignment.rb +2 -2
  48. data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
  49. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +1 -1
  50. data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
  51. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +18 -18
  52. data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
  53. data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
  54. data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
  55. data/lib/rubocop/cop/mixin/range_help.rb +15 -3
  56. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  57. data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
  58. data/lib/rubocop/cop/mixin/trailing_comma.rb +12 -0
  59. data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
  60. data/lib/rubocop/cop/naming/predicate_name.rb +44 -0
  61. data/lib/rubocop/cop/naming/variable_name.rb +64 -6
  62. data/lib/rubocop/cop/style/accessor_grouping.rb +19 -5
  63. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
  64. data/lib/rubocop/cop/style/class_and_module_children.rb +29 -7
  65. data/lib/rubocop/cop/style/commented_keyword.rb +10 -3
  66. data/lib/rubocop/cop/style/comparable_between.rb +75 -0
  67. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  68. data/lib/rubocop/cop/style/endless_method.rb +163 -18
  69. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
  70. data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
  71. data/lib/rubocop/cop/style/format_string_token.rb +38 -11
  72. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  73. data/lib/rubocop/cop/style/inverse_methods.rb +8 -5
  74. data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
  75. data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
  76. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +3 -3
  77. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
  78. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  79. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
  80. data/lib/rubocop/cop/style/redundant_condition.rb +45 -0
  81. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +14 -4
  82. data/lib/rubocop/cop/style/redundant_format.rb +250 -0
  83. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  84. data/lib/rubocop/cop/style/redundant_parentheses.rb +18 -4
  85. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
  86. data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
  87. data/lib/rubocop/cop/style/single_line_methods.rb +3 -3
  88. data/lib/rubocop/cop/style/sole_nested_conditional.rb +0 -6
  89. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  90. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
  91. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
  92. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  93. data/lib/rubocop/cop/util.rb +1 -1
  94. data/lib/rubocop/cop/utils/format_string.rb +10 -5
  95. data/lib/rubocop/cops_documentation_generator.rb +12 -1
  96. data/lib/rubocop/directive_comment.rb +36 -3
  97. data/lib/rubocop/ext/regexp_node.rb +0 -1
  98. data/lib/rubocop/lsp/runtime.rb +2 -0
  99. data/lib/rubocop/lsp/server.rb +0 -2
  100. data/lib/rubocop/options.rb +26 -11
  101. data/lib/rubocop/path_util.rb +4 -0
  102. data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
  103. data/lib/rubocop/plugin/load_error.rb +26 -0
  104. data/lib/rubocop/plugin/loader.rb +100 -0
  105. data/lib/rubocop/plugin/not_supported_error.rb +29 -0
  106. data/lib/rubocop/plugin.rb +46 -0
  107. data/lib/rubocop/rake_task.rb +4 -1
  108. data/lib/rubocop/rspec/cop_helper.rb +9 -0
  109. data/lib/rubocop/rspec/shared_contexts.rb +15 -0
  110. data/lib/rubocop/rspec/support.rb +1 -0
  111. data/lib/rubocop/server/cache.rb +35 -2
  112. data/lib/rubocop/server/cli.rb +2 -2
  113. data/lib/rubocop/version.rb +17 -2
  114. data/lib/rubocop.rb +6 -1
  115. data/lib/ruby_lsp/rubocop/addon.rb +7 -10
  116. data/lib/ruby_lsp/rubocop/{wraps_built_in_lsp_runtime.rb → runtime_adapter.rb} +5 -8
  117. metadata +37 -10
  118. data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
@@ -7,11 +7,6 @@ module RuboCop
7
7
  #
8
8
  # NOTE: empty `else` branches are handled by `Style/EmptyElse`.
9
9
  #
10
- # @safety
11
- # Autocorrection for this cop is not safe. The conditions for empty branches that
12
- # the autocorrection removes may have side effects, or the logic in subsequent
13
- # branches may change due to the removal of a previous condition.
14
- #
15
10
  # @example
16
11
  # # bad
17
12
  # if condition
@@ -41,6 +36,13 @@ module RuboCop
41
36
  # if condition
42
37
  # do_something
43
38
  # elsif other_condition
39
+ # nil
40
+ # end
41
+ #
42
+ # # good
43
+ # if condition
44
+ # do_something
45
+ # elsif other_condition
44
46
  # do_something_else
45
47
  # end
46
48
  #
@@ -63,11 +65,9 @@ module RuboCop
63
65
  class EmptyConditionalBody < Base
64
66
  extend AutoCorrector
65
67
  include CommentsHelp
66
- include RangeHelp
67
68
 
68
69
  MSG = 'Avoid `%<keyword>s` branches without a body.'
69
70
 
70
- # rubocop:disable Metrics/AbcSize
71
71
  def on_if(node)
72
72
  return if node.body || same_line?(node.loc.begin, node.loc.end)
73
73
  return if cop_config['AllowComments'] && contains_comments?(node)
@@ -75,12 +75,11 @@ module RuboCop
75
75
  range = offense_range(node)
76
76
 
77
77
  add_offense(range, message: format(MSG, keyword: node.keyword)) do |corrector|
78
- next if node.parent&.call_type?
78
+ next unless can_simplify_conditional?(node)
79
79
 
80
- autocorrect(corrector, node)
80
+ flip_orphaned_else(corrector, node)
81
81
  end
82
82
  end
83
- # rubocop:enable Metrics/AbcSize
84
83
 
85
84
  private
86
85
 
@@ -92,53 +91,23 @@ module RuboCop
92
91
  end
93
92
  end
94
93
 
95
- def autocorrect(corrector, node)
96
- remove_comments(corrector, node)
97
- remove_empty_branch(corrector, node)
98
- correct_other_branches(corrector, node)
99
- end
100
-
101
- def remove_comments(corrector, node)
102
- comments_in_range(node).each do |comment|
103
- range = range_by_whole_lines(comment.source_range, include_final_newline: true)
104
- corrector.remove(range)
105
- end
94
+ def can_simplify_conditional?(node)
95
+ node.else_branch && node.loc.else.source == 'else'
106
96
  end
107
97
 
108
- # rubocop:disable Metrics/AbcSize
109
98
  def remove_empty_branch(corrector, node)
110
99
  range = if empty_if_branch?(node) && else_branch?(node)
111
100
  branch_range(node)
112
- elsif same_line?(node, else_kw_loc = node.loc.else)
113
- node.source_range.begin.join(else_kw_loc.begin)
114
- elsif node.parent&.loc.respond_to?(:end) &&
115
- same_line?(node, end_loc = node.parent.loc.end)
116
- node.source_range.begin.join(end_loc.begin)
117
101
  else
118
102
  deletion_range(branch_range(node))
119
103
  end
120
104
 
121
105
  corrector.remove(range)
122
106
  end
123
- # rubocop:enable Metrics/AbcSize
124
-
125
- def correct_other_branches(corrector, node)
126
- return unless require_other_branches_correction?(node)
127
-
128
- if node.else_branch&.if_type? && !node.else_branch.modifier_form?
129
- # Replace an orphaned `elsif` with `if`
130
- corrector.replace(node.else_branch.loc.keyword, 'if')
131
- else
132
- # Flip orphaned `else`
133
- corrector.replace(node.loc.else, "#{node.inverse_keyword} #{node.condition.source}")
134
- end
135
- end
136
-
137
- def require_other_branches_correction?(node)
138
- return false unless node.if_type? && node.else?
139
- return false if !empty_if_branch?(node) && node.elsif?
140
107
 
141
- !empty_elsif_branch?(node)
108
+ def flip_orphaned_else(corrector, node)
109
+ corrector.replace(node.loc.else, "#{node.inverse_keyword} #{node.condition.source}")
110
+ remove_empty_branch(corrector, node)
142
111
  end
143
112
 
144
113
  def empty_if_branch?(node)
@@ -149,36 +118,17 @@ module RuboCop
149
118
  if_branch.if_type? && !if_branch.body
150
119
  end
151
120
 
152
- def empty_elsif_branch?(node)
153
- return false unless (else_branch = node.else_branch)
154
-
155
- else_branch.if_type? && !else_branch.body
156
- end
157
-
158
121
  def else_branch?(node)
159
122
  node.else_branch && !node.else_branch.if_type?
160
123
  end
161
124
 
162
- # rubocop:disable Metrics/AbcSize
163
125
  def branch_range(node)
164
126
  if empty_if_branch?(node) && else_branch?(node)
165
127
  node.source_range.with(end_pos: node.loc.else.begin_pos)
166
128
  elsif node.loc.else
167
129
  node.source_range.with(end_pos: node.condition.source_range.end_pos)
168
- elsif all_branches_body_missing?(node)
169
- if_node = node.ancestors.detect(&:if?)
170
- node.source_range.join(if_node.loc.end.end)
171
- else
172
- node.source_range
173
130
  end
174
131
  end
175
- # rubocop:enable Metrics/AbcSize
176
-
177
- def all_branches_body_missing?(node)
178
- return false unless node.parent&.if_type?
179
-
180
- node.parent.branches.compact.empty?
181
- end
182
132
 
183
133
  def deletion_range(range)
184
134
  # Collect a range between the start of the `if` node and the next relevant node,
@@ -156,12 +156,6 @@ module RuboCop
156
156
 
157
157
  overridden_kwargs
158
158
  end
159
-
160
- def arguments_range(node)
161
- arguments = node.arguments
162
-
163
- range_between(arguments.first.source_range.begin_pos, arguments.last.source_range.end_pos)
164
- end
165
159
  end
166
160
  end
167
161
  end
@@ -81,21 +81,16 @@ module RuboCop
81
81
  (node.numeric_type? && node.value.zero?) || node.nil_type?
82
82
  end
83
83
 
84
- # rubocop:disable Metrics/PerceivedComplexity
85
84
  def check_send(node)
86
85
  if node.arithmetic_operation?
87
86
  float?(node.receiver) || float?(node.first_argument)
88
87
  elsif FLOAT_RETURNING_METHODS.include?(node.method_name)
89
88
  true
90
89
  elsif node.receiver&.float_type?
91
- if FLOAT_INSTANCE_METHODS.include?(node.method_name)
92
- true
93
- else
90
+ FLOAT_INSTANCE_METHODS.include?(node.method_name) ||
94
91
  check_numeric_returning_method(node)
95
- end
96
92
  end
97
93
  end
98
- # rubocop:enable Metrics/PerceivedComplexity
99
94
 
100
95
  def check_numeric_returning_method(node)
101
96
  return false unless node.receiver
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # expected fields for format/sprintf/#% and what is actually
8
8
  # passed as arguments.
9
9
  #
10
- # In addition it checks whether different formats are used in the same
10
+ # In addition, it checks whether different formats are used in the same
11
11
  # format string. Do not mix numbered, unnumbered, and named formats in
12
12
  # the same format string.
13
13
  #
@@ -18,12 +18,15 @@ module RuboCop
18
18
  # end
19
19
  #
20
20
  # # bad
21
- # if some_var && true
21
+ # # We're only interested in the left hand side being a truthy literal,
22
+ # # because it affects the evaluation of the &&, whereas the right hand
23
+ # # side will be conditionally executed/called and can be a literal.
24
+ # if true && some_var
22
25
  # do_something
23
26
  # end
24
27
  #
25
28
  # # good
26
- # if some_var && some_condition
29
+ # if some_var
27
30
  # do_something
28
31
  # end
29
32
  #
@@ -34,27 +37,94 @@ module RuboCop
34
37
  # end
35
38
  class LiteralAsCondition < Base
36
39
  include RangeHelp
40
+ extend AutoCorrector
37
41
 
38
42
  MSG = 'Literal `%<literal>s` appeared as a condition.'
39
43
  RESTRICT_ON_SEND = [:!].freeze
40
44
 
45
+ def on_and(node)
46
+ return unless node.lhs.truthy_literal?
47
+
48
+ add_offense(node.lhs) do |corrector|
49
+ # Don't autocorrect `'foo' && return` because having `return` as
50
+ # the leftmost node can lead to a void value expression syntax error.
51
+ next if node.rhs.type?(:return, :break, :next)
52
+
53
+ corrector.replace(node, node.rhs.source)
54
+ end
55
+ end
56
+
41
57
  def on_if(node)
42
- check_for_literal(node)
58
+ cond = condition(node)
59
+
60
+ if node.unless?
61
+ correct_if_node(node, cond, true) if cond.falsey_literal?
62
+ correct_if_node(node, cond, false) if cond.truthy_literal?
63
+ else
64
+ correct_if_node(node, cond, true) if cond.truthy_literal?
65
+ correct_if_node(node, cond, false) if cond.falsey_literal?
66
+ end
43
67
  end
44
68
 
45
69
  def on_while(node)
46
- return if condition(node).true_type?
70
+ return if node.condition.source == 'true'
47
71
 
48
- check_for_literal(node)
72
+ if node.condition.truthy_literal?
73
+ add_offense(node.condition) do |corrector|
74
+ corrector.replace(node.condition, 'true')
75
+ end
76
+ elsif node.condition.falsey_literal?
77
+ add_offense(node.condition) do |corrector|
78
+ corrector.remove(node)
79
+ end
80
+ end
81
+ end
82
+
83
+ # rubocop:disable Metrics/AbcSize
84
+ def on_while_post(node)
85
+ return if node.condition.source == 'true'
86
+
87
+ if node.condition.truthy_literal?
88
+ add_offense(node.condition) do |corrector|
89
+ corrector.replace(node, node.source.sub(node.condition.source, 'true'))
90
+ end
91
+ elsif node.condition.falsey_literal?
92
+ add_offense(node.condition) do |corrector|
93
+ corrector.replace(node, node.body.child_nodes.map(&:source).join("\n"))
94
+ end
95
+ end
49
96
  end
50
- alias on_while_post on_while
97
+ # rubocop:enable Metrics/AbcSize
51
98
 
52
99
  def on_until(node)
53
- return if condition(node).false_type?
100
+ return if node.condition.source == 'false'
54
101
 
55
- check_for_literal(node)
102
+ if node.condition.falsey_literal?
103
+ add_offense(node.condition) do |corrector|
104
+ corrector.replace(node.condition, 'false')
105
+ end
106
+ elsif node.condition.truthy_literal?
107
+ add_offense(node.condition) do |corrector|
108
+ corrector.remove(node)
109
+ end
110
+ end
111
+ end
112
+
113
+ # rubocop:disable Metrics/AbcSize
114
+ def on_until_post(node)
115
+ return if node.condition.source == 'false'
116
+
117
+ if node.condition.falsey_literal?
118
+ add_offense(node.condition) do |corrector|
119
+ corrector.replace(node, node.source.sub(node.condition.source, 'false'))
120
+ end
121
+ elsif node.condition.truthy_literal?
122
+ add_offense(node.condition) do |corrector|
123
+ corrector.replace(node, node.body.child_nodes.map(&:source).join("\n"))
124
+ end
125
+ end
56
126
  end
57
- alias on_until_post on_until
127
+ # rubocop:enable Metrics/AbcSize
58
128
 
59
129
  def on_case(case_node)
60
130
  if case_node.condition
@@ -130,6 +200,8 @@ module RuboCop
130
200
 
131
201
  def handle_node(node)
132
202
  if node.literal?
203
+ return if node.parent.and_type?
204
+
133
205
  add_offense(node)
134
206
  elsif %i[send and or begin].include?(node.type)
135
207
  check_node(node)
@@ -159,6 +231,28 @@ module RuboCop
159
231
  when_node.conditions.last.source_range.end_pos
160
232
  )
161
233
  end
234
+
235
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
236
+ def correct_if_node(node, cond, result)
237
+ if result
238
+ add_offense(cond) do |corrector|
239
+ corrector.replace(node, node.if_branch.source)
240
+ end
241
+ elsif node.elsif_conditional?
242
+ add_offense(cond) do |corrector|
243
+ corrector.replace(node, "#{node.else_branch.source.sub('elsif', 'if')}\nend")
244
+ end
245
+ elsif node.else? || node.ternary?
246
+ add_offense(cond) do |corrector|
247
+ corrector.replace(node, node.else_branch.source)
248
+ end
249
+ else
250
+ add_offense(cond) do |corrector|
251
+ corrector.remove(node)
252
+ end
253
+ end
254
+ end
255
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
162
256
  end
163
257
  end
164
258
  end
@@ -79,7 +79,7 @@ module RuboCop
79
79
  end
80
80
 
81
81
  def range_pairs(expr)
82
- RuboCop::Cop::Utils::RegexpRanges.new(expr).pairs
82
+ expr.expressions.filter_map { |e| [e.expressions[0], e.expressions[1]] if e.type == :set }
83
83
  end
84
84
 
85
85
  def unsafe_range?(range_start, range_end)
@@ -94,7 +94,7 @@ module RuboCop
94
94
 
95
95
  def skip_range?(range_start, range_end)
96
96
  [range_start, range_end].any? do |bound|
97
- bound.type != :literal
97
+ bound&.type != :literal
98
98
  end
99
99
  end
100
100
 
@@ -46,7 +46,7 @@ module RuboCop
46
46
  def on_return(return_node)
47
47
  return if return_value?(return_node)
48
48
 
49
- return_node.each_ancestor(:block, :def, :defs) do |node|
49
+ return_node.each_ancestor(:any_block, :def, :defs) do |node|
50
50
  break if scoped_node?(node)
51
51
 
52
52
  # if a proc is passed to `Module#define_method` or
@@ -54,7 +54,7 @@ module RuboCop
54
54
  # non-local exit error
55
55
  break if define_method?(node.send_node)
56
56
 
57
- next unless node.arguments?
57
+ next if node.argument_list.empty?
58
58
 
59
59
  if chained_send?(node.send_node)
60
60
  add_offense(return_node.loc.keyword)
@@ -17,17 +17,12 @@ module RuboCop
17
17
  # * 2.0+ ... `enumerator`
18
18
  # * 2.1+ ... `thread`
19
19
  # * 2.2+ ... Add `rational` and `complex` above
20
- # * 2.5+ ... Add `pp` above
21
20
  # * 2.7+ ... Add `ruby2_keywords` above
22
21
  # * 3.1+ ... Add `fiber` above
23
22
  # * 3.2+ ... `set`
24
23
  #
25
24
  # This cop target those features.
26
25
  #
27
- # @safety
28
- # This cop's autocorrection is unsafe because if `require 'pp'` is removed from one file,
29
- # `NameError` can be encountered when another file uses `PP.pp`.
30
- #
31
26
  # @example
32
27
  # # bad
33
28
  # require 'unloaded_feature'
@@ -42,10 +37,6 @@ module RuboCop
42
37
  MSG = 'Remove unnecessary `require` statement.'
43
38
  RESTRICT_ON_SEND = %i[require].freeze
44
39
  RUBY_22_LOADED_FEATURES = %w[rational complex].freeze
45
- PRETTY_PRINT_METHODS = %i[
46
- pretty_inspect pretty_print pretty_print_cycle
47
- pretty_print_inspect pretty_print_instance_variables
48
- ].freeze
49
40
 
50
41
  # @!method redundant_require_statement?(node)
51
42
  def_node_matcher :redundant_require_statement?, <<~PATTERN
@@ -53,11 +44,6 @@ module RuboCop
53
44
  (str #redundant_feature?))
54
45
  PATTERN
55
46
 
56
- # @!method pp_const?(node)
57
- def_node_matcher :pp_const?, <<~PATTERN
58
- (const {nil? cbase} :PP)
59
- PATTERN
60
-
61
47
  def on_send(node)
62
48
  return unless redundant_require_statement?(node)
63
49
 
@@ -81,18 +67,11 @@ module RuboCop
81
67
  feature_name == 'enumerator' ||
82
68
  (target_ruby_version >= 2.1 && feature_name == 'thread') ||
83
69
  (target_ruby_version >= 2.2 && RUBY_22_LOADED_FEATURES.include?(feature_name)) ||
84
- (target_ruby_version >= 2.5 && feature_name == 'pp' && !need_to_require_pp?) ||
85
70
  (target_ruby_version >= 2.7 && feature_name == 'ruby2_keywords') ||
86
71
  (target_ruby_version >= 3.1 && feature_name == 'fiber') ||
87
72
  (target_ruby_version >= 3.2 && feature_name == 'set')
88
73
  end
89
74
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
90
-
91
- def need_to_require_pp?
92
- processed_source.ast.each_descendant(:send).any? do |node|
93
- pp_const?(node.receiver) || PRETTY_PRINT_METHODS.include?(node.method_name)
94
- end
95
- end
96
75
  end
97
76
  end
98
77
  end