fus 0.0.1
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 +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/bin/fus +34 -0
- data/lib/fus.rb +3 -0
- data/lib/fus/finder.rb +63 -0
- data/lib/fus/swift_class.rb +28 -0
- data/lib/fus/version.rb +3 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 286731628f2c28dcaa3c92e8f9542e8bda025895
|
4
|
+
data.tar.gz: d9bf7fcba759693edb44112175acf15f86fb6b2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ac13df6d7ebcf35dc9aa9837eb567aa6a134f4cb108c50eded8e4324feefe7c59a2dc3e8d3c010825798e6b360baa22c6dc95ffd165acaf6ad8f95fc8db0409
|
7
|
+
data.tar.gz: 6e89f31f36a0f3c8ddf42a829adc481b9898a4155bec9014398b714f8564613faaf630c3e9908b7d0622218948787ddbec72716e5b599e6cd84bf01c91eab21a
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 tsabend
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Fus:
|
2
|
+
|
3
|
+
## Stop compiling things you don't use.
|
4
|
+
Fus is a command line tool for finding unused Swift classes in your project.
|
5
|
+
|
6
|
+
This tool was inspired by [fui](https://github.com/dblock/fui)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
$ gem install fus
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
FUS commands:
|
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)
|
20
|
+
```
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( https://github.com/[my-github-username]/fus/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create a new Pull Request
|
data/bin/fus
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fus'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
class FusRunner < Thor
|
7
|
+
package_name "FUS"
|
8
|
+
class_option :path, aliases: "-p", desc: "path in which to search (defaults to #{Dir.pwd})", banner: "path"
|
9
|
+
|
10
|
+
default_task :find
|
11
|
+
desc "find", "Find unused swift classes"
|
12
|
+
def find
|
13
|
+
finder = Fus::Finder.new(path)
|
14
|
+
puts finder.unused_classnames
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "list", "List all swift classes"
|
18
|
+
def list
|
19
|
+
finder = Fus::Finder.new(path)
|
20
|
+
puts finder.swift_classnames
|
21
|
+
end
|
22
|
+
|
23
|
+
def help
|
24
|
+
say("\nFind Unused Swift Classes\n\n")
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def path
|
30
|
+
options[:path] || Dir.pwd
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
FusRunner.start(ARGV)
|
data/lib/fus.rb
ADDED
data/lib/fus/finder.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Fus
|
2
|
+
class Finder
|
3
|
+
attr_reader :swift_paths
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
raise Errno::ENOENT.new(path) unless Dir.exists?(path)
|
7
|
+
path = File.expand_path(path)
|
8
|
+
@swift_paths = Dir.glob("#{path}/**/*.swift")
|
9
|
+
@obj_c_paths = Dir.glob("#{path}/**/*.m") + Dir.glob("#{path}/**/*.h")
|
10
|
+
.select {|path| path.scan(/-Swift.h/).empty? }
|
11
|
+
@ib_paths = (Dir.glob("#{path}/**/*.xib") +
|
12
|
+
Dir.glob("#{path}/**/*.storyboard"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def unused_classnames
|
16
|
+
unused_classes.map(&:name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def swift_classnames
|
20
|
+
swift_classes.map(&:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
def swift_classes
|
26
|
+
@swift_classes ||=
|
27
|
+
@swift_paths
|
28
|
+
.reduce([]) { |names, path| names += find(File.open(path).read) }
|
29
|
+
.uniq
|
30
|
+
.map {|name| SwiftClass.new(name)}
|
31
|
+
end
|
32
|
+
|
33
|
+
def unused_classes
|
34
|
+
@unused_classes ||= swift_classes.reject do |swift_class|
|
35
|
+
swift_class.spec? ||
|
36
|
+
used_in_swift?(swift_class) ||
|
37
|
+
used_in_ib?(swift_class) ||
|
38
|
+
used_in_obj_c?(swift_class)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def find(swift_text)
|
43
|
+
swift_text
|
44
|
+
.scan(/class\s+([^func][^var][a-zA-Z_]+)\s*:?\s[a-zA-Z_]*\b?\s*{/)
|
45
|
+
.flatten
|
46
|
+
end
|
47
|
+
|
48
|
+
def used_in_swift?(swift_class, paths=@swift_paths)
|
49
|
+
paths.any? do |path|
|
50
|
+
next if swift_class.matches_classname?(path)
|
51
|
+
swift_class.used_in_swift?(File.open(path).read)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def used_in_obj_c?(swift_class, paths=@obj_c_paths)
|
56
|
+
paths.any? { |path| swift_class.used_in_obj_c?(File.open(path).read) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def used_in_ib?(swift_class, paths=@ib_paths)
|
60
|
+
paths.any? { |path| swift_class.used_in_xml?(File.open(path).read) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fus
|
2
|
+
class SwiftClass
|
3
|
+
attr_reader :name
|
4
|
+
def initialize(name)
|
5
|
+
@name = name
|
6
|
+
end
|
7
|
+
|
8
|
+
def spec?
|
9
|
+
name.match(/Spec/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches_classname?(path)
|
13
|
+
path.match(/#{name}\b/)
|
14
|
+
end
|
15
|
+
|
16
|
+
def used_in_xml?(xml)
|
17
|
+
xml.include?("customClass=\"#{name}\"")
|
18
|
+
end
|
19
|
+
|
20
|
+
def used_in_obj_c?(text)
|
21
|
+
text.match(/(^|[^@])#{name}/)
|
22
|
+
end
|
23
|
+
|
24
|
+
def used_in_swift?(text)
|
25
|
+
text.match(/(\b#{name}.?[.:(])|([:].?#{name})|(typealias\s+.*=.+#{name})/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/fus/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tsabend
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.11.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A tool for finding unused Swift classes in an xcode project
|
70
|
+
email:
|
71
|
+
- tsabend@gmail.com
|
72
|
+
executables:
|
73
|
+
- fus
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- bin/fus
|
80
|
+
- lib/fus.rb
|
81
|
+
- lib/fus/finder.rb
|
82
|
+
- lib/fus/swift_class.rb
|
83
|
+
- lib/fus/version.rb
|
84
|
+
homepage: https://github.com/tsabend/fus
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: A tool for finding unused Swift classes in an xcode project
|
108
|
+
test_files: []
|