leftovers 0.5.5 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -2
  3. data/README.md +22 -1
  4. data/docs/Configuration.md +173 -42
  5. data/docs/Custom-Precompilers.md +38 -0
  6. data/leftovers.gemspec +8 -5
  7. data/lib/config/actionmailer.yml +11 -11
  8. data/lib/config/actionpack.yml +5 -3
  9. data/lib/config/activesupport.yml +1 -1
  10. data/lib/config/haml.yml +4 -2
  11. data/lib/config/rails.yml +1 -1
  12. data/lib/config/railties.yml +11 -0
  13. data/lib/config/ruby.yml +76 -8
  14. data/lib/config/slim.yml +4 -2
  15. data/lib/leftovers/ast/node.rb +16 -11
  16. data/lib/leftovers/cli.rb +5 -0
  17. data/lib/leftovers/collector.rb +5 -2
  18. data/lib/leftovers/config.rb +3 -38
  19. data/lib/leftovers/config_loader/argument_position_schema.rb +11 -0
  20. data/lib/leftovers/config_loader/argumentless_transform_schema.rb +21 -0
  21. data/lib/leftovers/config_loader/attribute.rb +56 -0
  22. data/lib/leftovers/config_loader/built_in_precompiler_schema.rb +13 -0
  23. data/lib/leftovers/config_loader/document_schema.rb +48 -0
  24. data/lib/leftovers/config_loader/dynamic_schema.rb +17 -0
  25. data/lib/leftovers/config_loader/has_argument_schema.rb +13 -0
  26. data/lib/leftovers/config_loader/has_value_schema.rb +18 -0
  27. data/lib/leftovers/config_loader/inherit_schema_attributes.rb +22 -0
  28. data/lib/leftovers/config_loader/keep_test_only_schema.rb +13 -0
  29. data/lib/leftovers/config_loader/node.rb +106 -0
  30. data/lib/leftovers/config_loader/object_schema.rb +117 -0
  31. data/lib/leftovers/config_loader/precompile_schema.rb +12 -0
  32. data/lib/leftovers/config_loader/precompiler_schema.rb +11 -0
  33. data/lib/leftovers/config_loader/privacy_processor_schema.rb +10 -0
  34. data/lib/leftovers/config_loader/privacy_schema.rb +15 -0
  35. data/lib/leftovers/config_loader/require_schema.rb +11 -0
  36. data/lib/leftovers/config_loader/rule_pattern_schema.rb +18 -0
  37. data/lib/leftovers/config_loader/scalar_argument_schema.rb +14 -0
  38. data/lib/leftovers/config_loader/scalar_value_schema.rb +14 -0
  39. data/lib/leftovers/config_loader/schema.rb +23 -0
  40. data/lib/leftovers/config_loader/string_enum_schema.rb +62 -0
  41. data/lib/leftovers/config_loader/string_pattern_schema.rb +14 -0
  42. data/lib/leftovers/config_loader/string_schema.rb +14 -0
  43. data/lib/leftovers/config_loader/string_value_processor_schema.rb +11 -0
  44. data/lib/leftovers/config_loader/suggester.rb +22 -0
  45. data/lib/leftovers/config_loader/transform_schema.rb +26 -0
  46. data/lib/leftovers/config_loader/true_schema.rb +18 -0
  47. data/lib/leftovers/config_loader/value_matcher_schema.rb +18 -0
  48. data/lib/leftovers/config_loader/value_or_array_schema.rb +66 -0
  49. data/lib/leftovers/config_loader/value_or_object_schema.rb +40 -0
  50. data/lib/leftovers/config_loader/value_processor_schema.rb +14 -0
  51. data/lib/leftovers/config_loader/value_type_schema.rb +17 -0
  52. data/lib/leftovers/config_loader.rb +86 -0
  53. data/lib/leftovers/definition.rb +1 -1
  54. data/lib/leftovers/definition_node.rb +6 -17
  55. data/lib/leftovers/definition_node_set.rb +11 -0
  56. data/lib/leftovers/definition_to_add.rb +31 -0
  57. data/lib/leftovers/dynamic_processors/call.rb +4 -7
  58. data/lib/leftovers/dynamic_processors/call_definition.rb +14 -11
  59. data/lib/leftovers/dynamic_processors/definition.rb +8 -7
  60. data/lib/leftovers/dynamic_processors/set_default_privacy.rb +18 -0
  61. data/lib/leftovers/dynamic_processors/set_privacy.rb +23 -0
  62. data/lib/leftovers/dynamic_processors.rb +2 -0
  63. data/lib/leftovers/file.rb +12 -12
  64. data/lib/leftovers/file_collector/comments_processor.rb +57 -0
  65. data/lib/leftovers/file_collector/node_processor.rb +131 -0
  66. data/lib/leftovers/file_collector.rb +66 -169
  67. data/lib/leftovers/matcher_builders/and_not.rb +7 -5
  68. data/lib/leftovers/matcher_builders/document.rb +13 -0
  69. data/lib/leftovers/matcher_builders/name.rb +18 -17
  70. data/lib/leftovers/matcher_builders/node.rb +48 -28
  71. data/lib/leftovers/matcher_builders/node_has_argument.rb +48 -53
  72. data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +13 -10
  73. data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +29 -15
  74. data/lib/leftovers/matcher_builders/node_privacy.rb +13 -0
  75. data/lib/leftovers/matcher_builders/node_type.rb +4 -4
  76. data/lib/leftovers/matcher_builders/node_value.rb +28 -23
  77. data/lib/leftovers/matcher_builders/or.rb +50 -50
  78. data/lib/leftovers/matcher_builders/string_pattern.rb +14 -5
  79. data/lib/leftovers/matcher_builders.rb +2 -0
  80. data/lib/leftovers/matchers/all.rb +0 -4
  81. data/lib/leftovers/matchers/and.rb +0 -4
  82. data/lib/leftovers/matchers/any.rb +0 -4
  83. data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +1 -7
  84. data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +1 -7
  85. data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +0 -4
  86. data/lib/leftovers/matchers/node_name.rb +0 -4
  87. data/lib/leftovers/matchers/node_pair_value.rb +0 -4
  88. data/lib/leftovers/matchers/node_path.rb +0 -4
  89. data/lib/leftovers/matchers/node_privacy.rb +19 -0
  90. data/lib/leftovers/matchers/node_scalar_value.rb +0 -4
  91. data/lib/leftovers/matchers/node_type.rb +0 -4
  92. data/lib/leftovers/matchers/not.rb +0 -4
  93. data/lib/leftovers/matchers/or.rb +0 -4
  94. data/lib/leftovers/matchers.rb +1 -0
  95. data/lib/leftovers/merged_config.rb +15 -33
  96. data/lib/leftovers/precompilers/erb.rb +22 -0
  97. data/lib/leftovers/precompilers/haml.rb +15 -0
  98. data/lib/leftovers/precompilers/json.rb +27 -0
  99. data/lib/leftovers/precompilers/precompiler.rb +28 -0
  100. data/lib/leftovers/precompilers/slim.rb +15 -0
  101. data/lib/leftovers/precompilers/yaml.rb +75 -0
  102. data/lib/leftovers/precompilers.rb +50 -0
  103. data/lib/leftovers/processor_builders/action.rb +48 -39
  104. data/lib/leftovers/processor_builders/add_prefix.rb +2 -2
  105. data/lib/leftovers/processor_builders/add_suffix.rb +2 -2
  106. data/lib/leftovers/processor_builders/argument.rb +8 -11
  107. data/lib/leftovers/processor_builders/dynamic.rb +51 -16
  108. data/lib/leftovers/processor_builders/each.rb +2 -2
  109. data/lib/leftovers/processor_builders/each_action.rb +33 -33
  110. data/lib/leftovers/processor_builders/each_dynamic.rb +4 -8
  111. data/lib/leftovers/processor_builders/each_for_definition_set.rb +25 -21
  112. data/lib/leftovers/processor_builders/keyword.rb +3 -4
  113. data/lib/leftovers/processor_builders/transform.rb +4 -4
  114. data/lib/leftovers/processor_builders/transform_chain.rb +16 -8
  115. data/lib/leftovers/processor_builders/transform_set.rb +32 -28
  116. data/lib/leftovers/rake_task.rb +1 -1
  117. data/lib/leftovers/todo_reporter.rb +10 -35
  118. data/lib/leftovers/value_processors/add_dynamic_prefix.rb +3 -10
  119. data/lib/leftovers/value_processors/add_dynamic_suffix.rb +3 -10
  120. data/lib/leftovers/value_processors/delete_prefix.rb +0 -6
  121. data/lib/leftovers/value_processors/delete_suffix.rb +0 -6
  122. data/lib/leftovers/value_processors/each.rb +1 -1
  123. data/lib/leftovers/value_processors/each_for_definition_set.rb +4 -10
  124. data/lib/leftovers/value_processors/each_keyword.rb +1 -1
  125. data/lib/leftovers/value_processors/each_keyword_argument.rb +1 -1
  126. data/lib/leftovers/value_processors/each_positional_argument.rb +3 -2
  127. data/lib/leftovers/value_processors/keyword.rb +3 -11
  128. data/lib/leftovers/value_processors/keyword_argument.rb +2 -10
  129. data/lib/leftovers/value_processors/return_definition_node.rb +14 -0
  130. data/lib/leftovers/value_processors/{return_string.rb → return_sym.rb} +1 -1
  131. data/lib/leftovers/value_processors/split.rb +2 -2
  132. data/lib/leftovers/value_processors.rb +2 -2
  133. data/lib/leftovers/version.rb +1 -1
  134. data/lib/leftovers.rb +66 -23
  135. metadata +98 -39
  136. data/lib/config/actioncable.yml +0 -4
  137. data/lib/leftovers/backports.rb +0 -40
  138. data/lib/leftovers/config_validator/error_processor.rb +0 -196
  139. data/lib/leftovers/config_validator/schema_hash.rb +0 -530
  140. data/lib/leftovers/config_validator.rb +0 -60
  141. data/lib/leftovers/erb.rb +0 -20
  142. data/lib/leftovers/haml.rb +0 -21
  143. data/lib/leftovers/slim.rb +0 -21
  144. data/lib/leftovers/value_processors/return_definition.rb +0 -26
@@ -10,7 +10,7 @@ module Leftovers
10
10
  def initialize(
11
11
  name,
12
12
  location: method_node.loc.expression,
13
- test: method_node.test_line?
13
+ test: method_node.test_line? || ::Leftovers.config.test_only === method_node
14
14
  )
15
15
  @name = name
16
16
  @path = location.source_buffer.name.to_s
@@ -1,19 +1,15 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- # To give to matchers before creating a Definition
4
-
5
3
  module Leftovers
6
4
  class DefinitionNode
7
- attr_reader :path, :name
5
+ attr_reader :name, :loc, :node
8
6
 
9
- def initialize(name, path)
7
+ def initialize(node, name:, location: node.loc.expression)
8
+ @node = node
10
9
  @name = name
11
- @path = path
12
-
13
- freeze
10
+ @loc = location
14
11
  end
15
12
 
16
- # these are the methods checked by things in lib/leftovers/matchers
17
13
  def kwargs
18
14
  nil
19
15
  end
@@ -22,15 +18,8 @@ module Leftovers
22
18
  nil
23
19
  end
24
20
 
25
- # these two i'm not sure are possible with the current config flags
26
- # :nocov:
27
- def scalar?
28
- false
29
- end
30
-
31
- def type
32
- :leftovers_definition
21
+ def path
22
+ node.path
33
23
  end
34
- # :nocov:
35
24
  end
36
25
  end
@@ -0,0 +1,11 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Leftovers
4
+ class DefinitionNodeSet
5
+ attr_reader :definitions
6
+
7
+ def initialize(definitions)
8
+ @definitions = definitions
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Leftovers
4
+ class DefinitionToAdd
5
+ attr_reader :node, :name, :location
6
+
7
+ def initialize(node, name: node.name, location: node.loc.name)
8
+ @node = node
9
+ @name = name
10
+ @location = location
11
+ end
12
+
13
+ def privacy=(value)
14
+ @node.privacy = value
15
+ end
16
+
17
+ def keep?(file_collector)
18
+ @keep ||= file_collector.keep_line?(location.line) || ::Leftovers.config.keep === node
19
+ end
20
+
21
+ def test?(file_collector)
22
+ file_collector.test_line?(location.line) || ::Leftovers.config.test_only === node
23
+ end
24
+
25
+ def to_definition(file_collector)
26
+ return if keep?(file_collector)
27
+
28
+ Leftovers::Definition.new(name, location: location, test: test?(file_collector))
29
+ end
30
+ end
31
+ end
@@ -3,10 +3,6 @@
3
3
  module Leftovers
4
4
  module DynamicProcessors
5
5
  class Call
6
- # :nocov:
7
- using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
8
- # :nocov:
9
-
10
6
  def initialize(matcher, processor)
11
7
  @matcher = matcher
12
8
  @processor = processor
@@ -15,10 +11,11 @@ module Leftovers
15
11
  def process(node, file)
16
12
  return unless @matcher === node
17
13
 
18
- call = @processor.process(nil, node, node)
19
- return unless call
14
+ calls = @processor.process(nil, node, node)
20
15
 
21
- file.calls << call
16
+ ::Leftovers.each_or_self(calls) do |call|
17
+ file.calls << call
18
+ end
22
19
  end
23
20
  end
24
21
  end
@@ -3,28 +3,31 @@
3
3
  module Leftovers
4
4
  module DynamicProcessors
5
5
  class CallDefinition
6
- # :nocov:
7
- using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
8
- # :nocov:
9
-
10
6
  def initialize(matcher, call_processor, definition_processor)
11
7
  @matcher = matcher
12
8
  @call_processor = call_processor
13
9
  @definition_processor = definition_processor
14
10
  end
15
11
 
16
- def process(node, file)
12
+ def process(node, file) # rubocop:disable Metrics/MethodLength
17
13
  return unless @matcher === node
18
14
 
19
- call = @call_processor.process(nil, node, node)
20
- (file.calls << call) if call
15
+ calls = @call_processor.process(nil, node, node)
21
16
 
22
- return if node.keep_line?
17
+ ::Leftovers.each_or_self(calls) do |call|
18
+ file.calls << call
19
+ end
23
20
 
24
- definition = @definition_processor.process(nil, node, node)
25
- return unless definition
21
+ return if node.keep_line?
26
22
 
27
- file.definitions << definition
23
+ definitions = @definition_processor.process(nil, node, node)
24
+ ::Leftovers.each_or_self(definitions) do |definition|
25
+ if definition.is_a?(DefinitionNodeSet)
26
+ file.add_definition_set(definition)
27
+ else
28
+ file.add_definition(definition, loc: definition.loc)
29
+ end
30
+ end
28
31
  end
29
32
  end
30
33
  end
@@ -3,10 +3,6 @@
3
3
  module Leftovers
4
4
  module DynamicProcessors
5
5
  class Definition
6
- # :nocov:
7
- using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
8
- # :nocov:
9
-
10
6
  def initialize(matcher, processor)
11
7
  @matcher = matcher
12
8
  @processor = processor
@@ -16,10 +12,15 @@ module Leftovers
16
12
  return if node.keep_line?
17
13
  return unless @matcher === node
18
14
 
19
- definition = @processor.process(nil, node, node)
20
- return unless definition
15
+ definitions = @processor.process(nil, node, node)
21
16
 
22
- file.definitions << definition
17
+ ::Leftovers.each_or_self(definitions) do |definition|
18
+ if definition.is_a?(DefinitionNodeSet)
19
+ file.add_definition_set(definition)
20
+ else
21
+ file.add_definition(definition, loc: definition.loc)
22
+ end
23
+ end
23
24
  end
24
25
  end
25
26
  end
@@ -0,0 +1,18 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Leftovers
4
+ module DynamicProcessors
5
+ class SetDefaultPrivacy
6
+ def initialize(matcher, to)
7
+ @matcher = matcher
8
+ @to = to
9
+ end
10
+
11
+ def process(node, file)
12
+ return unless @matcher === node
13
+
14
+ file.default_method_privacy = @to
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Leftovers
4
+ module DynamicProcessors
5
+ class SetPrivacy
6
+ def initialize(matcher, processor, to)
7
+ @matcher = matcher
8
+ @processor = processor
9
+ @to = to
10
+ end
11
+
12
+ def process(node, file)
13
+ return unless @matcher === node
14
+
15
+ set_privacy = @processor.process(nil, node, node)
16
+
17
+ ::Leftovers.each_or_self(set_privacy) do |name|
18
+ file.set_privacy(name, @to)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -7,5 +7,7 @@ module Leftovers
7
7
  autoload(:Definition, "#{__dir__}/dynamic_processors/definition")
8
8
  autoload(:Each, "#{__dir__}/dynamic_processors/each")
9
9
  autoload(:Null, "#{__dir__}/dynamic_processors/null")
10
+ autoload(:SetDefaultPrivacy, "#{__dir__}/dynamic_processors/set_default_privacy")
11
+ autoload(:SetPrivacy, "#{__dir__}/dynamic_processors/set_privacy")
10
12
  end
11
13
  end
@@ -5,7 +5,11 @@ require 'pathname'
5
5
  module Leftovers
6
6
  class File < Pathname
7
7
  def relative_path
8
- @relative_path ||= relative_path_from(Leftovers.pwd)
8
+ @relative_path ||= begin
9
+ relative_path_from(Leftovers.pwd)
10
+ rescue ArgumentError
11
+ self
12
+ end
9
13
  end
10
14
 
11
15
  def test?
@@ -15,19 +19,15 @@ module Leftovers
15
19
  end
16
20
 
17
21
  def ruby
18
- precompiler&.precompile(read, self) || read
19
- end
22
+ read = self.read
20
23
 
21
- private
24
+ precompiled = ::Leftovers.config.precompilers.map do |precompiler|
25
+ precompiler.precompile(read, self)
26
+ end.compact
22
27
 
23
- def precompiler
24
- if Leftovers.config.haml_paths.allowed?(relative_path)
25
- ::Leftovers::Haml
26
- elsif Leftovers.config.slim_paths.allowed?(relative_path)
27
- ::Leftovers::Slim
28
- elsif Leftovers.config.erb_paths.allowed?(relative_path)
29
- ::Leftovers::ERB
30
- end
28
+ return read if precompiled.empty?
29
+
30
+ precompiled.join("\n")
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,57 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Leftovers
4
+ class FileCollector
5
+ module CommentsProcessor
6
+ METHOD_NAME_RE = /[[:alpha:]_][[:alnum:]_]*\b[?!=]?/.freeze
7
+ NON_ALNUM_METHOD_NAME_RE = Regexp.union(%w{
8
+ []= [] ** ~ +@ -@ * / % + - >> << &
9
+ ^ | <=> <= >= < > === == != =~ !~ !
10
+ }.map { |op| /#{Regexp.escape(op)}/ })
11
+ CONSTANT_NAME_RE = /[[:upper:]][[:alnum:]_]*\b/.freeze
12
+ NAME_RE = Regexp.union(METHOD_NAME_RE, NON_ALNUM_METHOD_NAME_RE, CONSTANT_NAME_RE)
13
+ NAME_LIST_RE = /#{NAME_RE}(?:[, :]+#{NAME_RE})*/.freeze
14
+ LEFTOVERS_CALL_RE = /\bleftovers:call(?:s|e(?:d|rs?))? (#{NAME_LIST_RE})/.freeze
15
+ LEFTOVERS_ALLOW_RE = /\bleftovers:(?:keeps?|skip(?:s|ped|)|allow(?:s|ed|))\b/.freeze
16
+ LEFTOVERS_TEST_RE = /\bleftovers:(?:for_tests?|tests?|testing|test_only)\b/.freeze
17
+ LEFTOVERS_DYNAMIC_RE = /\bleftovers:dynamic[: ](#{NAME_LIST_RE})/.freeze
18
+
19
+ class << self
20
+ def process(comments, collector)
21
+ comments.each do |comment|
22
+ process_leftovers_keep_comment(comment, collector)
23
+ process_leftovers_test_comment(comment, collector)
24
+ process_leftovers_dynamic_comment(comment, collector)
25
+ process_leftovers_call_comment(comment, collector)
26
+ end
27
+ end
28
+
29
+ def process_leftovers_keep_comment(comment, collector)
30
+ return unless comment.text.match?(LEFTOVERS_ALLOW_RE)
31
+
32
+ collector.allow_lines << comment.loc.line
33
+ end
34
+
35
+ def process_leftovers_test_comment(comment, collector)
36
+ return unless comment.text.match?(LEFTOVERS_TEST_RE)
37
+
38
+ collector.test_lines << comment.loc.line
39
+ end
40
+
41
+ def process_leftovers_dynamic_comment(comment, collector)
42
+ match = comment.text.match(LEFTOVERS_DYNAMIC_RE)
43
+ return unless match
44
+
45
+ collector.dynamic_lines[comment.loc.line] = match[1].scan(NAME_RE)
46
+ end
47
+
48
+ def process_leftovers_call_comment(comment, collector)
49
+ match = comment.text.match(LEFTOVERS_CALL_RE)
50
+ return unless match
51
+
52
+ match[1].scan(NAME_RE).each { |s| collector.add_call(s.to_sym) }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,131 @@
1
+ # frozen-string-literal: true
2
+
3
+ require 'parser'
4
+
5
+ module Leftovers
6
+ class FileCollector
7
+ class NodeProcessor < ::Parser::AST::Processor
8
+ def initialize(collector) # rubocop:disable Lint/MissingSuper # there isn't one to call
9
+ @collector = collector
10
+ end
11
+
12
+ def on_def(node)
13
+ node.privacy = @collector.default_method_privacy
14
+ @collector.add_definition(node)
15
+ super
16
+ end
17
+
18
+ def on_defs(node)
19
+ @collector.add_definition(node)
20
+ super
21
+ end
22
+
23
+ def on_ivasgn(node)
24
+ @collector.collect_variable_assign(node)
25
+ super
26
+ end
27
+
28
+ def on_gvasgn(node)
29
+ @collector.collect_variable_assign(node)
30
+ super
31
+ end
32
+
33
+ def on_cvasgn(node)
34
+ @collector.collect_variable_assign(node)
35
+ super
36
+ end
37
+
38
+ def on_ivar(node)
39
+ @collector.add_call(node.name)
40
+ super
41
+ end
42
+
43
+ def on_gvar(node)
44
+ @collector.add_call(node.name)
45
+ super
46
+ end
47
+
48
+ def on_cvar(node)
49
+ @collector.add_call(node.name)
50
+ super
51
+ end
52
+
53
+ def on_op_asgn(node)
54
+ @collector.collect_op_asgn(node)
55
+ super
56
+ end
57
+
58
+ def on_and_asgn(node)
59
+ @collector.collect_op_asgn(node)
60
+ super
61
+ end
62
+
63
+ def on_or_asgn(node)
64
+ @collector.collect_op_asgn(node)
65
+ super
66
+ end
67
+
68
+ def on_send(node)
69
+ super
70
+ @collector.collect_send(node)
71
+ end
72
+
73
+ def on_csend(node)
74
+ super
75
+ @collector.collect_send(node)
76
+ end
77
+
78
+ def on_const(node)
79
+ super
80
+ @collector.add_call(node.name)
81
+ end
82
+
83
+ def on_array(node)
84
+ super
85
+ @collector.collect_commented_dynamic(node)
86
+ end
87
+
88
+ def on_hash(node)
89
+ super
90
+ @collector.collect_commented_dynamic(node)
91
+ end
92
+
93
+ # grab e.g. :to_s in each(&:to_s)
94
+ def on_block_pass(node)
95
+ super
96
+ return unless node.first.string_or_symbol?
97
+
98
+ @collector.add_call(node.first.to_sym)
99
+ end
100
+
101
+ # grab class Constant or module Constant
102
+ def on_class(node)
103
+ # don't call super so we don't interpret the class name as being called by its definition
104
+ process_all(node.children.drop(1))
105
+
106
+ node = node.children.first
107
+
108
+ @collector.add_definition(node)
109
+ end
110
+ alias_method :on_module, :on_class
111
+
112
+ # grab Constant = Class.new or CONSTANT = 'string'.freeze
113
+ def on_casgn(node)
114
+ super
115
+
116
+ @collector.add_definition(node)
117
+ @collector.collect_dynamic(node)
118
+ end
119
+
120
+ # grab calls to `alias new_method original_method`
121
+ def on_alias(node)
122
+ super
123
+ new_method, original_method = node.children
124
+ @collector.add_definition(
125
+ new_method, name: new_method.children.first, loc: new_method.loc.expression
126
+ )
127
+ @collector.add_call(original_method.children.first)
128
+ end
129
+ end
130
+ end
131
+ end