rubocop 1.71.0 → 1.71.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  3. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  4. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  5. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
  6. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
  7. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
  8. data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
  9. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +1 -0
  10. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  11. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  13. data/lib/rubocop/cop/layout/class_structure.rb +2 -2
  14. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  15. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -5
  16. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  17. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  18. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  19. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
  20. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  21. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -5
  22. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
  23. data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
  24. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  25. data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
  26. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  27. data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
  28. data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
  29. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  30. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
  31. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
  32. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
  33. data/lib/rubocop/cop/lint/constant_reassignment.rb +2 -6
  34. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  35. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
  36. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  37. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  38. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  39. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  40. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
  41. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  42. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  43. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -1
  44. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
  45. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  46. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  47. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  48. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  49. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
  50. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  51. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
  52. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
  53. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  54. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
  55. data/lib/rubocop/cop/lint/void.rb +1 -1
  56. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  57. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  58. data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -5
  59. data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
  60. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
  61. data/lib/rubocop/cop/mixin/hash_subset.rb +19 -1
  62. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  63. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +22 -8
  64. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  65. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  66. data/lib/rubocop/cop/naming/block_forwarding.rb +18 -14
  67. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
  68. data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -4
  69. data/lib/rubocop/cop/style/arguments_forwarding.rb +38 -19
  70. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  71. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  72. data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
  73. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  74. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
  75. data/lib/rubocop/cop/style/conditional_assignment.rb +3 -3
  76. data/lib/rubocop/cop/style/documentation.rb +1 -1
  77. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  78. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  79. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  80. data/lib/rubocop/cop/style/hash_each_methods.rb +2 -5
  81. data/lib/rubocop/cop/style/hash_except.rb +15 -0
  82. data/lib/rubocop/cop/style/hash_slice.rb +15 -0
  83. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  84. data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
  85. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
  86. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  87. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
  88. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  89. data/lib/rubocop/cop/style/inverse_methods.rb +6 -6
  90. data/lib/rubocop/cop/style/it_assignment.rb +1 -1
  91. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  92. data/lib/rubocop/cop/style/map_into_array.rb +1 -1
  93. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  94. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  95. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +10 -13
  96. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
  97. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  98. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  99. data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
  100. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
  101. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  102. data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
  103. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
  104. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  105. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  106. data/lib/rubocop/cop/style/proc.rb +1 -2
  107. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  108. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  109. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
  110. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  111. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  112. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  113. data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -6
  114. data/lib/rubocop/cop/style/redundant_self_assignment.rb +12 -27
  115. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  116. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
  117. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  118. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  119. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  120. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  121. data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -1
  122. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  123. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  124. data/lib/rubocop/cop/style/super_arguments.rb +4 -4
  125. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  126. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  127. data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
  128. data/lib/rubocop/cop/util.rb +2 -2
  129. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  130. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
  131. data/lib/rubocop/rspec/support.rb +1 -2
  132. data/lib/rubocop/version.rb +1 -1
  133. metadata +9 -6
  134. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
@@ -83,7 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def scoped_node?(node)
86
- node.def_type? || node.defs_type? || node.lambda?
86
+ node.type?(:def, :defs) || node.lambda?
87
87
  end
88
88
 
89
89
  # @!method chained_send?(node)
@@ -312,7 +312,7 @@ module RuboCop
312
312
  end
313
313
 
314
314
  def chain_length(method_chain, method)
315
- method.each_ancestor(:send, :csend).inject(0) do |total, ancestor|
315
+ method.each_ancestor(:call).inject(0) do |total, ancestor|
316
316
  break total + 1 if ancestor == method_chain
317
317
 
318
318
  total + 1
@@ -164,7 +164,7 @@ module RuboCop
164
164
 
165
165
  ast = processed_source.ast
166
166
  @range_nodes = ast.range_type? ? [ast] : []
167
- @range_nodes.concat(ast.each_descendant(:irange, :erange).to_a)
167
+ @range_nodes.concat(ast.each_descendant(:range).to_a)
168
168
  end
169
169
  end
170
170
  end
@@ -68,7 +68,7 @@ module RuboCop
68
68
  return false if body_node.parent.assignment_method? ||
69
69
  NOT_SUPPORTED_ENDLESS_METHOD_BODY_TYPES.include?(body_node.type)
70
70
 
71
- !(body_node.begin_type? || body_node.kwbegin_type?)
71
+ !body_node.type?(:begin, :kwbegin)
72
72
  end
73
73
 
74
74
  def correct_to_multiline(corrector, node)
@@ -156,7 +156,7 @@ module RuboCop
156
156
  # Handle `send` and `block` nodes that need to be wrapped in parens
157
157
  # FIXME: autocorrection prevents syntax errors by wrapping the entire node in parens,
158
158
  # but wrapping the argument list would be a more ergonomic correction.
159
- node_to_check = condition&.block_type? ? condition.send_node : condition
159
+ node_to_check = condition&.any_block_type? ? condition.send_node : condition
160
160
  return unless wrap_condition?(node_to_check)
161
161
 
162
162
  if condition.call_type?
@@ -132,7 +132,7 @@ module RuboCop
132
132
  end
133
133
 
134
134
  def heredoc?(node)
135
- return false unless node.str_type? || node.dstr_type?
135
+ return false unless node.type?(:str, :dstr)
136
136
 
137
137
  node.heredoc?
138
138
  end
@@ -69,7 +69,7 @@ module RuboCop
69
69
  end
70
70
 
71
71
  def all_string_literals?(nodes)
72
- nodes.all? { |n| n.str_type? || n.dstr_type? }
72
+ nodes.all? { |n| n.type?(:str, :dstr) }
73
73
  end
74
74
 
75
75
  def detect_quote_styles(node)
@@ -98,7 +98,7 @@ module RuboCop
98
98
  # When defining dynamic methods, implicitly calling `super` is not possible.
99
99
  # Since there is a possibility of delegation to `define_method`,
100
100
  # `super` used within the block is always allowed.
101
- break if node.block_type? && !block_sends_to_super?(super_node, node)
101
+ break if node.any_block_type? && !block_sends_to_super?(super_node, node)
102
102
 
103
103
  break node if DEF_TYPES.include?(node.type)
104
104
  end
@@ -136,13 +136,13 @@ module RuboCop
136
136
  # Checks if the send node of a block is the given super node,
137
137
  # or a method chain containing it.
138
138
  return false unless parent_node
139
- return false unless parent_node.type?(:block, :numblock)
139
+ return false unless parent_node.any_block_type?
140
140
 
141
141
  parent_node.send_node.each_node(:super).any?(super_node)
142
142
  end
143
143
 
144
144
  def positional_arg_same?(def_arg, super_arg)
145
- return false unless def_arg.arg_type? || def_arg.optarg_type?
145
+ return false unless def_arg.type?(:arg, :optarg)
146
146
  return false unless super_arg.lvar_type?
147
147
 
148
148
  def_arg.name == super_arg.children.first
@@ -159,7 +159,7 @@ module RuboCop
159
159
  end
160
160
 
161
161
  def keyword_arg_same?(def_arg, super_arg)
162
- return false unless def_arg.kwarg_type? || def_arg.kwoptarg_type?
162
+ return false unless def_arg.type?(:kwarg, :kwoptarg)
163
163
  return false unless (pair_node = super_arg).pair_type?
164
164
  return false unless (sym_node = pair_node.key).sym_type?
165
165
  return false unless (lvar_node = pair_node.value).lvar_type?
@@ -232,7 +232,7 @@ module RuboCop
232
232
  end
233
233
 
234
234
  def node_with_args?(node)
235
- node.call_type? || node.defined_type?
235
+ node.type?(:call, :defined?)
236
236
  end
237
237
  end
238
238
  end
@@ -77,7 +77,7 @@ module RuboCop
77
77
 
78
78
  # @!method define_method_block?(node)
79
79
  def_node_matcher :define_method_block?, <<~PATTERN
80
- ({block numblock} (send _ :define_method _) ...)
80
+ (any_block (send _ :define_method _) ...)
81
81
  PATTERN
82
82
  end
83
83
  end
@@ -72,7 +72,7 @@ module RuboCop
72
72
  end
73
73
 
74
74
  def constant_portion?(node)
75
- node.numeric_type? || node.const_type?
75
+ node.type?(:numeric, :const)
76
76
  end
77
77
 
78
78
  def supported_operators
@@ -74,9 +74,9 @@ module RuboCop
74
74
 
75
75
  def args_begin(node)
76
76
  loc = node.loc
77
- selector = if node.super_type? || node.yield_type?
77
+ selector = if node.type?(:super, :yield)
78
78
  loc.keyword
79
- elsif node.def_type? || node.defs_type?
79
+ elsif node.type?(:def, :defs)
80
80
  loc.name
81
81
  else
82
82
  loc.selector
@@ -72,7 +72,7 @@ module RuboCop
72
72
  parent = parent.parent if parent&.begin_type?
73
73
  return false if parent.nil?
74
74
 
75
- (parent.if_type? || parent.while_type? || parent.until_type?) && parent.modifier_form?
75
+ parent.type?(:if, :while, :until) && parent.modifier_form?
76
76
  end
77
77
 
78
78
  def capture_with_block!
@@ -100,7 +100,7 @@ module RuboCop
100
100
 
101
101
  # Only block scope allows referencing outer scope variables.
102
102
  node = scope.node
103
- return nil unless node.block_type? || node.numblock_type?
103
+ return nil unless node.any_block_type?
104
104
  end
105
105
 
106
106
  nil
@@ -113,14 +113,14 @@ module RuboCop
113
113
  def accessible_variables
114
114
  scope_stack.reverse_each.with_object([]) do |scope, variables|
115
115
  variables.concat(scope.variables.values)
116
- break variables unless scope.node.block_type? || scope.node.numblock_type?
116
+ break variables unless scope.node.any_block_type?
117
117
  end
118
118
  end
119
119
 
120
120
  private
121
121
 
122
122
  def mark_variable_as_captured_by_block_if_so(variable)
123
- return unless current_scope.node.block_type? || current_scope.node.numblock_type?
123
+ return unless current_scope.node.any_block_type?
124
124
  return if variable.scope == current_scope
125
125
 
126
126
  variable.capture_with_block!
@@ -4,13 +4,12 @@
4
4
 
5
5
  require_relative 'cop_helper'
6
6
  require_relative 'expect_offense'
7
- require_relative 'host_environment_simulation_helper'
8
7
  require_relative 'parallel_formatter'
9
8
  require_relative 'shared_contexts'
10
9
 
11
10
  RSpec.configure do |config|
12
11
  config.include CopHelper
13
- config.include HostEnvironmentSimulatorHelper
12
+ config.include RuboCop::RSpec::ExpectOffense
14
13
  config.include_context 'config', :config
15
14
  config.include_context 'isolated environment', :isolated_environment
16
15
  config.include_context 'isolated bundler', :isolated_bundler
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.71.0'
6
+ STRING = '1.71.1'
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.71.0
4
+ version: 1.71.1
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-01-22 00:00:00.000000000 Z
12
+ date: 2025-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -113,7 +113,7 @@ dependencies:
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 1.36.2
116
+ version: 1.38.0
117
117
  - - "<"
118
118
  - !ruby/object:Gem::Version
119
119
  version: '2.0'
@@ -123,7 +123,7 @@ dependencies:
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: 1.36.2
126
+ version: 1.38.0
127
127
  - - "<"
128
128
  - !ruby/object:Gem::Version
129
129
  version: '2.0'
@@ -279,6 +279,10 @@ files:
279
279
  - lib/rubocop/cop/internal_affairs/node_destructuring.rb
280
280
  - lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb
281
281
  - lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
282
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups.rb
283
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb
284
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb
285
+ - lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb
282
286
  - lib/rubocop/cop/internal_affairs/node_type_predicate.rb
283
287
  - lib/rubocop/cop/internal_affairs/numblock_handler.rb
284
288
  - lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
@@ -1009,7 +1013,6 @@ files:
1009
1013
  - lib/rubocop/result_cache.rb
1010
1014
  - lib/rubocop/rspec/cop_helper.rb
1011
1015
  - lib/rubocop/rspec/expect_offense.rb
1012
- - lib/rubocop/rspec/host_environment_simulation_helper.rb
1013
1016
  - lib/rubocop/rspec/parallel_formatter.rb
1014
1017
  - lib/rubocop/rspec/shared_contexts.rb
1015
1018
  - lib/rubocop/rspec/support.rb
@@ -1046,7 +1049,7 @@ licenses:
1046
1049
  - MIT
1047
1050
  metadata:
1048
1051
  homepage_uri: https://rubocop.org/
1049
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.0
1052
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.1
1050
1053
  source_code_uri: https://github.com/rubocop/rubocop/
1051
1054
  documentation_uri: https://docs.rubocop.org/rubocop/1.71/
1052
1055
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # RuboCop can be run in contexts where unexpected other libraries are included,
4
- # which may interfere with its normal behavior. In order to test those
5
- # situations, it may be necessary to require another library for the duration
6
- # of one spec
7
- module HostEnvironmentSimulatorHelper
8
- def in_its_own_process_with(*files)
9
- if ::Process.respond_to?(:fork)
10
- pid = ::Process.fork do
11
- # Need to write coverage result under different name
12
- if defined?(SimpleCov)
13
- SimpleCov.command_name "rspec-fork-#{Process.pid}"
14
- SimpleCov.pid = Process.pid
15
- end
16
-
17
- files.each { |file| require file }
18
- yield
19
- end
20
- ::Process.wait(pid)
21
-
22
- # assert that the block did not fail
23
- expect($CHILD_STATUS).to be_success
24
- else
25
- warn 'Process.fork is not available.'
26
- end
27
- end
28
- end