degem 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/degem/find_unused.rb +2 -8
- data/lib/degem/gemfile.rb +1 -1
- data/lib/degem/parse_ruby.rb +14 -7
- data/lib/degem/rubygem.rb +10 -4
- data/lib/degem/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683ca7f47acea423692062935b4ccd5285e5aa764a12883a4f34237af7be248a
|
4
|
+
data.tar.gz: 1a9a8e898b9f4afcd1668b65a0ebc2b7928a84efa6c31e263c237114fa0a2069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8e874de8d90b2a2e833b1685938ce9302426c3af5acf8e60bcf26cb0dab994a1520173269a366969018e69fb1abba74f1c4900235a0f7051739073a3962f70d
|
7
|
+
data.tar.gz: 6c19cd8a7e75ef66396e4dc209a14b77765e323804952769cd30a0d9267abb15bf9388ab58ee3f22002320585bb211f80d9d0e86163c7ac0a6b50e992b046cb6
|
data/lib/degem/find_unused.rb
CHANGED
@@ -11,7 +11,7 @@ module Degem
|
|
11
11
|
|
12
12
|
def call
|
13
13
|
rubygems = gemfile.rubygems.reject { _1.name == "degem" }
|
14
|
-
rubygems = reject_railties(rubygems) if rails?
|
14
|
+
rubygems = reject_railties(rubygems) if gemfile.rails?
|
15
15
|
reject_used(rubygems)
|
16
16
|
end
|
17
17
|
|
@@ -20,9 +20,7 @@ module Degem
|
|
20
20
|
attr_reader :gemfile_path
|
21
21
|
|
22
22
|
def reject_railties(rubygems)
|
23
|
-
rubygems
|
24
|
-
.reject { _1.name == "rails" }
|
25
|
-
.reject { _1.consts.grep(/Rails::Railtie|Rails::Engine/).any? }
|
23
|
+
rubygems.reject(&:rails?).reject(&:railtie?)
|
26
24
|
end
|
27
25
|
|
28
26
|
def reject_used(rubygems)
|
@@ -53,9 +51,5 @@ module Degem
|
|
53
51
|
def gemfile
|
54
52
|
@gemfile ||= ParseGemfile.new(@gem_specification).call(gemfile_path)
|
55
53
|
end
|
56
|
-
|
57
|
-
def rails?
|
58
|
-
@rails ||= gemfile.rails?
|
59
|
-
end
|
60
54
|
end
|
61
55
|
end
|
data/lib/degem/gemfile.rb
CHANGED
data/lib/degem/parse_ruby.rb
CHANGED
@@ -22,14 +22,19 @@ module Degem
|
|
22
22
|
class Visitor < Prism::Visitor
|
23
23
|
def initialize
|
24
24
|
@requires = Set.new
|
25
|
-
@
|
25
|
+
@paths = Set.new
|
26
|
+
@classes = Set.new
|
27
|
+
@modules = Set.new
|
26
28
|
@path = nil
|
27
29
|
@stack = []
|
28
30
|
super
|
29
31
|
end
|
30
32
|
|
31
33
|
def requires = @requires.to_a
|
32
|
-
def consts = @
|
34
|
+
def consts = (@paths.union(@classes).union(@modules)).to_a
|
35
|
+
def paths = @paths.to_a
|
36
|
+
def classes = @classes.to_a
|
37
|
+
def modules = @modules.to_a
|
33
38
|
attr_writer :path
|
34
39
|
|
35
40
|
def visit_call_node(node)
|
@@ -40,24 +45,26 @@ module Degem
|
|
40
45
|
def visit_module_node(node)
|
41
46
|
@stack.push(node)
|
42
47
|
super
|
43
|
-
@
|
48
|
+
@modules.add(@stack.map(&:name).join("::"))
|
44
49
|
@stack.pop
|
45
50
|
end
|
46
51
|
|
47
52
|
def visit_class_node(node)
|
48
53
|
@stack.push(node)
|
49
54
|
super
|
50
|
-
@consts.add(@stack.map(&:name).join("::"))
|
51
55
|
@stack.pop
|
56
|
+
*modules, klass = node.constant_path.full_name_parts rescue [[], node.name]
|
57
|
+
@modules.add((@stack.map(&:name) + modules).join("::")) if modules.any?
|
58
|
+
@classes.add((@stack.map(&:name) + modules + [klass]).join("::"))
|
52
59
|
end
|
53
60
|
|
54
61
|
def visit_constant_path_node(node)
|
55
|
-
|
62
|
+
paths_from(node).each { @paths.add(_1) }
|
56
63
|
super
|
57
64
|
end
|
58
65
|
|
59
66
|
def visit_constant_read_node(node)
|
60
|
-
@
|
67
|
+
@paths.add(node.name.to_s) unless @stack.find { _1.constant_path == node }
|
61
68
|
super
|
62
69
|
end
|
63
70
|
|
@@ -83,7 +90,7 @@ module Degem
|
|
83
90
|
acc
|
84
91
|
end
|
85
92
|
|
86
|
-
def
|
93
|
+
def paths_from(node)
|
87
94
|
from_ancestor_to(node)
|
88
95
|
.filter_map { _1.respond_to?(:name) ? _1.name.to_s : nil }
|
89
96
|
.tap { _1.singleton_class.include(Scan) }
|
data/lib/degem/rubygem.rb
CHANGED
@@ -9,8 +9,12 @@ module Degem
|
|
9
9
|
super(rubygem)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def rails?
|
13
|
+
name == "rails"
|
14
|
+
end
|
15
|
+
|
16
|
+
def railtie?
|
17
|
+
parsed.consts.grep(/Rails::Railtie|Rails::Engine/).any?
|
14
18
|
end
|
15
19
|
|
16
20
|
def own_consts
|
@@ -25,7 +29,9 @@ module Degem
|
|
25
29
|
*name.split("-").each_cons(2).to_a.map(&:join)
|
26
30
|
]
|
27
31
|
|
28
|
-
|
32
|
+
parsed.classes + (parsed.modules + parsed.paths).filter do |const|
|
33
|
+
variations.any? { |variation| const.downcase == variation.downcase }
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
private
|
@@ -34,7 +40,7 @@ module Degem
|
|
34
40
|
@parsed ||=
|
35
41
|
begin
|
36
42
|
gem_path = @gem_specification.find_by_name(name).full_gem_path
|
37
|
-
paths = Dir.glob(File.join(gem_path, "**/*.rb"))
|
43
|
+
paths = Dir.glob(File.join(gem_path, "**", "lib", "**/*.rb"))
|
38
44
|
ParseRuby.new.call(paths)
|
39
45
|
end
|
40
46
|
end
|
data/lib/degem/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: degem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 3v0k4
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prism
|