leftovers 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/leftovers/cli.rb +8 -5
- data/lib/leftovers/collection.rb +2 -2
- data/lib/leftovers/file_collector/node_processor/error.rb +16 -0
- data/lib/leftovers/file_collector/node_processor.rb +11 -1
- data/lib/leftovers/file_collector.rb +19 -8
- data/lib/leftovers/matcher_builders/node_type.rb +8 -2
- data/lib/leftovers/matcher_builders/or.rb +1 -1
- data/lib/leftovers/merged_config.rb +1 -1
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers.rb +10 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7094671fa508c2a3af0cfdc0b64dfc41346c88a16a9203d901628fe40af66a86
|
4
|
+
data.tar.gz: 35ae640a73003aaf96a362ca08e3c92b51b46e93184b1c3641a5427a1dce31d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da3eb08e61869a3d5a82c8a0ecdfb7217872299cee46d1ec7ac0234c892c10a0afa5ca3786e23939d893302cf83e2d91e4cb33939c02e4f6b856c51aef22cdc
|
7
|
+
data.tar.gz: 29f81218dfad69a62ea35032cc4149eff849a363067b67aa9175a568674e473e6a28f2b0eeb5d6de36246917efb911a527163aab45e7382ff0d915a843777b99
|
data/CHANGELOG.md
CHANGED
data/lib/leftovers/cli.rb
CHANGED
@@ -9,11 +9,14 @@ module Leftovers
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
parse_options
|
13
|
+
|
14
|
+
runner.run
|
15
|
+
rescue ::Leftovers::Error => e
|
16
|
+
Leftovers.warn("\e[31m#{e.class}: #{e.message}\e[0m\n\n#{e.backtrace.join("\n")}")
|
17
|
+
1
|
18
|
+
rescue ::Leftovers::Exit => e
|
19
|
+
e.status # what why?
|
17
20
|
end
|
18
21
|
|
19
22
|
private
|
data/lib/leftovers/collection.rb
CHANGED
@@ -59,8 +59,8 @@ module Leftovers
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def freeze_calls
|
62
|
-
@calls = @calls.to_set.freeze
|
63
|
-
@test_calls = @test_calls.to_set.freeze
|
62
|
+
@calls = @calls.to_set.compare_by_identity.freeze
|
63
|
+
@test_calls = @test_calls.to_set.compare_by_identity.freeze
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Leftovers
|
4
|
+
class FileCollector
|
5
|
+
class NodeProcessor
|
6
|
+
class Error < ::Leftovers::FileCollector::Error
|
7
|
+
attr_reader :node
|
8
|
+
|
9
|
+
def initialize(message, node)
|
10
|
+
super(message)
|
11
|
+
@node = node
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -4,7 +4,17 @@ require 'parser'
|
|
4
4
|
|
5
5
|
module Leftovers
|
6
6
|
class FileCollector
|
7
|
-
class NodeProcessor < ::Parser::AST::Processor
|
7
|
+
class NodeProcessor < ::Parser::AST::Processor # rubocop:disable Metrics/ClassLength
|
8
|
+
include Autoloader
|
9
|
+
|
10
|
+
def process(ast)
|
11
|
+
super
|
12
|
+
rescue FileCollector::Error
|
13
|
+
raise
|
14
|
+
rescue StandardError => e
|
15
|
+
raise Error.new(e.message, ast)
|
16
|
+
end
|
17
|
+
|
8
18
|
def initialize(collector) # rubocop:disable Lint/MissingSuper # there isn't one to call
|
9
19
|
@collector = collector
|
10
20
|
end
|
@@ -4,6 +4,8 @@ require 'set'
|
|
4
4
|
|
5
5
|
module Leftovers
|
6
6
|
class FileCollector
|
7
|
+
class Error < ::Leftovers::Error; end
|
8
|
+
|
7
9
|
include Autoloader
|
8
10
|
|
9
11
|
attr_reader :calls, :allow_lines, :test_lines, :dynamic_lines
|
@@ -35,15 +37,27 @@ module Leftovers
|
|
35
37
|
list
|
36
38
|
end
|
37
39
|
|
38
|
-
def collect(ruby = @ruby, line = 1)
|
40
|
+
def collect(ruby = @ruby, line = 1) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
39
41
|
ast, comments = Parser.parse_with_comments(ruby, @file.relative_path, line)
|
40
42
|
CommentsProcessor.process(comments, self)
|
41
43
|
NodeProcessor.new(self).process(ast)
|
42
44
|
rescue ::Parser::SyntaxError => e
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
raise Error, <<~MESSAGE.chomp, e.backtrace
|
46
|
+
SyntaxError: #{e.message}
|
47
|
+
when processing #{filename}:#{e.diagnostic.location.line}:#{e.diagnostic.location.column}
|
48
|
+
MESSAGE
|
49
|
+
rescue NodeProcessor::Error => e
|
50
|
+
raise Error, <<~MESSAGE.chomp, e.backtrace
|
51
|
+
#{e.cause.class}: #{e.message}
|
52
|
+
when processing #{e.node} at #{filename}:#{e.node.loc.line}:#{e.node.loc.column}
|
53
|
+
MESSAGE
|
54
|
+
rescue Error
|
55
|
+
raise
|
56
|
+
rescue ::StandardError => e
|
57
|
+
raise Error, <<~MESSAGE.chomp, e.backtrace
|
58
|
+
#{e.class}: #{e.message}
|
59
|
+
when processing #{filename}
|
60
|
+
MESSAGE
|
47
61
|
end
|
48
62
|
|
49
63
|
def collect_subfile(string, location)
|
@@ -112,9 +126,6 @@ module Leftovers
|
|
112
126
|
|
113
127
|
def collect_dynamic(node)
|
114
128
|
::Leftovers.config.dynamic.process(nil, node, node, self)
|
115
|
-
rescue ::StandardError => e
|
116
|
-
raise Error, "#{e.class}: #{e.message}\n" \
|
117
|
-
"when processing #{node} at #{filename}:#{node.loc.line}:#{node.loc.column}", e.backtrace
|
118
129
|
end
|
119
130
|
|
120
131
|
private
|
@@ -15,8 +15,14 @@ module Leftovers
|
|
15
15
|
when :Array then Matchers::NodeType.new(:array)
|
16
16
|
when :Hash then Matchers::NodeType.new(:hash)
|
17
17
|
when :Proc then Matchers::NodeIsProc
|
18
|
-
when :Method
|
19
|
-
|
18
|
+
when :Method
|
19
|
+
Matchers::NodeType.new(
|
20
|
+
::Set[:send, :csend, :def, :defs].compare_by_identity.freeze
|
21
|
+
)
|
22
|
+
when :Constant
|
23
|
+
Matchers::NodeType.new(
|
24
|
+
::Set[:const, :class, :module, :casgn].compare_by_identity.freeze
|
25
|
+
)
|
20
26
|
# :nocov:
|
21
27
|
else raise UnexpectedCase, "Unhandled value #{type.inspect}"
|
22
28
|
# :nocov:
|
@@ -66,7 +66,7 @@ module Leftovers
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def build_grouped(set: nil, regexp: nil, nil: nil, **matcher_classes) # rubocop:disable Lint/UnusedMethodArgument i want to throw away nils
|
69
|
-
set = set.to_set.compare_by_identity if set.is_a?(::Array)
|
69
|
+
set = set.to_set.compare_by_identity.freeze if set.is_a?(::Array)
|
70
70
|
regexp = ::Regexp.union(regexp) if regexp.is_a?(::Array)
|
71
71
|
matcher_classes = matcher_classes.each_value.flat_map do |matchers|
|
72
72
|
build_grouped_for_matcher(matchers)
|
data/lib/leftovers/version.rb
CHANGED
data/lib/leftovers.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Leftovers
|
4
|
+
class Exit < ::StandardError
|
5
|
+
attr_reader :status
|
6
|
+
|
7
|
+
def initialize(status) # rubocop:disable Lint/MissingSuper
|
8
|
+
@status = status
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
require_relative 'leftovers/autoloader'
|
5
13
|
include Autoloader
|
6
14
|
|
@@ -44,7 +52,7 @@ module Leftovers
|
|
44
52
|
def error(message, did_you_mean = nil)
|
45
53
|
warn("\e[31m#{message}\e[0m")
|
46
54
|
warn("\n#{did_you_mean}") if did_you_mean
|
47
|
-
|
55
|
+
raise Exit, 1
|
48
56
|
end
|
49
57
|
|
50
58
|
def puts(message)
|
@@ -60,7 +68,7 @@ module Leftovers
|
|
60
68
|
end
|
61
69
|
|
62
70
|
def exit(status = 0)
|
63
|
-
|
71
|
+
raise Exit, status
|
64
72
|
end
|
65
73
|
|
66
74
|
def try_require(requirable, message: nil)
|
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.12.0
|
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: 2023-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -439,6 +439,7 @@ files:
|
|
439
439
|
- lib/leftovers/file_collector.rb
|
440
440
|
- lib/leftovers/file_collector/comments_processor.rb
|
441
441
|
- lib/leftovers/file_collector/node_processor.rb
|
442
|
+
- lib/leftovers/file_collector/node_processor/error.rb
|
442
443
|
- lib/leftovers/file_list.rb
|
443
444
|
- lib/leftovers/matcher_builders.rb
|
444
445
|
- lib/leftovers/matcher_builders/and.rb
|
@@ -584,7 +585,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
584
585
|
- !ruby/object:Gem::Version
|
585
586
|
version: '0'
|
586
587
|
requirements: []
|
587
|
-
rubygems_version: 3.
|
588
|
+
rubygems_version: 3.4.1
|
588
589
|
signing_key:
|
589
590
|
specification_version: 4
|
590
591
|
summary: Find unused methods and classes/modules
|