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.

Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +5 -0
  4. data/config/enabled.yml +2 -1
  5. data/lib/rubocop/ast/builder.rb +2 -2
  6. data/lib/rubocop/ast/node.rb +14 -14
  7. data/lib/rubocop/ast/node/send_node.rb +8 -3
  8. data/lib/rubocop/ast/traversal.rb +8 -8
  9. data/lib/rubocop/config.rb +3 -3
  10. data/lib/rubocop/config_loader.rb +2 -2
  11. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +26 -13
  12. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  13. data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
  14. data/lib/rubocop/cop/lint/literal_in_condition.rb +1 -1
  15. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  16. data/lib/rubocop/cop/lint/nested_method_definition.rb +26 -3
  17. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
  18. data/lib/rubocop/cop/lint/unreachable_code.rb +2 -2
  19. data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
  20. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  21. data/lib/rubocop/cop/lint/void.rb +1 -1
  22. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  23. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
  24. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
  25. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  26. data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
  27. data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
  28. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  29. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  30. data/lib/rubocop/cop/mixin/on_method_def.rb +1 -1
  31. data/lib/rubocop/cop/mixin/percent_literal.rb +45 -4
  32. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  33. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
  34. data/lib/rubocop/cop/offense.rb +2 -2
  35. data/lib/rubocop/cop/performance/casecmp.rb +1 -1
  36. data/lib/rubocop/cop/performance/end_with.rb +1 -2
  37. data/lib/rubocop/cop/performance/redundant_match.rb +1 -1
  38. data/lib/rubocop/cop/performance/regexp_match.rb +2 -2
  39. data/lib/rubocop/cop/performance/start_with.rb +1 -2
  40. data/lib/rubocop/cop/rails/action_filter.rb +4 -4
  41. data/lib/rubocop/cop/rails/blank.rb +1 -0
  42. data/lib/rubocop/cop/rails/date.rb +3 -3
  43. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  44. data/lib/rubocop/cop/rails/exit.rb +2 -2
  45. data/lib/rubocop/cop/rails/file_path.rb +5 -1
  46. data/lib/rubocop/cop/rails/find_by.rb +1 -1
  47. data/lib/rubocop/cop/rails/find_each.rb +2 -2
  48. data/lib/rubocop/cop/rails/http_positional_arguments.rb +3 -3
  49. data/lib/rubocop/cop/rails/relative_date_constant.rb +7 -3
  50. data/lib/rubocop/cop/rails/request_referer.rb +17 -2
  51. data/lib/rubocop/cop/rails/save_bang.rb +4 -4
  52. data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
  53. data/lib/rubocop/cop/rails/time_zone.rb +6 -6
  54. data/lib/rubocop/cop/rails/validation.rb +2 -2
  55. data/lib/rubocop/cop/severity.rb +1 -1
  56. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +34 -0
  57. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  58. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  59. data/lib/rubocop/cop/style/conditional_assignment.rb +3 -3
  60. data/lib/rubocop/cop/style/constant_name.rb +1 -1
  61. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  62. data/lib/rubocop/cop/style/empty_line_after_magic_comment.rb +1 -1
  63. data/lib/rubocop/cop/style/file_name.rb +2 -2
  64. data/lib/rubocop/cop/style/global_vars.rb +2 -2
  65. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  66. data/lib/rubocop/cop/style/indentation_width.rb +2 -2
  67. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  68. data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -5
  69. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +15 -7
  70. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -1
  71. data/lib/rubocop/cop/style/mixin_grouping.rb +2 -2
  72. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
  73. data/lib/rubocop/cop/style/next.rb +3 -3
  74. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  75. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
  76. data/lib/rubocop/cop/style/op_method.rb +2 -2
  77. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  78. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -36
  79. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  80. data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -2
  81. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  82. data/lib/rubocop/cop/style/redundant_self.rb +4 -5
  83. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  84. data/lib/rubocop/cop/style/self_assignment.rb +3 -3
  85. data/lib/rubocop/cop/style/space_around_keyword.rb +9 -9
  86. data/lib/rubocop/cop/style/space_around_operators.rb +1 -1
  87. data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -1
  88. data/lib/rubocop/cop/style/space_inside_parens.rb +1 -1
  89. data/lib/rubocop/cop/style/special_global_vars.rb +10 -10
  90. data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
  91. data/lib/rubocop/cop/style/ternary_parentheses.rb +3 -2
  92. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  93. data/lib/rubocop/cop/util.rb +7 -7
  94. data/lib/rubocop/cop/variable_force.rb +7 -7
  95. data/lib/rubocop/cop/variable_force/variable.rb +2 -2
  96. data/lib/rubocop/formatter/colorizable.rb +2 -2
  97. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  98. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  99. data/lib/rubocop/options.rb +20 -11
  100. data/lib/rubocop/processed_source.rb +1 -1
  101. data/lib/rubocop/result_cache.rb +2 -2
  102. data/lib/rubocop/rspec/shared_examples.rb +1 -1
  103. data/lib/rubocop/runner.rb +1 -1
  104. data/lib/rubocop/target_finder.rb +6 -6
  105. data/lib/rubocop/version.rb +1 -1
  106. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83278e7b0db6182dca6c9c459ec501d77879da8f
4
- data.tar.gz: f704ff6c92918ac9d981d2bc99a9cb5e8c93ae36
3
+ metadata.gz: b4aa95a4490b838949fa15403588cced4899c86b
4
+ data.tar.gz: e6715d302d3b009057392f4875453c5a9dd5bb29
5
5
  SHA512:
6
- metadata.gz: 6cfa68a81c85d90199e4c334b0c067956d0a44004651622c65ff62902bd1624d06f051dab10213bce4c0f00dd7cf13db8345e938cef0444f9762bb4d33222dcb
7
- data.tar.gz: f573cc40d97449a1b51925594c1b034ca047a1ee5cf3693851008fb4e1d5be21bae3d450296b11dfe904ec99324e6318d3e8e33271001854e3b1f161f134d94b
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.0', require: false
53
+ gem 'rubocop', '~> 0.48.1', require: false
54
54
  ```
55
55
 
56
56
  ## Quickstart
@@ -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
@@ -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 a newline after magic comments to separate them from code.'
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
 
@@ -26,9 +26,9 @@ module RuboCop
26
26
  PairNode => [:pair],
27
27
  ResbodyNode => [:resbody],
28
28
  SendNode => [:send],
29
- UntilNode => %i(until until_post),
29
+ UntilNode => %i[until until_post],
30
30
  WhenNode => [:when],
31
- WhileNode => %i(while while_post)
31
+ WhileNode => %i[while while_post]
32
32
  }.freeze
33
33
 
34
34
  # Generates {Node} from the given information.
@@ -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(! == === != <= >= > < <=>).freeze
24
+ COMPARISON_OPERATORS = %i[! == === != <= >= > < <=>].freeze
25
25
 
26
- TRUTHY_LITERALS = %i(str dstr xstr int float sym dsym array
26
+ TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
27
27
  hash regexp true irange erange complex
28
- rational regopt).freeze
29
- FALSEY_LITERALS = %i(false nil).freeze
28
+ rational regopt].freeze
29
+ FALSEY_LITERALS = %i[false nil].freeze
30
30
  LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
31
- COMPOSITE_LITERALS = %i(dstr xstr dsym array hash irange
32
- erange regexp).freeze
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(str dstr xstr array hash).freeze
34
+ MUTABLE_LITERALS = %i[str dstr xstr array hash].freeze
35
35
  IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
36
36
 
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?
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).freeze
44
- OPERATOR_KEYWORDS = %i(and or).freeze
45
- SPECIAL_KEYWORDS = %w(__FILE__ __LINE__ __ENCODING__).freeze
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(literal basic_literal).each do |kind|
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 && MACRO_PARENT_NODES.include?(parent && parent.type)
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(true false nil int float complex
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).freeze
21
- ONE_CHILD_NODE = %i(splat kwsplat block_pass not break next
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).freeze
24
- MANY_CHILD_NODES = %i(dstr dsym xstr regexp array hash pair
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).freeze
29
- SECOND_CHILD_ONLY = %i(lvasgn ivasgn cvasgn gvasgn optarg kwarg
30
- kwoptarg).freeze
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")
@@ -13,8 +13,8 @@ module RuboCop
13
13
  class Config
14
14
  include PathUtil
15
15
 
16
- COMMON_PARAMS = %w(Exclude Include Severity
17
- AutoCorrect StyleGuide Details).freeze
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(Exclude Include).each do |key|
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(http https))}\z/
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(!ruby/regexp))
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? || node.assignment? || node.method?(:[])
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.first_argument)
27
- first_param = node.first_argument.children.first
28
- return unless method_as_param?(first_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(first_param, node.method_name))
39
+ add_offense(node, :expression, message(node.last_argument))
31
40
  end
32
41
 
33
42
  private
34
43
 
35
- def method_with_block?(param)
36
- return false unless param
44
+ def allowed_method?(node)
45
+ node.assignment? || node.operator_method? || node.method?(:[])
46
+ end
37
47
 
38
- param.block_type?
48
+ def method_with_block?(param)
49
+ param && param.block_type?
39
50
  end
40
51
 
41
52
  def method_as_param?(param)
42
- return false unless param
43
-
44
- param.send_type? && !param.arguments?
53
+ param && param.send_type? && !param.arguments?
45
54
  end
46
55
 
47
- def message(param, method_name)
48
- format(MSG, param.children[1], method_name)
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
@@ -29,7 +29,7 @@ module RuboCop
29
29
  SHOVEL = '<<'.freeze
30
30
  PERCENT = '%'.freeze
31
31
  PERCENT_PERCENT = '%%'.freeze
32
- STRING_TYPES = %i(str dstr).freeze
32
+ STRING_TYPES = %i[str dstr].freeze
33
33
  NAMED_INTERPOLATION = /%(?:<\w+>|\{\w+\})/
34
34
 
35
35
  def on_send(node)
@@ -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
- ).freeze
52
+ ].freeze
53
53
 
54
54
  def on_class(node)
55
55
  _class, base_class, _body = *node
@@ -108,7 +108,7 @@ module RuboCop
108
108
  def handle_node(node)
109
109
  if node.literal?
110
110
  add_offense(node, :expression)
111
- elsif %i(send and or begin).include?(node.type)
111
+ elsif %i[send and or begin].include?(node.type)
112
112
  check_node(node)
113
113
  end
114
114
  end
@@ -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(array hash pair irange erange).freeze
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 !ignored_child?(child)
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 ignored_child?(child)
69
- eval_call?(child) || class_or_module_or_struct_new_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(lvasgn ivasgn cvasgn gvasgn).freeze
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(return next break retry redo).freeze
30
- FLOW_COMMANDS = %i(throw raise fail).freeze
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(== === != < > <= >= <=>).freeze
15
+ OPS = %w[== === != < > <= >= <=>].freeze
16
16
 
17
17
  def_node_matcher :useless_comparison?,
18
18
  "(send $_match {:#{OPS.join(' :')}} $_match)"
@@ -28,7 +28,7 @@ module RuboCop
28
28
  include OnMethodDef
29
29
 
30
30
  MSG = 'Useless setter call to local variable `%s`.'.freeze
31
- ASSIGNMENT_TYPES = %i(lvasgn ivasgn cvasgn gvasgn).freeze
31
+ ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn].freeze
32
32
 
33
33
  private
34
34
 
@@ -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(* / % + - == === != < > <= >= <=>).freeze
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(send csend).freeze
14
+ BRANCH_NODES = %i[send csend].freeze
15
15
  CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze
16
16
 
17
17
  private