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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4aa95a4490b838949fa15403588cced4899c86b
|
4
|
+
data.tar.gz: e6715d302d3b009057392f4875453c5a9dd5bb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0411e00f1c0b571dd45414ed595a6a0c5da0119bc2b1deeef053c21ba95dd6d2ebe84e91c426f5ab4b3471c9c5ed1d481cf6adfcff1c581cff9247f445c877aa
|
7
|
+
data.tar.gz: 901d75ba9adee9d27c26323d24bd44eeedac3112d11beb1081d1f385dd77989945a7011653b8b1595bda34c92a4faa56daa8688c434eaca6b8a52fe9c615a2b9
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
50
50
|
might want to use a conservative version locking in your `Gemfile`:
|
51
51
|
|
52
52
|
```rb
|
53
|
-
gem 'rubocop', '~> 0.48.
|
53
|
+
gem 'rubocop', '~> 0.48.1', require: false
|
54
54
|
```
|
55
55
|
|
56
56
|
## Quickstart
|
data/config/default.yml
CHANGED
@@ -902,6 +902,7 @@ Style/NonNilCheck:
|
|
902
902
|
|
903
903
|
Style/NumericLiterals:
|
904
904
|
MinDigits: 5
|
905
|
+
Strict: false
|
905
906
|
|
906
907
|
Style/NumericLiteralPrefix:
|
907
908
|
EnforcedOctalStyle: zero_with_o
|
@@ -938,7 +939,11 @@ Style/PercentLiteralDelimiters:
|
|
938
939
|
# an individual key
|
939
940
|
PreferredDelimiters:
|
940
941
|
default: ()
|
942
|
+
'%i': '[]'
|
943
|
+
'%I': '[]'
|
941
944
|
'%r': '{}'
|
945
|
+
'%w': '[]'
|
946
|
+
'%W': '[]'
|
942
947
|
|
943
948
|
Style/PercentQLiterals:
|
944
949
|
EnforcedStyle: lower_case_q
|
data/config/enabled.yml
CHANGED
@@ -360,6 +360,7 @@ Style/IfWithSemicolon:
|
|
360
360
|
|
361
361
|
Style/IndentationConsistency:
|
362
362
|
Description: 'Keep indentation straight.'
|
363
|
+
StyleGuide: '#spaces-indentation'
|
363
364
|
Enabled: true
|
364
365
|
|
365
366
|
Style/IndentationWidth:
|
@@ -566,7 +567,7 @@ Style/NestedTernaryOperator:
|
|
566
567
|
Enabled: true
|
567
568
|
|
568
569
|
Style/EmptyLineAfterMagicComment:
|
569
|
-
Description: 'Add
|
570
|
+
Description: 'Add an empty line after magic comments to separate them from code.'
|
570
571
|
StyleGuide: '#separate-magic-comments-from-code'
|
571
572
|
Enabled: true
|
572
573
|
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -26,9 +26,9 @@ module RuboCop
|
|
26
26
|
PairNode => [:pair],
|
27
27
|
ResbodyNode => [:resbody],
|
28
28
|
SendNode => [:send],
|
29
|
-
UntilNode => %i
|
29
|
+
UntilNode => %i[until until_post],
|
30
30
|
WhenNode => [:when],
|
31
|
-
WhileNode => %i
|
31
|
+
WhileNode => %i[while while_post]
|
32
32
|
}.freeze
|
33
33
|
|
34
34
|
# Generates {Node} from the given information.
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -21,28 +21,28 @@ module RuboCop
|
|
21
21
|
class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
|
22
22
|
include RuboCop::AST::Sexp
|
23
23
|
|
24
|
-
COMPARISON_OPERATORS = %i
|
24
|
+
COMPARISON_OPERATORS = %i[! == === != <= >= > < <=>].freeze
|
25
25
|
|
26
|
-
TRUTHY_LITERALS = %i
|
26
|
+
TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
|
27
27
|
hash regexp true irange erange complex
|
28
|
-
rational regopt
|
29
|
-
FALSEY_LITERALS = %i
|
28
|
+
rational regopt].freeze
|
29
|
+
FALSEY_LITERALS = %i[false nil].freeze
|
30
30
|
LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
|
31
|
-
COMPOSITE_LITERALS = %i
|
32
|
-
erange regexp
|
31
|
+
COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
|
32
|
+
erange regexp].freeze
|
33
33
|
BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
|
34
|
-
MUTABLE_LITERALS = %i
|
34
|
+
MUTABLE_LITERALS = %i[str dstr xstr array hash].freeze
|
35
35
|
IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
|
36
36
|
|
37
|
-
VARIABLES = %i
|
38
|
-
REFERENCES = %i
|
39
|
-
KEYWORDS = %i
|
37
|
+
VARIABLES = %i[ivar gvar cvar lvar].freeze
|
38
|
+
REFERENCES = %i[nth_ref back_ref].freeze
|
39
|
+
KEYWORDS = %i[alias and break case class def defs defined?
|
40
40
|
kwbegin do else ensure for if module next
|
41
41
|
not or postexe redo rescue retry return self
|
42
42
|
super zsuper then undef until when while
|
43
|
-
yield
|
44
|
-
OPERATOR_KEYWORDS = %i
|
45
|
-
SPECIAL_KEYWORDS = %w
|
43
|
+
yield].freeze
|
44
|
+
OPERATOR_KEYWORDS = %i[and or].freeze
|
45
|
+
SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].freeze
|
46
46
|
|
47
47
|
# def_matcher can be used to define a pattern-matching method on Node
|
48
48
|
class << self
|
@@ -361,7 +361,7 @@ module RuboCop
|
|
361
361
|
IMMUTABLE_LITERALS.include?(type)
|
362
362
|
end
|
363
363
|
|
364
|
-
%i
|
364
|
+
%i[literal basic_literal].each do |kind|
|
365
365
|
recursive_kind = :"recursive_#{kind}?"
|
366
366
|
kind_filter = :"#{kind}?"
|
367
367
|
define_method(recursive_kind) do
|
@@ -6,8 +6,6 @@ module RuboCop
|
|
6
6
|
# node when the builder constructs the AST, making its methods available
|
7
7
|
# to all `send` nodes within RuboCop.
|
8
8
|
class SendNode < Node
|
9
|
-
MACRO_PARENT_NODES = %i(class module).freeze
|
10
|
-
|
11
9
|
# The receiving node of the method invocation.
|
12
10
|
#
|
13
11
|
# @return [Node, nil] the receiver of the invoked method or `nil`
|
@@ -38,7 +36,7 @@ module RuboCop
|
|
38
36
|
#
|
39
37
|
# @return [Boolean] whether the method is a macro method
|
40
38
|
def macro?
|
41
|
-
!receiver &&
|
39
|
+
!receiver && macro_scope?
|
42
40
|
end
|
43
41
|
|
44
42
|
# Checks whether the method name matches the argument and has an
|
@@ -185,6 +183,13 @@ module RuboCop
|
|
185
183
|
def node_parts
|
186
184
|
[*self]
|
187
185
|
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
def_matcher :macro_scope?, <<-PATTERN
|
190
|
+
{^({class module} ...)
|
191
|
+
^^({class module} ... (begin ...))}
|
192
|
+
PATTERN
|
188
193
|
end
|
189
194
|
end
|
190
195
|
end
|
@@ -13,21 +13,21 @@ module RuboCop
|
|
13
13
|
nil
|
14
14
|
end
|
15
15
|
|
16
|
-
NO_CHILD_NODES = %i
|
16
|
+
NO_CHILD_NODES = %i[true false nil int float complex
|
17
17
|
rational str sym regopt self lvar
|
18
18
|
ivar cvar gvar nth_ref back_ref cbase
|
19
19
|
arg restarg blockarg shadowarg
|
20
|
-
kwrestarg zsuper lambda redo retry
|
21
|
-
ONE_CHILD_NODE = %i
|
20
|
+
kwrestarg zsuper lambda redo retry].freeze
|
21
|
+
ONE_CHILD_NODE = %i[splat kwsplat block_pass not break next
|
22
22
|
preexe postexe match_current_line defined?
|
23
|
-
arg_expr
|
24
|
-
MANY_CHILD_NODES = %i
|
23
|
+
arg_expr].freeze
|
24
|
+
MANY_CHILD_NODES = %i[dstr dsym xstr regexp array hash pair
|
25
25
|
irange erange mlhs masgn or_asgn and_asgn
|
26
26
|
undef alias args super yield or and
|
27
27
|
while_post until_post iflipflop eflipflop
|
28
|
-
match_with_lvasgn begin kwbegin return
|
29
|
-
SECOND_CHILD_ONLY = %i
|
30
|
-
kwoptarg
|
28
|
+
match_with_lvasgn begin kwbegin return].freeze
|
29
|
+
SECOND_CHILD_ONLY = %i[lvasgn ivasgn cvasgn gvasgn optarg kwarg
|
30
|
+
kwoptarg].freeze
|
31
31
|
|
32
32
|
NO_CHILD_NODES.each do |type|
|
33
33
|
module_eval("def on_#{type}(node); end")
|
data/lib/rubocop/config.rb
CHANGED
@@ -13,8 +13,8 @@ module RuboCop
|
|
13
13
|
class Config
|
14
14
|
include PathUtil
|
15
15
|
|
16
|
-
COMMON_PARAMS = %w
|
17
|
-
AutoCorrect StyleGuide Details
|
16
|
+
COMMON_PARAMS = %w[Exclude Include Severity
|
17
|
+
AutoCorrect StyleGuide Details].freeze
|
18
18
|
# 2.1 is the oldest officially supported Ruby version.
|
19
19
|
DEFAULT_RUBY_VERSION = 2.1
|
20
20
|
KNOWN_RUBIES = [1.9, 2.0, 2.1, 2.2, 2.3, 2.4].freeze
|
@@ -178,7 +178,7 @@ module RuboCop
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def deprecation_check
|
181
|
-
%w
|
181
|
+
%w[Exclude Include].each do |key|
|
182
182
|
plural = "#{key}s"
|
183
183
|
next unless for_all_cops[plural]
|
184
184
|
|
@@ -83,7 +83,7 @@ module RuboCop
|
|
83
83
|
|
84
84
|
def base_configs(path, inherit_from)
|
85
85
|
configs = Array(inherit_from).compact.map do |f|
|
86
|
-
if f =~ /\A#{URI::Parser.new.make_regexp(%w
|
86
|
+
if f =~ /\A#{URI::Parser.new.make_regexp(%w[http https])}\z/
|
87
87
|
f = RemoteConfig.new(f, File.dirname(path)).file
|
88
88
|
else
|
89
89
|
f = File.expand_path(f, File.dirname(path))
|
@@ -187,7 +187,7 @@ module RuboCop
|
|
187
187
|
if YAML.respond_to?(:safe_load) # Ruby 2.1+
|
188
188
|
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
|
189
189
|
SafeYAML.load(yaml_code, filename,
|
190
|
-
whitelisted_tags: %w
|
190
|
+
whitelisted_tags: %w[!ruby/regexp])
|
191
191
|
else
|
192
192
|
YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
|
193
193
|
end
|
@@ -16,37 +16,50 @@ module RuboCop
|
|
16
16
|
# # good
|
17
17
|
# # With parentheses, there's no ambiguity.
|
18
18
|
# some_method(a) { |val| puts val }
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# # Operator methods require no disambiguation
|
22
|
+
# foo == bar { |b| b.baz }
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# # Lambda arguments require no disambiguation
|
26
|
+
# foo = ->(bar) { bar.baz }
|
19
27
|
class AmbiguousBlockAssociation < Cop
|
20
28
|
MSG = 'Parenthesize the param `%s` to make sure that the block will be'\
|
21
29
|
' associated with the `%s` method call.'.freeze
|
22
30
|
|
23
31
|
def on_send(node)
|
24
|
-
return if node.parenthesized? ||
|
32
|
+
return if node.parenthesized? || allowed_method?(node)
|
33
|
+
return if lambda_argument?(node.first_argument)
|
25
34
|
|
26
|
-
return unless method_with_block?(node.
|
27
|
-
|
28
|
-
return unless method_as_param?(
|
35
|
+
return unless method_with_block?(node.last_argument)
|
36
|
+
last_param = node.last_argument.children.first
|
37
|
+
return unless method_as_param?(last_param)
|
29
38
|
|
30
|
-
add_offense(node, :expression, message(
|
39
|
+
add_offense(node, :expression, message(node.last_argument))
|
31
40
|
end
|
32
41
|
|
33
42
|
private
|
34
43
|
|
35
|
-
def
|
36
|
-
|
44
|
+
def allowed_method?(node)
|
45
|
+
node.assignment? || node.operator_method? || node.method?(:[])
|
46
|
+
end
|
37
47
|
|
38
|
-
|
48
|
+
def method_with_block?(param)
|
49
|
+
param && param.block_type?
|
39
50
|
end
|
40
51
|
|
41
52
|
def method_as_param?(param)
|
42
|
-
|
43
|
-
|
44
|
-
param.send_type? && !param.arguments?
|
53
|
+
param && param.send_type? && !param.arguments?
|
45
54
|
end
|
46
55
|
|
47
|
-
def message(param
|
48
|
-
format(MSG, param.
|
56
|
+
def message(param)
|
57
|
+
format(MSG, param.source, param.children.first.source)
|
49
58
|
end
|
59
|
+
|
60
|
+
def_node_matcher :lambda_argument?, <<-PATTERN
|
61
|
+
(block (send _ :lambda) ...)
|
62
|
+
PATTERN
|
50
63
|
end
|
51
64
|
end
|
52
65
|
end
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
runtime_error: 'RuntimeError',
|
38
38
|
standard_error: 'StandardError'
|
39
39
|
}.freeze
|
40
|
-
ILLEGAL_CLASSES = %w
|
40
|
+
ILLEGAL_CLASSES = %w[
|
41
41
|
Exception
|
42
42
|
SystemStackError
|
43
43
|
NoMemoryError
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
Interrupt
|
50
50
|
SignalException
|
51
51
|
SystemExit
|
52
|
-
|
52
|
+
].freeze
|
53
53
|
|
54
54
|
def on_class(node)
|
55
55
|
_class, base_class, _body = *node
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
# "result is 10"
|
19
19
|
class LiteralInInterpolation < Cop
|
20
20
|
MSG = 'Literal interpolation detected.'.freeze
|
21
|
-
COMPOSITE = %i
|
21
|
+
COMPOSITE = %i[array hash pair irange erange].freeze
|
22
22
|
|
23
23
|
def on_dstr(node)
|
24
24
|
node.each_child_node(:begin) do |begin_node|
|
@@ -36,6 +36,24 @@ module RuboCop
|
|
36
36
|
# end
|
37
37
|
# end
|
38
38
|
# end
|
39
|
+
#
|
40
|
+
# def foo
|
41
|
+
# self.module_exec do
|
42
|
+
# def bar
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
#
|
49
|
+
# # good
|
50
|
+
#
|
51
|
+
# def foo
|
52
|
+
# class << self
|
53
|
+
# def bar
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
39
57
|
class NestedMethodDefinition < Cop
|
40
58
|
include OnMethodDef
|
41
59
|
extend RuboCop::NodePattern::Macros
|
@@ -57,7 +75,7 @@ module RuboCop
|
|
57
75
|
subject, = *child
|
58
76
|
next if subject.lvar_type?
|
59
77
|
yield child
|
60
|
-
elsif !
|
78
|
+
elsif !scoping_method_call?(child)
|
61
79
|
find_nested_defs(child, &block)
|
62
80
|
end
|
63
81
|
end
|
@@ -65,14 +83,19 @@ module RuboCop
|
|
65
83
|
|
66
84
|
private
|
67
85
|
|
68
|
-
def
|
69
|
-
eval_call?(child) ||
|
86
|
+
def scoping_method_call?(child)
|
87
|
+
eval_call?(child) || exec_call?(child) || child.sclass_type? ||
|
88
|
+
class_or_module_or_struct_new_call?(child)
|
70
89
|
end
|
71
90
|
|
72
91
|
def_node_matcher :eval_call?, <<-PATTERN
|
73
92
|
(block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
74
93
|
PATTERN
|
75
94
|
|
95
|
+
def_node_matcher :exec_call?, <<-PATTERN
|
96
|
+
(block (send _ {:instance_exec :class_exec :module_exec} ...) ...)
|
97
|
+
PATTERN
|
98
|
+
|
76
99
|
def_node_matcher :class_or_module_or_struct_new_call?, <<-PATTERN
|
77
100
|
(block (send (const nil {:Class :Module :Struct}) :new ...) ...)
|
78
101
|
PATTERN
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
PERCENT_I = '%i'.freeze
|
58
58
|
PERCENT_CAPITAL_I = '%I'.freeze
|
59
59
|
ARRAY_NEW_PATTERN = '$(send (const nil :Array) :new ...)'.freeze
|
60
|
-
ASSIGNMENT_TYPES = %i
|
60
|
+
ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn].freeze
|
61
61
|
|
62
62
|
def_node_matcher :literal_expansion?, <<-PATTERN
|
63
63
|
(splat {$({str dstr int float array} ...) (block #{ARRAY_NEW_PATTERN} ...) #{ARRAY_NEW_PATTERN}} ...)
|
@@ -26,8 +26,8 @@ module RuboCop
|
|
26
26
|
class UnreachableCode < Cop
|
27
27
|
MSG = 'Unreachable code detected.'.freeze
|
28
28
|
|
29
|
-
NODE_TYPES = %i
|
30
|
-
FLOW_COMMANDS = %i
|
29
|
+
NODE_TYPES = %i[return next break retry redo].freeze
|
30
|
+
FLOW_COMMANDS = %i[throw raise fail].freeze
|
31
31
|
|
32
32
|
def on_begin(node)
|
33
33
|
expressions = *node
|
@@ -12,7 +12,7 @@ module RuboCop
|
|
12
12
|
# x.top >= x.top
|
13
13
|
class UselessComparison < Cop
|
14
14
|
MSG = 'Comparison of something with itself detected.'.freeze
|
15
|
-
OPS = %w
|
15
|
+
OPS = %w[== === != < > <= >= <=>].freeze
|
16
16
|
|
17
17
|
def_node_matcher :useless_comparison?,
|
18
18
|
"(send $_match {:#{OPS.join(' :')}} $_match)"
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
SELF_MSG = '`self` used in void context.'.freeze
|
49
49
|
DEFINED_MSG = '`%s` used in void context.'.freeze
|
50
50
|
|
51
|
-
OPS = %w
|
51
|
+
OPS = %w[* / % + - == === != < > <= >= <=>].freeze
|
52
52
|
|
53
53
|
def on_begin(node)
|
54
54
|
check_begin(node)
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
11
11
|
|
12
12
|
MSG = 'Assignment Branch Condition size for %s is too high. ' \
|
13
13
|
'[%.4g/%.4g]'.freeze
|
14
|
-
BRANCH_NODES = %i
|
14
|
+
BRANCH_NODES = %i[send csend].freeze
|
15
15
|
CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze
|
16
16
|
|
17
17
|
private
|