leftovers 0.4.3 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/docs/Configuration.md +46 -11
- data/lib/.DS_Store +0 -0
- data/lib/config/actioncable.yml +4 -0
- data/lib/config/actionmailer.yml +22 -0
- data/lib/config/actionpack.yml +190 -0
- data/lib/config/actionview.yml +64 -0
- data/lib/config/activejob.yml +29 -0
- data/lib/config/activemodel.yml +74 -0
- data/lib/config/activerecord.yml +179 -0
- data/lib/config/activesupport.yml +99 -0
- data/lib/config/haml.yml +2 -0
- data/lib/config/rails.yml +11 -450
- data/lib/config/ruby.yml +6 -0
- data/lib/leftovers/ast/node.rb +14 -0
- data/lib/leftovers/config.rb +8 -0
- data/lib/leftovers/config_validator/schema_hash.rb +62 -29
- data/lib/leftovers/erb.rb +2 -2
- data/lib/leftovers/file.rb +2 -3
- data/lib/leftovers/matcher_builders/node.rb +2 -0
- data/lib/leftovers/matcher_builders/node_has_argument.rb +11 -7
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +14 -10
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +17 -13
- data/lib/leftovers/matcher_builders/node_has_receiver.rb +15 -0
- data/lib/leftovers/matcher_builders/node_type.rb +7 -6
- data/lib/leftovers/matcher_builders/node_value.rb +50 -0
- data/lib/leftovers/matcher_builders.rb +3 -2
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +4 -1
- data/lib/leftovers/matchers/node_has_positional_argument.rb +0 -4
- data/lib/leftovers/matchers/node_has_receiver.rb +20 -0
- data/lib/leftovers/matchers/predicate.rb +19 -0
- data/lib/leftovers/matchers.rb +2 -0
- data/lib/leftovers/merged_config.rb +19 -1
- data/lib/leftovers/todo_reporter.rb +9 -6
- data/lib/leftovers/value_processors/camelize.rb +1 -1
- data/lib/leftovers/value_processors/deconstantize.rb +1 -1
- data/lib/leftovers/value_processors/demodulize.rb +1 -1
- data/lib/leftovers/value_processors/parameterize.rb +1 -1
- data/lib/leftovers/value_processors/pluralize.rb +1 -1
- data/lib/leftovers/value_processors/singularize.rb +1 -1
- data/lib/leftovers/value_processors/titleize.rb +1 -1
- data/lib/leftovers/value_processors/underscore.rb +1 -1
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +95 -92
- metadata +16 -4
- data/lib/leftovers/matcher_builders/argument_node_value.rb +0 -21
@@ -30,12 +30,9 @@ module Leftovers
|
|
30
30
|
def report_instructions
|
31
31
|
puts <<~MESSAGE
|
32
32
|
generated #{path.basename}.
|
33
|
-
running leftovers again will read this file and
|
34
|
-
not alert you to any unused items mentioned in it.
|
33
|
+
running leftovers again will read this file and not alert you to any unused items mentioned in it.
|
35
34
|
|
36
|
-
commit this file so you/your team can gradually
|
37
|
-
address these items while still having leftovers
|
38
|
-
alert you to any newly unused items.
|
35
|
+
commit this file so you/your team can gradually address these items while still having leftovers alert you to any newly unused items.
|
39
36
|
MESSAGE
|
40
37
|
end
|
41
38
|
|
@@ -108,12 +105,18 @@ module Leftovers
|
|
108
105
|
def generate_list(title, list)
|
109
106
|
<<~YML
|
110
107
|
# #{title}
|
111
|
-
#{list
|
108
|
+
#{print_definition_list(list)}
|
112
109
|
|
113
110
|
YML
|
114
111
|
end
|
115
112
|
|
113
|
+
def print_definition_list(definition_list)
|
114
|
+
definition_list.map { |definition| print_definition(definition) }.join("\n")
|
115
|
+
end
|
116
|
+
|
116
117
|
def print_definition(definition)
|
118
|
+
return print_definition_list(definition.definitions) if definition.is_a?(DefinitionSet)
|
119
|
+
|
117
120
|
" - #{definition.to_s.inspect} # #{definition.location_s} #{definition.source_line.strip}"
|
118
121
|
end
|
119
122
|
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#camelize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#deconstantize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#demodulize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#parameterize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#pluralize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#singularize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#titleize method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module Leftovers
|
|
16
16
|
rescue NoMethodError
|
17
17
|
Leftovers.error <<~MESSAGE
|
18
18
|
Tried using the String#underscore method, but the activesupport gem was not available and/or not required
|
19
|
-
`gem install activesupport`, and/or add `requires: 'active_support/core_ext/string'` to your .leftovers.yml
|
19
|
+
`gem install activesupport`, and/or add `requires: ['active_support', 'active_support/core_ext/string']` to your .leftovers.yml
|
20
20
|
MESSAGE
|
21
21
|
end
|
22
22
|
end
|
data/lib/leftovers/version.rb
CHANGED
data/lib/leftovers.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
module Leftovers # rubocop:disable Metrics/ModuleLength
|
4
4
|
class Error < ::StandardError; end
|
5
5
|
|
6
|
-
module_function
|
7
|
-
|
8
6
|
autoload(:AST, "#{__dir__}/leftovers/ast")
|
9
7
|
autoload(:Backports, "#{__dir__}/leftovers/backports")
|
10
8
|
autoload(:CLI, "#{__dir__}/leftovers/cli")
|
@@ -32,124 +30,129 @@ module Leftovers # rubocop:disable Metrics/ModuleLength
|
|
32
30
|
autoload(:VERSION, "#{__dir__}/leftovers/version")
|
33
31
|
|
34
32
|
class << self
|
35
|
-
attr_accessor :parallel, :progress
|
33
|
+
attr_accessor :parallel, :progress
|
34
|
+
attr_writer :reporter
|
36
35
|
alias_method :parallel?, :parallel
|
37
36
|
alias_method :progress?, :progress
|
38
|
-
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def stdout
|
39
|
+
@stdout ||= $stdout
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
def stderr
|
43
|
+
@stderr ||= $stderr
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
def config
|
47
|
+
@config ||= Leftovers::MergedConfig.new(load_defaults: true)
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
def collector
|
51
|
+
@collector ||= Leftovers::Collector.new
|
52
|
+
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
def reporter
|
55
|
+
@reporter ||= Leftovers::Reporter.new
|
56
|
+
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
def leftovers
|
59
|
+
@leftovers ||= begin
|
60
|
+
collector.collect
|
61
|
+
collector.definitions.reject(&:in_collection?)
|
62
|
+
end
|
64
63
|
end
|
65
|
-
end
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
65
|
+
def run(stdout: StringIO.new, stderr: StringIO.new) # rubocop:disable Metrics/MethodLength
|
66
|
+
@stdout = stdout
|
67
|
+
@stderr = stderr
|
68
|
+
return reporter.report_success if leftovers.empty?
|
69
|
+
|
70
|
+
only_test = []
|
71
|
+
none = []
|
72
|
+
leftovers.sort_by(&:location_s).each do |definition|
|
73
|
+
if !definition.test? && definition.in_test_collection?
|
74
|
+
only_test << definition
|
75
|
+
else
|
76
|
+
none << definition
|
77
|
+
end
|
79
78
|
end
|
79
|
+
|
80
|
+
reporter.report(only_test: only_test, none: none)
|
80
81
|
end
|
81
82
|
|
82
|
-
|
83
|
-
|
83
|
+
def reset # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
84
|
+
remove_instance_variable(:@config) if defined?(@config)
|
85
|
+
remove_instance_variable(:@collector) if defined?(@collector)
|
86
|
+
remove_instance_variable(:@reporter) if defined?(@reporter)
|
87
|
+
remove_instance_variable(:@leftovers) if defined?(@leftovers)
|
88
|
+
remove_instance_variable(:@try_require_cache) if defined?(@try_require_cache)
|
89
|
+
remove_instance_variable(:@stdout) if defined?(@stdout)
|
90
|
+
remove_instance_variable(:@stderr) if defined?(@stderr)
|
91
|
+
remove_instance_variable(:@parallel) if defined?(@parallel)
|
92
|
+
remove_instance_variable(:@pwd) if defined?(@pwd)
|
93
|
+
end
|
84
94
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
remove_instance_variable(:@reporter) if defined?(@reporter)
|
89
|
-
remove_instance_variable(:@leftovers) if defined?(@leftovers)
|
90
|
-
remove_instance_variable(:@try_require) if defined?(@try_require)
|
91
|
-
remove_instance_variable(:@stdout) if defined?(@stdout)
|
92
|
-
remove_instance_variable(:@stderr) if defined?(@stderr)
|
93
|
-
remove_instance_variable(:@parallel) if defined?(@parallel)
|
94
|
-
remove_instance_variable(:@pwd) if defined?(@pwd)
|
95
|
-
end
|
95
|
+
def resolution_instructions_link
|
96
|
+
"https://github.com/robotdana/leftovers/tree/v#{Leftovers::VERSION}/README.md#how_to_resolve"
|
97
|
+
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
def warn(message)
|
100
|
+
stderr.puts("\e[2K#{message}")
|
101
|
+
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
def error(message)
|
104
|
+
warn(message)
|
105
|
+
exit 1
|
106
|
+
end
|
104
107
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
108
|
+
def puts(message)
|
109
|
+
stdout.puts("\e[2K#{message}")
|
110
|
+
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
def print(message)
|
113
|
+
stdout.print(message)
|
114
|
+
end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
-
|
116
|
+
def newline
|
117
|
+
stdout.puts('')
|
118
|
+
end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
|
120
|
+
def pwd
|
121
|
+
@pwd ||= Pathname.new(Dir.pwd + '/')
|
122
|
+
end
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
def exit(status = 0)
|
125
|
+
throw :leftovers_exit, status
|
126
|
+
end
|
125
127
|
|
126
|
-
|
127
|
-
|
128
|
-
|
128
|
+
def try_require(requirable, message: nil)
|
129
|
+
warn message if !try_require_cache(requirable) && message
|
130
|
+
try_require_cache(requirable)
|
131
|
+
end
|
129
132
|
|
130
|
-
|
131
|
-
|
133
|
+
def each_or_self(value, &block)
|
134
|
+
return enum_for(__method__, value) unless block
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
else
|
137
|
-
require requirable
|
138
|
-
true
|
136
|
+
case value
|
137
|
+
when nil then nil
|
138
|
+
when Array then value.each(&block)
|
139
|
+
else yield(value)
|
139
140
|
end
|
140
|
-
rescue LoadError
|
141
|
-
false
|
142
141
|
end
|
143
142
|
|
144
|
-
|
145
|
-
@try_require[requirable]
|
146
|
-
end
|
143
|
+
private
|
147
144
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
145
|
+
def try_require_cache(requirable)
|
146
|
+
@try_require_cache ||= {}
|
147
|
+
|
148
|
+
@try_require_cache.fetch(requirable) do
|
149
|
+
begin
|
150
|
+
require requirable
|
151
|
+
@try_require_cache[requirable] = true
|
152
|
+
rescue LoadError
|
153
|
+
@try_require_cache[requirable] = false
|
154
|
+
end
|
155
|
+
end
|
153
156
|
end
|
154
157
|
end
|
155
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leftovers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -291,6 +291,15 @@ files:
|
|
291
291
|
- docs/Configuration.md
|
292
292
|
- exe/leftovers
|
293
293
|
- leftovers.gemspec
|
294
|
+
- lib/.DS_Store
|
295
|
+
- lib/config/actioncable.yml
|
296
|
+
- lib/config/actionmailer.yml
|
297
|
+
- lib/config/actionpack.yml
|
298
|
+
- lib/config/actionview.yml
|
299
|
+
- lib/config/activejob.yml
|
300
|
+
- lib/config/activemodel.yml
|
301
|
+
- lib/config/activerecord.yml
|
302
|
+
- lib/config/activesupport.yml
|
294
303
|
- lib/config/attr_encrypted.yml
|
295
304
|
- lib/config/audited.yml
|
296
305
|
- lib/config/builder.yml
|
@@ -343,17 +352,18 @@ files:
|
|
343
352
|
- lib/leftovers/matcher_builders.rb
|
344
353
|
- lib/leftovers/matcher_builders/and.rb
|
345
354
|
- lib/leftovers/matcher_builders/and_not.rb
|
346
|
-
- lib/leftovers/matcher_builders/argument_node_value.rb
|
347
355
|
- lib/leftovers/matcher_builders/name.rb
|
348
356
|
- lib/leftovers/matcher_builders/node.rb
|
349
357
|
- lib/leftovers/matcher_builders/node_has_argument.rb
|
350
358
|
- lib/leftovers/matcher_builders/node_has_keyword_argument.rb
|
351
359
|
- lib/leftovers/matcher_builders/node_has_positional_argument.rb
|
360
|
+
- lib/leftovers/matcher_builders/node_has_receiver.rb
|
352
361
|
- lib/leftovers/matcher_builders/node_name.rb
|
353
362
|
- lib/leftovers/matcher_builders/node_pair_name.rb
|
354
363
|
- lib/leftovers/matcher_builders/node_pair_value.rb
|
355
364
|
- lib/leftovers/matcher_builders/node_path.rb
|
356
365
|
- lib/leftovers/matcher_builders/node_type.rb
|
366
|
+
- lib/leftovers/matcher_builders/node_value.rb
|
357
367
|
- lib/leftovers/matcher_builders/or.rb
|
358
368
|
- lib/leftovers/matcher_builders/path.rb
|
359
369
|
- lib/leftovers/matcher_builders/string.rb
|
@@ -367,6 +377,7 @@ files:
|
|
367
377
|
- lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb
|
368
378
|
- lib/leftovers/matchers/node_has_positional_argument.rb
|
369
379
|
- lib/leftovers/matchers/node_has_positional_argument_with_value.rb
|
380
|
+
- lib/leftovers/matchers/node_has_receiver.rb
|
370
381
|
- lib/leftovers/matchers/node_name.rb
|
371
382
|
- lib/leftovers/matchers/node_pair_value.rb
|
372
383
|
- lib/leftovers/matchers/node_path.rb
|
@@ -374,6 +385,7 @@ files:
|
|
374
385
|
- lib/leftovers/matchers/node_type.rb
|
375
386
|
- lib/leftovers/matchers/not.rb
|
376
387
|
- lib/leftovers/matchers/or.rb
|
388
|
+
- lib/leftovers/matchers/predicate.rb
|
377
389
|
- lib/leftovers/merged_config.rb
|
378
390
|
- lib/leftovers/parser.rb
|
379
391
|
- lib/leftovers/processor_builders.rb
|
@@ -454,7 +466,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
454
466
|
- !ruby/object:Gem::Version
|
455
467
|
version: '0'
|
456
468
|
requirements: []
|
457
|
-
rubygems_version: 3.
|
469
|
+
rubygems_version: 3.2.15
|
458
470
|
signing_key:
|
459
471
|
specification_version: 4
|
460
472
|
summary: Find unused methods and classes/modules
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
module Leftovers
|
4
|
-
module MatcherBuilders
|
5
|
-
module ArgumentNodeValue
|
6
|
-
def self.build(pattern)
|
7
|
-
::Leftovers::MatcherBuilders::Or.each_or_self(pattern) do |pat|
|
8
|
-
case pat
|
9
|
-
when ::Integer, true, false, nil
|
10
|
-
::Leftovers::Matchers::NodeScalarValue.new(pat)
|
11
|
-
when ::String, ::Hash
|
12
|
-
::Leftovers::MatcherBuilders::NodeName.build(pat)
|
13
|
-
# :nocov:
|
14
|
-
else raise
|
15
|
-
# :nocov:
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|