leftovers 0.2.2 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/README.md +35 -49
- data/docs/Configuration.md +627 -0
- data/exe/leftovers +2 -2
- data/leftovers.gemspec +13 -7
- data/lib/config/attr_encrypted.yml +3 -4
- data/lib/config/audited.yml +9 -4
- data/lib/config/datagrid.yml +1 -1
- data/lib/config/flipper.yml +1 -3
- data/lib/config/graphql.yml +15 -13
- data/lib/config/okcomputer.yml +1 -3
- data/lib/config/parser.yml +89 -91
- data/lib/config/rails.yml +160 -97
- data/lib/config/redcarpet.yml +35 -38
- data/lib/config/rollbar.yml +1 -3
- data/lib/config/rspec.yml +18 -10
- data/lib/config/ruby.yml +42 -49
- data/lib/config/selenium-webdriver.yml +19 -0
- data/lib/config/sidekiq.yml +9 -0
- data/lib/config/will_paginate.yml +12 -14
- data/lib/leftovers.rb +61 -43
- data/lib/leftovers/ast.rb +8 -0
- data/lib/leftovers/ast/builder.rb +6 -3
- data/lib/leftovers/ast/node.rb +66 -107
- data/lib/leftovers/backports.rb +24 -40
- data/lib/leftovers/cli.rb +17 -14
- data/lib/leftovers/collector.rb +7 -11
- data/lib/leftovers/config.rb +38 -13
- data/lib/leftovers/config_validator.rb +60 -0
- data/lib/leftovers/config_validator/error_processor.rb +196 -0
- data/lib/leftovers/config_validator/schema_hash.rb +496 -0
- data/lib/leftovers/definition.rb +16 -41
- data/lib/leftovers/definition_node.rb +36 -0
- data/lib/leftovers/definition_set.rb +17 -24
- data/lib/leftovers/dynamic_processors.rb +11 -0
- data/lib/leftovers/dynamic_processors/call.rb +25 -0
- data/lib/leftovers/dynamic_processors/call_definition.rb +31 -0
- data/lib/leftovers/dynamic_processors/definition.rb +26 -0
- data/lib/leftovers/dynamic_processors/each.rb +19 -0
- data/lib/leftovers/dynamic_processors/null.rb +9 -0
- data/lib/leftovers/erb.rb +2 -2
- data/lib/leftovers/file.rb +3 -5
- data/lib/leftovers/file_collector.rb +82 -62
- data/lib/leftovers/file_list.rb +9 -15
- data/lib/leftovers/haml.rb +9 -12
- data/lib/leftovers/matcher_builders.rb +24 -0
- data/lib/leftovers/matcher_builders/and.rb +19 -0
- data/lib/leftovers/matcher_builders/and_not.rb +14 -0
- data/lib/leftovers/matcher_builders/argument_node_value.rb +21 -0
- data/lib/leftovers/matcher_builders/name.rb +29 -0
- data/lib/leftovers/matcher_builders/node.rb +40 -0
- data/lib/leftovers/matcher_builders/node_has_argument.rb +71 -0
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +22 -0
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +24 -0
- data/lib/leftovers/matcher_builders/node_name.rb +15 -0
- data/lib/leftovers/matcher_builders/node_pair_name.rb +18 -0
- data/lib/leftovers/matcher_builders/node_pair_value.rb +16 -0
- data/lib/leftovers/matcher_builders/node_path.rb +14 -0
- data/lib/leftovers/matcher_builders/node_type.rb +28 -0
- data/lib/leftovers/matcher_builders/or.rb +73 -0
- data/lib/leftovers/matcher_builders/path.rb +15 -0
- data/lib/leftovers/matcher_builders/string.rb +11 -0
- data/lib/leftovers/matcher_builders/string_pattern.rb +19 -0
- data/lib/leftovers/matcher_builders/unless.rb +13 -0
- data/lib/leftovers/matchers.rb +26 -0
- data/lib/leftovers/matchers/all.rb +25 -0
- data/lib/leftovers/matchers/and.rb +24 -0
- data/lib/leftovers/matchers/any.rb +27 -0
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +28 -0
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_has_positional_argument.rb +23 -0
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +25 -0
- data/lib/leftovers/matchers/node_name.rb +23 -0
- data/lib/leftovers/matchers/node_pair_value.rb +23 -0
- data/lib/leftovers/matchers/node_path.rb +23 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +25 -0
- data/lib/leftovers/matchers/node_type.rb +23 -0
- data/lib/leftovers/matchers/not.rb +23 -0
- data/lib/leftovers/matchers/or.rb +26 -0
- data/lib/leftovers/merged_config.rb +24 -14
- data/lib/leftovers/parser.rb +2 -5
- data/lib/leftovers/processor_builders.rb +22 -0
- data/lib/leftovers/processor_builders/action.rb +63 -0
- data/lib/leftovers/processor_builders/add_prefix.rb +20 -0
- data/lib/leftovers/processor_builders/add_suffix.rb +20 -0
- data/lib/leftovers/processor_builders/argument.rb +25 -0
- data/lib/leftovers/processor_builders/dynamic.rb +27 -0
- data/lib/leftovers/processor_builders/each.rb +36 -0
- data/lib/leftovers/processor_builders/each_action.rb +51 -0
- data/lib/leftovers/processor_builders/each_dynamic.rb +54 -0
- data/lib/leftovers/processor_builders/each_for_definition_set.rb +36 -0
- data/lib/leftovers/processor_builders/itself.rb +13 -0
- data/lib/leftovers/processor_builders/keyword.rb +24 -0
- data/lib/leftovers/processor_builders/keyword_argument.rb +14 -0
- data/lib/leftovers/processor_builders/transform.rb +55 -0
- data/lib/leftovers/processor_builders/transform_chain.rb +24 -0
- data/lib/leftovers/processor_builders/transform_set.rb +47 -0
- data/lib/leftovers/processor_builders/value.rb +13 -0
- data/lib/leftovers/rake_task.rb +4 -4
- data/lib/leftovers/reporter.rb +1 -1
- data/lib/leftovers/value_processors.rb +40 -0
- data/lib/leftovers/value_processors/add_dynamic_prefix.rb +31 -0
- data/lib/leftovers/value_processors/add_dynamic_suffix.rb +31 -0
- data/lib/leftovers/value_processors/add_prefix.rb +20 -0
- data/lib/leftovers/value_processors/add_suffix.rb +20 -0
- data/lib/leftovers/value_processors/camelize.rb +24 -0
- data/lib/leftovers/value_processors/capitalize.rb +19 -0
- data/lib/leftovers/value_processors/deconstantize.rb +24 -0
- data/lib/leftovers/value_processors/delete_after.rb +22 -0
- data/lib/leftovers/value_processors/delete_before.rb +22 -0
- data/lib/leftovers/value_processors/delete_prefix.rb +26 -0
- data/lib/leftovers/value_processors/delete_suffix.rb +26 -0
- data/lib/leftovers/value_processors/demodulize.rb +24 -0
- data/lib/leftovers/value_processors/downcase.rb +19 -0
- data/lib/leftovers/value_processors/each.rb +21 -0
- data/lib/leftovers/value_processors/each_for_definition_set.rb +29 -0
- data/lib/leftovers/value_processors/each_keyword.rb +27 -0
- data/lib/leftovers/value_processors/each_keyword_argument.rb +27 -0
- data/lib/leftovers/value_processors/each_positional_argument.rb +24 -0
- data/lib/leftovers/value_processors/itself.rb +17 -0
- data/lib/leftovers/value_processors/keyword.rb +36 -0
- data/lib/leftovers/value_processors/keyword_argument.rb +36 -0
- data/lib/leftovers/value_processors/parameterize.rb +24 -0
- data/lib/leftovers/value_processors/placeholder.rb +18 -0
- data/lib/leftovers/value_processors/pluralize.rb +24 -0
- data/lib/leftovers/value_processors/positional_argument.rb +26 -0
- data/lib/leftovers/value_processors/replace_value.rb +18 -0
- data/lib/leftovers/value_processors/return_definition.rb +26 -0
- data/lib/leftovers/value_processors/return_string.rb +14 -0
- data/lib/leftovers/value_processors/singularize.rb +24 -0
- data/lib/leftovers/value_processors/split.rb +22 -0
- data/lib/leftovers/value_processors/swapcase.rb +19 -0
- data/lib/leftovers/value_processors/titleize.rb +24 -0
- data/lib/leftovers/value_processors/underscore.rb +24 -0
- data/lib/leftovers/value_processors/upcase.rb +19 -0
- data/lib/leftovers/version.rb +1 -1
- metadata +190 -28
- data/lib/config/selenium.yml +0 -21
- data/lib/leftovers/argument_rule.rb +0 -219
- data/lib/leftovers/core_ext.rb +0 -13
- data/lib/leftovers/hash_rule.rb +0 -40
- data/lib/leftovers/name_rule.rb +0 -53
- data/lib/leftovers/rule.rb +0 -74
- data/lib/leftovers/transform_rule.rb +0 -171
- data/lib/leftovers/value_rule.rb +0 -56
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'parser'
|
4
|
+
|
3
5
|
module Leftovers
|
4
6
|
module AST
|
5
7
|
class Builder < ::Parser::Builders::Default
|
6
8
|
# Generates {Node} from the given information.
|
7
9
|
#
|
8
10
|
# @return [Node] the generated node
|
9
|
-
|
10
|
-
|
11
|
+
|
12
|
+
def n(type, children, source_map) # leftovers:keep
|
13
|
+
::Leftovers::AST::Node.new(type, children, location: source_map)
|
11
14
|
end
|
12
15
|
|
13
16
|
# Don't complain about invalid strings
|
14
|
-
def string_value(token)
|
17
|
+
def string_value(token) # leftovers:keep
|
15
18
|
value(token)
|
16
19
|
end
|
17
20
|
end
|
data/lib/leftovers/ast/node.rb
CHANGED
@@ -4,7 +4,7 @@ require 'parser'
|
|
4
4
|
|
5
5
|
module Leftovers
|
6
6
|
module AST
|
7
|
-
class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
|
7
|
+
class Node < ::Parser::AST::Node # rubocop:disable Metrics/ClassLength
|
8
8
|
def initialize(type, children = [], properties = {})
|
9
9
|
# ::AST::Node#initialize freezes itself.
|
10
10
|
# so can't use normal memoizations
|
@@ -17,85 +17,93 @@ module Leftovers
|
|
17
17
|
children.first
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def second
|
21
|
+
children[1]
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
@memo[:
|
24
|
+
def path
|
25
|
+
@memo[:path] ||= loc.expression.source_buffer.name.to_s
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
@memo[:
|
28
|
+
def test_line?
|
29
|
+
@memo[:test_line]
|
30
30
|
end
|
31
|
-
alias_method :test?, :test
|
32
31
|
|
33
|
-
def
|
34
|
-
@memo[:
|
32
|
+
def test_line=(value)
|
33
|
+
@memo[:test_line] = value
|
35
34
|
end
|
36
35
|
|
37
|
-
def
|
38
|
-
@memo[:
|
39
|
-
|
36
|
+
def keep_line=(value)
|
37
|
+
@memo[:keep_line] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def keep_line?
|
41
|
+
@memo[:keep_line]
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_scalar_value
|
45
|
+
case type
|
46
|
+
when :sym, :int, :float, :str
|
40
47
|
first
|
41
|
-
when :str
|
42
|
-
first.to_s.freeze
|
43
48
|
when :true
|
44
49
|
true
|
45
50
|
when :false
|
46
51
|
false
|
47
52
|
when :nil
|
48
53
|
nil
|
49
|
-
else
|
50
|
-
raise "Not scalar node, (#{type})"
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def scalar?
|
58
|
+
case type
|
59
|
+
when :sym, :int, :float, :str, :true, :false, :nil
|
60
|
+
true
|
61
|
+
else false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
@memo[:to_s] ||= name ? name.to_s : to_scalar_value.to_s
|
62
67
|
end
|
63
68
|
|
64
69
|
def to_sym
|
65
70
|
case type
|
66
|
-
when :
|
71
|
+
when :sym then first
|
67
72
|
when :nil, :true, :false then type
|
68
73
|
else to_s.to_sym
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
SCALAR_TYPES = %i{sym str true false nil}.freeze
|
73
|
-
def scalar?
|
74
|
-
SCALAR_TYPES.include?(type)
|
75
|
-
end
|
76
|
-
|
77
77
|
def string_or_symbol?
|
78
78
|
type == :str || type == :sym
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
def arguments
|
82
|
+
@memo.fetch(:arguments) do
|
83
|
+
@memo[:arguments] = case type
|
84
|
+
when :send, :csend then children.drop(2)
|
85
|
+
when :casgn then assign_arguments(children[2])
|
86
|
+
when :ivasgn, :cvasgn, :gvasgn then assign_arguments(second)
|
87
|
+
when :array then children
|
88
|
+
when :hash then [self]
|
89
|
+
end
|
90
|
+
end
|
87
91
|
end
|
88
92
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
when :
|
93
|
-
|
93
|
+
def assign_arguments(arguments_list)
|
94
|
+
arguments_list = arguments_list.unwrap_freeze
|
95
|
+
case arguments_list.type
|
96
|
+
when :array
|
97
|
+
arguments_list.children
|
98
|
+
when :hash, :str, :sym
|
99
|
+
[arguments_list]
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
97
103
|
def positional_arguments
|
98
|
-
@memo
|
104
|
+
@memo.fetch(:positional_arguments) do
|
105
|
+
@memo[:positional_arguments] = kwargs ? arguments[0...-1] : arguments
|
106
|
+
end
|
99
107
|
end
|
100
108
|
|
101
109
|
def unwrap_freeze
|
@@ -106,75 +114,26 @@ module Leftovers
|
|
106
114
|
|
107
115
|
def kwargs
|
108
116
|
@memo.fetch(:kwargs) do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
def keys
|
115
|
-
each_pair.map { |k, _| k }
|
116
|
-
end
|
117
|
-
|
118
|
-
def key?(key)
|
119
|
-
each_pair.find do |k, _v|
|
120
|
-
next unless k.string_or_symbol?
|
117
|
+
@memo[:kwargs] = begin
|
118
|
+
args = arguments
|
119
|
+
next unless args
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
def values
|
127
|
-
@memo[:kwargs] ||= case type
|
128
|
-
when :hash then each_pair.map { |_, v| v }
|
129
|
-
when :array then children
|
130
|
-
else []
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def values_at_match(matcher)
|
135
|
-
each_pair.with_object([]) do |(key, value), values|
|
136
|
-
values << value if matcher.match?(key.to_sym, key.to_s)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def positional_arguments_at(positions)
|
141
|
-
positional_arguments.values_at(*positions).compact
|
142
|
-
end
|
143
|
-
|
144
|
-
def each_pair
|
145
|
-
raise "not hash node (#{type})" unless type == :hash
|
146
|
-
|
147
|
-
return enum_for(:each_pair) unless block_given?
|
148
|
-
|
149
|
-
children.each do |pair|
|
150
|
-
yield(*pair.children) if pair.type == :pair
|
121
|
+
last_arg = args[-1]
|
122
|
+
last_arg if last_arg && last_arg.type == :hash
|
123
|
+
end
|
151
124
|
end
|
152
125
|
end
|
153
126
|
|
154
127
|
def name
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
def [](index) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
165
|
-
case type
|
166
|
-
when :send, :csend
|
167
|
-
index.is_a?(Integer) ? arguments[index] : kwargs && kwargs[index]
|
168
|
-
when :array
|
169
|
-
children[index]
|
170
|
-
when :hash
|
171
|
-
each_pair do |key, value|
|
172
|
-
next unless key.string_or_symbol?
|
173
|
-
|
174
|
-
return value if key.to_sym == index
|
175
|
-
end
|
176
|
-
|
177
|
-
nil
|
128
|
+
@memo[:name] ||= case type
|
129
|
+
when :send, :csend, :casgn, :const
|
130
|
+
second
|
131
|
+
when :def, :ivasgn, :ivar, :gvar, :cvar, :gvasgn, :cvasgn, :sym
|
132
|
+
first
|
133
|
+
when :str
|
134
|
+
first.to_sym
|
135
|
+
when :module, :class, :pair
|
136
|
+
first.name
|
178
137
|
end
|
179
138
|
end
|
180
139
|
end
|
data/lib/leftovers/backports.rb
CHANGED
@@ -1,54 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
|
-
|
5
|
-
|
6
|
-
module StringDeletePrefixSuffix
|
7
|
-
refine ::String do
|
8
|
-
def delete_prefix!(str)
|
9
|
-
slice!(0..(str.length - 1)) if start_with?(str)
|
10
|
-
self
|
11
|
-
end
|
12
|
-
|
13
|
-
def delete_suffix!(str)
|
14
|
-
slice!(-str.length..-1) if end_with?(str)
|
15
|
-
self
|
16
|
-
end
|
4
|
+
module Backports
|
5
|
+
ruby_version = Gem::Version.new(RUBY_VERSION)
|
17
6
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
7
|
+
unless ruby_version >= Gem::Version.new('2.5')
|
8
|
+
require 'set'
|
9
|
+
module SetCaseEq
|
10
|
+
refine ::Set do
|
11
|
+
def ===(value)
|
12
|
+
include?(value)
|
13
|
+
end
|
24
14
|
end
|
25
15
|
end
|
26
|
-
end
|
27
16
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if symbolize_names
|
34
|
-
symbolize_names!(safe_load_without_symbolize_names(path, *args, **kwargs))
|
35
|
-
else
|
36
|
-
safe_load_without_symbolize_names(path, *args, **kwargs)
|
17
|
+
module StringDeletePrefixSuffix
|
18
|
+
refine ::String do
|
19
|
+
def delete_prefix!(str)
|
20
|
+
slice!(0..(str.length - 1)) if start_with?(str)
|
21
|
+
self
|
37
22
|
end
|
38
|
-
end
|
39
23
|
|
40
|
-
|
24
|
+
def delete_suffix!(str)
|
25
|
+
slice!(-str.length..-1) if end_with?(str)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_prefix(str)
|
30
|
+
dup.delete_prefix!(str)
|
31
|
+
end
|
41
32
|
|
42
|
-
|
43
|
-
|
44
|
-
when Hash
|
45
|
-
obj.keys.each do |key| # rubocop:disable Style/HashEachMethods # each_key never finishes.
|
46
|
-
obj[key.to_sym] = symbolize_names!(obj.delete(key))
|
47
|
-
end
|
48
|
-
when Array
|
49
|
-
obj.map! { |ea| symbolize_names!(ea) }
|
33
|
+
def delete_suffix(str)
|
34
|
+
dup.delete_suffix!(str)
|
50
35
|
end
|
51
|
-
obj
|
52
36
|
end
|
53
37
|
end
|
54
38
|
end
|
data/lib/leftovers/cli.rb
CHANGED
@@ -1,30 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require_relative '../leftovers'
|
5
|
-
require_relative 'version'
|
6
|
-
|
7
4
|
module Leftovers
|
8
5
|
class CLI
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(argv: [], stdout: StringIO.new, stderr: StringIO.new)
|
6
|
+
def initialize(argv: [], stdout: $stdout, stderr: $stderr)
|
12
7
|
@argv = argv
|
13
8
|
@stdout = stdout
|
14
9
|
@stderr = stderr
|
10
|
+
end
|
15
11
|
|
16
|
-
|
12
|
+
def run
|
13
|
+
catch(:leftovers_exit) do
|
14
|
+
Leftovers.reset
|
15
|
+
parse_options
|
17
16
|
|
18
|
-
|
17
|
+
Leftovers.run(stdout: stdout, stderr: stderr)
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :argv, :stdout, :stderr
|
24
|
+
|
21
25
|
def parse_options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
22
26
|
opts = OptionParser.new
|
23
27
|
Leftovers.parallel = true
|
24
28
|
Leftovers.progress = true
|
25
29
|
|
26
30
|
opts.banner = 'Usage: leftovers [options]'
|
27
|
-
opts.on('-q', '--quiet', 'Silences output') { Leftovers.quiet = true }
|
28
31
|
opts.on('--[no-]parallel', 'Run in parallel or not, default --parallel') do |p|
|
29
32
|
Leftovers.parallel = p
|
30
33
|
end
|
@@ -32,16 +35,16 @@ module Leftovers
|
|
32
35
|
Leftovers.progress = p
|
33
36
|
end
|
34
37
|
opts.on('-v', '--version', 'Returns the current version') do
|
35
|
-
stdout.puts(Leftovers::
|
36
|
-
exit
|
38
|
+
stdout.puts(Leftovers::VERSION)
|
39
|
+
Leftovers.exit
|
37
40
|
end
|
38
41
|
opts.on('--dry-run', 'Output files that will be looked at') do
|
39
|
-
|
40
|
-
exit
|
42
|
+
Leftovers::FileList.new.each { |f| stdout.puts f.relative_path }
|
43
|
+
Leftovers.exit
|
41
44
|
end
|
42
45
|
opts.on('-h', '--help', 'Shows this message') do
|
43
46
|
stdout.puts(opts.help)
|
44
|
-
exit
|
47
|
+
Leftovers.exit
|
45
48
|
end
|
46
49
|
|
47
50
|
opts.parse(argv)
|
data/lib/leftovers/collector.rb
CHANGED
@@ -3,16 +3,12 @@
|
|
3
3
|
require 'fast_ignore'
|
4
4
|
require 'set'
|
5
5
|
require 'parallel'
|
6
|
-
require_relative 'file_collector'
|
7
|
-
require_relative 'file_list'
|
8
6
|
|
9
7
|
module Leftovers
|
10
8
|
class Collector
|
11
|
-
attr_reader :calls
|
12
|
-
attr_reader :test_calls
|
13
|
-
attr_reader :definitions
|
9
|
+
attr_reader :calls, :test_calls, :definitions
|
14
10
|
|
15
|
-
def initialize
|
11
|
+
def initialize
|
16
12
|
@calls = []
|
17
13
|
@test_calls = []
|
18
14
|
@definitions = []
|
@@ -31,14 +27,14 @@ module Leftovers
|
|
31
27
|
|
32
28
|
def collect_file_list(list)
|
33
29
|
if Leftovers.parallel?
|
34
|
-
Parallel.each(list, finish: method(:
|
30
|
+
Parallel.each(list, finish: method(:finish_file), &method(:collect_file))
|
35
31
|
else
|
36
|
-
list.each { |file|
|
32
|
+
list.each { |file| finish_file(nil, nil, collect_file(file)) }
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
40
36
|
def collect_file(file)
|
41
|
-
file_collector = Leftovers::FileCollector.new(file.ruby, file)
|
37
|
+
file_collector = ::Leftovers::FileCollector.new(file.ruby, file)
|
42
38
|
file_collector.collect
|
43
39
|
|
44
40
|
file_collector.to_h
|
@@ -46,11 +42,11 @@ module Leftovers
|
|
46
42
|
|
47
43
|
def print_progress
|
48
44
|
Leftovers.print(
|
49
|
-
"
|
45
|
+
"\e[2Kchecked #{@count} files, collected #{@count_calls} calls, #{@count_definitions} definitions\r" # rubocop:disable Layout/LineLength
|
50
46
|
)
|
51
47
|
end
|
52
48
|
|
53
|
-
def
|
49
|
+
def finish_file(_item, _index, result)
|
54
50
|
@count += 1
|
55
51
|
@count_calls += result[:calls].length
|
56
52
|
@count_definitions += result[:definitions].length
|