rubocop 1.92.0 → 1.92.1

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +1 -0
  3. data/lib/rubocop/cop/badge.rb +1 -1
  4. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +16 -1
  5. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
  6. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +34 -0
  7. data/lib/rubocop/cop/layout/argument_alignment.rb +5 -1
  8. data/lib/rubocop/cop/layout/class_structure.rb +21 -7
  9. data/lib/rubocop/cop/layout/dot_position.rb +25 -15
  10. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +11 -7
  11. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +9 -3
  12. data/lib/rubocop/cop/layout/end_alignment.rb +3 -7
  13. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  14. data/lib/rubocop/cop/layout/first_argument_indentation.rb +26 -1
  15. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +15 -0
  16. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +11 -5
  17. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -3
  18. data/lib/rubocop/cop/layout/indentation_consistency.rb +22 -5
  19. data/lib/rubocop/cop/layout/line_length.rb +104 -6
  20. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +6 -4
  21. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +16 -5
  22. data/lib/rubocop/cop/layout/single_line_block_chain.rb +3 -3
  23. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -12
  24. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +6 -1
  25. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +4 -0
  26. data/lib/rubocop/cop/lint/number_conversion.rb +2 -0
  27. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +47 -1
  28. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -0
  29. data/lib/rubocop/cop/lint/useless_setter_call.rb +7 -4
  30. data/lib/rubocop/cop/mixin/check_line_breakable.rb +7 -6
  31. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +3 -1
  32. data/lib/rubocop/cop/mixin/endless_method_body_help.rb +36 -0
  33. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +9 -4
  34. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
  35. data/lib/rubocop/cop/mixin/visibility_help.rb +2 -1
  36. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  37. data/lib/rubocop/cop/style/access_modifier_declarations.rb +30 -2
  38. data/lib/rubocop/cop/style/and_or.rb +3 -3
  39. data/lib/rubocop/cop/style/arguments_forwarding.rb +28 -2
  40. data/lib/rubocop/cop/style/block_delimiters.rb +6 -0
  41. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
  42. data/lib/rubocop/cop/style/class_methods_definitions.rb +7 -0
  43. data/lib/rubocop/cop/style/collection_querying.rb +79 -46
  44. data/lib/rubocop/cop/style/combinable_loops.rb +4 -0
  45. data/lib/rubocop/cop/style/concat_array_literals.rb +13 -1
  46. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +53 -11
  47. data/lib/rubocop/cop/style/endless_method.rb +5 -1
  48. data/lib/rubocop/cop/style/for.rb +14 -1
  49. data/lib/rubocop/cop/style/guard_clause.rb +22 -21
  50. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +4 -0
  51. data/lib/rubocop/cop/style/if_unless_modifier.rb +19 -12
  52. data/lib/rubocop/cop/style/it_block_parameter.rb +63 -2
  53. data/lib/rubocop/cop/style/lambda.rb +16 -1
  54. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +36 -4
  55. data/lib/rubocop/cop/style/mixin_grouping.rb +12 -3
  56. data/lib/rubocop/cop/style/mutable_constant.rb +25 -7
  57. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  58. data/lib/rubocop/cop/style/raise_args.rb +19 -9
  59. data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
  60. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -2
  61. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +24 -1
  62. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +28 -0
  63. data/lib/rubocop/cop/style/redundant_sort.rb +38 -4
  64. data/lib/rubocop/cop/style/require_order.rb +16 -8
  65. data/lib/rubocop/cop/style/rescue_modifier.rb +6 -0
  66. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +4 -0
  67. data/lib/rubocop/cop/style/single_line_methods.rb +5 -0
  68. data/lib/rubocop/cop/style/struct_inheritance.rb +6 -0
  69. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  70. data/lib/rubocop/lsp/routes.rb +23 -23
  71. data/lib/rubocop/server/cache.rb +4 -4
  72. data/lib/rubocop/target_ruby.rb +21 -9
  73. data/lib/rubocop/version.rb +1 -1
  74. metadata +2 -2
@@ -101,17 +101,19 @@ module RuboCop
101
101
  end
102
102
 
103
103
  def find_previous_older_sibling(node) # rubocop:disable Metrics
104
- search_node(node).left_siblings.reverse.find do |sibling|
104
+ oldest = nil
105
+ search_node(node).left_siblings.reverse_each do |sibling|
105
106
  next unless sibling.is_a?(AST::Node)
106
107
 
107
- sibling = sibling_node(sibling)
108
- break unless sibling&.send_type? && sibling.method?(node.method_name)
109
- break unless sibling.arguments? && !sibling.receiver
110
- break unless in_same_section?(sibling, node)
111
- break unless node.first_argument.str_type? && sibling.first_argument.str_type?
108
+ required = sibling_node(sibling)
109
+ break unless required&.send_type? && required.method?(node.method_name)
110
+ break unless required.arguments? && !required.receiver
111
+ break unless in_same_section?(required, node)
112
+ break unless node.first_argument.str_type? && required.first_argument.str_type?
112
113
 
113
- node.first_argument.value < sibling.first_argument.value
114
+ oldest = sibling if node.first_argument.value < required.first_argument.value
114
115
  end
116
+ oldest
115
117
  end
116
118
 
117
119
  def own_lines?(node)
@@ -124,9 +126,15 @@ module RuboCop
124
126
  def autocorrect(corrector, node, previous_older_sibling)
125
127
  range1 = range_with_comments_and_lines(previous_older_sibling)
126
128
  range2 = range_with_comments_and_lines(node.parent.if_type? ? node.parent : node)
129
+ source = range2.source
130
+
131
+ unless source.end_with?("\n")
132
+ source += "\n"
133
+ range2 = range2.with(begin_pos: range2.begin_pos - 1)
134
+ end
127
135
 
128
136
  corrector.remove(range2)
129
- corrector.insert_before(range1, range2.source)
137
+ corrector.insert_before(range1.begin, source)
130
138
  end
131
139
 
132
140
  def search_node(node)
@@ -56,16 +56,22 @@ module RuboCop
56
56
  add_offense(rescue_node) do |corrector|
57
57
  # The heredoc body would be left behind when the rescue body is moved.
58
58
  next if heredoc_end(node)
59
+ next if inside_corrected_rescue_body?(rescue_node)
59
60
 
60
61
  parenthesized = parenthesized?(rescue_node)
61
62
 
62
63
  correct_rescue_block(corrector, rescue_node, parenthesized)
63
64
  ParenthesesCorrector.correct(corrector, rescue_node.parent) if parenthesized
65
+ ignore_node(rescue_node)
64
66
  end
65
67
  end
66
68
 
67
69
  private
68
70
 
71
+ def inside_corrected_rescue_body?(node)
72
+ node.each_ancestor(:resbody).any? { |resbody| ignored_node?(resbody.parent) }
73
+ end
74
+
69
75
  def parenthesized?(node)
70
76
  node.parent && parentheses?(node.parent)
71
77
  end
@@ -64,6 +64,10 @@ module RuboCop
64
64
  undef unless until when while yield
65
65
  ].freeze
66
66
 
67
+ def self.autocorrect_incompatible_with
68
+ [Layout::MultilineMethodArgumentLineBreaks]
69
+ end
70
+
67
71
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
68
72
  def on_send(node)
69
73
  return if allow_send? && !node.method?(:public_send)
@@ -78,6 +78,11 @@ module RuboCop
78
78
  NOT_SUPPORTED_ENDLESS_METHOD_BODY_TYPES.include?(body_node.type)
79
79
  end
80
80
 
81
+ # The body gets parenthesized when it becomes endless, so it is no longer a command.
82
+ def command_body_in_argument?(body)
83
+ !require_parentheses?(body) && super
84
+ end
85
+
81
86
  def correct_to_multiline(corrector, node)
82
87
  if (body = node.body) && body.begin_type? && body.parenthesized_call?
83
88
  break_line_before(corrector, node, body)
@@ -41,6 +41,12 @@ module RuboCop
41
41
  MSG = "Don't extend an instance initialized by `Struct.new`. " \
42
42
  'Use a block to customize the struct.'
43
43
 
44
+ # When the closing parenthesis of `Struct.new` is on its own line, omitting the
45
+ # parentheses in the same pass leaves a line break before the appended `do`.
46
+ def self.autocorrect_incompatible_with
47
+ [Style::MethodCallWithArgsParentheses]
48
+ end
49
+
44
50
  def on_class(node)
45
51
  return unless struct_constructor?(node.parent_class)
46
52
  return if defines_constants?(node.body)
@@ -166,7 +166,7 @@ module RuboCop
166
166
  PATTERN
167
167
 
168
168
  def self.autocorrect_incompatible_with
169
- [Layout::SpaceBeforeBlockBraces]
169
+ [Layout::SpaceBeforeBlockBraces, Style::TrailingCommaInArguments]
170
170
  end
171
171
 
172
172
  # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -25,12 +25,6 @@ module RuboCop
25
25
  # via `executeCommandProvider` so it knows which commands it can invoke.
26
26
  EXECUTE_COMMANDS = %w[rubocop.formatAutocorrects rubocop.formatAutocorrectsAll].freeze
27
27
 
28
- def self.handle(name, &block)
29
- define_method(:"handle_#{name}", &block)
30
- end
31
-
32
- private_class_method :handle
33
-
34
28
  def initialize(server)
35
29
  @server = server
36
30
 
@@ -44,6 +38,29 @@ module RuboCop
44
38
  method(name)
45
39
  end
46
40
 
41
+ def handle_unsupported_method(request, method = request[:method])
42
+ @server.write(
43
+ id: request[:id],
44
+ error: LanguageServer::Protocol::Interface::ResponseError.new(
45
+ code: LanguageServer::Protocol::Constant::ErrorCodes::METHOD_NOT_FOUND,
46
+ message: "Unsupported Method: #{method}"
47
+ )
48
+ )
49
+ Logger.log("Unsupported Method: #{method}")
50
+ end
51
+
52
+ def handle_method_missing(request)
53
+ return unless request.key?(:id)
54
+
55
+ @server.write(id: request[:id], result: nil)
56
+ end
57
+
58
+ def self.handle(name, &block)
59
+ define_method(:"handle_#{name}", &block)
60
+ end
61
+
62
+ private_class_method :handle
63
+
47
64
  handle 'initialize' do |request|
48
65
  initialization_options = extract_initialization_options_from(request)
49
66
 
@@ -178,23 +195,6 @@ module RuboCop
178
195
  # No-op, we log everything
179
196
  end
180
197
 
181
- def handle_unsupported_method(request, method = request[:method])
182
- @server.write(
183
- id: request[:id],
184
- error: LanguageServer::Protocol::Interface::ResponseError.new(
185
- code: LanguageServer::Protocol::Constant::ErrorCodes::METHOD_NOT_FOUND,
186
- message: "Unsupported Method: #{method}"
187
- )
188
- )
189
- Logger.log("Unsupported Method: #{method}")
190
- end
191
-
192
- def handle_method_missing(request)
193
- return unless request.key?(:id)
194
-
195
- @server.write(id: request[:id], result: nil)
196
- end
197
-
198
198
  private
199
199
 
200
200
  def extract_initialization_options_from(request)
@@ -51,9 +51,9 @@ module RuboCop
51
51
  Pathname(project_dir).join(lockfile_name)
52
52
  end.find(&:exist?)
53
53
  version_data = lockfile_path&.read || RuboCop::Version::STRING
54
- config_data = Pathname(
55
- args_config_file_path || ConfigFinder.find_config_path(Dir.pwd)
56
- ).read
54
+ config_path = Pathname(args_config_file_path || ConfigFinder.find_config_path(Dir.pwd))
55
+ # NOTE: A missing config file is reported by `RuboCop::CLI` with a friendly message.
56
+ config_data = config_path.exist? ? config_path.read : ''
57
57
  yaml = load_erb_templated_yaml(config_data)
58
58
 
59
59
  inherit_from_data = inherit_from_data(yaml)
@@ -181,7 +181,7 @@ module RuboCop
181
181
  yaml_code = ERB.new(content).result
182
182
 
183
183
  require 'yaml'
184
- YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true)
184
+ YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true) || {}
185
185
  end
186
186
  end
187
187
  end
@@ -100,15 +100,23 @@ module RuboCop
100
100
  def gemspec_filepath
101
101
  return @gemspec_filepath if defined?(@gemspec_filepath)
102
102
 
103
- @gemspec_filepath =
104
- @config.traverse_directories_upwards(@config.base_dir_for_path_parameters) do |dir|
105
- # NOTE: Can't use `dir.glob` because of JRuby 9.4.8.0 incompatibility:
106
- # https://github.com/jruby/jruby/issues/8358
107
- candidates = Pathname.glob("#{dir}/*.gemspec")
108
- # Bundler will use a gemspec whatever the filename is, as long as its the only one in
109
- # the folder.
110
- break candidates.first if candidates.one?
111
- end
103
+ @gemspec_filepath = @config.traverse_directories_upwards(
104
+ @config.base_dir_for_path_parameters, ConfigFinder.project_root
105
+ ) do |dir|
106
+ candidates = gemspec_candidates(dir)
107
+
108
+ # Bundler will use a gemspec whatever the filename is, as long as its the only one in
109
+ # the folder.
110
+ break candidates.first if candidates.one?
111
+ end
112
+ end
113
+
114
+ def gemspec_candidates(dir)
115
+ # NOTE: Can't use `dir.glob` because of JRuby 9.4.8.0 incompatibility:
116
+ # https://github.com/jruby/jruby/issues/8358
117
+ Pathname.glob("#{dir}/*.gemspec")
118
+ rescue SystemCallError
119
+ []
112
120
  end
113
121
 
114
122
  def version_from_gemspec_file(file)
@@ -179,6 +187,8 @@ module RuboCop
179
187
  return unless file && File.file?(file)
180
188
 
181
189
  File.read(file).match(pattern) { |md| md[:version].to_f }
190
+ rescue SystemCallError
191
+ nil
182
192
  end
183
193
 
184
194
  def version_file
@@ -250,6 +260,8 @@ module RuboCop
250
260
  result = line.match(/^\s*ruby\s+(\d+\.\d+)[p.\d]*\s*$/)
251
261
  return result.captures.first.to_f if result
252
262
  end
263
+ rescue SystemCallError
264
+ nil
253
265
  end
254
266
 
255
267
  def bundler_lock_file_path
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.92.0'
6
+ STRING = '1.92.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.92.0
4
+ version: 1.92.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -1157,7 +1157,7 @@ licenses:
1157
1157
  - MIT
1158
1158
  metadata:
1159
1159
  homepage_uri: https://rubocop.org/
1160
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.92.0
1160
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.92.1
1161
1161
  source_code_uri: https://github.com/rubocop/rubocop/
1162
1162
  documentation_uri: https://docs.rubocop.org/rubocop/1.92/
1163
1163
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues