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
@@ -159,7 +159,13 @@ module RuboCop
159
159
  node_to_check = condition&.block_type? ? condition.send_node : condition
160
160
  return unless wrap_condition?(node_to_check)
161
161
 
162
- corrector.wrap(condition, '(', ')')
162
+ if condition.call_type?
163
+ source = parenthesized_method_arguments(condition)
164
+
165
+ corrector.replace(condition, source)
166
+ else
167
+ corrector.wrap(condition, '(', ')')
168
+ end
163
169
  end
164
170
 
165
171
  def correct_for_outer_condition_modify_form_style(corrector, node, if_branch)
@@ -236,7 +242,20 @@ module RuboCop
236
242
  end
237
243
 
238
244
  def replace_condition(condition)
239
- wrap_condition?(condition) ? "(#{condition.source})" : condition.source
245
+ return condition.source unless wrap_condition?(condition)
246
+
247
+ if condition.call_type?
248
+ parenthesized_method_arguments(condition)
249
+ else
250
+ "(#{condition.source})"
251
+ end
252
+ end
253
+
254
+ def parenthesized_method_arguments(node)
255
+ method_call = node.source_range.begin.join(node.loc.selector.end).source
256
+ arguments = node.first_argument.source_range.begin.join(node.source_range.end).source
257
+
258
+ "#{method_call}(#{arguments})"
240
259
  end
241
260
 
242
261
  def allow_modifier?
@@ -17,8 +17,6 @@ module RuboCop
17
17
  # do_something(x.pop)
18
18
  # end
19
19
  #
20
- # @example
21
- #
22
20
  # # bad
23
21
  # until x.empty? do
24
22
  # do_something(x.pop)
@@ -16,7 +16,6 @@ module RuboCop
16
16
  # # good
17
17
  # x += 1 while x < 10
18
18
  #
19
- # @example
20
19
  # # bad
21
20
  # until x > 10
22
21
  # x += 1
@@ -47,7 +47,11 @@ module RuboCop
47
47
  check_zero_length_comparison(node)
48
48
  check_nonzero_length_comparison(node)
49
49
  end
50
- alias on_csend on_send
50
+
51
+ def on_csend(node)
52
+ check_zero_length_predicate(node)
53
+ check_zero_length_comparison(node)
54
+ end
51
55
 
52
56
  private
53
57
 
@@ -27,7 +27,10 @@ module RuboCop
27
27
  class VariableForce < Force # rubocop:disable Metrics/ClassLength
28
28
  VARIABLE_ASSIGNMENT_TYPE = :lvasgn
29
29
  REGEXP_NAMED_CAPTURE_TYPE = :match_with_lvasgn
30
- VARIABLE_ASSIGNMENT_TYPES = [VARIABLE_ASSIGNMENT_TYPE, REGEXP_NAMED_CAPTURE_TYPE].freeze
30
+ PATTERN_MATCH_VARIABLE_TYPE = :match_var
31
+ VARIABLE_ASSIGNMENT_TYPES = [
32
+ VARIABLE_ASSIGNMENT_TYPE, REGEXP_NAMED_CAPTURE_TYPE, PATTERN_MATCH_VARIABLE_TYPE
33
+ ].freeze
31
34
 
32
35
  ARGUMENT_DECLARATION_TYPES = [
33
36
  :arg, :optarg, :restarg,
@@ -112,6 +115,7 @@ module RuboCop
112
115
  NODE_HANDLER_METHOD_NAMES = [
113
116
  [VARIABLE_ASSIGNMENT_TYPE, :process_variable_assignment],
114
117
  [REGEXP_NAMED_CAPTURE_TYPE, :process_regexp_named_captures],
118
+ [PATTERN_MATCH_VARIABLE_TYPE, :process_pattern_match_variable],
115
119
  [MULTIPLE_ASSIGNMENT_TYPE, :process_variable_multiple_assignment],
116
120
  [VARIABLE_REFERENCE_TYPE, :process_variable_referencing],
117
121
  [RESCUE_TYPE, :process_rescue],
@@ -175,6 +179,14 @@ module RuboCop
175
179
  skip_children!
176
180
  end
177
181
 
182
+ def process_pattern_match_variable(node)
183
+ name = node.children.first
184
+
185
+ variable_table.declare_variable(name, node) unless variable_table.variable_exist?(name)
186
+
187
+ skip_children!
188
+ end
189
+
178
190
  def regexp_captured_names(node)
179
191
  regexp = node.to_regexp
180
192
 
@@ -9,12 +9,8 @@ class String
9
9
  # @return [Boolean] true is the string is blank, false otherwise
10
10
  #
11
11
  # @example
12
- # ''.blank? #=> true
13
- #
14
- # @example
15
- # ' '.blank? #=> true
16
- #
17
- # @example
12
+ # ''.blank? #=> true
13
+ # ' '.blank? #=> true
18
14
  # ' test'.blank? #=> false
19
15
  def blank?
20
16
  empty? || lstrip.empty?
@@ -15,39 +15,17 @@ module RuboCop
15
15
  # see `ext/regexp_parser`.
16
16
  attr_reader :parsed_tree
17
17
 
18
- if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
19
- def assign_properties(*)
20
- super
18
+ def assign_properties(*)
19
+ super
21
20
 
22
- str = with_interpolations_blanked
23
- @parsed_tree = begin
24
- Regexp::Parser.parse(str, options: options)
25
- rescue StandardError
26
- nil
27
- end
28
- origin = loc.begin.end
29
- @parsed_tree&.each_expression(true) { |e| e.origin = origin }
30
- end
31
- # Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
32
- # It's for compatibility with regexp_parser 1.8 and will never be maintained.
33
- else
34
- def assign_properties(*)
35
- super
36
-
37
- str = with_interpolations_blanked
38
- begin
39
- @parsed_tree = Regexp::Parser.parse(str, options: options)
40
- rescue StandardError
41
- @parsed_tree = nil
42
- else
43
- origin = loc.begin.end
44
- source = @parsed_tree.to_s
45
- @parsed_tree.each_expression(true) do |e|
46
- e.origin = origin
47
- e.source = source
48
- end
49
- end
21
+ str = with_interpolations_blanked
22
+ @parsed_tree = begin
23
+ Regexp::Parser.parse(str, options: options)
24
+ rescue StandardError
25
+ nil
50
26
  end
27
+ origin = loc.begin.end
28
+ @parsed_tree&.each_expression(true) { |e| e.origin = origin }
51
29
  end
52
30
 
53
31
  def each_capture(named: ANY)
@@ -615,7 +615,9 @@ module RuboCop
615
615
  version: 'Display version.',
616
616
  verbose_version: 'Display verbose version.',
617
617
  parallel: ['Use available CPUs to execute inspection in',
618
- 'parallel. Default is true.'],
618
+ 'parallel. Default is true.',
619
+ 'You can specify the number of parallel processes using',
620
+ 'the $PARALLEL_PROCESSOR_COUNT environment variable.'],
619
621
  stdin: ['Pipe source from STDIN, using FILE in offense',
620
622
  'reports. This is useful for editor integration.'],
621
623
  editor_mode: ['Optimize real-time feedback in editors,',
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.65.0'
6
+ STRING = '1.65.1'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'English'
4
+
5
+ # fileutils is autoloaded by pathname,
6
+ # but must be explicitly loaded here for inclusion in `$LOADED_FEATURES`.
7
+ require 'fileutils'
8
+
4
9
  before_us = $LOADED_FEATURES.dup
5
10
  require 'rainbow'
6
11
 
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.65.0
4
+ version: 1.65.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-07-10 00:00:00.000000000 Z
13
+ date: 2024-08-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -1035,12 +1035,12 @@ licenses:
1035
1035
  - MIT
1036
1036
  metadata:
1037
1037
  homepage_uri: https://rubocop.org/
1038
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.65.0
1038
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.65.1
1039
1039
  source_code_uri: https://github.com/rubocop/rubocop/
1040
1040
  documentation_uri: https://docs.rubocop.org/rubocop/1.65/
1041
1041
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1042
1042
  rubygems_mfa_required: 'true'
1043
- post_install_message:
1043
+ post_install_message:
1044
1044
  rdoc_options: []
1045
1045
  require_paths:
1046
1046
  - lib
@@ -1055,8 +1055,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1055
1055
  - !ruby/object:Gem::Version
1056
1056
  version: '0'
1057
1057
  requirements: []
1058
- rubygems_version: 3.4.22
1059
- signing_key:
1058
+ rubygems_version: 3.3.7
1059
+ signing_key:
1060
1060
  specification_version: 4
1061
1061
  summary: Automatic Ruby code style checking tool.
1062
1062
  test_files: []