rubocop 1.25.1 → 1.27.0

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +29 -6
  4. data/lib/rubocop/cli.rb +1 -1
  5. data/lib/rubocop/config_obsoletion/extracted_cop.rb +3 -1
  6. data/lib/rubocop/cop/autocorrect_logic.rb +4 -0
  7. data/lib/rubocop/cop/badge.rb +7 -1
  8. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -5
  9. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -5
  10. data/lib/rubocop/cop/gemspec/require_mfa.rb +4 -3
  11. data/lib/rubocop/cop/generator.rb +2 -7
  12. data/lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb +46 -0
  13. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  14. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  15. data/lib/rubocop/cop/layout/indentation_width.rb +1 -2
  16. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +7 -8
  17. data/lib/rubocop/cop/layout/redundant_line_break.rb +3 -4
  18. data/lib/rubocop/cop/lint/ambiguous_operator.rb +6 -6
  19. data/lib/rubocop/cop/lint/empty_conditional_body.rb +3 -1
  20. data/lib/rubocop/cop/lint/empty_in_pattern.rb +3 -1
  21. data/lib/rubocop/cop/lint/empty_when.rb +3 -1
  22. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +11 -4
  23. data/lib/rubocop/cop/lint/inherit_exception.rb +19 -28
  24. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +8 -1
  25. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -2
  26. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +5 -0
  27. data/lib/rubocop/cop/lint/refinement_import_methods.rb +51 -0
  28. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +10 -0
  29. data/lib/rubocop/cop/lint/symbol_conversion.rb +3 -2
  30. data/lib/rubocop/cop/lint/syntax.rb +1 -2
  31. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  32. data/lib/rubocop/cop/lint/useless_times.rb +13 -9
  33. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
  34. data/lib/rubocop/cop/mixin/comments_help.rb +22 -2
  35. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +2 -3
  36. data/lib/rubocop/cop/mixin/line_length_help.rb +17 -6
  37. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
  38. data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -2
  39. data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
  40. data/lib/rubocop/cop/security/yaml_load.rb +9 -3
  41. data/lib/rubocop/cop/style/def_with_parentheses.rb +16 -11
  42. data/lib/rubocop/cop/style/double_negation.rb +32 -1
  43. data/lib/rubocop/cop/style/empty_case_condition.rb +1 -2
  44. data/lib/rubocop/cop/style/file_write.rb +12 -0
  45. data/lib/rubocop/cop/style/for.rb +4 -0
  46. data/lib/rubocop/cop/style/lambda_call.rb +12 -20
  47. data/lib/rubocop/cop/style/nested_file_dirname.rb +66 -0
  48. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +3 -2
  49. data/lib/rubocop/cop/style/raise_args.rb +5 -2
  50. data/lib/rubocop/cop/style/redundant_capital_w.rb +1 -2
  51. data/lib/rubocop/cop/style/redundant_initialize.rb +119 -0
  52. data/lib/rubocop/cop/style/safe_navigation.rb +12 -7
  53. data/lib/rubocop/cop/style/select_by_regexp.rb +6 -1
  54. data/lib/rubocop/cop/style/sole_nested_conditional.rb +50 -12
  55. data/lib/rubocop/cop/style/string_concatenation.rb +7 -1
  56. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
  57. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  58. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  59. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -4
  60. data/lib/rubocop/cop/style/unless_else.rb +4 -0
  61. data/lib/rubocop/cop/variable_force.rb +1 -5
  62. data/lib/rubocop/cops_documentation_generator.rb +2 -2
  63. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
  64. data/lib/rubocop/formatter/offense_count_formatter.rb +6 -2
  65. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -2
  66. data/lib/rubocop/options.rb +8 -2
  67. data/lib/rubocop/result_cache.rb +9 -1
  68. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  69. data/lib/rubocop/runner.rb +1 -1
  70. data/lib/rubocop/target_ruby.rb +1 -1
  71. data/lib/rubocop/version.rb +1 -1
  72. data/lib/rubocop.rb +3 -0
  73. metadata +9 -5
@@ -37,8 +37,7 @@ module RuboCop
37
37
 
38
38
  def requires_interpolation?(node)
39
39
  node.child_nodes.any? do |string|
40
- string.dstr_type? ||
41
- double_quotes_required?(string.source)
40
+ string.dstr_type? || double_quotes_required?(string.source)
42
41
  end
43
42
  end
44
43
  end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # Checks for `initialize` methods that are redundant.
7
+ #
8
+ # An initializer is redundant if it does not do anything, or if it only
9
+ # calls `super` with the same arguments given to it. If the initializer takes
10
+ # an argument that accepts multiple values (`restarg`, `kwrestarg`, etc.) it
11
+ # will not register an offense, because it allows the initializer to take a different
12
+ # number of arguments as its superclass potentially does.
13
+ #
14
+ # NOTE: If an initializer argument has a default value, RuboCop assumes it
15
+ # to *not* be redundant.
16
+ #
17
+ # NOTE: Empty initializers are registered as offenses, but it is possible
18
+ # to purposely create an empty `initialize` method to override a superclass's
19
+ # initializer.
20
+ #
21
+ # @example
22
+ # # bad
23
+ # def initialize
24
+ # end
25
+ #
26
+ # # bad
27
+ # def initialize
28
+ # super
29
+ # end
30
+ #
31
+ # # bad
32
+ # def initialize(a, b)
33
+ # super
34
+ # end
35
+ #
36
+ # # bad
37
+ # def initialize(a, b)
38
+ # super(a, b)
39
+ # end
40
+ #
41
+ # # good
42
+ # def initialize
43
+ # do_something
44
+ # end
45
+ #
46
+ # # good
47
+ # def initialize
48
+ # do_something
49
+ # super
50
+ # end
51
+ #
52
+ # # good (different number of parameters)
53
+ # def initialize(a, b)
54
+ # super(a)
55
+ # end
56
+ #
57
+ # # good (default value)
58
+ # def initialize(a, b = 5)
59
+ # super
60
+ # end
61
+ #
62
+ # # good (default value)
63
+ # def initialize(a, b: 5)
64
+ # super
65
+ # end
66
+ #
67
+ # # good (changes the parameter requirements)
68
+ # def initialize(*)
69
+ # end
70
+ #
71
+ # # good (changes the parameter requirements)
72
+ # def initialize(**)
73
+ # end
74
+ #
75
+ # # good (changes the parameter requirements)
76
+ # def initialize(...)
77
+ # end
78
+ #
79
+ class RedundantInitialize < Base
80
+ MSG = 'Remove unnecessary `initialize` method.'
81
+ MSG_EMPTY = 'Remove unnecessary empty `initialize` method.'
82
+
83
+ # @!method initialize_forwards?(node)
84
+ def_node_matcher :initialize_forwards?, <<~PATTERN
85
+ (def _ (args $arg*) $({super zsuper} ...))
86
+ PATTERN
87
+
88
+ def on_def(node)
89
+ return unless node.method?(:initialize)
90
+ return if forwards?(node)
91
+
92
+ if node.body.nil?
93
+ add_offense(node, message: MSG_EMPTY)
94
+ else
95
+ return if node.body.begin_type?
96
+
97
+ if (args, super_node = initialize_forwards?(node))
98
+ return unless same_args?(super_node, args)
99
+
100
+ add_offense(node)
101
+ end
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def forwards?(node)
108
+ node.arguments.each_child_node(:restarg, :kwrestarg, :forward_args, :forward_arg).any?
109
+ end
110
+
111
+ def same_args?(super_node, args)
112
+ return true if super_node.zsuper_type?
113
+
114
+ args.map(&:name) == super_node.arguments.map { |a| a.children[0] }
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -7,8 +7,7 @@ module RuboCop
7
7
  # check for the variable whose method is being called to
8
8
  # safe navigation (`&.`). If there is a method chain, all of the methods
9
9
  # in the chain need to be checked for safety, and all of the methods will
10
- # need to be changed to use safe navigation. We have limited the cop to
11
- # not register an offense for method chains that exceed 2 methods.
10
+ # need to be changed to use safe navigation.
12
11
  #
13
12
  # The default for `ConvertCodeThatCanStartToReturnNil` is `false`.
14
13
  # When configured to `true`, this will
@@ -18,6 +17,10 @@ module RuboCop
18
17
  # `foo&.bar` can start returning `nil` as well as what the method
19
18
  # returns.
20
19
  #
20
+ # The default for `MaxChainLength` is `2`
21
+ # We have limited the cop to not register an offense for method chains
22
+ # that exceed this option is set.
23
+ #
21
24
  # @safety
22
25
  # Autocorrection is unsafe because if a value is `false`, the resulting
23
26
  # code will have different behaviour or raise an error.
@@ -116,9 +119,7 @@ module RuboCop
116
119
  checked_variable, receiver, method_chain, method = extract_parts(node)
117
120
  return unless receiver == checked_variable
118
121
  return if use_var_only_in_unless_modifier?(node, checked_variable)
119
- # method is already a method call so this is actually checking for a
120
- # chain greater than 2
121
- return if chain_size(method_chain, method) > 1
122
+ return if chain_length(method_chain, method) > max_chain_length
122
123
  return if unsafe_method_used?(method_chain, method)
123
124
  return if method_chain.method?(:empty?)
124
125
 
@@ -225,8 +226,8 @@ module RuboCop
225
226
  find_matching_receiver_invocation(receiver, checked_variable)
226
227
  end
227
228
 
228
- def chain_size(method_chain, method)
229
- method.each_ancestor(:send).inject(0) do |total, ancestor|
229
+ def chain_length(method_chain, method)
230
+ method.each_ancestor(:send).inject(1) do |total, ancestor|
230
231
  break total + 1 if ancestor == method_chain
231
232
 
232
233
  total + 1
@@ -281,6 +282,10 @@ module RuboCop
281
282
  break if ancestor == method_chain
282
283
  end
283
284
  end
285
+
286
+ def max_chain_length
287
+ cop_config.fetch('MaxChainLength', 2)
288
+ end
284
289
  end
285
290
  end
286
291
  end
@@ -69,6 +69,11 @@ module RuboCop
69
69
  }
70
70
  PATTERN
71
71
 
72
+ # @!method env_const?(node)
73
+ def_node_matcher :env_const?, <<~PATTERN
74
+ (const {nil? cbase} :ENV)
75
+ PATTERN
76
+
72
77
  # @!method calls_lvar?(node, name)
73
78
  def_node_matcher :calls_lvar?, <<~PATTERN
74
79
  {
@@ -94,7 +99,7 @@ module RuboCop
94
99
  def receiver_allowed?(node)
95
100
  return false unless node
96
101
 
97
- node.hash_type? || creates_hash?(node)
102
+ node.hash_type? || creates_hash?(node) || env_const?(node)
98
103
  end
99
104
 
100
105
  def register_offense(node, block_node, regexp)
@@ -15,6 +15,11 @@ module RuboCop
15
15
  # end
16
16
  # end
17
17
  #
18
+ # # bad
19
+ # if condition_b
20
+ # do_something
21
+ # end if condition_a
22
+ #
18
23
  # # good
19
24
  # if condition_a && condition_b
20
25
  # do_something
@@ -26,12 +31,21 @@ module RuboCop
26
31
  # do_something if condition_b
27
32
  # end
28
33
  #
34
+ # # bad
35
+ # if condition_b
36
+ # do_something
37
+ # end if condition_a
38
+ #
29
39
  # @example AllowModifier: true
30
40
  # # good
31
41
  # if condition_a
32
42
  # do_something if condition_b
33
43
  # end
34
44
  #
45
+ # # good
46
+ # if condition_b
47
+ # do_something
48
+ # end if condition_a
35
49
  class SoleNestedConditional < Base
36
50
  include RangeHelp
37
51
  extend AutoCorrector
@@ -47,7 +61,7 @@ module RuboCop
47
61
 
48
62
  if_branch = node.if_branch
49
63
  return if use_variable_assignment_in_condition?(node.condition, if_branch)
50
- return unless offending_branch?(if_branch)
64
+ return unless offending_branch?(node, if_branch)
51
65
 
52
66
  message = format(MSG, conditional_type: node.keyword)
53
67
  add_offense(if_branch.loc.keyword, message: message) do |corrector|
@@ -72,13 +86,13 @@ module RuboCop
72
86
  end
73
87
  end
74
88
 
75
- def offending_branch?(branch)
89
+ def offending_branch?(node, branch)
76
90
  return false unless branch
77
91
 
78
92
  branch.if_type? &&
79
93
  !branch.else? &&
80
94
  !branch.ternary? &&
81
- !(branch.modifier_form? && allow_modifier?)
95
+ !((node.modifier_form? || branch.modifier_form?) && allow_modifier?)
82
96
  end
83
97
 
84
98
  def autocorrect(corrector, node, if_branch)
@@ -86,6 +100,14 @@ module RuboCop
86
100
  corrector.wrap(node.condition, '(', ')')
87
101
  end
88
102
 
103
+ if outer_condition_modify_form?(node, if_branch)
104
+ autocorrect_outer_condition_modify_form(corrector, node, if_branch)
105
+ else
106
+ autocorrect_outer_condition_basic(corrector, node, if_branch)
107
+ end
108
+ end
109
+
110
+ def autocorrect_outer_condition_basic(corrector, node, if_branch)
89
111
  correct_from_unless_to_if(corrector, node) if node.unless?
90
112
 
91
113
  and_operator = if_branch.unless? ? ' && !' : ' && '
@@ -97,11 +119,17 @@ module RuboCop
97
119
  end
98
120
  end
99
121
 
100
- def correct_from_unless_to_if(corrector, node)
122
+ def autocorrect_outer_condition_modify_form(corrector, node, if_branch)
123
+ correct_from_unless_to_if(corrector, if_branch, is_modify_form: true) if if_branch.unless?
124
+ correct_for_outer_condition_modify_form_style(corrector, node, if_branch)
125
+ end
126
+
127
+ def correct_from_unless_to_if(corrector, node, is_modify_form: false)
101
128
  corrector.replace(node.loc.keyword, 'if')
102
129
 
103
130
  condition = node.condition
104
- if condition.send_type? && condition.comparison_method? && !condition.parenthesized?
131
+ if (condition.send_type? && condition.comparison_method? && !condition.parenthesized?) ||
132
+ (is_modify_form && wrap_condition?(condition))
105
133
  corrector.wrap(node.condition, '!(', ')')
106
134
  else
107
135
  corrector.insert_before(node.condition, '!')
@@ -113,7 +141,7 @@ module RuboCop
113
141
  correct_outer_condition(corrector, outer_condition)
114
142
 
115
143
  condition = if_branch.condition
116
- corrector.insert_after(outer_condition, replacement_condition(and_operator, condition))
144
+ corrector.insert_after(outer_condition, "#{and_operator}#{replace_condition(condition)}")
117
145
 
118
146
  range = range_between(if_branch.loc.keyword.begin_pos, condition.source_range.end_pos)
119
147
  corrector.remove(range_with_surrounding_space(range: range, newlines: false))
@@ -129,6 +157,16 @@ module RuboCop
129
157
  corrector.wrap(if_branch.condition, '(', ')') if wrap_condition?(if_branch.condition)
130
158
  end
131
159
 
160
+ def correct_for_outer_condition_modify_form_style(corrector, node, if_branch)
161
+ condition = if_branch.condition
162
+ corrector.insert_before(condition,
163
+ "#{'!' if node.unless?}#{replace_condition(node.condition)} && ")
164
+
165
+ corrector.remove(node.condition.loc.expression)
166
+ corrector.remove(range_with_surrounding_space(range: node.loc.keyword, newlines: false))
167
+ corrector.replace(if_branch.loc.keyword, 'if')
168
+ end
169
+
132
170
  def correct_for_comment(corrector, node, if_branch)
133
171
  return if config.for_cop('Style/IfUnlessModifier')['Enabled']
134
172
 
@@ -165,17 +203,17 @@ module RuboCop
165
203
  (node.send_type? && node.arguments.any? && !node.parenthesized?)
166
204
  end
167
205
 
168
- def replacement_condition(and_operator, condition)
169
- if wrap_condition?(condition)
170
- "#{and_operator}(#{condition.source})"
171
- else
172
- "#{and_operator}#{condition.source}"
173
- end
206
+ def replace_condition(condition)
207
+ wrap_condition?(condition) ? "(#{condition.source})" : condition.source
174
208
  end
175
209
 
176
210
  def allow_modifier?
177
211
  cop_config['AllowModifier']
178
212
  end
213
+
214
+ def outer_condition_modify_form?(node, if_branch)
215
+ node.condition.loc.expression.begin_pos > if_branch.condition.loc.expression.begin_pos
216
+ end
179
217
  end
180
218
  end
181
219
  end
@@ -134,7 +134,13 @@ module RuboCop
134
134
  end
135
135
 
136
136
  def uncorrectable?(part)
137
- part.multiline? || (part.str_type? && part.heredoc?) || part.each_descendant(:block).any?
137
+ part.multiline? || heredoc?(part) || part.each_descendant(:block).any?
138
+ end
139
+
140
+ def heredoc?(node)
141
+ return false unless node.str_type? || node.dstr_type?
142
+
143
+ node.heredoc?
138
144
  end
139
145
 
140
146
  def corrected_ancestor?(node)
@@ -184,8 +184,7 @@ module RuboCop
184
184
 
185
185
  def unsafe_autocorrect?(condition)
186
186
  condition.children.any? do |child|
187
- unparenthesized_method_call?(child) ||
188
- below_ternary_precedence?(child)
187
+ unparenthesized_method_call?(child) || below_ternary_precedence?(child)
189
188
  end
190
189
  end
191
190
 
@@ -10,7 +10,7 @@ module RuboCop
10
10
  # last item of all non-empty, multiline array literals.
11
11
  # * `comma`: Requires a comma after last item in an array,
12
12
  # but only when each item is on its own line.
13
- # * `no_comma`: Does not requires a comma after the
13
+ # * `no_comma`: Does not require a comma after the
14
14
  # last item in an array
15
15
  #
16
16
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -10,7 +10,7 @@ module RuboCop
10
10
  # last item of all non-empty, multiline hash literals.
11
11
  # * `comma`: Requires a comma after the last item in a hash,
12
12
  # but only when each item is on its own line.
13
- # * `no_comma`: Does not requires a comma after the
13
+ # * `no_comma`: Does not require a comma after the
14
14
  # last item in a hash
15
15
  #
16
16
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -42,10 +42,7 @@ module RuboCop
42
42
  return if node.endless? || !trailing_end?(node)
43
43
 
44
44
  add_offense(node.loc.end) do |corrector|
45
- corrector.insert_before(
46
- node.loc.end,
47
- "\n#{' ' * node.loc.keyword.column}"
48
- )
45
+ corrector.insert_before(node.loc.end, "\n#{' ' * node.loc.keyword.column}")
49
46
  end
50
47
  end
51
48
 
@@ -32,10 +32,14 @@ module RuboCop
32
32
  body_range = range_between_condition_and_else(node, node.condition)
33
33
  else_range = range_between_else_and_end(node)
34
34
 
35
+ next if part_of_ignored_node?(node)
36
+
35
37
  corrector.replace(node.loc.keyword, 'if')
36
38
  corrector.replace(body_range, else_range.source)
37
39
  corrector.replace(else_range, body_range.source)
38
40
  end
41
+
42
+ ignore_node(node)
39
43
  end
40
44
 
41
45
  def range_between_condition_and_else(node, condition)
@@ -186,11 +186,7 @@ module RuboCop
186
186
  end
187
187
 
188
188
  def regexp_captured_names(node)
189
- regexp_string = node.children.select(&:str_type?).map do |child|
190
- child.children.first
191
- end.join || ''
192
-
193
- regexp = Regexp.new(regexp_string)
189
+ regexp = node.to_regexp
194
190
 
195
191
  regexp.named_captures.keys
196
192
  end
@@ -191,8 +191,8 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
191
191
 
192
192
  def wrap_backtick(value)
193
193
  if value.is_a?(String)
194
- # Use `+` to prevent text like `**/*.gemspec` from being bold.
195
- value.start_with?('*') ? "`+#{value}+`" : "`#{value}`"
194
+ # Use `+` to prevent text like `**/*.gemspec`, `spec/**/*` from being bold.
195
+ value.include?('*') ? "`+#{value}+`" : "`#{value}`"
196
196
  else
197
197
  "`#{value}`"
198
198
  end
@@ -124,9 +124,9 @@ module RuboCop
124
124
  default_cfg = default_config(cop_name)
125
125
 
126
126
  if supports_safe_auto_correct?(cop_class, default_cfg)
127
- output_buffer.puts '# Cop supports --auto-correct.'
127
+ output_buffer.puts '# This cop supports safe auto-correction (--auto-correct).'
128
128
  elsif supports_unsafe_autocorrect?(cop_class, default_cfg)
129
- output_buffer.puts '# Cop supports --auto-correct-all.'
129
+ output_buffer.puts '# This cop supports unsafe auto-correction (--auto-correct-all).'
130
130
  end
131
131
 
132
132
  return unless default_cfg
@@ -17,6 +17,7 @@ module RuboCop
17
17
  def started(target_files)
18
18
  super
19
19
  @offense_counts = Hash.new(0)
20
+ @style_guide_links = {}
20
21
 
21
22
  return unless output.tty?
22
23
 
@@ -37,6 +38,9 @@ module RuboCop
37
38
 
38
39
  def file_finished(_file, offenses)
39
40
  offenses.each { |o| @offense_counts[o.cop_name] += 1 }
41
+ if options[:display_style_guide]
42
+ offenses.each { |o| @style_guide_links[o.cop_name] ||= o.message[/ \(http\S+\)\Z/] }
43
+ end
40
44
  @progressbar.increment if instance_variable_defined?(:@progressbar)
41
45
  end
42
46
 
@@ -52,8 +56,8 @@ module RuboCop
52
56
  output.puts
53
57
 
54
58
  per_cop_counts.each do |cop_name, count|
55
- output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}" \
56
- "#{cop_name}\n"
59
+ output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}#{cop_name}" \
60
+ "#{@style_guide_links[cop_name]}\n"
57
61
  end
58
62
  output.puts '--'
59
63
  output.puts "#{total_count} Total"
@@ -40,8 +40,7 @@ module RuboCop
40
40
  output.puts
41
41
 
42
42
  per_file_counts.each do |file_name, count|
43
- output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}" \
44
- "#{file_name}\n"
43
+ output.puts "#{count.to_s.ljust(total_count.to_s.length + 2)}#{file_name}\n"
45
44
  end
46
45
  output.puts '--'
47
46
  output.puts "#{total_count} Total"
@@ -467,8 +467,14 @@ module RuboCop
467
467
  'This option applies to the previously',
468
468
  'specified --format, or the default format',
469
469
  'if no format is specified.'],
470
- fail_level: ['Minimum severity (A/I/R/C/W/E/F) for exit',
471
- 'with error code.'],
470
+ fail_level: ['Minimum severity for exit with error code.',
471
+ ' [A] autocorrect',
472
+ ' [I] info',
473
+ ' [R] refactor',
474
+ ' [C] convention',
475
+ ' [W] warning',
476
+ ' [E] error',
477
+ ' [F] fatal'],
472
478
  display_time: 'Display elapsed time in seconds.',
473
479
  display_only_failed: ['Only output offense messages. Omit passing',
474
480
  'cops. Only valid for --format junit.'],
@@ -73,7 +73,15 @@ module RuboCop
73
73
  # access.
74
74
  File.join(ENV['XDG_CACHE_HOME'], Process.uid.to_s)
75
75
  else
76
- File.join(ENV['HOME'], '.cache')
76
+ # On FreeBSD, the /home path is a symbolic link to /usr/home
77
+ # and the $HOME environment variable returns the /home path.
78
+ #
79
+ # As $HOME is a built-in environment variable, FreeBSD users
80
+ # always get a warning message.
81
+ #
82
+ # To avoid raising warn log messages on FreeBSD, we retrieve
83
+ # the real path of the home folder.
84
+ File.join(File.realpath(ENV['HOME']), '.cache')
77
85
  end
78
86
  File.join(root, 'rubocop_cache')
79
87
  end
@@ -135,3 +135,7 @@ end
135
135
  RSpec.shared_context 'ruby 3.1', :ruby31 do
136
136
  let(:ruby_version) { 3.1 }
137
137
  end
138
+
139
+ RSpec.shared_context 'ruby 3.2', :ruby32 do
140
+ let(:ruby_version) { 3.2 }
141
+ end
@@ -8,7 +8,7 @@ module RuboCop
8
8
  class Runner # rubocop:disable Metrics/ClassLength
9
9
  # An exception indicating that the inspection loop got stuck correcting
10
10
  # offenses back and forth.
11
- class InfiniteCorrectionLoop < RuntimeError
11
+ class InfiniteCorrectionLoop < StandardError
12
12
  attr_reader :offenses
13
13
 
14
14
  def initialize(path, offenses_by_iteration, loop_start: -1)
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  # @api private
6
6
  class TargetRuby
7
- KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1].freeze
7
+ KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1, 3.2].freeze
8
8
  DEFAULT_VERSION = KNOWN_RUBIES.first
9
9
 
10
10
  OBSOLETE_RUBIES = {
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.25.1'
6
+ STRING = '1.27.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
@@ -348,6 +348,7 @@ require_relative 'rubocop/cop/lint/redundant_splat_expansion'
348
348
  require_relative 'rubocop/cop/lint/redundant_string_coercion'
349
349
  require_relative 'rubocop/cop/lint/redundant_with_index'
350
350
  require_relative 'rubocop/cop/lint/redundant_with_object'
351
+ require_relative 'rubocop/cop/lint/refinement_import_methods'
351
352
  require_relative 'rubocop/cop/lint/regexp_as_condition'
352
353
  require_relative 'rubocop/cop/lint/require_parentheses'
353
354
  require_relative 'rubocop/cop/lint/require_relative_self_path'
@@ -527,6 +528,7 @@ require_relative 'rubocop/cop/style/open_struct_use'
527
528
  require_relative 'rubocop/cop/style/redundant_assignment'
528
529
  require_relative 'rubocop/cop/style/redundant_fetch_block'
529
530
  require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
531
+ require_relative 'rubocop/cop/style/redundant_initialize'
530
532
  require_relative 'rubocop/cop/style/redundant_self_assignment'
531
533
  require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
532
534
  require_relative 'rubocop/cop/style/sole_nested_conditional'
@@ -552,6 +554,7 @@ require_relative 'rubocop/cop/style/negated_if'
552
554
  require_relative 'rubocop/cop/style/negated_if_else_condition'
553
555
  require_relative 'rubocop/cop/style/negated_unless'
554
556
  require_relative 'rubocop/cop/style/negated_while'
557
+ require_relative 'rubocop/cop/style/nested_file_dirname'
555
558
  require_relative 'rubocop/cop/style/nested_modifier'
556
559
  require_relative 'rubocop/cop/style/nested_parenthesized_calls'
557
560
  require_relative 'rubocop/cop/style/nested_ternary_operator'