Skip to content

Commit

Permalink
Fui: Add support for .mm files.
Browse files Browse the repository at this point in the history
Files that are imported within .mm files will not be marked as unused.
  • Loading branch information
Shachlan committed Aug 13, 2017
1 parent 4487b57 commit 23381ff
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
### 0.4.1 (Next)
### 0.4.2 (Next)

* Your contribution here.

### 0.4.1 (8/13/2017)

* Support .mm files.

### 0.4.0 (5/14/2016)

* [#20](https://github.com/dblock/fui/pull/20): Added `-x`, `--ignorexib`, find unused classes referenced from its own XIB - [@Ezor](https://github.com/Ezor).
Expand Down
2 changes: 1 addition & 1 deletion lib/fui/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def references(&block)
end
Find.find(path) do |path|
next unless File.ftype(path) == 'file'
if ['.m', '.h', '.pch'].include?(File.extname(path))
if ['.m', '.mm', '.h', '.pch'].include?(File.extname(path))
process_code references, path, &block
elsif ['.storyboard', '.xib'].include?(File.extname(path))
process_xml references, path, &block
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/mm/main.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "used_class.h"

- void main()
{

}
8 changes: 8 additions & 0 deletions spec/fixtures/mm/unused_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// UnusedClass.h
// FUI
//

@interface UnusedClass

@end
10 changes: 10 additions & 0 deletions spec/fixtures/mm/unused_class.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// UnusedClass.mm
// FUI
//

#import "unused_class.h"

@implementation UnusedClass

@end
10 changes: 10 additions & 0 deletions spec/fixtures/mm/used_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// ImageView.h
// FUI
//

#import <UIKit/UIKit.h>

@interface ImageView
- (NSString *)fooForBar;
@end
14 changes: 14 additions & 0 deletions spec/fixtures/mm/used_class.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

//
// UsedClass.mm
// FUI
//

#import "used_class.h"

@implementation UsedClass
- (NSString *)fooForBar
{

}
@end
33 changes: 33 additions & 0 deletions spec/fui/finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,39 @@
end
end
end
context 'included from a .mm file' do
before :each do
@fixtures_dir = File.expand_path(File.join(__FILE__, '../../fixtures/mm'))
end
describe '#find' do
it 'finds all files for which the block yields true' do
files = Fui::Finder.send(:find, @fixtures_dir) do |file|
File.extname(file) == '.h'
end
expect(files.sort).to eq Dir["#{@fixtures_dir}/*.h"].sort
end
end
describe '#headers' do
it 'finds all headers' do
finder = Fui::Finder.new(@fixtures_dir)
expect(finder.headers.map(&:filename).sort).to eq(['unused_class.h', 'used_class.h'])
end
end
describe '#references' do
it 'maps references' do
finder = Fui::Finder.new(@fixtures_dir)
expect(finder.references.size).to eq(2)
expect(Hash[finder.references.map { |k, v| [k.filename, v.count] }]).to eq('unused_class.h' => 0,
'used_class.h' => 1)
end
end
describe '#unsed_references' do
it 'finds unused references' do
finder = Fui::Finder.new(@fixtures_dir)
expect(Hash[finder.unused_references.map { |k, v| [k.filename, v.count] }]).to eq('unused_class.h' => 0)
end
end
end
context 'included from a .pch file' do
before :each do
@fixtures_dir = File.expand_path(File.join(__FILE__, '../../fixtures/pch'))
Expand Down

0 comments on commit 23381ff

Please sign in to comment.