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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dba5f457f541be403c090a1e65bb79ecec9cb44d20caf6468f7dea47dc14074
4
- data.tar.gz: f50ff42c73bd17159540297bc823e0979f1fdd26e8ccf0add7f371f99b6b3669
3
+ metadata.gz: ca0a417513e7e81c8c52ba5637cf8ab60ec57ee22b6c328bd6564a4cea90376f
4
+ data.tar.gz: b6a8bc46c9c4b1b43ad52cb8cfd301193246abc2fc0bbe156e3b9cd663d77c53
5
5
  SHA512:
6
- metadata.gz: 6994e2accbbacb5dcd032aaff1fda0193165ed849ccb1483b52151066b3df1f9c4ce0c925caea2fd306b047a9d489da263ac3f9ff946a3c0298a2a276fde8f5f
7
- data.tar.gz: b017c04fc55eeef70492a75495cf799a6a550bc8dd4f4e4802c68e16753d721f074b1d63439866d9c3535db2975f5763f2031d489fdf235aba4ee86f1428df8b
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.0', require: false
56
+ gem 'rubocop', '~> 0.68.1', require: false
57
57
  ```
58
58
 
59
59
  ## Quickstart
@@ -743,7 +743,7 @@ Layout/IndentFirstParameter:
743
743
  Enabled: true
744
744
  VersionAdded: '0.49'
745
745
  VersionChanged: '0.68'
746
- EnforcedStyle: special_for_inner_method_call_in_parentheses
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 :add_offense_kwargs, <<-PATTERN
25
- (send nil? :add_offense _ $hash)
26
- PATTERN
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 $_ :belongs_to _ (hash $...))
70
- PATTERN
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
- opt = extract_required_option(node)
82
- return unless opt
83
- return unless match_required_true?(opt) || match_required_false?(opt)
84
-
85
- message =
86
- if match_required_true?(opt)
87
- SUPERFLOUS_REQUIRE_TRUE_MSG
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
- add_offense(node, message: message, location: :selector)
83
+ add_offense(node, message: message, location: :selector)
84
+ end
93
85
  end
94
86
 
95
87
  def autocorrect(node)
96
- opt = extract_required_option(node)
97
- return unless opt
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 match_required_true?(opt)
101
- corrector.replace(opt.loc.expression, 'optional: false')
102
- elsif match_required_false?(opt)
103
- corrector.replace(opt.loc.expression, 'optional: true')
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 :delegate_options, <<-PATTERN
20
- (send nil? :delegate _ $hash)
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
- offending_node = allow_blank_option(node)
29
-
30
- return unless offending_node
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 :status_pair?, <<-PATTERN
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 :association_with_options?, <<-PATTERN
20
- (send nil? {:has_many :has_one :belongs_to} _ (hash $...))
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
- def_node_search :reflection_class_name, <<-PATTERN
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
- return unless association_with_options?(node)
29
-
30
- reflection_class_name = reflection_class_name(node).first
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 return_value_chaining?(node)
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
- (return_value_chaining?(node) ? '{' : 'do')
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
- !ALLOWED_LITERALS.include?(node.type) &&
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?, <<-PATTERN
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?(node)
150
+ modifier_if_safe_navigation_candidate(node)
151
151
 
152
152
  checked_variable, matching_receiver, method =
153
153
  extract_common_parts(receiver, variable)
154
- matching_receiver = nil if LOGIC_JUMP_KEYWORDS.include?(receiver.type)
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
- case arg.type
81
- when :erange, :irange
80
+ if arg.range_type?
82
81
  range_size(arg)
83
- when :int
82
+ elsif arg.int_type?
84
83
  [0, -1].include?(arg.to_a.first) ? nil : :unknown
85
84
  else
86
85
  :unknown
@@ -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.0'.freeze
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.0
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-29 00:00:00.000000000 Z
13
+ date: 2019-04-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jaro_winkler