fus 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -7
- data/lib/fus/finder.rb +14 -1
- data/lib/fus/swift_class.rb +8 -2
- data/lib/fus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfcacd9d75754dbe979b47f6c6499be68711dc6c
|
4
|
+
data.tar.gz: 08a9509df0f86f9a604d269430d501f7f257af2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384a22d13e0350ec977e6c3725cb38d90aea0fba0bee6be28c991a6a5f69d6d8416a95ebcd3182b8120bd8bf2e3dda488137dbbc803dad0ef9173ab6cc5eb0b1
|
7
|
+
data.tar.gz: 043cec1b9e239c2febbef1b32aeda5b193635309dec175220cd1025617d63aad28eb72a36a2db18f8caaa8224b46bd6a70a72a658811d9b3fb336e69df738425
|
data/README.md
CHANGED
@@ -6,20 +6,45 @@ Fus is a command line tool for finding unused Swift classes in your project.
|
|
6
6
|
This tool was inspired by [fui](https://github.com/dblock/fui)
|
7
7
|
|
8
8
|
## Installation
|
9
|
-
|
9
|
+
```
|
10
|
+
$ gem install fus
|
11
|
+
```
|
10
12
|
|
11
13
|
## Usage
|
12
14
|
|
15
|
+
#### Get Help
|
16
|
+
|
17
|
+
```
|
18
|
+
fus help
|
19
|
+
```
|
20
|
+
|
21
|
+
#### Find Unused Classes in the Current Directory
|
22
|
+
|
13
23
|
```
|
14
|
-
|
15
|
-
fus find # Find unused swift classes
|
16
|
-
fus list # List all swift classes
|
17
|
-
|
18
|
-
Options:
|
19
|
-
-p, [--path=path] # path in which to search (defaults to /Users/thomasabend/Desktop/Programming/fus)
|
24
|
+
fus find
|
20
25
|
```
|
26
|
+
|
27
|
+
The `find` command lists the names of all unused classes.
|
28
|
+
|
29
|
+
#### List all Swift Classes in the Current Directory
|
30
|
+
|
31
|
+
```
|
32
|
+
fus list
|
33
|
+
```
|
34
|
+
|
35
|
+
The `list` command lists the names of all the Swift classes identified by FUS.
|
36
|
+
|
37
|
+
#### Find Unused Classes at a Path
|
38
|
+
|
39
|
+
```
|
40
|
+
fus find --path [the path to search at]
|
41
|
+
```
|
42
|
+
|
21
43
|
## Contributing
|
22
44
|
|
45
|
+
This project (like Swift itself) is a work in progress.
|
46
|
+
Contributions are very welcome.
|
47
|
+
|
23
48
|
1. Fork it ( https://github.com/[my-github-username]/fus/fork )
|
24
49
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
50
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/lib/fus/finder.rb
CHANGED
@@ -1,27 +1,34 @@
|
|
1
1
|
module Fus
|
2
|
+
# The thing that finds the stuff
|
2
3
|
class Finder
|
3
4
|
attr_reader :swift_paths
|
4
5
|
|
5
6
|
def initialize(path)
|
6
7
|
raise Errno::ENOENT.new(path) unless Dir.exists?(path)
|
7
8
|
path = File.expand_path(path)
|
8
|
-
@swift_paths = Dir
|
9
|
+
@swift_paths = Dir
|
10
|
+
.glob("#{path}/**/*.swift")
|
11
|
+
.select {|path| path.scan(/\/Pods\//).empty? }
|
9
12
|
@obj_c_paths = Dir.glob("#{path}/**/*.m") + Dir.glob("#{path}/**/*.h")
|
10
13
|
.select {|path| path.scan(/-Swift.h/).empty? }
|
11
14
|
@ib_paths = (Dir.glob("#{path}/**/*.xib") +
|
12
15
|
Dir.glob("#{path}/**/*.storyboard"))
|
13
16
|
end
|
14
17
|
|
18
|
+
# A list of names of unused classes
|
15
19
|
def unused_classnames
|
16
20
|
unused_classes.map(&:name)
|
17
21
|
end
|
18
22
|
|
23
|
+
# A list of names of all Swift classes
|
19
24
|
def swift_classnames
|
20
25
|
swift_classes.map(&:name)
|
21
26
|
end
|
22
27
|
|
23
28
|
|
24
29
|
private
|
30
|
+
# Search all the swift paths and find things that look like classes
|
31
|
+
# then map those names into SwiftClasses
|
25
32
|
def swift_classes
|
26
33
|
@swift_classes ||=
|
27
34
|
@swift_paths
|
@@ -30,6 +37,8 @@ module Fus
|
|
30
37
|
.map {|name| SwiftClass.new(name)}
|
31
38
|
end
|
32
39
|
|
40
|
+
# Go through the list of all Swift classes and filter out the ones
|
41
|
+
# that are used in Swift, IB, or Obj-C
|
33
42
|
def unused_classes
|
34
43
|
@unused_classes ||= swift_classes.reject do |swift_class|
|
35
44
|
swift_class.spec? ||
|
@@ -39,12 +48,14 @@ module Fus
|
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
51
|
+
# Given some text, identify Swift classes
|
42
52
|
def find(swift_text)
|
43
53
|
swift_text
|
44
54
|
.scan(/class\s+([^func][^var][a-zA-Z_]+)\s*:?\s[a-zA-Z_]*\b?\s*{/)
|
45
55
|
.flatten
|
46
56
|
end
|
47
57
|
|
58
|
+
# Determines if a class is used in Swift
|
48
59
|
def used_in_swift?(swift_class, paths=@swift_paths)
|
49
60
|
paths.any? do |path|
|
50
61
|
next if swift_class.matches_classname?(path)
|
@@ -52,10 +63,12 @@ module Fus
|
|
52
63
|
end
|
53
64
|
end
|
54
65
|
|
66
|
+
# Determines if a class is used in Obj-C
|
55
67
|
def used_in_obj_c?(swift_class, paths=@obj_c_paths)
|
56
68
|
paths.any? { |path| swift_class.used_in_obj_c?(File.open(path).read) }
|
57
69
|
end
|
58
70
|
|
71
|
+
# Determines if a class is used in InterfaceBuilder
|
59
72
|
def used_in_ib?(swift_class, paths=@ib_paths)
|
60
73
|
paths.any? { |path| swift_class.used_in_xml?(File.open(path).read) }
|
61
74
|
end
|
data/lib/fus/swift_class.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
module Fus
|
2
|
+
# A thin wrapper around the name of a Swift class
|
2
3
|
class SwiftClass
|
3
4
|
attr_reader :name
|
4
5
|
def initialize(name)
|
5
6
|
@name = name
|
6
7
|
end
|
7
8
|
|
9
|
+
# Is this class a test class
|
8
10
|
def spec?
|
9
|
-
name.match(/Spec/)
|
11
|
+
name.match(/Spec|Tests|Test/)
|
10
12
|
end
|
11
13
|
|
14
|
+
# Does this class name match this path
|
12
15
|
def matches_classname?(path)
|
13
16
|
path.match(/#{name}\b/)
|
14
17
|
end
|
15
18
|
|
19
|
+
# Is this class used in this XML
|
16
20
|
def used_in_xml?(xml)
|
17
21
|
xml.include?("customClass=\"#{name}\"")
|
18
22
|
end
|
19
23
|
|
24
|
+
# Is this class used in this Obj-C text
|
20
25
|
def used_in_obj_c?(text)
|
21
26
|
text.match(/(^|[^@])#{name}/)
|
22
27
|
end
|
23
28
|
|
29
|
+
# Is this class used in this Swift text
|
24
30
|
def used_in_swift?(text)
|
25
|
-
text.match(/(\b#{name}.?[.:(])|([:].?#{name})|(typealias\s+.*=.+#{name})/)
|
31
|
+
text.match(/(\b#{name}.?[.:(])|([:].?#{name})|((typealias|associatedType)\s+.*=.+#{name})/)
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/fus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tsabend
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|