rubocop 0.68.0 → 0.68.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +1 -1
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +4 -17
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +9 -0
- data/lib/rubocop/cop/rails/belongs_to.rb +18 -36
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +5 -19
- data/lib/rubocop/cop/rails/http_status.rb +2 -9
- data/lib/rubocop/cop/rails/reflection_class_name.rb +8 -9
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -6
- data/lib/rubocop/cop/style/inverse_methods.rb +10 -0
- data/lib/rubocop/cop/style/next.rb +4 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/safe_navigation.rb +7 -3
- data/lib/rubocop/cop/style/sample.rb +2 -3
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0a417513e7e81c8c52ba5637cf8ab60ec57ee22b6c328bd6564a4cea90376f
|
4
|
+
data.tar.gz: b6a8bc46c9c4b1b43ad52cb8cfd301193246abc2fc0bbe156e3b9cd663d77c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 954a7c8b1155ec9359cf59675084554c0e3c17e2d8e87d621a73fb1ddbd7b8fe522dafe4ad816aa5162fb81a65305616299c4b248cb72554f69729ecb77c1fae
|
7
|
+
data.tar.gz: 9bbc404dc1c34e98033deae94361924489747ae5ff5b740884e26f08f6eb7ae15c73693af3b82bb505c1db89701599aa166916f06360a95208d9c903153fbbb8
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
53
53
|
might want to use a conservative version lock in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 0.68.
|
56
|
+
gem 'rubocop', '~> 0.68.1', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
## Quickstart
|
data/config/default.yml
CHANGED
@@ -743,7 +743,7 @@ Layout/IndentFirstParameter:
|
|
743
743
|
Enabled: true
|
744
744
|
VersionAdded: '0.49'
|
745
745
|
VersionChanged: '0.68'
|
746
|
-
EnforcedStyle:
|
746
|
+
EnforcedStyle: consistent
|
747
747
|
SupportedStyles:
|
748
748
|
- consistent
|
749
749
|
- align_parentheses
|
@@ -212,7 +212,7 @@ module RuboCop
|
|
212
212
|
|
213
213
|
def_node_matcher :macro_scope?, <<-PATTERN
|
214
214
|
{^{({sclass class module block} ...) class_constructor?}
|
215
|
-
^^{({sclass class module block} ... (begin ...)) class_constructor?}
|
215
|
+
^^{({sclass class module block} ... ({begin if} ...)) class_constructor?}
|
216
216
|
^#macro_kwbegin_wrapper?
|
217
217
|
#root_node?}
|
218
218
|
PATTERN
|
@@ -21,12 +21,10 @@ module RuboCop
|
|
21
21
|
|
22
22
|
MSG = 'Redundant location argument to `#add_offense`.'.freeze
|
23
23
|
|
24
|
-
def_node_matcher :
|
25
|
-
(send nil? :add_offense _
|
26
|
-
|
27
|
-
|
28
|
-
def_node_matcher :redundant_location_argument?, <<-PATTERN
|
29
|
-
(pair (sym :location) (sym :expression))
|
24
|
+
def_node_matcher :redundant_location_argument, <<-PATTERN
|
25
|
+
(send nil? :add_offense _
|
26
|
+
(hash <$(pair (sym :location) (sym :expression)) ...>)
|
27
|
+
)
|
30
28
|
PATTERN
|
31
29
|
|
32
30
|
def on_send(node)
|
@@ -39,17 +37,6 @@ module RuboCop
|
|
39
37
|
->(corrector) { corrector.remove(range) }
|
40
38
|
end
|
41
39
|
|
42
|
-
private
|
43
|
-
|
44
|
-
def redundant_location_argument(node)
|
45
|
-
add_offense_kwargs(node) do |kwargs|
|
46
|
-
result =
|
47
|
-
kwargs.pairs.find { |arg| redundant_location_argument?(arg) }
|
48
|
-
|
49
|
-
yield result if result
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
40
|
def offending_range(node)
|
54
41
|
with_space = range_with_surrounding_space(range: node.loc.expression)
|
55
42
|
|
@@ -69,7 +69,16 @@ module RuboCop
|
|
69
69
|
|
70
70
|
def autocorrect(node)
|
71
71
|
lambda do |corrector|
|
72
|
+
offending_name = node.exception_variable.children.first
|
72
73
|
corrector.replace(offense_range(node), preferred_name)
|
74
|
+
|
75
|
+
return unless node.body
|
76
|
+
|
77
|
+
node.body.each_descendant(:lvar) do |var|
|
78
|
+
next unless var.children.first == offending_name
|
79
|
+
|
80
|
+
corrector.replace(var.loc.expression, preferred_name)
|
81
|
+
end
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
@@ -66,54 +66,36 @@ module RuboCop
|
|
66
66
|
'this option altogether'.freeze
|
67
67
|
|
68
68
|
def_node_matcher :match_belongs_to_with_options, <<-PATTERN
|
69
|
-
(send
|
70
|
-
|
71
|
-
|
72
|
-
def_node_matcher :match_required_false?, <<-PATTERN
|
73
|
-
(pair (sym :required) false)
|
74
|
-
PATTERN
|
75
|
-
|
76
|
-
def_node_matcher :match_required_true?, <<-PATTERN
|
77
|
-
(pair (sym :required) true)
|
69
|
+
(send _ :belongs_to _
|
70
|
+
(hash <$(pair (sym :required) ${true false}) ...>)
|
71
|
+
)
|
78
72
|
PATTERN
|
79
73
|
|
80
74
|
def on_send(node)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
elsif match_required_false?(opt)
|
89
|
-
SUPERFLOUS_REQUIRE_FALSE_MSG
|
90
|
-
end
|
75
|
+
match_belongs_to_with_options(node) do |_option_node, option_value|
|
76
|
+
message =
|
77
|
+
if option_value.true_type?
|
78
|
+
SUPERFLOUS_REQUIRE_TRUE_MSG
|
79
|
+
elsif option_value.false_type?
|
80
|
+
SUPERFLOUS_REQUIRE_FALSE_MSG
|
81
|
+
end
|
91
82
|
|
92
|
-
|
83
|
+
add_offense(node, message: message, location: :selector)
|
84
|
+
end
|
93
85
|
end
|
94
86
|
|
95
87
|
def autocorrect(node)
|
96
|
-
|
97
|
-
return unless
|
88
|
+
option_node, option_value = match_belongs_to_with_options(node)
|
89
|
+
return unless option_node
|
98
90
|
|
99
91
|
lambda do |corrector|
|
100
|
-
if
|
101
|
-
corrector.replace(
|
102
|
-
elsif
|
103
|
-
corrector.replace(
|
92
|
+
if option_value.true_type?
|
93
|
+
corrector.replace(option_node.loc.expression, 'optional: false')
|
94
|
+
elsif option_value.false_type?
|
95
|
+
corrector.replace(option_node.loc.expression, 'optional: true')
|
104
96
|
end
|
105
97
|
end
|
106
98
|
end
|
107
|
-
|
108
|
-
def extract_required_option(node)
|
109
|
-
_, opts = match_belongs_to_with_options(node)
|
110
|
-
return unless opts
|
111
|
-
|
112
|
-
opts.find do |opt|
|
113
|
-
match_required_true?(opt) ||
|
114
|
-
match_required_false?(opt)
|
115
|
-
end
|
116
|
-
end
|
117
99
|
end
|
118
100
|
end
|
119
101
|
end
|
@@ -16,20 +16,14 @@ module RuboCop
|
|
16
16
|
class DelegateAllowBlank < Cop
|
17
17
|
MSG = '`allow_blank` is not a valid option, use `allow_nil`.'.freeze
|
18
18
|
|
19
|
-
def_node_matcher :
|
20
|
-
(send nil? :delegate _
|
21
|
-
PATTERN
|
22
|
-
|
23
|
-
def_node_matcher :allow_blank_option?, <<-PATTERN
|
24
|
-
(pair (sym :allow_blank) true)
|
19
|
+
def_node_matcher :allow_blank_option, <<-PATTERN
|
20
|
+
(send nil? :delegate _ (hash <$(pair (sym :allow_blank) true) ...>))
|
25
21
|
PATTERN
|
26
22
|
|
27
23
|
def on_send(node)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
add_offense(offending_node)
|
24
|
+
allow_blank_option(node) do |offending_node|
|
25
|
+
add_offense(offending_node)
|
26
|
+
end
|
33
27
|
end
|
34
28
|
|
35
29
|
def autocorrect(pair_node)
|
@@ -37,14 +31,6 @@ module RuboCop
|
|
37
31
|
corrector.replace(pair_node.key.source_range, 'allow_nil')
|
38
32
|
end
|
39
33
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def allow_blank_option(node)
|
44
|
-
delegate_options(node) do |hash|
|
45
|
-
hash.pairs.find { |opt| allow_blank_option?(opt) }
|
46
|
-
end
|
47
|
-
end
|
48
34
|
end
|
49
35
|
end
|
50
36
|
end
|
@@ -48,8 +48,8 @@ module RuboCop
|
|
48
48
|
}
|
49
49
|
PATTERN
|
50
50
|
|
51
|
-
def_node_matcher :
|
52
|
-
(pair (sym :status) ${int sym})
|
51
|
+
def_node_matcher :status_code, <<-PATTERN
|
52
|
+
(hash <(pair (sym :status) ${int sym}) ...>)
|
53
53
|
PATTERN
|
54
54
|
|
55
55
|
def on_send(node)
|
@@ -77,13 +77,6 @@ module RuboCop
|
|
77
77
|
|
78
78
|
private
|
79
79
|
|
80
|
-
def status_code(node)
|
81
|
-
node.each_pair.each do |pair|
|
82
|
-
status_pair?(pair) { |code| return code }
|
83
|
-
end
|
84
|
-
false
|
85
|
-
end
|
86
|
-
|
87
80
|
def checker_class
|
88
81
|
case style
|
89
82
|
when :symbolic
|
@@ -16,21 +16,20 @@ module RuboCop
|
|
16
16
|
class ReflectionClassName < Cop
|
17
17
|
MSG = 'Use a string value for `class_name`.'.freeze
|
18
18
|
|
19
|
-
def_node_matcher :
|
20
|
-
(send nil? {:has_many :has_one :belongs_to} _
|
19
|
+
def_node_matcher :association_with_reflection, <<-PATTERN
|
20
|
+
(send nil? {:has_many :has_one :belongs_to} _
|
21
|
+
(hash <$#reflection_class_name ...>)
|
22
|
+
)
|
21
23
|
PATTERN
|
22
24
|
|
23
|
-
|
25
|
+
def_node_matcher :reflection_class_name, <<-PATTERN
|
24
26
|
(pair (sym :class_name) [!dstr !str !sym])
|
25
27
|
PATTERN
|
26
28
|
|
27
29
|
def on_send(node)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return unless reflection_class_name
|
32
|
-
|
33
|
-
add_offense(node, location: reflection_class_name.loc.expression)
|
30
|
+
association_with_reflection(node) do |reflection_class_name|
|
31
|
+
add_offense(node, location: reflection_class_name.loc.expression)
|
32
|
+
end
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -165,7 +165,7 @@ module RuboCop
|
|
165
165
|
|
166
166
|
def braces_for_chaining_message(node)
|
167
167
|
if node.multiline?
|
168
|
-
if
|
168
|
+
if node.chained?
|
169
169
|
'Prefer `{...}` over `do...end` for multi-line chained blocks.'
|
170
170
|
else
|
171
171
|
'Prefer `do...end` for multi-line blocks without chaining.'
|
@@ -267,7 +267,7 @@ module RuboCop
|
|
267
267
|
block_begin = node.loc.begin.source
|
268
268
|
|
269
269
|
block_begin == if node.multiline?
|
270
|
-
(
|
270
|
+
(node.chained? ? '{' : 'do')
|
271
271
|
else
|
272
272
|
'{'
|
273
273
|
end
|
@@ -277,10 +277,6 @@ module RuboCop
|
|
277
277
|
node.loc.begin.source == '{'
|
278
278
|
end
|
279
279
|
|
280
|
-
def return_value_chaining?(node)
|
281
|
-
node.parent && node.parent.send_type? && node.parent.dot?
|
282
|
-
end
|
283
|
-
|
284
280
|
def correction_would_break_code?(node)
|
285
281
|
return unless node.keywords?
|
286
282
|
|
@@ -30,6 +30,7 @@ module RuboCop
|
|
30
30
|
# !(foo.class < Numeric) # Checking class hierarchy is allowed
|
31
31
|
class InverseMethods < Cop
|
32
32
|
include IgnoredNode
|
33
|
+
include RangeHelp
|
33
34
|
|
34
35
|
MSG = 'Use `%<inverse>s` instead of inverting `%<method>s`.'.freeze
|
35
36
|
CLASS_COMPARISON_METHODS = %i[<= >= < >].freeze
|
@@ -121,6 +122,11 @@ module RuboCop
|
|
121
122
|
selector[0] = '='
|
122
123
|
corrector.replace(block.loc.selector, selector)
|
123
124
|
else
|
125
|
+
if block.loc.dot
|
126
|
+
range = dot_range(block.loc)
|
127
|
+
corrector.remove(range)
|
128
|
+
end
|
129
|
+
|
124
130
|
corrector.remove(block.loc.selector)
|
125
131
|
end
|
126
132
|
end
|
@@ -165,6 +171,10 @@ module RuboCop
|
|
165
171
|
def camel_case_constant?(node)
|
166
172
|
node.const_type? && node.source =~ CAMEL_CASE
|
167
173
|
end
|
174
|
+
|
175
|
+
def dot_range(loc)
|
176
|
+
range_between(loc.dot.begin_pos, loc.expression.end_pos)
|
177
|
+
end
|
168
178
|
end
|
169
179
|
end
|
170
180
|
end
|
@@ -54,6 +54,10 @@ module RuboCop
|
|
54
54
|
MSG = 'Use `next` to skip iteration.'.freeze
|
55
55
|
EXIT_TYPES = %i[break return].freeze
|
56
56
|
|
57
|
+
def self.autocorrect_incompatible_with
|
58
|
+
[Style::SafeNavigation]
|
59
|
+
end
|
60
|
+
|
57
61
|
def investigate(_processed_source)
|
58
62
|
# When correcting nested offenses, we need to keep track of how much
|
59
63
|
# we have adjusted the indentation of each line
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
def_node_matcher :operation_produces_immutable_object?, <<-PATTERN
|
55
55
|
{
|
56
56
|
(begin (send {float int} {:+ :- :* :** :/ :% :<<} _))
|
57
|
-
(begin (send _ {:+ :- :* :** :/ :%} {float int}))
|
57
|
+
(begin (send !(str _) {:+ :- :* :** :/ :%} {float int}))
|
58
58
|
(begin (send _ {:== :=== :!= :<= :>= :< :>} _))
|
59
59
|
(send (const nil? :ENV) :[] _)
|
60
60
|
(send _ {:count :length :size} ...)
|
@@ -16,8 +16,6 @@ module RuboCop
|
|
16
16
|
class RedundantParentheses < Cop
|
17
17
|
include Parentheses
|
18
18
|
|
19
|
-
ALLOWED_LITERALS = %i[irange erange].freeze
|
20
|
-
|
21
19
|
def_node_matcher :square_brackets?,
|
22
20
|
'(send {(send _recv _msg) str array hash} :[] ...)'
|
23
21
|
def_node_matcher :range_end?, '^^{irange erange}'
|
@@ -28,6 +26,8 @@ module RuboCop
|
|
28
26
|
|
29
27
|
def on_begin(node)
|
30
28
|
return if !parentheses?(node) || parens_allowed?(node)
|
29
|
+
return if node.parent && (node.parent.while_post_type? ||
|
30
|
+
node.parent.until_post_type?)
|
31
31
|
|
32
32
|
check(node)
|
33
33
|
end
|
@@ -156,7 +156,7 @@ module RuboCop
|
|
156
156
|
|
157
157
|
def disallowed_literal?(begin_node, node)
|
158
158
|
node.literal? &&
|
159
|
-
!
|
159
|
+
!node.range_type? &&
|
160
160
|
!raised_to_power_negative_numeric?(begin_node, node)
|
161
161
|
end
|
162
162
|
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
|
73
73
|
# if format: (if checked_variable body nil)
|
74
74
|
# unless format: (if checked_variable nil body)
|
75
|
-
def_node_matcher :modifier_if_safe_navigation_candidate
|
75
|
+
def_node_matcher :modifier_if_safe_navigation_candidate, <<-PATTERN
|
76
76
|
{
|
77
77
|
(if {
|
78
78
|
(send $_ {:nil? :!})
|
@@ -147,11 +147,15 @@ module RuboCop
|
|
147
147
|
|
148
148
|
def extract_parts_from_if(node)
|
149
149
|
variable, receiver =
|
150
|
-
modifier_if_safe_navigation_candidate
|
150
|
+
modifier_if_safe_navigation_candidate(node)
|
151
151
|
|
152
152
|
checked_variable, matching_receiver, method =
|
153
153
|
extract_common_parts(receiver, variable)
|
154
|
-
|
154
|
+
|
155
|
+
if receiver && LOGIC_JUMP_KEYWORDS.include?(receiver.type)
|
156
|
+
matching_receiver = nil
|
157
|
+
end
|
158
|
+
|
155
159
|
[checked_variable, matching_receiver, receiver, method]
|
156
160
|
end
|
157
161
|
|
@@ -77,10 +77,9 @@ module RuboCop
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def sample_size_for_one_arg(arg)
|
80
|
-
|
81
|
-
when :erange, :irange
|
80
|
+
if arg.range_type?
|
82
81
|
range_size(arg)
|
83
|
-
|
82
|
+
elsif arg.int_type?
|
84
83
|
[0, -1].include?(arg.to_a.first) ? nil : :unknown
|
85
84
|
else
|
86
85
|
:unknown
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '0.68.
|
6
|
+
STRING = '0.68.1'.freeze
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
|
9
9
|
'%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
|
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: 0.68.
|
4
|
+
version: 0.68.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: 2019-04-
|
13
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|