rubocop-ast 0.7.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eae5a550b84ac088fb1065c539710b04b9885883c367ab0b26f8d3b455291ccb
4
- data.tar.gz: 424d68c1b31693d5de3dc83aaf88823147ecf5a446c2b68f39c8e992f9b10c4e
3
+ metadata.gz: 80da9c79ffae899ecc1eea266704e35274d85ce07d3f46a9bed2a7ac573445b9
4
+ data.tar.gz: af113442d1be42f61c17b369e097c6c0ad9c5c9c49cac27c70dee3c21aa39568
5
5
  SHA512:
6
- metadata.gz: e16362b75f0e898818a6bfd9a17fc83d86f682fd83328d07ed5bd71a561dfc4b8d3f9bab97e8175f367969dd2938666bb6b5d6ea21a18e65d9760fc83df1201e
7
- data.tar.gz: c32c20ef1936d110845c9564680c57753cb2f22c0fc4a98b13a8a7e7dfe18f7920c8f2ef96f8a3fafcdaf566e0f41b3214d6988dad1dc1416b3c70437cee046f
6
+ metadata.gz: d4d26dca602b849000686fa68f1b543681d8e51598741a6a4bf9e69a57ca6bab21ce8ac270b8578ad473808ed985f13ce9b080ac2259ad73fd6f87110e345305
7
+ data.tar.gz: 72d5d9852cd5286ba8d01c7f5b46b774fdfb7bae7382aebd9cf766b8bd103f22477d3ba7d47a62c3466bc35d74eba4784e6b53725aa4332669d20a8801d46936
@@ -484,10 +484,11 @@ module RuboCop
484
484
  def_node_matcher :global_const?, '(const {nil? cbase} %1)'
485
485
 
486
486
  def_node_matcher :class_constructor?, <<~PATTERN
487
- { (send #global_const?({:Class :Module}) :new ...)
488
- (block (send #global_const?({:Class :Module}) :new ...) ...)}
487
+ { (send #global_const?({:Class :Module :Struct}) :new ...)
488
+ (block (send #global_const?({:Class :Module :Struct}) :new ...) ...)}
489
489
  PATTERN
490
490
 
491
+ # @deprecated Use `:class_constructor?`
491
492
  def_node_matcher :struct_constructor?, <<~PATTERN
492
493
  (block (send #global_const?(:Struct) :new ...) _ $_)
493
494
  PATTERN
@@ -58,6 +58,11 @@ module RuboCop
58
58
  def receiver
59
59
  children[-4]
60
60
  end
61
+
62
+ # @return [Boolean] if the definition is without an `end` or not.
63
+ def endless?
64
+ !loc.end
65
+ end
61
66
  end
62
67
  end
63
68
  end
@@ -174,7 +174,7 @@ module RuboCop
174
174
  # @return [Boolean] whether the dispatched method is a `def` modifier
175
175
  def def_modifier?
176
176
  send_type? &&
177
- [self, *each_descendant(:send)].any?(&:adjacent_def_modifier?)
177
+ adjacent_def_modifier? || each_child_node(:send).any?(&:def_modifier?)
178
178
  end
179
179
 
180
180
  # Checks whether this is a lambda. Some versions of parser parses
@@ -6,7 +6,7 @@ module RuboCop
6
6
  module AST
7
7
  # This class performs a pattern-matching operation on an AST node.
8
8
  #
9
- # Detailed syntax: /doc/modules/ROOT/pages/node_pattern.md
9
+ # Detailed syntax: /docs/modules/ROOT/pages/node_pattern.adoc
10
10
  #
11
11
  # Initialize a new `NodePattern` with `NodePattern.new(pattern_string)`, then
12
12
  # pass an AST node to `NodePattern#match`. Alternatively, use one of the class
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Responsible to build the AST nodes for `NodePattern`
7
7
  #
8
8
  # Doc on how this fits in the compiling process:
9
- # /doc/modules/ROOT/pages/node_pattern.md
9
+ # /docs/modules/ROOT/pages/node_pattern.adoc
10
10
  class Builder
11
11
  def emit_capture(capture_token, node)
12
12
  return node if capture_token.nil?
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # Defers work to its subcompilers
8
8
  #
9
9
  # Doc on how this fits in the compiling process:
10
- # /doc/modules/ROOT/pages/node_pattern.md
10
+ # /docs/modules/ROOT/pages/node_pattern.adoc
11
11
  class Compiler
12
12
  extend Forwardable
13
13
  attr_reader :captures, :named_parameters, :positional_parameters, :binding
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # This value responds to `===`.
9
9
  #
10
10
  # Doc on how this fits in the compiling process:
11
- # /doc/modules/ROOT/pages/node_pattern.md
11
+ # /docs/modules/ROOT/pages/node_pattern.adoc
12
12
  class AtomSubcompiler < Subcompiler
13
13
  private
14
14
 
@@ -43,7 +43,7 @@ module RuboCop
43
43
 
44
44
  # Result of a NodePattern run against a particular AST
45
45
  # Consider constructor is private
46
- Result = Struct.new(:colorizer, :trace, :returned, :ruby_ast) do # rubocop:disable Metrics/BlockLength
46
+ Result = Struct.new(:colorizer, :trace, :returned, :ruby_ast) do
47
47
  # @return [String] a Rainbow colorized version of ruby
48
48
  def colorize(color_scheme = COLOR_SCHEME)
49
49
  map = color_map(color_scheme)
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # or it's `node.type` if `seq_head` is true
10
10
  #
11
11
  # Doc on how this fits in the compiling process:
12
- # /doc/modules/ROOT/pages/node_pattern.md
12
+ # /docs/modules/ROOT/pages/node_pattern.adoc
13
13
  class NodePatternSubcompiler < Subcompiler
14
14
  attr_reader :access, :seq_head
15
15
 
@@ -11,7 +11,7 @@ module RuboCop
11
11
  # Assumes the given `var` is a `::RuboCop::AST::Node`
12
12
  #
13
13
  # Doc on how this fits in the compiling process:
14
- # /doc/modules/ROOT/pages/node_pattern.md
14
+ # /docs/modules/ROOT/pages/node_pattern.adoc
15
15
  #
16
16
  # rubocop:disable Metrics/ClassLength
17
17
  class SequenceSubcompiler < Subcompiler
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # Implements visitor pattern
9
9
  #
10
10
  # Doc on how this fits in the compiling process:
11
- # /doc/modules/ROOT/pages/node_pattern.md
11
+ # /docs/modules/ROOT/pages/node_pattern.adoc
12
12
  class Subcompiler
13
13
  attr_reader :compiler
14
14
 
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # Lexer class for `NodePattern`
15
15
  #
16
16
  # Doc on how this fits in the compiling process:
17
- # /doc/modules/ROOT/pages/node_pattern.md
17
+ # /docs/modules/ROOT/pages/node_pattern.adoc
18
18
  class Lexer < LexerRex
19
19
  Error = ScanError
20
20
 
@@ -38,7 +38,7 @@ module RuboCop
38
38
 
39
39
  # @return [token]
40
40
  def emit(type)
41
- value = ss.captures.first || ss.matched
41
+ value = ss[1] || ss.matched
42
42
  value = yield value if block_given?
43
43
  token = token(type, value)
44
44
  @tokens << token
@@ -50,7 +50,8 @@ module RuboCop
50
50
  end
51
51
 
52
52
  def emit_regexp
53
- body, options = ss.captures
53
+ body = ss[1]
54
+ options = ss[2]
54
55
  flag = options.each_char.map { |c| REGEXP_OPTIONS[c] }.sum
55
56
 
56
57
  emit(:tREGEXP) { Regexp.new(body, flag) }
@@ -11,8 +11,10 @@
11
11
  class RuboCop::AST::NodePattern::LexerRex
12
12
 
13
13
  macros
14
+ CONST_NAME /[A-Z:][a-zA-Z_:]+/
14
15
  SYMBOL_NAME /[\w+@*\/?!<>=~|%^-]+|\[\]=?/
15
16
  IDENTIFIER /[a-zA-Z_][a-zA-Z0-9_-]*/
17
+ CALL /(?:#{CONST_NAME}\.)?#{IDENTIFIER}[!?]?/
16
18
  REGEXP_BODY /(?:[^\/]|\\\/)*/
17
19
  REGEXP /\/(#{REGEXP_BODY})(?<!\\)\/([imxo]*)/
18
20
  rules
@@ -25,12 +27,12 @@ rules
25
27
  %w"( ) { | } [ ] < > $ ! ^ ` ... + * ? ,"
26
28
  )}/o { emit ss.matched, &:to_sym }
27
29
  /#{REGEXP}/o { emit_regexp }
28
- /%([A-Z:][a-zA-Z_:]+)/ { emit :tPARAM_CONST }
30
+ /%(#{CONST_NAME})/o { emit :tPARAM_CONST }
29
31
  /%([a-z_]+)/ { emit :tPARAM_NAMED }
30
32
  /%(\d*)/ { emit(:tPARAM_NUMBER) { |s| s.empty? ? 1 : s.to_i } } # Map `%` to `%1`
31
33
  /_(#{IDENTIFIER})/o { emit :tUNIFY }
32
34
  /_/o { emit :tWILDCARD }
33
- /\#(#{IDENTIFIER}[!?]?)/o { @state = :ARG; emit :tFUNCTION_CALL, &:to_sym }
35
+ /\#(#{CALL})/o { @state = :ARG; emit :tFUNCTION_CALL, &:to_sym }
34
36
  /#{IDENTIFIER}\?/o { @state = :ARG; emit :tPREDICATE, &:to_sym }
35
37
  /#{IDENTIFIER}/o { emit :tNODE_TYPE, &:to_sym }
36
38
  :ARG /\(/ { @state = nil; emit :tARG_LIST }
@@ -24,8 +24,10 @@ class RuboCop::AST::NodePattern::LexerRex
24
24
  require 'strscan'
25
25
 
26
26
  # :stopdoc:
27
+ CONST_NAME = /[A-Z:][a-zA-Z_:]+/
27
28
  SYMBOL_NAME = /[\w+@*\/?!<>=~|%^-]+|\[\]=?/
28
29
  IDENTIFIER = /[a-zA-Z_][a-zA-Z0-9_-]*/
30
+ CALL = /(?:#{CONST_NAME}\.)?#{IDENTIFIER}[!?]?/
29
31
  REGEXP_BODY = /(?:[^\/]|\\\/)*/
30
32
  REGEXP = /\/(#{REGEXP_BODY})(?<!\\)\/([imxo]*)/
31
33
  # :startdoc:
@@ -132,7 +134,7 @@ class RuboCop::AST::NodePattern::LexerRex
132
134
  action { emit ss.matched, &:to_sym }
133
135
  when ss.skip(/#{REGEXP}/o) then
134
136
  action { emit_regexp }
135
- when ss.skip(/%([A-Z:][a-zA-Z_:]+)/) then
137
+ when ss.skip(/%(#{CONST_NAME})/o) then
136
138
  action { emit :tPARAM_CONST }
137
139
  when ss.skip(/%([a-z_]+)/) then
138
140
  action { emit :tPARAM_NAMED }
@@ -142,7 +144,7 @@ class RuboCop::AST::NodePattern::LexerRex
142
144
  action { emit :tUNIFY }
143
145
  when ss.skip(/_/o) then
144
146
  action { emit :tWILDCARD }
145
- when ss.skip(/\#(#{IDENTIFIER}[!?]?)/o) then
147
+ when ss.skip(/\#(#{CALL})/o) then
146
148
  action { @state = :ARG; emit :tFUNCTION_CALL, &:to_sym }
147
149
  when ss.skip(/#{IDENTIFIER}\?/o) then
148
150
  action { @state = :ARG; emit :tPREDICATE, &:to_sym }
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # Note: class reopened in `parser.racc`
10
10
  #
11
11
  # Doc on how this fits in the compiling process:
12
- # /doc/modules/ROOT/pages/node_pattern.md
12
+ # /docs/modules/ROOT/pages/node_pattern.adoc
13
13
  class Parser < Racc::Parser
14
14
  extend Forwardable
15
15
 
@@ -20,6 +20,9 @@ module RuboCop
20
20
  new(file, ruby_version, path)
21
21
  end
22
22
 
23
+ INVALID_LEVELS = %i[error fatal].freeze
24
+ private_constant :INVALID_LEVELS
25
+
23
26
  def initialize(source, ruby_version, path = nil)
24
27
  # Defaults source encoding to UTF-8, regardless of the encoding it has
25
28
  # been read with, which could be non-utf8 depending on the default
@@ -64,7 +67,7 @@ module RuboCop
64
67
  def valid_syntax?
65
68
  return false if @parser_error
66
69
 
67
- @diagnostics.none? { |d| %i[error fatal].include?(d.level) }
70
+ @diagnostics.none? { |d| INVALID_LEVELS.include?(d.level) }
68
71
  end
69
72
 
70
73
  # Raw source checksum for tracking infinite loops.
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ModuleLength
4
3
  module RuboCop
5
4
  module AST
6
5
  # Provides methods for traversing an AST.
@@ -8,198 +7,175 @@ module RuboCop
8
7
  # Override methods to perform custom processing. Remember to call `super`
9
8
  # if you want to recursively process descendant nodes.
10
9
  module Traversal
10
+ # Only for debugging.
11
+ # @api private
12
+ class DebugError < RuntimeError
13
+ end
14
+
15
+ TYPE_TO_METHOD = Hash.new { |h, type| h[type] = :"on_#{type}" }
16
+
11
17
  def walk(node)
12
18
  return if node.nil?
13
19
 
14
- send(:"on_#{node.type}", node)
20
+ send(TYPE_TO_METHOD[node.type], node)
15
21
  nil
16
22
  end
17
23
 
18
- NO_CHILD_NODES = %i[true false nil int float complex
19
- rational str sym regopt self lvar
20
- ivar cvar gvar nth_ref back_ref cbase
21
- arg restarg blockarg shadowarg
22
- kwrestarg zsuper redo retry
23
- forward_args forwarded_args
24
- match_var match_nil_pattern empty_else
25
- forward_arg lambda procarg0 __ENCODING__].freeze
26
- ONE_CHILD_NODE = %i[splat kwsplat block_pass not break next
27
- preexe postexe match_current_line defined?
28
- arg_expr pin match_rest if_guard unless_guard
29
- match_with_trailing_comma].freeze
30
- MANY_CHILD_NODES = %i[dstr dsym xstr regexp array hash pair
31
- mlhs masgn or_asgn and_asgn rasgn mrasgn
32
- undef alias args super yield or and
33
- while_post until_post iflipflop eflipflop
34
- match_with_lvasgn begin kwbegin return
35
- in_match match_alt
36
- match_as array_pattern array_pattern_with_tail
37
- hash_pattern const_pattern find_pattern
38
- index indexasgn].freeze
39
- SECOND_CHILD_ONLY = %i[lvasgn ivasgn cvasgn gvasgn optarg kwarg
40
- kwoptarg].freeze
41
- private_constant :NO_CHILD_NODES, :ONE_CHILD_NODE, :MANY_CHILD_NODES, :SECOND_CHILD_ONLY
42
-
43
- NO_CHILD_NODES.each do |type|
44
- module_eval("def on_#{type}(node); end", __FILE__, __LINE__)
45
- end
46
-
47
- ONE_CHILD_NODE.each do |type|
48
- module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
49
- def on_#{type}(node)
50
- if (child = node.children[0])
51
- send(:"on_\#{child.type}", child)
24
+ # @api private
25
+ module CallbackCompiler
26
+ SEND = 'send(TYPE_TO_METHOD[child.type], child)'
27
+ assign_code = 'child = node.children[%<index>i]'
28
+ code = "#{assign_code}\n#{SEND}"
29
+ TEMPLATE = {
30
+ skip: '',
31
+ always: code,
32
+ nil?: "#{code} if child"
33
+ }.freeze
34
+
35
+ def def_callback(type, *signature,
36
+ arity: signature.size..signature.size,
37
+ arity_check: ENV['RUBOCOP_DEBUG'] && self.arity_check(arity),
38
+ body: self.body(signature, arity_check))
39
+ type, *aliases = type
40
+ lineno = caller_locations(1, 1).first.lineno
41
+ module_eval(<<~RUBY, __FILE__, lineno) # rubocop:disable Style/EvalWithLocation
42
+ def on_#{type}(node)
43
+ #{body}
44
+ nil
52
45
  end
46
+ RUBY
47
+ aliases.each do |m|
48
+ alias_method "on_#{m}", "on_#{type}"
53
49
  end
54
- RUBY
55
- end
56
-
57
- MANY_CHILD_NODES.each do |type|
58
- module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
59
- def on_#{type}(node)
60
- node.children.each { |child| send(:"on_\#{child.type}", child) }
61
- nil
62
- end
63
- RUBY
64
- end
50
+ end
65
51
 
66
- SECOND_CHILD_ONLY.each do |type|
67
- # Guard clause is for nodes nested within mlhs
68
- module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
69
- def on_#{type}(node)
70
- if (child = node.children[1])
71
- send(:"on_\#{child.type}", child)
52
+ def body(signature, prelude)
53
+ signature
54
+ .map.with_index do |arg, i|
55
+ TEMPLATE[arg].gsub('%<index>i', i.to_s)
72
56
  end
73
- end
74
- RUBY
75
- end
76
-
77
- def on_const(node)
78
- return unless (child = node.children[0])
79
-
80
- send(:"on_#{child.type}", child)
81
- end
82
-
83
- def on_casgn(node)
84
- children = node.children
85
- if (child = children[0]) # always const???
86
- send(:"on_#{child.type}", child)
57
+ .unshift(prelude)
58
+ .join("\n")
87
59
  end
88
- return unless (child = children[2])
89
-
90
- send(:"on_#{child.type}", child)
91
- end
92
60
 
93
- def on_class(node)
94
- children = node.children
95
- child = children[0] # always const???
96
- send(:"on_#{child.type}", child)
97
- if (child = children[1])
98
- send(:"on_#{child.type}", child)
61
+ def arity_check(range)
62
+ <<~RUBY
63
+ n = node.children.size
64
+ raise DebugError, [
65
+ 'Expected #{range} children, got',
66
+ n, 'for', node.inspect
67
+ ].join(' ') unless (#{range}).cover?(node.children.size)
68
+ RUBY
99
69
  end
100
- return unless (child = children[2])
101
-
102
- send(:"on_#{child.type}", child)
103
- end
104
-
105
- def on_def(node)
106
- children = node.children
107
- on_args(children[1])
108
- return unless (child = children[2])
109
-
110
- send(:"on_#{child.type}", child)
111
70
  end
112
-
113
- def on_send(node)
71
+ private_constant :CallbackCompiler
72
+ extend CallbackCompiler
73
+ send_code = CallbackCompiler::SEND
74
+
75
+ ### arity == 0
76
+ no_children = %i[true false nil self cbase zsuper redo retry
77
+ forward_args forwarded_args match_nil_pattern
78
+ forward_arg lambda empty_else kwnilarg
79
+ __FILE__ __LINE__ __ENCODING__]
80
+
81
+ ### arity == 0..1
82
+ opt_symbol_child = %i[restarg kwrestarg]
83
+ opt_node_child = %i[splat kwsplat match_rest]
84
+
85
+ ### arity == 1
86
+ literal_child = %i[int float complex
87
+ rational str sym lvar
88
+ ivar cvar gvar nth_ref back_ref
89
+ arg blockarg shadowarg
90
+ kwarg match_var]
91
+
92
+ many_symbol_children = %i[regopt]
93
+
94
+ node_child = %i[block_pass not
95
+ match_current_line defined?
96
+ arg_expr pin if_guard unless_guard
97
+ match_with_trailing_comma]
98
+ node_or_nil_child = %i[preexe postexe]
99
+
100
+ NO_CHILD_NODES = (no_children + opt_symbol_child + literal_child).to_set.freeze
101
+ private_constant :NO_CHILD_NODES # Used by Commissioner
102
+
103
+ ### arity > 1
104
+ symbol_then_opt_node = %i[lvasgn ivasgn cvasgn gvasgn]
105
+ symbol_then_node_or_nil = %i[optarg kwoptarg]
106
+ node_then_opt_node = %i[while until module sclass]
107
+
108
+ ### variable arity
109
+ many_node_children = %i[dstr dsym xstr regexp array hash pair
110
+ mlhs masgn or_asgn and_asgn rasgn mrasgn
111
+ undef alias args super yield or and
112
+ while_post until_post iflipflop eflipflop
113
+ match_with_lvasgn begin kwbegin return
114
+ in_match match_alt break next
115
+ match_as array_pattern array_pattern_with_tail
116
+ hash_pattern const_pattern find_pattern
117
+ index indexasgn procarg0]
118
+ many_opt_node_children = %i[case rescue resbody ensure for when
119
+ case_match in_pattern irange erange]
120
+
121
+ ### Callbacks for above
122
+ def_callback no_children
123
+ def_callback opt_symbol_child, :skip, arity: 0..1
124
+ def_callback opt_node_child, :nil?, arity: 0..1
125
+
126
+ def_callback literal_child, :skip
127
+ def_callback node_child, :always
128
+ def_callback node_or_nil_child, :nil?
129
+
130
+ def_callback symbol_then_opt_node, :skip, :nil?, arity: 1..2
131
+ def_callback symbol_then_node_or_nil, :skip, :nil?
132
+ def_callback node_then_opt_node, :always, :nil?
133
+
134
+ def_callback many_symbol_children, :skip, arity_check: nil
135
+ def_callback many_node_children, body: <<~RUBY
136
+ node.children.each { |child| #{send_code} }
137
+ RUBY
138
+ def_callback many_opt_node_children,
139
+ body: <<~RUBY
140
+ node.children.each { |child| #{send_code} if child }
141
+ RUBY
142
+
143
+ ### Other particular cases
144
+ def_callback :const, :nil?, :skip
145
+ def_callback :casgn, :nil?, :skip, :nil?, arity: 2..3
146
+ def_callback :class, :always, :nil?, :nil?
147
+ def_callback :def, :skip, :always, :nil?
148
+ def_callback :op_asgn, :always, :skip, :always
149
+ def_callback :if, :always, :nil?, :nil?
150
+ def_callback :block, :always, :always, :nil?
151
+ def_callback :numblock, :always, :skip, :nil?
152
+ def_callback :defs, :always, :skip, :always, :nil?
153
+
154
+ def_callback %i[send csend], body: <<~RUBY
114
155
  node.children.each_with_index do |child, i|
115
156
  next if i == 1
116
157
 
117
- send(:"on_#{child.type}", child) if child
158
+ #{send_code} if child
118
159
  end
119
- nil
120
- end
121
-
122
- alias on_csend on_send
123
-
124
- def on_op_asgn(node)
125
- children = node.children
126
- child = children[0]
127
- send(:"on_#{child.type}", child)
128
- child = children[2]
129
- send(:"on_#{child.type}", child)
130
- end
131
-
132
- def on_defs(node)
133
- children = node.children
134
- child = children[0]
135
- send(:"on_#{child.type}", child)
136
- on_args(children[2])
137
- return unless (child = children[3])
138
-
139
- send(:"on_#{child.type}", child)
140
- end
141
-
142
- def on_if(node)
143
- children = node.children
144
- child = children[0]
145
- send(:"on_#{child.type}", child)
146
- if (child = children[1])
147
- send(:"on_#{child.type}", child)
148
- end
149
- return unless (child = children[2])
150
-
151
- send(:"on_#{child.type}", child)
152
- end
153
-
154
- def on_while(node)
155
- children = node.children
156
- child = children[0]
157
- send(:"on_#{child.type}", child)
158
- return unless (child = children[1])
159
-
160
- send(:"on_#{child.type}", child)
161
- end
162
-
163
- alias on_until on_while
164
- alias on_module on_while
165
- alias on_sclass on_while
166
-
167
- def on_block(node)
168
- children = node.children
169
- child = children[0]
170
- send(:"on_#{child.type}", child) # can be send, zsuper...
171
- on_args(children[1])
172
- return unless (child = children[2])
173
-
174
- send(:"on_#{child.type}", child)
175
- end
176
-
177
- def on_case(node)
160
+ RUBY
161
+
162
+ ### generic processing of any other node (forward compatibility)
163
+ defined = instance_methods(false)
164
+ .grep(/^on_/)
165
+ .map { |s| s.to_s[3..-1].to_sym } # :on_foo => :foo
166
+
167
+ to_define = ::Parser::Meta::NODE_TYPES.to_a
168
+ to_define -= defined
169
+ to_define -= %i[numargs ident] # transient
170
+ to_define -= %i[blockarg_expr restarg_expr] # obsolete
171
+ to_define -= %i[objc_kwarg objc_restarg objc_varargs] # mac_ruby
172
+ def_callback to_define, body: <<~RUBY
178
173
  node.children.each do |child|
179
- send(:"on_#{child.type}", child) if child
174
+ next unless child.class == Node
175
+ #{send_code}
180
176
  end
181
- nil
182
- end
183
-
184
- alias on_rescue on_case
185
- alias on_resbody on_case
186
- alias on_ensure on_case
187
- alias on_for on_case
188
- alias on_when on_case
189
- alias on_case_match on_case
190
- alias on_in_pattern on_case
191
- alias on_irange on_case
192
- alias on_erange on_case
193
-
194
- def on_numblock(node)
195
- children = node.children
196
- child = children[0]
197
- send(:"on_#{child.type}", child)
198
- return unless (child = children[2])
199
-
200
- send(:"on_#{child.type}", child)
201
- end
177
+ RUBY
178
+ MISSING = to_define if ENV['RUBOCOP_DEBUG']
202
179
  end
203
180
  end
204
181
  end
205
- # rubocop:enable Metrics/ModuleLength
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  module Version
6
- STRING = '0.7.0'
6
+ STRING = '1.1.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-28 00:00:00.000000000 Z
13
+ date: 2020-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parser
@@ -26,20 +26,6 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 2.7.1.5
29
- - !ruby/object:Gem::Dependency
30
- name: strscan
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: 1.0.0
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.0.0
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: bundler
45
31
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
165
  - !ruby/object:Gem::Version
180
166
  version: '0'
181
167
  requirements: []
182
- rubygems_version: 3.1.2
168
+ rubygems_version: 3.1.4
183
169
  signing_key:
184
170
  specification_version: 4
185
171
  summary: RuboCop tools to deal with Ruby code AST.