rubocop 0.48.0 → 0.48.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +5 -0
- data/config/enabled.yml +2 -1
- data/lib/rubocop/ast/builder.rb +2 -2
- data/lib/rubocop/ast/node.rb +14 -14
- data/lib/rubocop/ast/node/send_node.rb +8 -3
- data/lib/rubocop/ast/traversal.rb +8 -8
- data/lib/rubocop/config.rb +3 -3
- data/lib/rubocop/config_loader.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +26 -13
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/literal_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +26 -3
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -2
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +1 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/on_method_def.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_literal.rb +45 -4
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
- data/lib/rubocop/cop/offense.rb +2 -2
- data/lib/rubocop/cop/performance/casecmp.rb +1 -1
- data/lib/rubocop/cop/performance/end_with.rb +1 -2
- data/lib/rubocop/cop/performance/redundant_match.rb +1 -1
- data/lib/rubocop/cop/performance/regexp_match.rb +2 -2
- data/lib/rubocop/cop/performance/start_with.rb +1 -2
- data/lib/rubocop/cop/rails/action_filter.rb +4 -4
- data/lib/rubocop/cop/rails/blank.rb +1 -0
- data/lib/rubocop/cop/rails/date.rb +3 -3
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/exit.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +5 -1
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +2 -2
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +3 -3
- data/lib/rubocop/cop/rails/relative_date_constant.rb +7 -3
- data/lib/rubocop/cop/rails/request_referer.rb +17 -2
- data/lib/rubocop/cop/rails/save_bang.rb +4 -4
- data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
- data/lib/rubocop/cop/rails/time_zone.rb +6 -6
- data/lib/rubocop/cop/rails/validation.rb +2 -2
- data/lib/rubocop/cop/severity.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +34 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +3 -3
- data/lib/rubocop/cop/style/constant_name.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_line_after_magic_comment.rb +1 -1
- data/lib/rubocop/cop/style/file_name.rb +2 -2
- data/lib/rubocop/cop/style/global_vars.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
- data/lib/rubocop/cop/style/indentation_width.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +15 -7
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/mixin_grouping.rb +2 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +3 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -36
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +4 -5
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +3 -3
- data/lib/rubocop/cop/style/space_around_keyword.rb +9 -9
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +10 -10
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +3 -2
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/util.rb +7 -7
- data/lib/rubocop/cop/variable_force.rb +7 -7
- data/lib/rubocop/cop/variable_force/variable.rb +2 -2
- data/lib/rubocop/formatter/colorizable.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/options.rb +20 -11
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/result_cache.rb +2 -2
- data/lib/rubocop/rspec/shared_examples.rb +1 -1
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/target_finder.rb +6 -6
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
@@ -12,22 +12,20 @@ module RuboCop
|
|
12
12
|
# @example
|
13
13
|
# # Style/PercentLiteralDelimiters:
|
14
14
|
# # PreferredDelimiters:
|
15
|
-
# # default:
|
16
|
-
# # %i:
|
15
|
+
# # default: []
|
16
|
+
# # %i: ()
|
17
17
|
#
|
18
18
|
# # good
|
19
|
-
# %w
|
19
|
+
# %w[alpha beta] + %i(gamma delta)
|
20
20
|
#
|
21
21
|
# # bad
|
22
|
-
# %W
|
22
|
+
# %W(alpha #{beta})
|
23
23
|
#
|
24
24
|
# # bad
|
25
|
-
# %I
|
25
|
+
# %I(alpha beta)
|
26
26
|
class PercentLiteralDelimiters < Cop
|
27
27
|
include PercentLiteral
|
28
28
|
|
29
|
-
PERCENT_LITERAL_TYPES = %w(% %i %I %q %Q %r %s %w %W %x).freeze
|
30
|
-
|
31
29
|
def on_array(node)
|
32
30
|
process(node, '%w', '%W', '%i', '%I')
|
33
31
|
end
|
@@ -78,35 +76,6 @@ module RuboCop
|
|
78
76
|
add_offense(node, :expression)
|
79
77
|
end
|
80
78
|
|
81
|
-
def preferred_delimiters
|
82
|
-
@preferred_delimiters ||=
|
83
|
-
begin
|
84
|
-
ensure_valid_preferred_delimiters
|
85
|
-
|
86
|
-
if cop_config['PreferredDelimiters'].key?('default')
|
87
|
-
Hash[PERCENT_LITERAL_TYPES.map do |type|
|
88
|
-
[type, cop_config['PreferredDelimiters'][type] ||
|
89
|
-
cop_config['PreferredDelimiters']['default']]
|
90
|
-
end]
|
91
|
-
else
|
92
|
-
cop_config['PreferredDelimiters']
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def ensure_valid_preferred_delimiters
|
98
|
-
invalid = cop_config['PreferredDelimiters'].keys -
|
99
|
-
(PERCENT_LITERAL_TYPES + %w(default))
|
100
|
-
return if invalid.empty?
|
101
|
-
|
102
|
-
raise ArgumentError,
|
103
|
-
"Invalid preferred delimiter config key: #{invalid.join(', ')}"
|
104
|
-
end
|
105
|
-
|
106
|
-
def preferred_delimiters_for(type)
|
107
|
-
preferred_delimiters[type].split(//)
|
108
|
-
end
|
109
|
-
|
110
79
|
def uses_preferred_delimiter?(node, type)
|
111
80
|
preferred_delimiters_for(type)[0] == begin_source(node)[-1]
|
112
81
|
end
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
lambda do |corrector|
|
17
17
|
backref, = *node
|
18
18
|
parent_type = node.parent ? node.parent.type : nil
|
19
|
-
if %i
|
19
|
+
if %i[dstr xstr regexp].include?(parent_type)
|
20
20
|
corrector.replace(node.source_range,
|
21
21
|
"{Regexp.last_match(#{backref})}")
|
22
22
|
else
|
@@ -37,8 +37,8 @@ module RuboCop
|
|
37
37
|
MSG = 'Use `Hash#%s` instead of `Hash#%s`.'.freeze
|
38
38
|
|
39
39
|
OFFENDING_SELECTORS = {
|
40
|
-
short: %i
|
41
|
-
verbose: %i
|
40
|
+
short: %i[has_key? has_value?],
|
41
|
+
verbose: %i[key? value?]
|
42
42
|
}.freeze
|
43
43
|
|
44
44
|
def on_send(node)
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
class RedundantParentheses < Cop
|
17
17
|
include Parentheses
|
18
18
|
|
19
|
-
ALLOWED_LITERALS = %i
|
19
|
+
ALLOWED_LITERALS = %i[irange erange].freeze
|
20
20
|
|
21
21
|
def_node_matcher :square_brackets?,
|
22
22
|
'(send {(send _recv _msg) str array hash} :[] ...)'
|
@@ -71,9 +71,7 @@ module RuboCop
|
|
71
71
|
add_scope(node)
|
72
72
|
end
|
73
73
|
|
74
|
-
|
75
|
-
add_scope(node)
|
76
|
-
end
|
74
|
+
alias on_defs on_def
|
77
75
|
|
78
76
|
def on_args(node)
|
79
77
|
node.children.each { |arg| on_argument(arg) }
|
@@ -90,6 +88,7 @@ module RuboCop
|
|
90
88
|
|
91
89
|
def on_send(node)
|
92
90
|
return unless node.self_receiver? && regular_method_call?(node)
|
91
|
+
return if node.parent && node.parent.mlhs_type?
|
93
92
|
|
94
93
|
return if @allowed_send_nodes.include?(node) ||
|
95
94
|
@local_variables_scopes[node].include?(node.method_name)
|
@@ -127,11 +126,11 @@ module RuboCop
|
|
127
126
|
end
|
128
127
|
|
129
128
|
def keyword?(method_name)
|
130
|
-
%i
|
129
|
+
%i[alias and begin break case class def defined? do
|
131
130
|
else elsif end ensure false for if in module
|
132
131
|
next nil not or redo rescue retry return self
|
133
132
|
super then true undef unless until when while
|
134
|
-
yield
|
133
|
+
yield].include?(method_name)
|
135
134
|
end
|
136
135
|
|
137
136
|
def allow_self(node)
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# x += 1
|
15
15
|
class SelfAssignment < Cop
|
16
16
|
MSG = 'Use self-assignment shorthand `%s=`.'.freeze
|
17
|
-
OPS = %i
|
17
|
+
OPS = %i[+ - * ** / | &].freeze
|
18
18
|
|
19
19
|
def on_lvasgn(node)
|
20
20
|
check(node, :lvar)
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
|
37
37
|
if rhs.send_type?
|
38
38
|
check_send_node(node, rhs, var_name, var_type)
|
39
|
-
elsif %i
|
39
|
+
elsif %i[and or].include?(rhs.type)
|
40
40
|
check_boolean_node(node, rhs, var_name, var_type)
|
41
41
|
end
|
42
42
|
end
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
|
67
67
|
if rhs.send_type?
|
68
68
|
autocorrect_send_node(node, rhs)
|
69
|
-
elsif %i
|
69
|
+
elsif %i[and or].include?(rhs.type)
|
70
70
|
autocorrect_boolean_node(node, rhs)
|
71
71
|
end
|
72
72
|
end
|
@@ -31,16 +31,16 @@ module RuboCop
|
|
31
31
|
DO = 'do'.freeze
|
32
32
|
SAFE_NAVIGATION = '&.'.freeze
|
33
33
|
ACCEPT_LEFT_PAREN =
|
34
|
-
%w
|
34
|
+
%w[break defined? next not rescue return super yield].freeze
|
35
35
|
ACCEPT_LEFT_SQUARE_BRACKET =
|
36
|
-
%w
|
36
|
+
%w[super yield].freeze
|
37
37
|
|
38
38
|
def on_and(node)
|
39
39
|
check(node, [:operator].freeze) if node.keyword?
|
40
40
|
end
|
41
41
|
|
42
42
|
def on_block(node)
|
43
|
-
check(node, %i
|
43
|
+
check(node, %i[begin end].freeze)
|
44
44
|
end
|
45
45
|
|
46
46
|
def on_break(node)
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def on_case(node)
|
51
|
-
check(node, %i
|
51
|
+
check(node, %i[keyword else].freeze)
|
52
52
|
end
|
53
53
|
|
54
54
|
def on_ensure(node)
|
@@ -56,15 +56,15 @@ module RuboCop
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def on_for(node)
|
59
|
-
check(node, %i
|
59
|
+
check(node, %i[begin end].freeze)
|
60
60
|
end
|
61
61
|
|
62
62
|
def on_if(node)
|
63
|
-
check(node, %i
|
63
|
+
check(node, %i[keyword else begin end].freeze, 'then'.freeze)
|
64
64
|
end
|
65
65
|
|
66
66
|
def on_kwbegin(node)
|
67
|
-
check(node, %i
|
67
|
+
check(node, %i[begin end].freeze, nil)
|
68
68
|
end
|
69
69
|
|
70
70
|
def on_next(node)
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def on_until(node)
|
111
|
-
check(node, %i
|
111
|
+
check(node, %i[begin end keyword].freeze)
|
112
112
|
end
|
113
113
|
|
114
114
|
def on_when(node)
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def on_while(node)
|
119
|
-
check(node, %i
|
119
|
+
check(node, %i[begin end keyword].freeze)
|
120
120
|
end
|
121
121
|
|
122
122
|
def on_yield(node)
|
@@ -19,19 +19,19 @@ module RuboCop
|
|
19
19
|
:$0 => [:$PROGRAM_NAME],
|
20
20
|
:$! => [:$ERROR_INFO],
|
21
21
|
:$@ => [:$ERROR_POSITION],
|
22
|
-
:$; => %i
|
23
|
-
:$, => %i
|
24
|
-
:$/ => %i
|
25
|
-
:$\ => %i
|
26
|
-
:$. => %i
|
22
|
+
:$; => %i[$FIELD_SEPARATOR $FS],
|
23
|
+
:$, => %i[$OUTPUT_FIELD_SEPARATOR $OFS],
|
24
|
+
:$/ => %i[$INPUT_RECORD_SEPARATOR $RS],
|
25
|
+
:$\ => %i[$OUTPUT_RECORD_SEPARATOR $ORS],
|
26
|
+
:$. => %i[$INPUT_LINE_NUMBER $NR],
|
27
27
|
:$_ => [:$LAST_READ_LINE],
|
28
28
|
:$> => [:$DEFAULT_OUTPUT],
|
29
29
|
:$< => [:$DEFAULT_INPUT],
|
30
|
-
:$$ => %i
|
30
|
+
:$$ => %i[$PROCESS_ID $PID],
|
31
31
|
:$? => [:$CHILD_STATUS],
|
32
32
|
:$~ => [:$LAST_MATCH_INFO],
|
33
33
|
:$= => [:$IGNORECASE],
|
34
|
-
:$* => %i
|
34
|
+
:$* => %i[$ARGV ARGV],
|
35
35
|
:$& => [:$MATCH],
|
36
36
|
:$` => [:$PREMATCH],
|
37
37
|
:$' => [:$POSTMATCH],
|
@@ -51,12 +51,12 @@ module RuboCop
|
|
51
51
|
PERL_VARS.each { |_, v| v.freeze }.freeze
|
52
52
|
|
53
53
|
# Anything *not* in this set is provided by the English library.
|
54
|
-
NON_ENGLISH_VARS = Set.new(%i
|
54
|
+
NON_ENGLISH_VARS = Set.new(%i[
|
55
55
|
$LOAD_PATH
|
56
56
|
$LOADED_FEATURES
|
57
57
|
$PROGRAM_NAME
|
58
58
|
ARGV
|
59
|
-
)
|
59
|
+
]).freeze
|
60
60
|
|
61
61
|
def on_gvar(node)
|
62
62
|
global_var, = *node
|
@@ -126,7 +126,7 @@ module RuboCop
|
|
126
126
|
parent_type = node.parent && node.parent.type
|
127
127
|
preferred_name = preferred_names(global_var).first
|
128
128
|
|
129
|
-
unless %i
|
129
|
+
unless %i[dstr xstr regexp].include?(parent_type)
|
130
130
|
return preferred_name.to_s
|
131
131
|
end
|
132
132
|
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
# something.map(&:upcase)
|
14
14
|
class SymbolProc < Cop
|
15
15
|
MSG = 'Pass `&:%s` as an argument to `%s` instead of a block.'.freeze
|
16
|
-
SUPER_TYPES = %i
|
16
|
+
SUPER_TYPES = %i[super zsuper].freeze
|
17
17
|
|
18
18
|
def_node_matcher :proc_node?, '(send (const nil :Proc) :new)'
|
19
19
|
def_node_matcher :symbol_proc?, <<-PATTERN
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
# configurable - https://github.com/bbatsov/rubocop/issues/1485
|
32
32
|
# we should ignore lambdas & procs
|
33
33
|
return if proc_node?(send_or_super)
|
34
|
-
return if %i
|
34
|
+
return if %i[lambda proc].include?(block_method_name)
|
35
35
|
return if ignored_method?(block_method_name)
|
36
36
|
return unless can_shorten?(block_args, block_body)
|
37
37
|
|
@@ -5,7 +5,8 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cop checks for the presence of parentheses around ternary
|
7
7
|
# conditions. It is configurable to enforce inclusion or omission of
|
8
|
-
# parentheses using `EnforcedStyle`.
|
8
|
+
# parentheses using `EnforcedStyle`. Omission is only enforced when
|
9
|
+
# removing the parentheses won't cause a different behaviour.
|
9
10
|
#
|
10
11
|
# @example
|
11
12
|
#
|
@@ -161,7 +162,7 @@ module RuboCop
|
|
161
162
|
|
162
163
|
def_node_matcher :method_call_argument, <<-PATTERN
|
163
164
|
{(:defined? $...)
|
164
|
-
(send {
|
165
|
+
(send {_ nil} _ $(send nil _)...)}
|
165
166
|
PATTERN
|
166
167
|
|
167
168
|
def_node_matcher :square_brackets?,
|
@@ -95,7 +95,7 @@ module RuboCop
|
|
95
95
|
|
96
96
|
def looks_like_trivial_writer?(args, body)
|
97
97
|
args.children.one? &&
|
98
|
-
!%i
|
98
|
+
!%i[restarg blockarg].include?(args.children[0].type) &&
|
99
99
|
body && body.ivasgn_type? &&
|
100
100
|
body.children[1] && body.children[1].lvar_type?
|
101
101
|
end
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -10,14 +10,14 @@ module RuboCop
|
|
10
10
|
|
11
11
|
BYTE_ORDER_MARK = 0xfeff # The Unicode codepoint
|
12
12
|
|
13
|
-
EQUALS_ASGN_NODES = %i
|
14
|
-
casgn masgn
|
15
|
-
SHORTHAND_ASGN_NODES = %i
|
13
|
+
EQUALS_ASGN_NODES = %i[lvasgn ivasgn cvasgn gvasgn
|
14
|
+
casgn masgn].freeze
|
15
|
+
SHORTHAND_ASGN_NODES = %i[op_asgn or_asgn and_asgn].freeze
|
16
16
|
ASGN_NODES = (EQUALS_ASGN_NODES + SHORTHAND_ASGN_NODES).freeze
|
17
17
|
|
18
|
-
MODIFIER_NODES = %i
|
18
|
+
MODIFIER_NODES = %i[if while until].freeze
|
19
19
|
CONDITIONAL_NODES = (MODIFIER_NODES + [:case]).freeze
|
20
|
-
LOGICAL_OPERATOR_NODES = %i
|
20
|
+
LOGICAL_OPERATOR_NODES = %i[and or].freeze
|
21
21
|
|
22
22
|
# http://phrogz.net/programmingruby/language.html#table_18.4
|
23
23
|
# Backtick is added last just to help editors parse this code.
|
@@ -236,10 +236,10 @@ module RuboCop
|
|
236
236
|
end
|
237
237
|
|
238
238
|
def symbol_without_quote?(string)
|
239
|
-
special_gvars = %w
|
239
|
+
special_gvars = %w[
|
240
240
|
$! $" $$ $& $' $* $+ $, $/ $; $: $. $< $= $> $? $@ $\\ $_ $` $~ $0
|
241
241
|
$-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w
|
242
|
-
|
242
|
+
]
|
243
243
|
redefinable_operators = %w(
|
244
244
|
| ^ & <=> == === =~ > >= < <= << >>
|
245
245
|
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
:shadowarg # This means block local variable (obj.each { |arg; this| }).
|
36
36
|
].freeze
|
37
37
|
|
38
|
-
LOGICAL_OPERATOR_ASSIGNMENT_TYPES = %i
|
38
|
+
LOGICAL_OPERATOR_ASSIGNMENT_TYPES = %i[or_asgn and_asgn].freeze
|
39
39
|
OPERATOR_ASSIGNMENT_TYPES =
|
40
40
|
(LOGICAL_OPERATOR_ASSIGNMENT_TYPES + [:op_asgn]).freeze
|
41
41
|
|
@@ -43,15 +43,15 @@ module RuboCop
|
|
43
43
|
|
44
44
|
VARIABLE_REFERENCE_TYPE = :lvar
|
45
45
|
|
46
|
-
POST_CONDITION_LOOP_TYPES = %i
|
47
|
-
LOOP_TYPES = (POST_CONDITION_LOOP_TYPES + %i
|
46
|
+
POST_CONDITION_LOOP_TYPES = %i[while_post until_post].freeze
|
47
|
+
LOOP_TYPES = (POST_CONDITION_LOOP_TYPES + %i[while until for]).freeze
|
48
48
|
|
49
49
|
RESCUE_TYPE = :rescue
|
50
50
|
|
51
51
|
ZERO_ARITY_SUPER_TYPE = :zsuper
|
52
52
|
|
53
|
-
TWISTED_SCOPE_TYPES = %i
|
54
|
-
SCOPE_TYPES = (TWISTED_SCOPE_TYPES + %i
|
53
|
+
TWISTED_SCOPE_TYPES = %i[block class sclass defs].freeze
|
54
|
+
SCOPE_TYPES = (TWISTED_SCOPE_TYPES + %i[module def]).freeze
|
55
55
|
|
56
56
|
SEND_TYPE = :send
|
57
57
|
|
@@ -376,14 +376,14 @@ module RuboCop
|
|
376
376
|
end
|
377
377
|
|
378
378
|
# Hooks invoked by VariableTable.
|
379
|
-
%i
|
379
|
+
%i[
|
380
380
|
before_entering_scope
|
381
381
|
after_entering_scope
|
382
382
|
before_leaving_scope
|
383
383
|
after_leaving_scope
|
384
384
|
before_declaring_variable
|
385
385
|
after_declaring_variable
|
386
|
-
|
386
|
+
].each do |hook|
|
387
387
|
define_method(hook) do |arg|
|
388
388
|
# Invoke hook in cops.
|
389
389
|
run_hook(hook, arg, variable_table)
|
@@ -83,7 +83,7 @@ module RuboCop
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def method_argument?
|
86
|
-
argument? && %i
|
86
|
+
argument? && %i[def defs].include?(@scope.node.type)
|
87
87
|
end
|
88
88
|
|
89
89
|
def block_argument?
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def keyword_argument?
|
94
|
-
%i
|
94
|
+
%i[kwarg kwoptarg].include?(@declaration_node.type)
|
95
95
|
end
|
96
96
|
|
97
97
|
def explicit_block_local_variable?
|