rubocop 1.18.3 → 1.18.4

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: b6123e3d35feebac08e838afcff3f912fa24f7abcc71403f6368fffb346fa9bc
4
- data.tar.gz: 40f3ff08e0efc288e7a11af7016d702f743b8ab343de0c3fd045035c7ac7605f
3
+ metadata.gz: ca5a85edf6c093ecee74e82617e0c618424e907cbb6a71fb1f996492073a98e4
4
+ data.tar.gz: 1ceb28336ce8913d79d4260000f5a86ca93190f5e36f6809d690aa20559674fa
5
5
  SHA512:
6
- metadata.gz: 3ac2d860eccd7ac0d655649d36f64cf52ed1587357b2ef35707a1c2ced408cf645d1a8be2dd6e660c5e338c298adef876814fdf35b22f5c71da4ec5bc830e388
7
- data.tar.gz: adab3ee6563260ced11848bc9b1c62ff2641a28a6b4aca80cb703ef9136562bbdc6a2efff4670d12dee329cc7cf5306a8c9d11106ff13d9cbf5539b5094ba388
6
+ metadata.gz: c020a6c2b13ad36e18afac1a2293f7c30fec5d2d62a36f5f7ffea8887816985ec27b94295fba1e08f9f1b7f462c8b4ca28a4949a32baadcea17e15ff4181b0e3
7
+ data.tar.gz: 06e9a6431dc25b8152b0b380d4de434409579fcb0b66da5335b434798889fd8f6d6a58064a044595b1a45b2bad7830e8045011c7e20e64f1337ccdd11a04e29c
@@ -104,12 +104,9 @@ module RuboCop
104
104
  # to do so than to pass the value around to various methods.
105
105
  next if name == 'inherit_mode'
106
106
 
107
- suggestions = NameSimilarity.find_similar_names(name, Cop::Registry.global.map(&:cop_name))
108
- suggestion = "Did you mean `#{suggestions.join('`, `')}`?" if suggestions.any?
109
-
110
107
  message = <<~MESSAGE.rstrip
111
- unrecognized cop #{name} found in #{smart_loaded_path}
112
- #{suggestion}
108
+ unrecognized cop or department #{name} found in #{smart_loaded_path}
109
+ #{suggestion(name)}
113
110
  MESSAGE
114
111
 
115
112
  unknown_cops << message
@@ -117,6 +114,22 @@ module RuboCop
117
114
  raise ValidationError, unknown_cops.join("\n") if unknown_cops.any?
118
115
  end
119
116
 
117
+ def suggestion(name)
118
+ registry = Cop::Registry.global
119
+ departments = registry.departments.map(&:to_s)
120
+ suggestions = NameSimilarity.find_similar_names(name, departments + registry.map(&:cop_name))
121
+ if suggestions.any?
122
+ "Did you mean `#{suggestions.join('`, `')}`?"
123
+ else
124
+ # Department names can contain slashes, e.g. Chef/Correctness, but there's no support for
125
+ # the concept of higher level departments in RuboCop. It's a flat structure. So if the user
126
+ # tries to configure a "top level department", we hint that it's the bottom level
127
+ # departments that should be configured.
128
+ suggestions = departments.select { |department| department.start_with?("#{name}/") }
129
+ "#{name} is not a department. Use `#{suggestions.join('`, `')}`." if suggestions.any?
130
+ end
131
+ end
132
+
120
133
  def validate_syntax_cop
121
134
  syntax_config = @config['Lint/Syntax']
122
135
  default_config = ConfigLoader.default_configuration['Lint/Syntax']
@@ -289,12 +289,16 @@ module RuboCop
289
289
  (node.first_line - 1).downto(1) do |annotation_line|
290
290
  break unless (comment = processed_source.comment_at_line(annotation_line))
291
291
 
292
- first_comment = comment
292
+ first_comment = comment if whole_line_comment_at_line?(annotation_line)
293
293
  end
294
294
 
295
295
  start_line_position(first_comment || node)
296
296
  end
297
297
 
298
+ def whole_line_comment_at_line?(line)
299
+ /\A\s*#/.match?(processed_source.lines[line - 1])
300
+ end
301
+
298
302
  def start_line_position(node)
299
303
  buffer.line_range(node.loc.line).begin_pos - 1
300
304
  end
@@ -167,7 +167,8 @@ module RuboCop
167
167
  def alignment_node_for_variable_style(node)
168
168
  return node.parent if node.case_type? && node.argument?
169
169
 
170
- assignment = node.ancestors.find(&:assignment_or_similar?)
170
+ assignment = assignment_or_operator_method(node)
171
+
171
172
  if assignment && !line_break_before_keyword?(assignment.source_range, node)
172
173
  assignment
173
174
  else
@@ -177,6 +178,12 @@ module RuboCop
177
178
  node
178
179
  end
179
180
  end
181
+
182
+ def assignment_or_operator_method(node)
183
+ node.ancestors.find do |ancestor|
184
+ ancestor.assignment_or_similar? || ancestor.send_type? && ancestor.operator_method?
185
+ end
186
+ end
180
187
  end
181
188
  end
182
189
  end
@@ -154,7 +154,7 @@ module RuboCop
154
154
 
155
155
  def on_send(node)
156
156
  return if style != :consistent && enforce_first_argument_with_fixed_indentation?
157
- return if !node.arguments? || bare_operator?(node)
157
+ return if !node.arguments? || bare_operator?(node) || node.setter_method?
158
158
 
159
159
  indent = base_indentation(node) + configured_indentation_width
160
160
 
@@ -213,7 +213,7 @@ module RuboCop
213
213
  check_pairs(node)
214
214
  end
215
215
 
216
- attr_accessor :offences_by, :column_deltas
216
+ attr_accessor :offenses_by, :column_deltas
217
217
 
218
218
  private
219
219
 
@@ -224,7 +224,7 @@ module RuboCop
224
224
  end
225
225
 
226
226
  def reset!
227
- self.offences_by = {}
227
+ self.offenses_by = {}
228
228
  self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
229
229
  end
230
230
 
@@ -248,33 +248,33 @@ module RuboCop
248
248
  end
249
249
  end
250
250
 
251
- add_offences
251
+ add_offenses
252
252
  end
253
253
 
254
- def add_offences
255
- kwsplat_offences = offences_by.delete(KeywordSplatAlignment)
256
- register_offences_with_format(kwsplat_offences, KeywordSplatAlignment)
254
+ def add_offenses
255
+ kwsplat_offenses = offenses_by.delete(KeywordSplatAlignment)
256
+ register_offenses_with_format(kwsplat_offenses, KeywordSplatAlignment)
257
257
 
258
- format, offences = offences_by.min_by { |_, v| v.length }
259
- register_offences_with_format(offences, format)
258
+ format, offenses = offenses_by.min_by { |_, v| v.length }
259
+ register_offenses_with_format(offenses, format)
260
260
  end
261
261
 
262
- def register_offences_with_format(offences, format)
263
- (offences || []).each do |offence|
264
- add_offense(offence, message: MESSAGES[format]) do |corrector|
265
- delta = column_deltas[alignment_for(offence).first.class][offence]
262
+ def register_offenses_with_format(offenses, format)
263
+ (offenses || []).each do |offense|
264
+ add_offense(offense, message: MESSAGES[format]) do |corrector|
265
+ delta = column_deltas[alignment_for(offense).first.class][offense]
266
266
 
267
- correct_node(corrector, offence, delta) unless delta.nil?
267
+ correct_node(corrector, offense, delta) unless delta.nil?
268
268
  end
269
269
  end
270
270
  end
271
271
 
272
272
  def check_delta(delta, node:, alignment:)
273
- offences_by[alignment.class] ||= []
273
+ offenses_by[alignment.class] ||= []
274
274
  return if good_alignment? delta
275
275
 
276
276
  column_deltas[alignment.class][node] = delta
277
- offences_by[alignment.class].push(node)
277
+ offenses_by[alignment.class].push(node)
278
278
  end
279
279
 
280
280
  def ignore_hash_argument?(node)
@@ -43,7 +43,7 @@ module RuboCop
43
43
  str_ranges = string_literal_ranges(processed_source.ast)
44
44
 
45
45
  processed_source.lines.each.with_index(1) do |line, lineno|
46
- next unless (range = find_offence(line, lineno))
46
+ next unless (range = find_offense(line, lineno))
47
47
  next if in_string_literal?(str_ranges, range)
48
48
 
49
49
  add_offense(range) { |corrector| autocorrect(corrector, range) }
@@ -60,7 +60,7 @@ module RuboCop
60
60
  end
61
61
  end
62
62
 
63
- def find_offence(line, lineno)
63
+ def find_offense(line, lineno)
64
64
  match = if style == :spaces
65
65
  line.match(/\A\s*\t+/)
66
66
  else
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  # This cop checks that there are no repeated bodies
7
- # within `if/unless`, `case-when` and `rescue` constructs.
7
+ # within `if/unless`, `case-when`, `case-in` and `rescue` constructs.
8
8
  #
9
9
  # With `IgnoreLiteralBranches: true`, branches are not registered
10
10
  # as offenses if they return a basic literal value (string, symbol,
@@ -97,6 +97,7 @@ module RuboCop
97
97
  end
98
98
  alias on_if on_branching_statement
99
99
  alias on_case on_branching_statement
100
+ alias on_case_match on_branching_statement
100
101
  alias on_rescue on_branching_statement
101
102
 
102
103
  private
@@ -97,9 +97,9 @@ module RuboCop
97
97
  # If a send node contains a heredoc argument, splitting cannot happen
98
98
  # after the heredoc or else it will cause a syntax error.
99
99
  def shift_elements_for_heredoc_arg(node, elements, index)
100
- return index unless node.send_type?
100
+ return index unless node.send_type? || node.array_type?
101
101
 
102
- heredoc_index = elements.index { |arg| (arg.str_type? || arg.dstr_type?) && arg.heredoc? }
102
+ heredoc_index = elements.index { |arg| arg.respond_to?(:heredoc?) && arg.heredoc? }
103
103
  return index unless heredoc_index
104
104
  return nil if heredoc_index.zero?
105
105
 
@@ -175,7 +175,12 @@ module RuboCop
175
175
  end
176
176
 
177
177
  def set_new_body_expression(transforming_body_expr, corrector)
178
- corrector.replace(block_node.body, transforming_body_expr.loc.expression.source)
178
+ body_source = transforming_body_expr.loc.expression.source
179
+ if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
180
+ body_source = "{ #{body_source} }"
181
+ end
182
+
183
+ corrector.replace(block_node.body, body_source)
179
184
  end
180
185
  end
181
186
  end
@@ -36,13 +36,7 @@ module RuboCop
36
36
  next unless comment.text.scan(/# rubocop:(?:disable|todo)/).size > 1
37
37
 
38
38
  add_offense(comment) do |corrector|
39
- prefix = if comment.text.start_with?('# rubocop:disable')
40
- '# rubocop:disable'
41
- else
42
- '# rubocop:todo'
43
- end
44
-
45
- corrector.replace(comment, comment.text[/#{prefix} \S+/])
39
+ corrector.replace(comment, comment.text.gsub(%r{ # rubocop:(disable|todo)}, ','))
46
40
  end
47
41
  end
48
42
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
  # RUBY
44
44
  #
45
45
  # This cop works only when a string literal is given as a code string.
46
- # No offence is reported if a string variable is given as below:
46
+ # No offense is reported if a string variable is given as below:
47
47
  #
48
48
  # @example
49
49
  # # not checked
@@ -61,13 +61,12 @@ module RuboCop
61
61
 
62
62
  def on_casgn(node)
63
63
  _scope, _const_name, value = *node
64
- on_assignment(value)
65
- end
64
+ if value.nil? # This is only the case for `CONST += ...` or similarg66
65
+ parent = node.parent
66
+ return unless parent.or_asgn_type? # We only care about `CONST ||= ...`
66
67
 
67
- def on_or_asgn(node)
68
- lhs, value = *node
69
-
70
- return unless lhs&.casgn_type?
68
+ value = parent.children.last
69
+ end
71
70
 
72
71
  on_assignment(value)
73
72
  end
@@ -118,14 +117,13 @@ module RuboCop
118
117
  end
119
118
 
120
119
  def mutable_literal?(value)
121
- return false if value.nil?
122
120
  return false if frozen_regexp_or_range_literals?(value)
123
121
 
124
122
  value.mutable_literal?
125
123
  end
126
124
 
127
125
  def immutable_literal?(node)
128
- node.nil? || frozen_regexp_or_range_literals?(node) || node.immutable_literal?
126
+ frozen_regexp_or_range_literals?(node) || node.immutable_literal?
129
127
  end
130
128
 
131
129
  def frozen_string_literal?(node)
@@ -72,17 +72,15 @@ module RuboCop
72
72
  end
73
73
 
74
74
  def correct_to_multiline(corrector, node)
75
- each_part(node.body) do |part|
76
- LineBreakCorrector.break_line_before(
77
- range: part, node: node, corrector: corrector,
78
- configured_width: configured_indentation_width
79
- )
75
+ if (body = node.body) && body.begin_type? && body.parenthesized_call?
76
+ break_line_before(corrector, node, body)
77
+ else
78
+ each_part(body) do |part|
79
+ break_line_before(corrector, node, part)
80
+ end
80
81
  end
81
82
 
82
- LineBreakCorrector.break_line_before(
83
- range: node.loc.end, node: node, corrector: corrector,
84
- indent_steps: 0, configured_width: configured_indentation_width
85
- )
83
+ break_line_before(corrector, node, node.loc.end, indent_steps: 0)
86
84
 
87
85
  move_comment(node, corrector)
88
86
  end
@@ -96,6 +94,13 @@ module RuboCop
96
94
  corrector.replace(node, replacement)
97
95
  end
98
96
 
97
+ def break_line_before(corrector, node, range, indent_steps: 1)
98
+ LineBreakCorrector.break_line_before(
99
+ range: range, node: node, corrector: corrector,
100
+ configured_width: configured_indentation_width, indent_steps: indent_steps
101
+ )
102
+ end
103
+
99
104
  def each_part(body)
100
105
  return unless body
101
106
 
@@ -33,7 +33,7 @@ module RuboCop
33
33
  output.printf(
34
34
  "\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s\n",
35
35
  severity: github_severity(offense),
36
- file: file,
36
+ file: PathUtil.smart_path(file),
37
37
  line: offense.line,
38
38
  column: offense.real_column,
39
39
  message: github_escape(offense.message)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.18.3'
6
+ STRING = '1.18.4'
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.18.3
4
+ version: 1.18.4
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: 2021-07-06 00:00:00.000000000 Z
13
+ date: 2021-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 1.7.0
103
+ version: 1.8.0
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '2.0'
@@ -110,7 +110,7 @@ dependencies:
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 1.7.0
113
+ version: 1.8.0
114
114
  - - "<"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '2.0'