rubocop 1.57.2 → 1.58.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +37 -2
  4. data/lib/rubocop/config_obsoletion.rb +11 -8
  5. data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
  6. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
  7. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
  8. data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
  9. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
  10. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  11. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
  12. data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
  13. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +6 -6
  14. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  15. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  16. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
  17. data/lib/rubocop/cop/layout/single_line_block_chain.rb +4 -0
  18. data/lib/rubocop/cop/layout/space_around_operators.rb +50 -20
  19. data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -4
  20. data/lib/rubocop/cop/lint/debugger.rb +2 -1
  21. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
  22. data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -3
  23. data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
  24. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +64 -0
  25. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
  26. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +43 -0
  27. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -4
  28. data/lib/rubocop/cop/lint/self_assignment.rb +37 -0
  29. data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
  30. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
  31. data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
  32. data/lib/rubocop/cop/lint/void.rb +14 -1
  33. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  34. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  35. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  36. data/lib/rubocop/cop/naming/block_forwarding.rb +2 -2
  37. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  38. data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -2
  39. data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
  40. data/lib/rubocop/cop/style/arguments_forwarding.rb +68 -6
  41. data/lib/rubocop/cop/style/array_first_last.rb +64 -0
  42. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
  43. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
  44. data/lib/rubocop/cop/style/case_like_if.rb +4 -4
  45. data/lib/rubocop/cop/style/combinable_loops.rb +2 -7
  46. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  47. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  48. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  49. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  50. data/lib/rubocop/cop/style/hash_each_methods.rb +58 -10
  51. data/lib/rubocop/cop/style/inverse_methods.rb +6 -5
  52. data/lib/rubocop/cop/style/map_to_hash.rb +9 -4
  53. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  54. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  55. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
  56. data/lib/rubocop/cop/style/redundant_argument.rb +2 -2
  57. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +3 -3
  58. data/lib/rubocop/cop/style/redundant_line_continuation.rb +2 -0
  59. data/lib/rubocop/cop/style/redundant_parentheses.rb +11 -3
  60. data/lib/rubocop/cop/style/redundant_return.rb +1 -1
  61. data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
  62. data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
  63. data/lib/rubocop/cop/style/select_by_regexp.rb +1 -1
  64. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  65. data/lib/rubocop/cop/style/semicolon.rb +8 -0
  66. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  67. data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
  68. data/lib/rubocop/formatter/html_formatter.rb +1 -2
  69. data/lib/rubocop/result_cache.rb +0 -1
  70. data/lib/rubocop/runner.rb +1 -1
  71. data/lib/rubocop/version.rb +1 -1
  72. data/lib/rubocop.rb +3 -0
  73. metadata +10 -6
@@ -80,6 +80,7 @@ module RuboCop
80
80
  processed_source.tokens.group_by(&:line)
81
81
  end
82
82
 
83
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
83
84
  def semicolon_position(tokens)
84
85
  if tokens.last.semicolon?
85
86
  -1
@@ -90,10 +91,13 @@ module RuboCop
90
91
  elsif exist_semicolon_after_left_curly_brace?(tokens) ||
91
92
  exist_semicolon_after_left_string_interpolation_brace?(tokens)
92
93
  2
94
+ elsif exist_semicolon_after_left_lambda_curly_brace?(tokens)
95
+ 3
93
96
  elsif exist_semicolon_before_right_string_interpolation_brace?(tokens)
94
97
  -4
95
98
  end
96
99
  end
100
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
97
101
 
98
102
  def exist_semicolon_before_right_curly_brace?(tokens)
99
103
  tokens[-2]&.right_curly_brace? && tokens[-3]&.semicolon?
@@ -103,6 +107,10 @@ module RuboCop
103
107
  tokens[1]&.left_curly_brace? && tokens[2]&.semicolon?
104
108
  end
105
109
 
110
+ def exist_semicolon_after_left_lambda_curly_brace?(tokens)
111
+ tokens[2]&.type == :tLAMBEG && tokens[3]&.semicolon?
112
+ end
113
+
106
114
  def exist_semicolon_before_right_string_interpolation_brace?(tokens)
107
115
  tokens[-3]&.type == :tSTRING_DEND && tokens[-4]&.semicolon?
108
116
  end
@@ -39,7 +39,7 @@ module RuboCop
39
39
 
40
40
  def on_send(node)
41
41
  return unless node.arguments.count == 1
42
- return unless range_till_minus_one?(node.arguments.first)
42
+ return unless range_till_minus_one?(node.first_argument)
43
43
 
44
44
  add_offense(node.first_argument) do |corrector|
45
45
  corrector.remove(node.first_argument.end)
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # Enforces the presence of parentheses in `super` containing arguments.
7
+ #
8
+ # `super` is a keyword and is provided as a distinct cop from those designed for method call.
9
+ #
10
+ # @example
11
+ #
12
+ # # bad
13
+ # super name, age
14
+ #
15
+ # # good
16
+ # super(name, age)
17
+ #
18
+ class SuperWithArgsParentheses < Base
19
+ extend AutoCorrector
20
+
21
+ MSG = 'Use parentheses for `super` with arguments.'
22
+
23
+ def on_super(node)
24
+ return if node.parenthesized?
25
+
26
+ add_offense(node) do |corrector|
27
+ range = node.loc.keyword.end.join(node.first_argument.source_range.begin)
28
+ corrector.replace(range, '(')
29
+ corrector.insert_after(node.last_argument, ')')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'cgi'
4
4
  require 'erb'
5
- require 'ostruct'
6
5
 
7
6
  module RuboCop
8
7
  module Formatter
@@ -87,7 +86,7 @@ module RuboCop
87
86
  # rubocop:enable Lint/UselessMethodDefinition
88
87
 
89
88
  def decorated_message(offense)
90
- offense.message.gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" }
89
+ offense.message.gsub(/`(.+?)`/) { "<code>#{escape(Regexp.last_match(1))}</code>" }
91
90
  end
92
91
 
93
92
  def highlighted_source_line(offense)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest/sha1'
4
- require 'etc'
5
4
  require 'find'
6
5
  require 'zlib'
7
6
  require_relative 'cache_config'
@@ -20,7 +20,7 @@ module RuboCop
20
20
  message = 'Infinite loop detected'
21
21
  message += " in #{path}" if path
22
22
  message += " and caused by #{root_cause}" if root_cause
23
- super message
23
+ super(message)
24
24
  end
25
25
  end
26
26
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.57.2'
6
+ STRING = '1.58.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -334,6 +334,7 @@ require_relative 'rubocop/cop/lint/inherit_exception'
334
334
  require_relative 'rubocop/cop/lint/interpolation_check'
335
335
  require_relative 'rubocop/cop/lint/lambda_without_literal_block'
336
336
  require_relative 'rubocop/cop/lint/literal_as_condition'
337
+ require_relative 'rubocop/cop/lint/literal_assignment_in_condition'
337
338
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
338
339
  require_relative 'rubocop/cop/lint/loop'
339
340
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
@@ -454,6 +455,7 @@ require_relative 'rubocop/cop/style/alias'
454
455
  require_relative 'rubocop/cop/style/and_or'
455
456
  require_relative 'rubocop/cop/style/arguments_forwarding'
456
457
  require_relative 'rubocop/cop/style/array_coercion'
458
+ require_relative 'rubocop/cop/style/array_first_last'
457
459
  require_relative 'rubocop/cop/style/array_intersect'
458
460
  require_relative 'rubocop/cop/style/array_join'
459
461
  require_relative 'rubocop/cop/style/ascii_comments'
@@ -678,6 +680,7 @@ require_relative 'rubocop/cop/style/string_literals_in_interpolation'
678
680
  require_relative 'rubocop/cop/style/string_methods'
679
681
  require_relative 'rubocop/cop/style/strip'
680
682
  require_relative 'rubocop/cop/style/struct_inheritance'
683
+ require_relative 'rubocop/cop/style/super_with_args_parentheses'
681
684
  require_relative 'rubocop/cop/style/swap_values'
682
685
  require_relative 'rubocop/cop/style/symbol_array'
683
686
  require_relative 'rubocop/cop/style/symbol_literal'
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.57.2
4
+ version: 1.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-10-26 00:00:00.000000000 Z
13
+ date: 2023-12-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -134,7 +134,7 @@ dependencies:
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 1.28.1
137
+ version: 1.30.0
138
138
  - - "<"
139
139
  - !ruby/object:Gem::Version
140
140
  version: '2.0'
@@ -144,7 +144,7 @@ dependencies:
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: 1.28.1
147
+ version: 1.30.0
148
148
  - - "<"
149
149
  - !ruby/object:Gem::Version
150
150
  version: '2.0'
@@ -294,6 +294,7 @@ files:
294
294
  - lib/rubocop/cop/internal_affairs/method_name_end_with.rb
295
295
  - lib/rubocop/cop/internal_affairs/method_name_equal.rb
296
296
  - lib/rubocop/cop/internal_affairs/node_destructuring.rb
297
+ - lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb
297
298
  - lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
298
299
  - lib/rubocop/cop/internal_affairs/node_type_predicate.rb
299
300
  - lib/rubocop/cop/internal_affairs/numblock_handler.rb
@@ -468,6 +469,7 @@ files:
468
469
  - lib/rubocop/cop/lint/interpolation_check.rb
469
470
  - lib/rubocop/cop/lint/lambda_without_literal_block.rb
470
471
  - lib/rubocop/cop/lint/literal_as_condition.rb
472
+ - lib/rubocop/cop/lint/literal_assignment_in_condition.rb
471
473
  - lib/rubocop/cop/lint/literal_in_interpolation.rb
472
474
  - lib/rubocop/cop/lint/loop.rb
473
475
  - lib/rubocop/cop/lint/missing_cop_enable_directive.rb
@@ -670,6 +672,7 @@ files:
670
672
  - lib/rubocop/cop/style/and_or.rb
671
673
  - lib/rubocop/cop/style/arguments_forwarding.rb
672
674
  - lib/rubocop/cop/style/array_coercion.rb
675
+ - lib/rubocop/cop/style/array_first_last.rb
673
676
  - lib/rubocop/cop/style/array_intersect.rb
674
677
  - lib/rubocop/cop/style/array_join.rb
675
678
  - lib/rubocop/cop/style/ascii_comments.rb
@@ -897,6 +900,7 @@ files:
897
900
  - lib/rubocop/cop/style/string_methods.rb
898
901
  - lib/rubocop/cop/style/strip.rb
899
902
  - lib/rubocop/cop/style/struct_inheritance.rb
903
+ - lib/rubocop/cop/style/super_with_args_parentheses.rb
900
904
  - lib/rubocop/cop/style/swap_values.rb
901
905
  - lib/rubocop/cop/style/symbol_array.rb
902
906
  - lib/rubocop/cop/style/symbol_literal.rb
@@ -1025,7 +1029,7 @@ metadata:
1025
1029
  homepage_uri: https://rubocop.org/
1026
1030
  changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
1027
1031
  source_code_uri: https://github.com/rubocop/rubocop/
1028
- documentation_uri: https://docs.rubocop.org/rubocop/1.57/
1032
+ documentation_uri: https://docs.rubocop.org/rubocop/1.58/
1029
1033
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1030
1034
  rubygems_mfa_required: 'true'
1031
1035
  post_install_message:
@@ -1043,7 +1047,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1043
1047
  - !ruby/object:Gem::Version
1044
1048
  version: '0'
1045
1049
  requirements: []
1046
- rubygems_version: 3.4.6
1050
+ rubygems_version: 3.4.22
1047
1051
  signing_key:
1048
1052
  specification_version: 4
1049
1053
  summary: Automatic Ruby code style checking tool.