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
@@ -44,10 +44,10 @@ module RuboCop
|
|
44
44
|
CREATE_CONDITIONAL_MSG = '`%s` returns a model which is always truthy.'
|
45
45
|
.freeze
|
46
46
|
|
47
|
-
CREATE_PERSIST_METHODS = %i
|
48
|
-
first_or_create find_or_create_by
|
49
|
-
MODIFY_PERSIST_METHODS = %i
|
50
|
-
update update_attributes destroy
|
47
|
+
CREATE_PERSIST_METHODS = %i[create
|
48
|
+
first_or_create find_or_create_by].freeze
|
49
|
+
MODIFY_PERSIST_METHODS = %i[save
|
50
|
+
update update_attributes destroy].freeze
|
51
51
|
PERSIST_METHODS = (CREATE_PERSIST_METHODS +
|
52
52
|
MODIFY_PERSIST_METHODS).freeze
|
53
53
|
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
class SkipsModelValidations < Cop
|
26
26
|
MSG = 'Avoid using `%s` because it skips validations.'.freeze
|
27
27
|
|
28
|
-
METHODS_WITH_ARGUMENTS = %w
|
28
|
+
METHODS_WITH_ARGUMENTS = %w[decrement!
|
29
29
|
decrement_counter
|
30
30
|
increment!
|
31
31
|
increment_counter
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
update_attribute
|
35
35
|
update_column
|
36
36
|
update_columns
|
37
|
-
update_counters
|
37
|
+
update_counters].freeze
|
38
38
|
|
39
39
|
def on_send(node)
|
40
40
|
return unless blacklist.include?(node.method_name.to_s)
|
@@ -40,16 +40,16 @@ module RuboCop
|
|
40
40
|
|
41
41
|
MSG_CURRENT = 'Do not use `%s`. Use `Time.zone.now` instead.'.freeze
|
42
42
|
|
43
|
-
TIMECLASS = %i
|
43
|
+
TIMECLASS = %i[Time DateTime].freeze
|
44
44
|
|
45
|
-
GOOD_METHODS = %i
|
45
|
+
GOOD_METHODS = %i[zone zone_default find_zone find_zone!].freeze
|
46
46
|
|
47
|
-
DANGEROUS_METHODS = %i
|
48
|
-
parse at current
|
47
|
+
DANGEROUS_METHODS = %i[now local new strftime
|
48
|
+
parse at current].freeze
|
49
49
|
|
50
|
-
ACCEPTED_METHODS = %i
|
50
|
+
ACCEPTED_METHODS = %i[in_time_zone utc getlocal
|
51
51
|
iso8601 jisx0301 rfc3339
|
52
|
-
to_i to_f
|
52
|
+
to_i to_f].freeze
|
53
53
|
|
54
54
|
def on_const(node)
|
55
55
|
mod, klass = *node
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
class Validation < Cop
|
8
8
|
MSG = 'Prefer the new style validations `%s` over `%s`.'.freeze
|
9
9
|
|
10
|
-
TYPES = %w
|
10
|
+
TYPES = %w[
|
11
11
|
acceptance
|
12
12
|
confirmation
|
13
13
|
exclusion
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
presence
|
19
19
|
size
|
20
20
|
uniqueness
|
21
|
-
|
21
|
+
].freeze
|
22
22
|
|
23
23
|
BLACKLIST = TYPES.map { |p| "validates_#{p}_of".to_sym }.freeze
|
24
24
|
WHITELIST = TYPES.map { |p| "validates :column, #{p}: value" }.freeze
|
data/lib/rubocop/cop/severity.rb
CHANGED
@@ -5,6 +5,40 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cop checks for braces around the last parameter in a method call
|
7
7
|
# if the last parameter is a hash.
|
8
|
+
# It supports 3 styles:
|
9
|
+
#
|
10
|
+
# * The `braces` style enforces braces around all method
|
11
|
+
# parameters that are hashes.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# some_method(x, y, a: 1, b: 2)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# some_method(x, y, {a: 1, b: 2})
|
19
|
+
#
|
20
|
+
# * The `no_braces` style checks that the last parameter doesn't
|
21
|
+
# have braces around it.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# # bad
|
25
|
+
# some_method(x, y, {a: 1, b: 2})
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# some_method(x, y, a: 1, b: 2)
|
29
|
+
#
|
30
|
+
# * The `context_dependent` style checks that the last parameter
|
31
|
+
# doesn't have braces around it, but requires braces if the
|
32
|
+
# second to last parameter is also a hash literal.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# # bad
|
36
|
+
# some_method(x, y, {a: 1, b: 2})
|
37
|
+
# some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
|
38
|
+
#
|
39
|
+
# # good
|
40
|
+
# some_method(x, y, a: 1, b: 2)
|
41
|
+
# some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
|
8
42
|
class BracesAroundHashParameters < Cop
|
9
43
|
include ConfigurableEnforcedStyle
|
10
44
|
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
|
91
91
|
def setter_method?(method_name)
|
92
92
|
method_name.to_s.end_with?(EQUAL) &&
|
93
|
-
!%i
|
93
|
+
!%i[!= == === >= <=].include?(method_name)
|
94
94
|
end
|
95
95
|
|
96
96
|
def assignment_rhs_exist?(node)
|
@@ -205,9 +205,9 @@ module RuboCop
|
|
205
205
|
ASSIGN_TO_CONDITION_MSG =
|
206
206
|
'Assign variables inside of conditionals'.freeze
|
207
207
|
VARIABLE_ASSIGNMENT_TYPES =
|
208
|
-
%i
|
208
|
+
%i[casgn cvasgn gvasgn ivasgn lvasgn].freeze
|
209
209
|
ASSIGNMENT_TYPES = VARIABLE_ASSIGNMENT_TYPES +
|
210
|
-
%i
|
210
|
+
%i[and_asgn or_asgn op_asgn masgn].freeze
|
211
211
|
LINE_LENGTH = 'Metrics/LineLength'.freeze
|
212
212
|
INDENTATION_WIDTH = 'Style/IndentationWidth'.freeze
|
213
213
|
ENABLED = 'Enabled'.freeze
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
# NewClass = something_that_returns_a_class
|
20
20
|
# It's also ok to assign a class constant another class constant
|
21
21
|
# SomeClass = SomeOtherClass
|
22
|
-
return if value && %i
|
22
|
+
return if value && %i[send block const].include?(value.type)
|
23
23
|
|
24
24
|
add_offense(node, :name) if const_name !~ SNAKE_CASE
|
25
25
|
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
# [1, 2].each_with_object({}) { |e, a| a[e] = e }
|
19
19
|
class EachWithObject < Cop
|
20
20
|
MSG = 'Use `each_with_object` instead of `%s`.'.freeze
|
21
|
-
METHODS = %i
|
21
|
+
METHODS = %i[inject reduce].freeze
|
22
22
|
|
23
23
|
def_node_matcher :each_with_object_candidate?, <<-PATTERN
|
24
24
|
(block $(send _ {:inject :reduce} _) $_ $_)
|
@@ -91,7 +91,7 @@ module RuboCop
|
|
91
91
|
return nil if node.nil?
|
92
92
|
name = namespace.pop
|
93
93
|
|
94
|
-
on_node(%i
|
94
|
+
on_node(%i[class module casgn], node) do |child|
|
95
95
|
next unless (const = child.defined_module)
|
96
96
|
|
97
97
|
const_namespace, const_name = *const
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
152
152
|
# But RC can be run from any working directory, and can check any path
|
153
153
|
# We can't assume that the working directory, or any other, is the
|
154
154
|
# "starting point" to build a namespace
|
155
|
-
start = %w
|
155
|
+
start = %w[lib spec test src]
|
156
156
|
start_index = nil
|
157
157
|
|
158
158
|
# To find the closest namespace root take the path components, and
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
|
15
15
|
# predefined global variables their English aliases
|
16
16
|
# http://www.zenspider.com/Languages/Ruby/QuickRef.html
|
17
|
-
BUILT_IN_VARS = %w
|
17
|
+
BUILT_IN_VARS = %w[
|
18
18
|
$: $LOAD_PATH
|
19
19
|
$" $LOADED_FEATURES
|
20
20
|
$0 $PROGRAM_NAME
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
$DEBUG $FILENAME $VERBOSE $SAFE
|
42
42
|
$-0 $-a $-d $-F $-i $-I $-l $-p $-v $-w
|
43
43
|
$CLASSPATH $JRUBY_VERSION $JRUBY_REVISION $ENV_JAVA
|
44
|
-
|
44
|
+
].map(&:to_sym)
|
45
45
|
|
46
46
|
def user_vars
|
47
47
|
cop_config['AllowedVariables'].map(&:to_sym)
|
@@ -13,8 +13,8 @@ module RuboCop
|
|
13
13
|
'Another good alternative is the usage of control flow ' \
|
14
14
|
'`&&`/`||`.'.freeze
|
15
15
|
|
16
|
-
ASSIGNMENT_TYPES = %i
|
17
|
-
gvasgn ivasgn masgn
|
16
|
+
ASSIGNMENT_TYPES = %i[lvasgn casgn cvasgn
|
17
|
+
gvasgn ivasgn masgn].freeze
|
18
18
|
|
19
19
|
def on_if(node)
|
20
20
|
return unless eligible_node?(node)
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
include AccessModifierNode
|
54
54
|
include IgnoredPattern
|
55
55
|
|
56
|
-
SPECIAL_MODIFIERS = %w
|
56
|
+
SPECIAL_MODIFIERS = %w[private protected].freeze
|
57
57
|
|
58
58
|
def on_rescue(node)
|
59
59
|
_begin_node, *_rescue_nodes, else_node = *node
|
@@ -259,7 +259,7 @@ module RuboCop
|
|
259
259
|
def indentation_to_check?(base_loc, body_node)
|
260
260
|
return false if skip_check?(base_loc, body_node)
|
261
261
|
|
262
|
-
if %i
|
262
|
+
if %i[rescue ensure].include?(body_node.type)
|
263
263
|
block_body, = *body_node
|
264
264
|
return unless block_body
|
265
265
|
end
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
# foo == bar
|
29
29
|
class InverseMethods < Cop
|
30
30
|
MSG = 'Use `%{inverse}` instead of inverting `%{method}`.'.freeze
|
31
|
-
EQUALITY_METHODS = %i
|
31
|
+
EQUALITY_METHODS = %i[== != =~ !~ <= >= < >].freeze
|
32
32
|
|
33
33
|
def_node_matcher :inverse_candidate?, <<-PATTERN
|
34
34
|
{
|
@@ -22,12 +22,12 @@ module RuboCop
|
|
22
22
|
class LineEndConcatenation < Cop
|
23
23
|
MSG = 'Use `\\` instead of `+` or `<<` to concatenate ' \
|
24
24
|
'those strings.'.freeze
|
25
|
-
CONCAT_TOKEN_TYPES = %i
|
25
|
+
CONCAT_TOKEN_TYPES = %i[tPLUS tLSHFT].freeze
|
26
26
|
SIMPLE_STRING_TOKEN_TYPE = :tSTRING
|
27
|
-
COMPLEX_STRING_EDGE_TOKEN_TYPES = %i
|
28
|
-
HIGH_PRECEDENCE_OP_TOKEN_TYPES = %i
|
29
|
-
tLBRACK2
|
30
|
-
QUOTE_DELIMITERS = %w
|
27
|
+
COMPLEX_STRING_EDGE_TOKEN_TYPES = %i[tSTRING_BEG tSTRING_END].freeze
|
28
|
+
HIGH_PRECEDENCE_OP_TOKEN_TYPES = %i[tSTAR2 tPERCENT tDOT
|
29
|
+
tLBRACK2].freeze
|
30
|
+
QUOTE_DELIMITERS = %w[' "].freeze
|
31
31
|
|
32
32
|
def investigate(processed_source)
|
33
33
|
processed_source.tokens.each_index do |index|
|
@@ -15,6 +15,14 @@ module RuboCop
|
|
15
15
|
# # good
|
16
16
|
# array.delete(e)
|
17
17
|
#
|
18
|
+
# # good
|
19
|
+
# # Operators don't need parens
|
20
|
+
# foo == bar
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# # Setter methods don't need parens
|
24
|
+
# foo.bar = baz
|
25
|
+
#
|
18
26
|
# # okay with `puts` listed in `IgnoredMethods`
|
19
27
|
# puts 'test'
|
20
28
|
#
|
@@ -35,10 +43,8 @@ module RuboCop
|
|
35
43
|
MSG = 'Use parentheses for method calls with arguments.'.freeze
|
36
44
|
|
37
45
|
def on_send(node)
|
38
|
-
return if
|
46
|
+
return if ignored_method?(node)
|
39
47
|
return unless node.arguments? && !node.parenthesized?
|
40
|
-
return if operator_call?(node)
|
41
|
-
return if ignore_macros? && node.macro?
|
42
48
|
|
43
49
|
add_offense(node, :selector)
|
44
50
|
end
|
@@ -67,6 +73,12 @@ module RuboCop
|
|
67
73
|
|
68
74
|
private
|
69
75
|
|
76
|
+
def ignored_method?(node)
|
77
|
+
node.operator_method? || node.setter_method? ||
|
78
|
+
ignore_macros? && node.macro? ||
|
79
|
+
ignored_list.include?(node.method_name)
|
80
|
+
end
|
81
|
+
|
70
82
|
def ignored_list
|
71
83
|
cop_config['IgnoredMethods'].map(&:to_sym)
|
72
84
|
end
|
@@ -79,10 +91,6 @@ module RuboCop
|
|
79
91
|
node.loc.begin
|
80
92
|
end
|
81
93
|
|
82
|
-
def operator_call?(node)
|
83
|
-
node.operator_method?
|
84
|
-
end
|
85
|
-
|
86
94
|
def args_begin(node)
|
87
95
|
loc = node.loc
|
88
96
|
selector = node.super_type? ? loc.keyword : loc.selector
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
MSG = 'Do not use parentheses for method calls with ' \
|
16
16
|
'no arguments.'.freeze
|
17
17
|
|
18
|
-
ASGN_NODES = %i
|
18
|
+
ASGN_NODES = %i[lvasgn masgn] + SHORTHAND_ASGN_NODES
|
19
19
|
|
20
20
|
def on_send(node)
|
21
21
|
return if node.camel_case_method?
|
@@ -37,11 +37,11 @@ module RuboCop
|
|
37
37
|
class MixinGrouping < Cop
|
38
38
|
include ConfigurableEnforcedStyle
|
39
39
|
|
40
|
-
MIXIN_METHODS = %i
|
40
|
+
MIXIN_METHODS = %i[extend include prepend].freeze
|
41
41
|
MSG = 'Put `%s` mixins in %s.'.freeze
|
42
42
|
|
43
43
|
def on_send(node)
|
44
|
-
return unless MIXIN_METHODS.include?(node.method_name)
|
44
|
+
return unless node.macro? && MIXIN_METHODS.include?(node.method_name)
|
45
45
|
|
46
46
|
check(node)
|
47
47
|
end
|
@@ -14,9 +14,9 @@ module RuboCop
|
|
14
14
|
# method1(method2 arg, method3, arg)
|
15
15
|
class NestedParenthesizedCalls < Cop
|
16
16
|
MSG = 'Add parentheses to nested method call `%s`.'.freeze
|
17
|
-
RSPEC_MATCHERS = %i
|
17
|
+
RSPEC_MATCHERS = %i[be eq eql equal be_kind_of be_instance_of
|
18
18
|
respond_to be_between match be_within
|
19
|
-
start_with end_with include raise_error
|
19
|
+
start_with end_with include raise_error].freeze
|
20
20
|
|
21
21
|
def on_send(node)
|
22
22
|
return unless node.parenthesized?
|
@@ -23,12 +23,12 @@ module RuboCop
|
|
23
23
|
include MinBodyLength
|
24
24
|
|
25
25
|
MSG = 'Use `next` to skip iteration.'.freeze
|
26
|
-
EXIT_TYPES = %i
|
26
|
+
EXIT_TYPES = %i[break return].freeze
|
27
27
|
EACH_ = 'each_'.freeze
|
28
|
-
ENUMERATORS = %i
|
28
|
+
ENUMERATORS = %i[collect collect_concat detect downto each
|
29
29
|
find find_all find_index inject loop map!
|
30
30
|
map reduce reject reject! reverse_each select
|
31
|
-
select! times upto
|
31
|
+
select! times upto].freeze
|
32
32
|
|
33
33
|
def investigate(_processed_source)
|
34
34
|
# When correcting nested offenses, we need to keep track of how much
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
def replacement(node)
|
27
27
|
return to_ternary(node) unless node.parent
|
28
28
|
|
29
|
-
if %i
|
29
|
+
if %i[and or].include?(node.parent.type)
|
30
30
|
return "(#{to_ternary(node)})"
|
31
31
|
end
|
32
32
|
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def requires_parentheses?(node)
|
51
|
-
return true if %i
|
51
|
+
return true if %i[and or if].include?(node.type)
|
52
52
|
return true if node.assignment?
|
53
53
|
return true if method_call_with_changed_precedence?(node)
|
54
54
|
|
@@ -17,8 +17,8 @@ module RuboCop
|
|
17
17
|
MSG = 'When defining the `%s` operator, ' \
|
18
18
|
'name its argument `other`.'.freeze
|
19
19
|
|
20
|
-
OP_LIKE_METHODS = %i
|
21
|
-
BLACKLISTED = %i
|
20
|
+
OP_LIKE_METHODS = %i[eql? equal?].freeze
|
21
|
+
BLACKLISTED = %i[+@ -@ [] []= << `].freeze
|
22
22
|
|
23
23
|
def_node_matcher :op_method_candidate?, <<-PATTERN
|
24
24
|
(def $_ (args $(arg [!:other !:_other])) _)
|