rubocop 1.41.0 → 1.41.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b5fe782c4a109e75c380273e08f38b9c61eb519f11f19a606a380080f1f0a2
4
- data.tar.gz: fa67b5a3f120d6f1538963f9ddbc8bd0508b7f54763bd7c76da725054c9e0459
3
+ metadata.gz: 56e97cb2571864e1514ba2e8837cabf2135356847edac7dacc239f77a30b6463
4
+ data.tar.gz: 94a8c7c1c876e0491ceb26e18cfa633d5204ba9f2a7a86c177c803ecbbbbbd30
5
5
  SHA512:
6
- metadata.gz: 1475ad1af84e34c10ccf4905247b6e1090e0bd2969d6eb5ef2c4f4dec116841d438b42c5f4c84678870ffac0703f663e1f1ea79ce588b74caca27162f5ad6c07
7
- data.tar.gz: 267189e76baac7ebc2632d3249957987ba9a3db3df26fa1bf7abe4510a7f9baf8cf5bec399b024d1e900accd1b55f2a5c72e8ab3686d1edc656272ef9723bdaf
6
+ metadata.gz: 782246da9932f0785322b49085efc7db06fb0a4043d1ca684957c8cf34e70dbc395fc0e09e654be3336f6060f48171ac79bcc81bc44b5b31f58b9e433ab02876
7
+ data.tar.gz: '093fe7537462df3ed1114995a785ea5390428c3e2a1aab982c8a70b19e50bb073c6ee051a4f2b168755b532cb276dc16e6d1965ec4590efbbb916c4932de8bda'
data/config/default.yml CHANGED
@@ -3429,6 +3429,7 @@ Style/CommentedKeyword:
3429
3429
  Style/ConcatArrayLiterals:
3430
3430
  Description: 'Enforces the use of `Array#push(item)` instead of `Array#concat([item])` to avoid redundant array literals.'
3431
3431
  Enabled: pending
3432
+ Safe: false
3432
3433
  VersionAdded: '1.41'
3433
3434
 
3434
3435
  Style/ConditionalAssignment:
@@ -132,7 +132,6 @@ module RuboCop
132
132
  # end
133
133
  # end
134
134
  #
135
- # @see https://rubystyle.guide#consistent-classes
136
135
  class ClassStructure < Base
137
136
  include VisibilityHelp
138
137
  extend AutoCorrector
@@ -128,6 +128,7 @@ module RuboCop
128
128
  end
129
129
  end
130
130
 
131
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
131
132
  def each_already_disabled(cop, line_ranges)
132
133
  line_ranges.each_cons(2) do |previous_range, range|
133
134
  next if ignore_offense?(range)
@@ -152,9 +153,10 @@ module RuboCop
152
153
  cop
153
154
  end
154
155
 
155
- yield comment, redundant
156
+ yield comment, redundant if redundant
156
157
  end
157
158
  end
159
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
158
160
 
159
161
  def find_redundant_cop(cop, range)
160
162
  cop_offenses = offenses_to_check.select { |offense| offense.cop_name == cop }
@@ -108,7 +108,7 @@ module RuboCop
108
108
  return if node.body.nil?
109
109
 
110
110
  node.body.each_descendant(:lvar, :lvasgn).any? do |lvar|
111
- !lvar.parent.block_pass_type? && lvar.source == last_argument
111
+ !lvar.parent.block_pass_type? && lvar.node_parts[0].to_s == last_argument
112
112
  end
113
113
  end
114
114
 
@@ -7,6 +7,11 @@ module RuboCop
7
7
  # depending on configuration.
8
8
  # It also flags uses of `alias :symbol` rather than `alias bareword`.
9
9
  #
10
+ # However, it will always enforce `method_alias` when used `alias`
11
+ # in an instance method definition and in a singleton method definition.
12
+ # If used in a block, always enforce `alias_method`
13
+ # unless it is an `instance_eval` block.
14
+ #
10
15
  # @example EnforcedStyle: prefer_alias (default)
11
16
  # # bad
12
17
  # alias_method :bar, :foo
@@ -22,6 +27,7 @@ module RuboCop
22
27
  #
23
28
  # # good
24
29
  # alias_method :bar, :foo
30
+ #
25
31
  class Alias < Base
26
32
  include ConfigurableEnforcedStyle
27
33
  extend AutoCorrector
@@ -71,7 +77,9 @@ module RuboCop
71
77
  end
72
78
 
73
79
  def alias_method_possible?(node)
74
- scope_type(node) != :instance_eval && node.children.none?(&:gvar_type?)
80
+ scope_type(node) != :instance_eval &&
81
+ node.children.none?(&:gvar_type?) &&
82
+ node&.parent&.type != :def
75
83
  end
76
84
 
77
85
  def add_offense_for_args(node, &block)
@@ -86,6 +86,11 @@ module RuboCop
86
86
  (send nil? {:public_constant :private_constant} ({sym str} _))
87
87
  PATTERN
88
88
 
89
+ # @!method include_statement?(node)
90
+ def_node_matcher :include_statement?, <<~PATTERN
91
+ (send nil? {:include :extend :prepend} const)
92
+ PATTERN
93
+
89
94
  def on_class(node)
90
95
  return unless node.body
91
96
 
@@ -103,7 +108,7 @@ module RuboCop
103
108
  return if documentation_comment?(node)
104
109
  return if constant_allowed?(node)
105
110
  return if nodoc_self_or_outer_module?(node)
106
- return if macro_only?(body)
111
+ return if include_statement_only?(body)
107
112
 
108
113
  range = range_between(node.loc.expression.begin_pos, node.loc.name.end_pos)
109
114
  message = format(MSG, type: node.type, identifier: identifier(node))
@@ -115,9 +120,10 @@ module RuboCop
115
120
  (compact_namespace?(node) && nodoc_comment?(outer_module(node).first))
116
121
  end
117
122
 
118
- def macro_only?(body)
119
- (body.respond_to?(:macro?) && body.macro?) ||
120
- (body.respond_to?(:children) && body.children&.all? { |child| macro_only?(child) })
123
+ def include_statement_only?(body)
124
+ return true if include_statement?(body)
125
+
126
+ body.respond_to?(:children) && body.children.all? { |node| include_statement_only?(node) }
121
127
  end
122
128
 
123
129
  def namespace?(node)
@@ -189,7 +189,7 @@ module RuboCop
189
189
 
190
190
  if if_branch&.send_type? && heredoc?(if_branch.last_argument)
191
191
  autocorrect_heredoc_argument(corrector, node, if_branch, else_branch, guard)
192
- elsif else_branch&.send_type? && else_branch.last_argument&.heredoc?
192
+ elsif else_branch&.send_type? && heredoc?(else_branch.last_argument)
193
193
  autocorrect_heredoc_argument(corrector, node, else_branch, if_branch, guard)
194
194
  else
195
195
  corrector.remove(node.loc.end)
@@ -169,9 +169,10 @@ module RuboCop
169
169
  # Allow \#{foo}, \#$foo, \#@foo, and \#@@foo
170
170
  # for escaping local, global, instance and class variable interpolations
171
171
  return true if range.source.match?(/\A\\#[{$@]/)
172
-
173
172
  # Also allow #\{foo}, #\$foo, #\@foo and #\@@foo
174
173
  return true if range.adjust(begin_pos: -2).source.match?(/\A[^\\]#\\[{$@]/)
174
+ # For `\#\{foo} allow `\#` and warn `\{`
175
+ return true if range.adjust(end_pos: 1).source == '\\#\\{'
175
176
 
176
177
  false
177
178
  end
@@ -33,7 +33,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
33
33
  cops.with_department(department).sort!
34
34
  end
35
35
 
36
- def cops_body(cop, description, examples_objects, safety_objects, pars) # rubocop:disable Metrics/AbcSize
36
+ def cops_body(cop, description, examples_objects, safety_objects, see_objects, pars) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
37
37
  check_examples_to_have_the_default_enforced_style!(examples_objects, cop)
38
38
 
39
39
  content = h2(cop.cop_name)
@@ -43,7 +43,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
43
43
  content << safety_object(safety_objects) if safety_objects.any? { |s| !s.text.blank? }
44
44
  content << examples(examples_objects) if examples_objects.any?
45
45
  content << configurations(cop.department, pars)
46
- content << references(cop)
46
+ content << references(cop, see_objects)
47
47
  content
48
48
  end
49
49
 
@@ -224,14 +224,16 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
224
224
  end
225
225
  end
226
226
 
227
- def references(cop)
227
+ def references(cop, see_objects) # rubocop:disable Metrics/AbcSize
228
228
  cop_config = config.for_cop(cop)
229
229
  urls = RuboCop::Cop::MessageAnnotator.new(config, cop.name, cop_config, {}).urls
230
- return '' if urls.empty?
230
+ return '' if urls.empty? && see_objects.empty?
231
231
 
232
232
  content = h3('References')
233
233
  content << urls.map { |url| "* #{url}" }.join("\n")
234
- content << "\n"
234
+ content << "\n" unless urls.empty?
235
+ content << see_objects.map { |see| "* #{see.name}" }.join("\n")
236
+ content << "\n" unless see_objects.empty?
235
237
  content
236
238
  end
237
239
 
@@ -257,7 +259,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
257
259
  end
258
260
  end
259
261
 
260
- def print_cop_with_doc(cop)
262
+ def print_cop_with_doc(cop) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
261
263
  cop_config = config.for_cop(cop)
262
264
  non_display_keys = %w[
263
265
  Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
@@ -265,13 +267,14 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
265
267
  ]
266
268
  pars = cop_config.reject { |k| non_display_keys.include? k }
267
269
  description = 'No documentation'
268
- examples_object = safety_object = []
270
+ examples_object = safety_object = see_object = []
269
271
  cop_code(cop) do |code_object|
270
272
  description = code_object.docstring unless code_object.docstring.blank?
271
273
  examples_object = code_object.tags('example')
272
274
  safety_object = code_object.tags('safety')
275
+ see_object = code_object.tags('see')
273
276
  end
274
- cops_body(cop, description, examples_object, safety_object, pars)
277
+ cops_body(cop, description, examples_object, safety_object, see_object, pars)
275
278
  end
276
279
 
277
280
  def cop_code(cop)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
+ # The bootstrap module for formatter.
5
+ # @api private
4
6
  module Formatter
5
7
  require_relative 'formatter/text_util'
6
8
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.41.0'
6
+ STRING = '1.41.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<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.41.0
4
+ version: 1.41.1
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: 2022-12-20 00:00:00.000000000 Z
13
+ date: 2022-12-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json