rubocop 1.75.1 → 1.75.2

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
  3. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  4. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  5. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
  6. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -4
  7. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  8. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -3
  9. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  10. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  11. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  12. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +7 -4
  13. data/lib/rubocop/cop/lint/return_in_void_context.rb +7 -2
  14. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  15. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
  16. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  17. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  18. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +1 -1
  19. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  20. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  21. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +0 -1
  22. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  23. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  24. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
  25. data/lib/rubocop/cop/style/conditional_assignment.rb +3 -0
  26. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  27. data/lib/rubocop/cop/style/empty_literal.rb +4 -0
  28. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  29. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  30. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  31. data/lib/rubocop/cop/style/hash_syntax.rb +3 -0
  32. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  33. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -1
  34. data/lib/rubocop/cop/style/redundant_condition.rb +13 -1
  35. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  36. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  37. data/lib/rubocop/cop/util.rb +1 -1
  38. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  39. data/lib/rubocop/magic_comment.rb +8 -0
  40. data/lib/rubocop/server/cache.rb +13 -10
  41. data/lib/rubocop/target_finder.rb +1 -1
  42. data/lib/rubocop/version.rb +1 -1
  43. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a064330786019e0efee6b496e761b05bea0286f0afdcbb4fffad2f07433aef9d
4
- data.tar.gz: eb1ee00d5fe060ea49203635df3c7457df6f416de93c9801a687386aa02f4768
3
+ metadata.gz: 707ab6b769b30dc2f2c34c7e879fde41cab6dd694820d8f071db17a1ef0ef48f
4
+ data.tar.gz: abafc2d95cd2c358b4699211ce58e544852707630c55ec2950a3fd01899b8dd4
5
5
  SHA512:
6
- metadata.gz: 336c6e38cc6162a00ca4c9780dcc71fb4b03a785af0eb6abb6c30baf2e1c8512af12e921a2036564102290324e418278cb83ceb06d7a1ec44ddf314923275f89
7
- data.tar.gz: cbe9d5ab5685dbab70de2b281ecc807494631a294273260d87315d6875b753d9c2b60f6d7c14379eaf5b384894a4400c747ef91a57323c418c66a51076b33f06
6
+ metadata.gz: 290274c929ba840ebf66f9e2978f5853e04732ef05bfaee7dd45ab445ae4cc41e7913bc6204ef1e11618ec9bfb8fe1c234bc6febbcb3e65e7c651f73f31936ba
7
+ data.tar.gz: 56f21668db3004f7a6846319911b3c7fe37d71a1d0ee43c9eee0f032ba324fc4745693fc4996907efd81975b23e1926c65f8129182e1f57e1b4c2e910af32984
@@ -28,6 +28,7 @@ module RuboCop
28
28
  RESTRICT_ON_SEND = %i[def_node_matcher def_node_search].freeze
29
29
  NODE_GROUPS = {
30
30
  any_block: %i[block numblock itblock],
31
+ any_def: %i[def defs],
31
32
  argument: %i[arg optarg restarg kwarg kwoptarg kwrestarg blockarg forward_arg shadowarg],
32
33
  boolean: %i[true false],
33
34
  call: %i[send csend],
@@ -73,8 +73,7 @@ module RuboCop
73
73
  # @!method block_end_align_target?(node, child)
74
74
  def_node_matcher :block_end_align_target?, <<~PATTERN
75
75
  {assignment?
76
- def
77
- defs
76
+ any_def
78
77
  splat
79
78
  and
80
79
  or
@@ -48,7 +48,7 @@ module RuboCop
48
48
  def on_send(node)
49
49
  return unless node.def_modifier?
50
50
 
51
- method_def = node.each_descendant(:def, :defs).first
51
+ method_def = node.each_descendant(:any_def).first
52
52
  expr = node.source_range
53
53
 
54
54
  line_start = range_between(expr.begin_pos, method_def.loc.keyword.end_pos)
@@ -180,7 +180,7 @@ module RuboCop
180
180
  end
181
181
 
182
182
  def method_candidate?(node)
183
- cop_config['EmptyLineBetweenMethodDefs'] && node.type?(:def, :defs)
183
+ cop_config['EmptyLineBetweenMethodDefs'] && node.any_def_type?
184
184
  end
185
185
 
186
186
  def class_candidate?(node)
@@ -252,7 +252,7 @@ module RuboCop
252
252
  end
253
253
 
254
254
  def end_loc(node)
255
- if node.type?(:def, :defs) && node.endless?
255
+ if node.any_def_type? && node.endless?
256
256
  node.source_range.end
257
257
  else
258
258
  node.loc.end
@@ -29,8 +29,7 @@ module RuboCop
29
29
  MSG = '`%<kw_loc>s` at %<kw_loc_line>d, %<kw_loc_column>d is not ' \
30
30
  'aligned with `%<beginning>s` at ' \
31
31
  '%<begin_loc_line>d, %<begin_loc_column>d.'
32
- ANCESTOR_TYPES = %i[kwbegin def defs class module any_block].freeze
33
- ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS = %i[def defs].freeze
32
+ ANCESTOR_TYPES = %i[kwbegin any_def class module any_block].freeze
34
33
  ALTERNATIVE_ACCESS_MODIFIERS = %i[public_class_method private_class_method].freeze
35
34
 
36
35
  def on_resbody(node)
@@ -162,8 +161,7 @@ module RuboCop
162
161
  end
163
162
 
164
163
  def access_modifier_node(node)
165
- return nil unless
166
- ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS.include?(node.type)
164
+ return nil unless node.any_def_type?
167
165
 
168
166
  access_modifier_node = node.ancestors.first
169
167
  return nil unless access_modifier?(access_modifier_node)
@@ -134,7 +134,7 @@ module RuboCop
134
134
  if NO_ARG_ALGORITHM.include?(algorithm_parts.first.upcase) && no_arguments
135
135
  "'#{algorithm_parts.first}'"
136
136
  else
137
- mode = 'cbc' unless size_and_mode == ['cbc']
137
+ mode = 'cbc' if size_and_mode.empty?
138
138
 
139
139
  "'#{(algorithm_parts + size_and_mode + [mode]).compact.take(3).join('-')}'"
140
140
  end
@@ -42,7 +42,6 @@ module RuboCop
42
42
  class DuplicateMethods < Base
43
43
  MSG = 'Method `%<method>s` is defined at both %<defined>s and %<current>s.'
44
44
  RESTRICT_ON_SEND = %i[alias_method attr_reader attr_writer attr_accessor attr].freeze
45
- DEF_TYPES = %i[def defs].freeze
46
45
 
47
46
  def initialize(config = nil, options = nil)
48
47
  super
@@ -162,7 +161,7 @@ module RuboCop
162
161
  end
163
162
 
164
163
  def method_key(node, method_name)
165
- if (ancestor_def = node.each_ancestor(*DEF_TYPES).first)
164
+ if (ancestor_def = node.each_ancestor(:any_def).first)
166
165
  "#{ancestor_def.method_name}.#{method_name}"
167
166
  else
168
167
  method_name
@@ -170,7 +169,7 @@ module RuboCop
170
169
  end
171
170
 
172
171
  def location(node)
173
- if DEF_TYPES.include?(node.type)
172
+ if node.any_def_type?
174
173
  node.loc.keyword.join(node.loc.name)
175
174
  else
176
175
  node.source_range
@@ -98,7 +98,7 @@ module RuboCop
98
98
  subject, = *node # rubocop:disable InternalAffairs/NodeDestructuring
99
99
  return if node.defs_type? && allowed_subject_type?(subject)
100
100
 
101
- def_ancestor = node.each_ancestor(:def, :defs).first
101
+ def_ancestor = node.each_ancestor(:any_def).first
102
102
  return unless def_ancestor
103
103
 
104
104
  within_scoping_def =
@@ -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(:any_block, :def, :defs) do |node|
49
+ return_node.each_ancestor(:any_block, :any_def) do |node|
50
50
  break if scoped_node?(node)
51
51
 
52
52
  # if a proc is passed to `Module#define_method` or
@@ -66,7 +66,7 @@ module RuboCop
66
66
  private
67
67
 
68
68
  def scoped_node?(node)
69
- node.type?(:def, :defs) || node.lambda?
69
+ node.any_def_type? || node.lambda?
70
70
  end
71
71
 
72
72
  def return_value?(return_node)
@@ -30,7 +30,7 @@ module RuboCop
30
30
  return unless node.lhs&.casgn_type?
31
31
 
32
32
  add_offense(node.loc.operator) do |corrector|
33
- next if node.each_ancestor(:def, :defs).any?
33
+ next if node.each_ancestor(:any_def).any?
34
34
 
35
35
  corrector.replace(node.loc.operator, '=')
36
36
  end
@@ -27,7 +27,8 @@ module RuboCop
27
27
  # In all cases, chaining one same `to_*` conversion methods listed above is redundant.
28
28
  #
29
29
  # The cop can also register an offense for chaining conversion methods on methods that are
30
- # expected to return a specific type regardless of receiver (eg. `foo.inspect.to_s`).
30
+ # expected to return a specific type regardless of receiver (eg. `foo.inspect.to_s` and
31
+ # `foo.to_json.to_s`).
31
32
  #
32
33
  # @example
33
34
  # # bad
@@ -69,10 +70,12 @@ module RuboCop
69
70
  # foo.to_s
70
71
  #
71
72
  # # bad - chaining a conversion to a method that is expected to return the same type
72
- # inspect.to_s
73
+ # foo.inspect.to_s
74
+ # foo.to_json.to_s
73
75
  #
74
76
  # # good
75
- # inspect
77
+ # foo.inspect
78
+ # foo.to_json
76
79
  #
77
80
  class RedundantTypeConversion < Base
78
81
  extend AutoCorrector
@@ -108,7 +111,7 @@ module RuboCop
108
111
 
109
112
  # Methods that already are expected to return a given type, which makes a further
110
113
  # conversion redundant.
111
- TYPED_METHODS = { to_s: %i[inspect] }.freeze
114
+ TYPED_METHODS = { to_s: %i[inspect to_json] }.freeze
112
115
 
113
116
  CONVERSION_METHODS = Set[*LITERAL_NODE_TYPES.keys].freeze
114
117
  RESTRICT_ON_SEND = CONVERSION_METHODS + [:to_d]
@@ -32,12 +32,17 @@ module RuboCop
32
32
  class ReturnInVoidContext < Base
33
33
  MSG = 'Do not return a value in `%<method>s`.'
34
34
 
35
+ # Returning out of these methods only exits the block itself.
36
+ SCOPE_CHANGING_METHODS = %i[lambda define_method define_singleton_method].freeze
37
+
35
38
  def on_return(return_node)
36
39
  return unless return_node.descendants.any?
37
40
 
38
- def_node = return_node.each_ancestor(:def).first
41
+ def_node = return_node.each_ancestor(:any_def).first
39
42
  return unless def_node&.void_context?
40
- return if return_node.each_ancestor(:any_block).any?(&:lambda?)
43
+ return if return_node.each_ancestor(:any_block).any? do |block_node|
44
+ SCOPE_CHANGING_METHODS.include?(block_node.method_name)
45
+ end
41
46
 
42
47
  add_offense(
43
48
  return_node.loc.keyword,
@@ -116,7 +116,7 @@ module RuboCop
116
116
  private
117
117
 
118
118
  def comment_between_rescue_and_end?(node)
119
- ancestor = node.each_ancestor(:kwbegin, :def, :defs, :any_block).first
119
+ ancestor = node.each_ancestor(:kwbegin, :any_def, :any_block).first
120
120
  return false unless ancestor
121
121
 
122
122
  end_line = ancestor.loc.end&.line || ancestor.loc.last_line
@@ -45,7 +45,7 @@ module RuboCop
45
45
  PATTERN
46
46
 
47
47
  def on_send(node)
48
- def_node = node.each_ancestor(:def, :defs).first
48
+ def_node = node.each_ancestor(:any_def).first
49
49
  return unless def_node
50
50
 
51
51
  enum_conversion_call?(node) do |method_node, arguments|
@@ -40,7 +40,7 @@ module RuboCop
40
40
  # top-level return node's ancestors should not be of block, def, or
41
41
  # defs type.
42
42
  def top_level_return?(return_node)
43
- return_node.each_ancestor(:block, :def, :defs).none?
43
+ return_node.each_ancestor(:block, :any_def).none?
44
44
  end
45
45
  end
46
46
  end
@@ -48,7 +48,7 @@ module RuboCop
48
48
 
49
49
  args = process_args(node.arguments)
50
50
  return extract_breakable_node_from_elements(node, args, max)
51
- elsif node.type?(:def, :defs)
51
+ elsif node.any_def_type?
52
52
  return extract_breakable_node_from_elements(node, node.arguments, max)
53
53
  elsif node.type?(:array, :hash)
54
54
  return extract_breakable_node_from_elements(node, node.children, max)
@@ -220,7 +220,7 @@ module RuboCop
220
220
 
221
221
  # @api private
222
222
  def already_on_multiple_lines?(node)
223
- return node.first_line != node.last_argument.last_line if node.type?(:def, :defs)
223
+ return node.first_line != node.last_argument.last_line if node.any_def_type?
224
224
 
225
225
  !node.single_line?
226
226
  end
@@ -40,7 +40,7 @@ module RuboCop
40
40
  end
41
41
 
42
42
  def safe_to_split?(node)
43
- node.each_descendant(:if, :case, :kwbegin, :def, :defs).none? &&
43
+ node.each_descendant(:if, :case, :kwbegin, :any_def).none? &&
44
44
  node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
45
45
  node.each_descendant(:begin, :sym).none? { |b| !b.single_line? }
46
46
  end
@@ -19,7 +19,7 @@ module RuboCop
19
19
 
20
20
  # @!method non_public_modifier?(node)
21
21
  def_node_matcher :non_public_modifier?, <<~PATTERN
22
- (send nil? {:private :protected :private_class_method} ({def defs} ...))
22
+ (send nil? {:private :protected :private_class_method} (any_def ...))
23
23
  PATTERN
24
24
  end
25
25
  end
@@ -21,7 +21,7 @@ module RuboCop
21
21
 
22
22
  # @!method empty_line_required?(node)
23
23
  def_node_matcher :empty_line_required?,
24
- '{def defs class module (send nil? {:private :protected :public})}'
24
+ '{any_def class module (send nil? {:private :protected :public})}'
25
25
 
26
26
  def check(node, body, adjusted_first_line: nil)
27
27
  return if valid_body_style?(body)
@@ -6,7 +6,6 @@ module RuboCop
6
6
  module FrozenStringLiteral
7
7
  module_function
8
8
 
9
- FROZEN_STRING_LITERAL_REGEXP = /#\s*frozen[-_]?string[-_]?literal:/i.freeze
10
9
  FROZEN_STRING_LITERAL_ENABLED = '# frozen_string_literal: true'
11
10
  FROZEN_STRING_LITERAL_TYPES_RUBY27 = %i[str dstr].freeze
12
11
 
@@ -242,7 +242,7 @@ module RuboCop
242
242
  def find_definition(node)
243
243
  # Methods can be defined in a `def` or `defs`,
244
244
  # or dynamically via a `block` node.
245
- node.each_ancestor(:def, :defs, :block).each do |ancestor|
245
+ node.each_ancestor(:any_def, :block).each do |ancestor|
246
246
  method_node, method_name = method_definition?(ancestor)
247
247
  return [method_node, method_name] if method_node
248
248
  end
@@ -105,7 +105,7 @@ module RuboCop
105
105
  end
106
106
 
107
107
  def register_forbidden_name(node)
108
- if node.type?(:def, :defs)
108
+ if node.any_def_type?
109
109
  name_node = node.loc.name
110
110
  method_name = node.method_name
111
111
  else
@@ -68,7 +68,7 @@ module RuboCop
68
68
  PATTERN
69
69
 
70
70
  def on_send(node)
71
- def_node = node.each_ancestor(:def, :defs).first
71
+ def_node = node.each_ancestor(:any_def).first
72
72
  return if def_node &&
73
73
  (allowed_method?(def_node.method_name) ||
74
74
  matches_allowed_pattern?(def_node.method_name))
@@ -436,9 +436,11 @@ module RuboCop
436
436
  # Helper module to provide common methods to ConditionalAssignment
437
437
  # correctors
438
438
  module ConditionalCorrectorHelper
439
+ # rubocop:disable Metrics/AbcSize
439
440
  def remove_whitespace_in_branches(corrector, branch, condition, column)
440
441
  branch.each_node do |child|
441
442
  next if child.source_range.nil?
443
+ next if child.parent.dstr_type?
442
444
 
443
445
  white_space = white_space_range(child, column)
444
446
  corrector.remove(white_space) if white_space.source.strip.empty?
@@ -450,6 +452,7 @@ module RuboCop
450
452
  corrector.remove_preceding(loc, loc.column - column)
451
453
  end
452
454
  end
455
+ # rubocop:enable Metrics/AbcSize
453
456
 
454
457
  def white_space_range(node, column)
455
458
  expression = node.source_range
@@ -102,7 +102,7 @@ module RuboCop
102
102
 
103
103
  def find_def_node_from_ascendant(node)
104
104
  return unless (parent = node.parent)
105
- return parent if parent.type?(:def, :defs)
105
+ return parent if parent.any_def_type?
106
106
  return node.parent.child_nodes.first if define_method?(parent)
107
107
 
108
108
  find_def_node_from_ascendant(node.parent)
@@ -6,6 +6,10 @@ module RuboCop
6
6
  # Checks for the use of a method, the result of which
7
7
  # would be a literal, like an empty array, hash, or string.
8
8
  #
9
+ # NOTE: When frozen string literals are enabled, `String.new`
10
+ # isn't corrected to an empty string since the former is
11
+ # mutable and the latter would be frozen.
12
+ #
9
13
  # @example
10
14
  # # bad
11
15
  # a = Array.new
@@ -65,7 +65,7 @@ module RuboCop
65
65
  yielding_block?(block_node) do |send_node, block_args, yield_args|
66
66
  return unless yielding_arguments?(block_args, yield_args)
67
67
 
68
- def_node = block_node.each_ancestor(:def, :defs).first
68
+ def_node = block_node.each_ancestor(:any_def).first
69
69
  # if `yield` is being called outside of a method context, ignore
70
70
  # this is not a valid ruby pattern, but can happen in haml or erb,
71
71
  # so this can cause crashes in haml_lint
@@ -151,7 +151,7 @@ module RuboCop
151
151
  end
152
152
 
153
153
  def build_new_arguments_for_zsuper(node)
154
- def_node = node.each_ancestor(:def, :defs).first
154
+ def_node = node.each_ancestor(:any_def).first
155
155
  def_node.arguments.map do |arg|
156
156
  arg.optarg_type? ? arg.node_parts[0] : arg.source
157
157
  end
@@ -151,7 +151,7 @@ module RuboCop
151
151
 
152
152
  def frozen_string_literal_comment(processed_source)
153
153
  processed_source.tokens.find do |token|
154
- token.text.start_with?(FROZEN_STRING_LITERAL_REGEXP)
154
+ MagicComment.parse(token.text).frozen_string_literal_specified?
155
155
  end
156
156
  end
157
157
 
@@ -189,8 +189,9 @@ module RuboCop
189
189
 
190
190
  def enable_comment(corrector)
191
191
  comment = frozen_string_literal_comment(processed_source)
192
+ replacement = MagicComment.parse(comment.text).new_frozen_string_literal(true)
192
193
 
193
- corrector.replace(line_range(comment.line), FROZEN_STRING_LITERAL_ENABLED)
194
+ corrector.replace(line_range(comment.line), replacement)
194
195
  end
195
196
 
196
197
  def insert_comment(corrector)
@@ -8,6 +8,9 @@ module RuboCop
8
8
  # reassign (possibly to redirect some stream) constants in Ruby, you'll get
9
9
  # an interpreter warning if you do so.
10
10
  #
11
+ # Additionally, `$stdout/$stderr/$stdin` can safely be accessed in a Ractor because they
12
+ # are ractor-local, while `STDOUT/STDERR/STDIN` will raise `Ractor::IsolationError`.
13
+ #
11
14
  # @safety
12
15
  # Autocorrection is unsafe because `STDOUT` and `$stdout` may point to different
13
16
  # objects, for example.
@@ -76,6 +76,9 @@ module RuboCop
76
76
  # # good
77
77
  # {foo:, bar:}
78
78
  #
79
+ # # good - allowed to mix syntaxes
80
+ # {foo:, bar: baz}
81
+ #
79
82
  # @example EnforcedShorthandSyntax: never
80
83
  #
81
84
  # # bad
@@ -42,7 +42,7 @@ module RuboCop
42
42
  return if kwarg_nodes.empty?
43
43
 
44
44
  add_offense(node) do |corrector|
45
- defining_node = node.each_ancestor(:def, :defs, :block).first
45
+ defining_node = node.each_ancestor(:any_def, :block).first
46
46
  next if processed_source.contains_comment?(arguments_range(defining_node))
47
47
  next unless node.parent.find(&:kwoptarg_type?) == node
48
48
 
@@ -49,7 +49,7 @@ module RuboCop
49
49
 
50
50
  def inside_endless_method_def?(node)
51
51
  # parens are required around arguments inside an endless method
52
- node.each_ancestor(:def, :defs).any?(&:endless?) && node.arguments.any?
52
+ node.each_ancestor(:any_def).any?(&:endless?) && node.arguments.any?
53
53
  end
54
54
 
55
55
  def require_parentheses_for_hash_value_omission?(node) # rubocop:disable Metrics/PerceivedComplexity
@@ -230,6 +230,14 @@ module RuboCop
230
230
  node.type?(:kwsplat, :forwarded_kwrestarg)
231
231
  end
232
232
 
233
+ def wrap_arguments_with_parens(condition)
234
+ method = condition.source_range.begin.join(condition.loc.selector.end)
235
+ arguments = condition.first_argument.source_range.begin.join(condition.source_range.end)
236
+
237
+ "#{method.source}(#{arguments.source})"
238
+ end
239
+
240
+ # rubocop:disable Metrics/AbcSize
233
241
  def if_source(if_branch, arithmetic_operation)
234
242
  if branches_have_method?(if_branch.parent) && if_branch.parenthesized?
235
243
  if_branch.source.delete_suffix(')')
@@ -238,11 +246,15 @@ module RuboCop
238
246
 
239
247
  "#{if_branch.receiver.source} #{if_branch.method_name} (#{argument_source}"
240
248
  elsif if_branch.true_type?
241
- if_branch.parent.condition.source
249
+ condition = if_branch.parent.condition
250
+ return condition.source if condition.arguments.empty?
251
+
252
+ wrap_arguments_with_parens(condition)
242
253
  else
243
254
  if_branch.source
244
255
  end
245
256
  end
257
+ # rubocop:enable Metrics/AbcSize
246
258
 
247
259
  def else_source(else_branch, arithmetic_operation) # rubocop:disable Metrics/AbcSize
248
260
  if arithmetic_operation
@@ -47,7 +47,7 @@ module RuboCop
47
47
 
48
48
  def on_return(node)
49
49
  # Check Lint/NonLocalExitFromIterator first before this cop
50
- node.each_ancestor(:block, :def, :defs) do |n|
50
+ node.each_ancestor(:block, :any_def) do |n|
51
51
  break if scoped_node?(n)
52
52
 
53
53
  send_node, args_node, _body_node = *n
@@ -83,7 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def scoped_node?(node)
86
- node.type?(:def, :defs) || node.lambda?
86
+ node.any_def_type? || node.lambda?
87
87
  end
88
88
 
89
89
  # @!method chained_send?(node)
@@ -68,7 +68,6 @@ module RuboCop
68
68
  class SuperArguments < Base
69
69
  extend AutoCorrector
70
70
 
71
- DEF_TYPES = %i[def defs].freeze
72
71
  ASSIGN_TYPES = %i[or_asgn lvasgn].freeze
73
72
 
74
73
  MSG = 'Call `super` without arguments and parentheses when the signature is identical.'
@@ -100,7 +99,7 @@ module RuboCop
100
99
  # `super` used within the block is always allowed.
101
100
  break if node.any_block_type? && !block_sends_to_super?(super_node, node)
102
101
 
103
- break node if DEF_TYPES.include?(node.type)
102
+ break node if node.any_def_type?
104
103
  end
105
104
  end
106
105
 
@@ -76,7 +76,7 @@ module RuboCop
76
76
  loc = node.loc
77
77
  selector = if node.type?(:super, :yield)
78
78
  loc.keyword
79
- elsif node.type?(:def, :defs)
79
+ elsif node.any_def_type?
80
80
  loc.name
81
81
  else
82
82
  loc.selector
@@ -107,7 +107,7 @@ module RuboCop
107
107
  end
108
108
 
109
109
  def method_argument?
110
- argument? && %i[def defs].include?(@scope.node.type)
110
+ argument? && @scope.node.any_def_type?
111
111
  end
112
112
 
113
113
  def block_argument?
@@ -193,6 +193,10 @@ module RuboCop
193
193
  SEPARATOR = ';'
194
194
  OPERATOR = ':'
195
195
 
196
+ def new_frozen_string_literal(value)
197
+ "# -*- frozen_string_literal: #{value} -*-"
198
+ end
199
+
196
200
  private
197
201
 
198
202
  def extract_frozen_string_literal
@@ -275,6 +279,10 @@ module RuboCop
275
279
  end
276
280
  end
277
281
 
282
+ def new_frozen_string_literal(value)
283
+ "# frozen_string_literal: #{value}"
284
+ end
285
+
278
286
  private
279
287
 
280
288
  # Extract `frozen_string_literal`.
@@ -52,7 +52,8 @@ module RuboCop
52
52
  end.find(&:exist?)
53
53
  version_data = lockfile_path&.read || RuboCop::Version::STRING
54
54
  config_data = Pathname(ConfigFinder.find_config_path(Dir.pwd)).read
55
- yaml = YAML.safe_load(config_data, permitted_classes: [Regexp, Symbol], aliases: true)
55
+ yaml = load_erb_templated_yaml(config_data)
56
+
56
57
  inherit_from_data = inherit_from_data(yaml)
57
58
  require_data = require_data(yaml)
58
59
 
@@ -76,7 +77,6 @@ module RuboCop
76
77
  File.expand_path(File.join(cache_root_dir, 'server'))
77
78
  end
78
79
 
79
- # rubocop:disable Metrics/MethodLength
80
80
  def cache_root_dir_from_config
81
81
  CacheConfig.root_dir do
82
82
  # `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
@@ -87,13 +87,7 @@ module RuboCop
87
87
  # Returns early if `CacheRootDirectory` is not used before requiring `erb` or `yaml`.
88
88
  next unless file_contents.include?('CacheRootDirectory')
89
89
 
90
- require 'erb'
91
- yaml_code = ERB.new(file_contents).result
92
-
93
- require 'yaml'
94
- config_yaml = YAML.safe_load(
95
- yaml_code, permitted_classes: [Regexp, Symbol], aliases: true
96
- )
90
+ config_yaml = load_erb_templated_yaml(file_contents)
97
91
 
98
92
  # For compatibility with Ruby 3.0 or lower.
99
93
  if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
@@ -103,7 +97,6 @@ module RuboCop
103
97
  config_yaml&.dig('AllCops', 'CacheRootDirectory')
104
98
  end
105
99
  end
106
- # rubocop:enable Metrics/MethodLength
107
100
 
108
101
  def port_path
109
102
  dir.join('port')
@@ -197,6 +190,16 @@ module RuboCop
197
190
  path.exist? ? path.read : ''
198
191
  end.join
199
192
  end
193
+
194
+ private
195
+
196
+ def load_erb_templated_yaml(content)
197
+ require 'erb'
198
+ yaml_code = ERB.new(content).result
199
+
200
+ require 'yaml'
201
+ YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true)
202
+ end
200
203
  end
201
204
  end
202
205
  end
@@ -175,7 +175,7 @@ module RuboCop
175
175
  end
176
176
 
177
177
  def ruby_executable?(file)
178
- return false unless File.extname(file).empty? && File.exist?(file)
178
+ return false if !File.extname(file).empty? || !File.exist?(file) || File.empty?(file)
179
179
 
180
180
  first_line = File.open(file, &:readline)
181
181
  /#!.*(#{ruby_interpreters(file).join('|')})/.match?(first_line)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.75.1'
6
+ STRING = '1.75.2'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.75.1
4
+ version: 1.75.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-03-26 00:00:00.000000000 Z
12
+ date: 2025-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -127,7 +127,7 @@ dependencies:
127
127
  requirements:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: 1.43.0
130
+ version: 1.44.0
131
131
  - - "<"
132
132
  - !ruby/object:Gem::Version
133
133
  version: '2.0'
@@ -137,7 +137,7 @@ dependencies:
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 1.43.0
140
+ version: 1.44.0
141
141
  - - "<"
142
142
  - !ruby/object:Gem::Version
143
143
  version: '2.0'
@@ -1080,7 +1080,7 @@ licenses:
1080
1080
  - MIT
1081
1081
  metadata:
1082
1082
  homepage_uri: https://rubocop.org/
1083
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.1
1083
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.2
1084
1084
  source_code_uri: https://github.com/rubocop/rubocop/
1085
1085
  documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1086
1086
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues