fui 0.1.0
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/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +10 -0
- data/LICENSE.md +22 -0
- data/README.md +46 -0
- data/bin/fui +82 -0
- data/lib/fui.rb +6 -0
- data/lib/fui/finder.rb +50 -0
- data/lib/fui/header.rb +15 -0
- data/lib/fui/version.rb +3 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5272144b25c0da4a5f51f42c5008fae6a6e5de88
|
4
|
+
data.tar.gz: 7b51afae0ab0291c66085ac33474b0d74d557524
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ddb81f1c2e3a9fa6c63cfa72eb4e4e676e403f47af7cbbe89b0492a726a53f88a6acf4c234129c00a7dd12a63530b96e5dd0b9250a7200d9948eb977f2ce1fd
|
7
|
+
data.tar.gz: f43ed4e65196c51fbfde8fe74cfc41e9901a07ba139c64f12730a5e6161a3ca6661c3dadf3988526eafda7cf694aecf288fb5fe750b74f3e5d8b7eeecb0d0afe
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Daniel Doubrovkine.
|
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,46 @@
|
|
1
|
+
Fui
|
2
|
+
==========
|
3
|
+
|
4
|
+
[](https://travis-ci.org/dblock/fui)
|
5
|
+
|
6
|
+
Find unused Objective-C imports.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install fui
|
12
|
+
```
|
13
|
+
|
14
|
+
#### Get Help
|
15
|
+
|
16
|
+
```
|
17
|
+
fui help
|
18
|
+
```
|
19
|
+
|
20
|
+
#### Find Unused Classes in the Current Directory
|
21
|
+
|
22
|
+
```
|
23
|
+
fui find
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Find Unused Classes in a Path
|
27
|
+
|
28
|
+
```
|
29
|
+
fui --path=~/source/project/Name find
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Delete All Unused Class Files w/ Prompt
|
33
|
+
|
34
|
+
```
|
35
|
+
fui --path=~/source/project/Name delete --perform --prompt
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
41
|
+
|
42
|
+
## Copyright and License
|
43
|
+
|
44
|
+
Copyright (c) 2014, Daniel Doubrovkine, [Artsy](http://artsy.github.io), based on code by [@dstnbrkr](https://github.com/dstnbrkr).
|
45
|
+
|
46
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
data/bin/fui
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
require 'fui'
|
4
|
+
|
5
|
+
include GLI::App
|
6
|
+
|
7
|
+
program_desc 'Find unused imports in an Objective-C codebase'
|
8
|
+
|
9
|
+
flag [:p, :path], desc: 'Path to search', default_value: Dir.pwd
|
10
|
+
switch [:v, :verbose], desc: 'Verbose', default_value: false
|
11
|
+
|
12
|
+
default_command :find
|
13
|
+
|
14
|
+
pre do |global_options, command, options, args|
|
15
|
+
$fui = Fui::Finder.new(global_options[:path])
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Find unused classes"
|
19
|
+
command :find do |c|
|
20
|
+
c.action do |global_options, options, args|
|
21
|
+
root = Pathname.new($fui.path)
|
22
|
+
$fui.unused_references { |filename|
|
23
|
+
relative_path = Pathname.new(filename).relative_path_from(root).to_s
|
24
|
+
puts "Checking #{relative_path} ..." if global_options[:verbose]
|
25
|
+
}.each do |k, v|
|
26
|
+
relative_path = Pathname.new(k.path).relative_path_from(root).to_s
|
27
|
+
if global_options[:verbose]
|
28
|
+
puts "Found #{relative_path}"
|
29
|
+
else
|
30
|
+
puts relative_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Delete header and implementation files of unused classes"
|
37
|
+
command :delete do |c|
|
38
|
+
|
39
|
+
c.switch [:t, :prompt], desc: 'Prompt on delete', default_value: true
|
40
|
+
c.switch [:f, :perform], desc: 'Actually perform deletion', default_value: false, :negatable => false
|
41
|
+
|
42
|
+
c.action do |global_options, options, args|
|
43
|
+
begin
|
44
|
+
system("stty raw -echo")
|
45
|
+
|
46
|
+
root = Pathname.new($fui.path)
|
47
|
+
$fui.unused_references { |filename|
|
48
|
+
relative_path = Pathname.new(filename).relative_path_from(root).to_s
|
49
|
+
puts "Checking #{relative_path} ..." if global_options[:verbose]
|
50
|
+
}.each do |k, v|
|
51
|
+
relative_path = Pathname.new(k.path).relative_path_from(root).to_s
|
52
|
+
if options[:prompt]
|
53
|
+
print "Remove #{relative_path}(.m) [y/N] "
|
54
|
+
response = STDIN.getc.upcase
|
55
|
+
puts "#{response.chr}\r\n"
|
56
|
+
next unless response.chr == 'Y'
|
57
|
+
end
|
58
|
+
if global_options[:verbose]
|
59
|
+
puts "Removing #{relative_path}\r\n"
|
60
|
+
else
|
61
|
+
puts "#{relative_path}\r\n"
|
62
|
+
end
|
63
|
+
File.delete(k.path) if options[:perform]
|
64
|
+
impl_path = k.path.gsub(/\.h$/, '.m')
|
65
|
+
if File.exists?(impl_path)
|
66
|
+
relative_path = Pathname.new(impl_path).relative_path_from(root).to_s
|
67
|
+
if global_options[:verbose]
|
68
|
+
puts "Removing #{relative_path}\r\n"
|
69
|
+
else
|
70
|
+
puts "#{relative_path}\r\n"
|
71
|
+
end
|
72
|
+
File.delete(impl_path) if options[:perform]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ensure
|
77
|
+
system("stty -raw echo")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
exit run(ARGV)
|
data/lib/fui.rb
ADDED
data/lib/fui/finder.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Fui
|
2
|
+
class Finder
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = File.expand_path(path)
|
7
|
+
raise Errno::ENOENT.new(path) unless Dir.exists?(@path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def headers
|
11
|
+
@headers ||= Finder.find(path) { |path| Header.header?(path) }.collect { |path| Header.new(path) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def references(&block)
|
15
|
+
@references ||= begin
|
16
|
+
references = {}
|
17
|
+
headers.each do |header|
|
18
|
+
references[header] = []
|
19
|
+
end
|
20
|
+
Find.find(path) do |path|
|
21
|
+
next unless [".m", ".h", "*.pch"].include?(File.extname(path)) && File.ftype(path) == "file"
|
22
|
+
File.open(path) do |file|
|
23
|
+
filename = File.basename(path)
|
24
|
+
yield path if block_given?
|
25
|
+
headers.each do |header|
|
26
|
+
filename_without_extension = File.basename(path, File.extname(path))
|
27
|
+
references[header] << path if filename_without_extension != header.filename_without_extension && File.read(file).include?("#import \"#{header.filename}\"")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
references
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def unused_references(&block)
|
36
|
+
@unused_references ||= references(&block).select { |k, v| v.count == 0 }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Find all files for which the block yields.
|
42
|
+
def self.find(path, &block)
|
43
|
+
results = []
|
44
|
+
Find.find(path) { |fpath|
|
45
|
+
results << fpath if yield fpath
|
46
|
+
}
|
47
|
+
results
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/fui/header.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fui
|
2
|
+
class Header
|
3
|
+
attr_accessor :filename, :filename_without_extension, :path
|
4
|
+
|
5
|
+
def self.header?(path)
|
6
|
+
File.extname(path) == ".h"
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
@filename = File.basename(path)
|
12
|
+
@filename_without_extension = File.basename(path, File.extname(path))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/fui/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Doubrovkine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
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
|
+
description:
|
28
|
+
email: dblock@dblock.org
|
29
|
+
executables:
|
30
|
+
- fui
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/fui
|
35
|
+
- lib/fui/finder.rb
|
36
|
+
- lib/fui/header.rb
|
37
|
+
- lib/fui/version.rb
|
38
|
+
- lib/fui.rb
|
39
|
+
- CHANGELOG.md
|
40
|
+
- CONTRIBUTING.md
|
41
|
+
- LICENSE.md
|
42
|
+
- README.md
|
43
|
+
homepage: http://github.com/dblock/fui
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.3.6
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.0.14
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Find unused Objective-C imports.
|
67
|
+
test_files: []
|