rubocop 1.16.0 → 1.16.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: 87761564ea69f6968eb595204b979c7accaee729c8c27005d8f4d22fe7d7c588
4
- data.tar.gz: f1b08e98a6bfed772381c159a5bc1c22e697b965acb48154c7fb4b2c58566077
3
+ metadata.gz: 336b4f09242c5130a3e66be9c17bb23a1d884d0e9d788799f3ff3291616367d7
4
+ data.tar.gz: 2bbcb0fed39b66808dac5bf4c4df3f6bf4fbf606fcb6f0136acdaff5a1212d42
5
5
  SHA512:
6
- metadata.gz: '0709e83e22cd4b7ffd86e2144ce9da499a8aa6ded608337c6e88f0418feb313c9d46d2c0a46245297a8e2ff5e072b45af7c7797d30f0a172fb0ab0e377c70264'
7
- data.tar.gz: 19bf9b1b665b3421665f29196702aaedcedd7599b7ba22c547ac2b4871241ddcab1103c017aa8c447d2a4b882a09a835a3ac8e101f8db06f91cd8957fad077c0
6
+ metadata.gz: 006de603e9c559a6c34fb1e25d7c7b255ca8231773e4e8f4c99a6f31a2914ba11069597e66806564bd761a493581f62e0028bd0e47d470fc28ff7822bd9e90d9
7
+ data.tar.gz: e5fb0bf4851cd7273834f1b89e952406942379298b93ac130dcfc254e3fe427dfdae8adca3666ac45db9314645e74f3bb86aae9fe199f1bb0fe3e0e21047fcb6
data/config/default.yml CHANGED
@@ -1649,6 +1649,7 @@ Lint/EmptyFile:
1649
1649
  Lint/EmptyInPattern:
1650
1650
  Description: 'Checks for the presence of `in` pattern branches without a body.'
1651
1651
  Enabled: pending
1652
+ AllowComments: true
1652
1653
  VersionAdded: '1.16'
1653
1654
 
1654
1655
  Lint/EmptyInterpolation:
@@ -217,7 +217,8 @@ module RuboCop
217
217
  private
218
218
 
219
219
  def autocorrect_incompatible_with_other_cops?(node)
220
- enforce_first_argument_with_fixed_indentation? && !node.braces? && node.parent&.call_type?
220
+ enforce_first_argument_with_fixed_indentation? &&
221
+ node.parent&.call_type? && node.parent.loc.line == node.pairs.first.loc.line
221
222
  end
222
223
 
223
224
  def reset!
@@ -116,7 +116,8 @@ module RuboCop
116
116
  end
117
117
 
118
118
  def call_with_braced_block?(node)
119
- (node.send_type? || node.super_type?) && node.block_node && node.block_node.braces?
119
+ (node.send_type? || node.super_type?) &&
120
+ ((node.parent&.block_type? || node.parent&.numblock_type?) && node.parent&.braces?)
120
121
  end
121
122
 
122
123
  def call_as_argument_or_chain?(node)
@@ -35,17 +35,7 @@ module RuboCop
35
35
  MSG = 'Do not use `then` for multiline `when` statement.'
36
36
 
37
37
  def on_when(node)
38
- # Without `then`, there's no offense
39
- return unless node.then?
40
-
41
- # Single line usage of `then` is not an offense
42
- return if !node.children.last.nil? && !node.multiline?
43
-
44
- # Requires `then` for write `when` and its body on the same line.
45
- return if require_then?(node)
46
-
47
- # For arrays and hashes there's no offense
48
- return if accept_node_type?(node.body)
38
+ return if !node.then? || require_then?(node)
49
39
 
50
40
  range = node.loc.begin
51
41
  add_offense(range) do |corrector|
@@ -57,6 +47,7 @@ module RuboCop
57
47
 
58
48
  private
59
49
 
50
+ # Requires `then` for write `when` and its body on the same line.
60
51
  def require_then?(when_node)
61
52
  unless when_node.conditions.first.first_line == when_node.conditions.last.last_line
62
53
  return true
@@ -58,7 +58,7 @@ module RuboCop
58
58
  private
59
59
 
60
60
  def autocorrect(corrector, node)
61
- str = if hash_key?(node)
61
+ str = if hash_colon_key?(node)
62
62
  # strip quotes
63
63
  correct_quotes(node.source[1..-2])
64
64
  else
@@ -69,6 +69,11 @@ module RuboCop
69
69
  corrector.replace(node, str)
70
70
  end
71
71
 
72
+ def hash_colon_key?(node)
73
+ # Is the node a hash key with the colon style?
74
+ hash_key?(node) && node.parent.colon?
75
+ end
76
+
72
77
  def correct_quotes(str)
73
78
  if style == :single_quotes
74
79
  to_string_literal(str)
@@ -92,7 +92,7 @@ module RuboCop
92
92
 
93
93
  def on_masgn(node)
94
94
  lhs, rhs = *node
95
- lhs.children.each { |child| add_lhs_to_local_variables_scopes(rhs, child.to_a.first) }
95
+ add_masgn_lhs_variables(rhs, lhs)
96
96
  end
97
97
 
98
98
  def on_lvasgn(node)
@@ -106,7 +106,7 @@ module RuboCop
106
106
 
107
107
  return if allowed_send_node?(node)
108
108
 
109
- add_offense(node) do |corrector|
109
+ add_offense(node.receiver) do |corrector|
110
110
  corrector.remove(node.receiver)
111
111
  corrector.remove(node.loc.dot)
112
112
  end
@@ -116,6 +116,22 @@ module RuboCop
116
116
  add_scope(node, @local_variables_scopes[node])
117
117
  end
118
118
 
119
+ def on_if(node)
120
+ # Allow conditional nodes to use `self` in the condition if that variable
121
+ # name is used in an `lvasgn` or `masgn` within the `if`.
122
+ node.child_nodes.each do |child_node|
123
+ lhs, _rhs = *child_node
124
+
125
+ if child_node.lvasgn_type?
126
+ add_lhs_to_local_variables_scopes(node.condition, lhs)
127
+ elsif child_node.masgn_type?
128
+ add_masgn_lhs_variables(node.condition, lhs)
129
+ end
130
+ end
131
+ end
132
+ alias on_while on_if
133
+ alias on_until on_if
134
+
119
135
  private
120
136
 
121
137
  def add_scope(node, local_variables = [])
@@ -163,6 +179,12 @@ module RuboCop
163
179
  @local_variables_scopes[rhs] << lhs
164
180
  end
165
181
  end
182
+
183
+ def add_masgn_lhs_variables(rhs, lhs)
184
+ lhs.children.each do |child|
185
+ add_lhs_to_local_variables_scopes(rhs, child.to_a.first)
186
+ end
187
+ end
166
188
  end
167
189
  end
168
190
  end
@@ -70,7 +70,7 @@ module RuboCop
70
70
  options = full_options.unshift('--auto-correct-all')
71
71
  # `parallel` will automatically be removed from the options internally.
72
72
  # This is a nice to have to suppress the warning message
73
- # about parallel and auto-corrent not being compatible.
73
+ # about parallel and auto-correct not being compatible.
74
74
  options.delete('--parallel')
75
75
  run_cli(verbose, options)
76
76
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.16.0'
6
+ STRING = '1.16.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.16.0
4
+ version: 1.16.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: 2021-06-01 00:00:00.000000000 Z
13
+ date: 2021-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel