rubocop 1.25.0 → 1.25.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +11 -11
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +5 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +6 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +27 -13
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +11 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -6
- data/lib/rubocop/cop/style/swap_values.rb +2 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +16 -2
- 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: 54b88752efa8bb84dc034391460b9071f31179dcb279550a209d31829e7b8c93
|
4
|
+
data.tar.gz: 31115cff5fdbf562dee62cf7e07033205d150b61ac5fd11476708f21e67000cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acdaf069659a775853b20e05734e85cd65c0c8734b09e568d4360dc9a7440a49ec8e47928b0da78866e1326a588638d18f2564e6e94023bb17b2f39493555027
|
7
|
+
data.tar.gz: 2765d9c9c10966c485be6cd70190b69a25aa99800c8d483bd67c1fdfe3dc5d13bb97cb1ca7f9f663776869acda5a426bc797f3b40adda17e0241ff8b62a374f1
|
data/config/default.yml
CHANGED
@@ -430,13 +430,13 @@ Layout/ClassStructure:
|
|
430
430
|
- prepend
|
431
431
|
- extend
|
432
432
|
ExpectedOrder:
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
433
|
+
- module_inclusion
|
434
|
+
- constants
|
435
|
+
- public_class_methods
|
436
|
+
- initializer
|
437
|
+
- public_methods
|
438
|
+
- protected_methods
|
439
|
+
- private_methods
|
440
440
|
|
441
441
|
Layout/ClosingHeredocIndentation:
|
442
442
|
Description: 'Checks the indentation of here document closings.'
|
@@ -1900,7 +1900,7 @@ Lint/NestedPercentLiteral:
|
|
1900
1900
|
VersionAdded: '0.52'
|
1901
1901
|
|
1902
1902
|
Lint/NextWithoutAccumulator:
|
1903
|
-
Description:
|
1903
|
+
Description: >-
|
1904
1904
|
Do not omit the accumulator when calling `next`
|
1905
1905
|
in a `reduce`/`inject` block.
|
1906
1906
|
Enabled: true
|
@@ -3153,7 +3153,7 @@ Style/ClassMethodsDefinitions:
|
|
3153
3153
|
StyleGuide: '#def-self-class-methods'
|
3154
3154
|
Enabled: false
|
3155
3155
|
VersionAdded: '0.89'
|
3156
|
-
EnforcedStyle:
|
3156
|
+
EnforcedStyle: def_self
|
3157
3157
|
SupportedStyles:
|
3158
3158
|
- def_self
|
3159
3159
|
- self_class
|
@@ -3815,8 +3815,8 @@ Style/InverseMethods:
|
|
3815
3815
|
:>: :<=
|
3816
3816
|
# `ActiveSupport` defines some common inverse methods. They are listed below,
|
3817
3817
|
# and not enabled by default.
|
3818
|
-
|
3819
|
-
|
3818
|
+
# :present?: :blank?,
|
3819
|
+
# :include?: :exclude?
|
3820
3820
|
# `InverseBlocks` are methods that are inverted by inverting the return
|
3821
3821
|
# of the block that is passed to the method
|
3822
3822
|
InverseBlocks:
|
@@ -81,7 +81,7 @@ module RuboCop
|
|
81
81
|
|
82
82
|
locations.each do |loc|
|
83
83
|
line = loc.line
|
84
|
-
next if line == line_of_def_or_kwbegin
|
84
|
+
next if line == line_of_def_or_kwbegin || last_rescue_and_end_on_same_line(body)
|
85
85
|
|
86
86
|
keyword = loc.source
|
87
87
|
# below the keyword
|
@@ -91,6 +91,10 @@ module RuboCop
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def last_rescue_and_end_on_same_line(body)
|
95
|
+
body.rescue_type? && body.resbody_branches.last.loc.line == body.parent.loc.end.line
|
96
|
+
end
|
97
|
+
|
94
98
|
def message(location, keyword)
|
95
99
|
format(MSG, location: location, keyword: keyword)
|
96
100
|
end
|
@@ -222,11 +222,16 @@ module RuboCop
|
|
222
222
|
node.pairs.any? &&
|
223
223
|
node.parent&.call_type?
|
224
224
|
|
225
|
+
left_sibling = argument_before_hash(node)
|
225
226
|
parent_loc = node.parent.loc
|
226
|
-
selector = parent_loc.selector || parent_loc.expression
|
227
|
+
selector = left_sibling || parent_loc.selector || parent_loc.expression
|
227
228
|
same_line?(selector, node.pairs.first)
|
228
229
|
end
|
229
230
|
|
231
|
+
def argument_before_hash(hash_node)
|
232
|
+
hash_node.left_sibling.respond_to?(:loc) ? hash_node.left_sibling : nil
|
233
|
+
end
|
234
|
+
|
230
235
|
def reset!
|
231
236
|
self.offenses_by = {}
|
232
237
|
self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
return true
|
144
144
|
end
|
145
145
|
|
146
|
-
do_keyword_line == selector
|
146
|
+
do_keyword_line == selector&.line && rescue_keyword_column == selector.column
|
147
147
|
end
|
148
148
|
|
149
149
|
def aligned_with_leading_dot?(do_keyword_line, send_node_loc, rescue_keyword_column)
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
EXPLICIT_HASH_VALUE_MSG = 'Explicit the hash value.'
|
9
9
|
|
10
10
|
def on_pair(node)
|
11
|
-
return if
|
11
|
+
return if ignore_hash_shorthand_syntax?(node)
|
12
12
|
|
13
13
|
hash_key_source = node.key.source
|
14
14
|
|
@@ -31,12 +31,17 @@ module RuboCop
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def ignore_hash_shorthand_syntax?(pair_node)
|
35
|
+
target_ruby_version <= 3.0 || enforced_shorthand_syntax == 'either' ||
|
36
|
+
!pair_node.parent.hash_type?
|
37
|
+
end
|
38
|
+
|
34
39
|
def enforced_shorthand_syntax
|
35
40
|
cop_config.fetch('EnforcedShorthandSyntax', 'always')
|
36
41
|
end
|
37
42
|
|
38
43
|
def require_hash_value?(hash_key_source, node)
|
39
|
-
return true if
|
44
|
+
return true if require_hash_value_for_around_hash_literal?(node)
|
40
45
|
|
41
46
|
hash_value = node.value
|
42
47
|
return true unless hash_value.send_type? || hash_value.lvar_type?
|
@@ -44,24 +49,33 @@ module RuboCop
|
|
44
49
|
hash_key_source != hash_value.source || hash_key_source.end_with?('!', '?')
|
45
50
|
end
|
46
51
|
|
47
|
-
def
|
52
|
+
def require_hash_value_for_around_hash_literal?(node)
|
48
53
|
return false unless (ancestor = node.parent.parent)
|
54
|
+
return false if ancestor.send_type? && ancestor.method?(:[])
|
49
55
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
return true if node_with_block_and_arguments?(right_sibling)
|
56
|
+
!node.parent.braces? && !use_element_of_hash_literal_as_receiver?(ancestor, node.parent) &&
|
57
|
+
(use_modifier_form_without_parenthesized_method_call?(ancestor) ||
|
58
|
+
without_parentheses_call_expr_follows?(ancestor))
|
59
|
+
end
|
55
60
|
|
56
|
-
|
61
|
+
def use_element_of_hash_literal_as_receiver?(ancestor, parent)
|
62
|
+
# `{value:}.do_something` is a valid syntax.
|
63
|
+
ancestor.send_type? && ancestor.receiver == parent
|
57
64
|
end
|
58
65
|
|
59
|
-
def
|
60
|
-
|
66
|
+
def use_modifier_form_without_parenthesized_method_call?(ancestor)
|
67
|
+
return false if ancestor.respond_to?(:parenthesized?) && ancestor.parenthesized?
|
68
|
+
return false unless (parent = ancestor.parent)
|
69
|
+
|
70
|
+
parent.respond_to?(:modifier_form?) && parent.modifier_form?
|
61
71
|
end
|
62
72
|
|
63
|
-
def
|
64
|
-
|
73
|
+
def without_parentheses_call_expr_follows?(ancestor)
|
74
|
+
right_sibling = ancestor.right_sibling
|
75
|
+
right_sibling ||= ancestor.each_ancestor.find(&:assignment?)&.right_sibling
|
76
|
+
return false unless right_sibling
|
77
|
+
|
78
|
+
ancestor.respond_to?(:parenthesized?) && !ancestor.parenthesized? && !!right_sibling
|
65
79
|
end
|
66
80
|
end
|
67
81
|
end
|
@@ -48,15 +48,21 @@ module RuboCop
|
|
48
48
|
node.each_ancestor(:def, :defs).any?(&:endless?) && node.arguments.any?
|
49
49
|
end
|
50
50
|
|
51
|
-
# Require hash value omission be enclosed in parentheses to prevent the following issue:
|
52
|
-
# https://bugs.ruby-lang.org/issues/18396.
|
53
51
|
def require_parentheses_for_hash_value_omission?(node)
|
54
52
|
return false unless (last_argument = node.last_argument)
|
53
|
+
return false if !last_argument.hash_type? || !last_argument.pairs.last&.value_omission?
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
modifier_form?(node) || exist_next_line_expression?(node)
|
56
|
+
end
|
58
57
|
|
59
|
-
|
58
|
+
def modifier_form?(node)
|
59
|
+
node.parent.respond_to?(:modifier_form?) && node.parent.modifier_form?
|
60
|
+
end
|
61
|
+
|
62
|
+
# Require hash value omission be enclosed in parentheses to prevent the following issue:
|
63
|
+
# https://bugs.ruby-lang.org/issues/18396.
|
64
|
+
def exist_next_line_expression?(node)
|
65
|
+
node.parent&.assignment? ? node.parent.right_sibling : node.right_sibling
|
60
66
|
end
|
61
67
|
|
62
68
|
def syntax_like_method_call?(node)
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
offense_range = node.loc.begin
|
98
98
|
|
99
99
|
add_offense(offense_range) do |corrector|
|
100
|
-
if
|
100
|
+
if node.parent&.assignment?
|
101
101
|
replace_begin_with_statement(corrector, offense_range, node)
|
102
102
|
else
|
103
103
|
corrector.remove(offense_range)
|
@@ -170,11 +170,7 @@ module RuboCop
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def valid_begin_assignment?(node)
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
def any_ancestor_assignment_node?(node)
|
177
|
-
node.each_ancestor.any?(&:assignment?)
|
173
|
+
node.parent&.assignment? && !node.children.one?
|
178
174
|
end
|
179
175
|
end
|
180
176
|
end
|
@@ -121,9 +121,14 @@ module RuboCop
|
|
121
121
|
output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?
|
122
122
|
|
123
123
|
cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
|
124
|
-
output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
|
125
|
-
|
126
124
|
default_cfg = default_config(cop_name)
|
125
|
+
|
126
|
+
if supports_safe_auto_correct?(cop_class, default_cfg)
|
127
|
+
output_buffer.puts '# Cop supports --auto-correct.'
|
128
|
+
elsif supports_unsafe_autocorrect?(cop_class, default_cfg)
|
129
|
+
output_buffer.puts '# Cop supports --auto-correct-all.'
|
130
|
+
end
|
131
|
+
|
127
132
|
return unless default_cfg
|
128
133
|
|
129
134
|
params = cop_config_params(default_cfg, cfg)
|
@@ -132,6 +137,15 @@ module RuboCop
|
|
132
137
|
output_cop_param_comments(output_buffer, params, default_cfg)
|
133
138
|
end
|
134
139
|
|
140
|
+
def supports_safe_auto_correct?(cop_class, default_cfg)
|
141
|
+
cop_class&.support_autocorrect? &&
|
142
|
+
(default_cfg.nil? || default_cfg['Safe'] || default_cfg['Safe'].nil?)
|
143
|
+
end
|
144
|
+
|
145
|
+
def supports_unsafe_autocorrect?(cop_class, default_cfg)
|
146
|
+
cop_class&.support_autocorrect? && !default_cfg.nil? && default_cfg['Safe'] == false
|
147
|
+
end
|
148
|
+
|
135
149
|
def cop_config_params(default_cfg, cfg)
|
136
150
|
default_cfg.keys -
|
137
151
|
%w[Description StyleGuide Reference Enabled Exclude Safe
|
data/lib/rubocop/version.rb
CHANGED
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.25.
|
4
|
+
version: 1.25.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-
|
13
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|