diff --git a/.gitignore b/.gitignore index bd0feec..4b963ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Gemfile.lock pkg .bundle xcuserdata +!._* diff --git a/lib/fui/finder.rb b/lib/fui/finder.rb index 41c009b..ad3c5b3 100644 --- a/lib/fui/finder.rb +++ b/lib/fui/finder.rb @@ -50,6 +50,10 @@ def unused_references(&block) private + def fix_encoding(file_contents) + file_contents.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') + end + # Find all files for which the block yields. def find(path) results = [] @@ -89,6 +93,10 @@ def process_code(references, path) headers.each do |header| filename_without_extension = File.basename(path, File.extname(path)) file_contents = File.read(file) + unless file_contents.valid_encoding? + puts "Invalid encoding for #{filename_without_extension}" if options[:verbose] + file_contents = fix_encoding(file_contents) + end global_import_exists = global_imported(file_contents, header) local_import_exists = local_imported(file_contents, header) references[header] << path if filename_without_extension != header.filename_without_extension && (local_import_exists || global_import_exists) diff --git a/lib/fui/project.rb b/lib/fui/project.rb index 9f8bfc1..477c03d 100644 --- a/lib/fui/project.rb +++ b/lib/fui/project.rb @@ -22,7 +22,7 @@ def bridging_headers(verbose) path_tokens = tokens[1].split('/') bridging_header = path_tokens[path_tokens.length - 1] - puts "Bridging Header Found: #{bridging_header} in #{project_path}." if verbose + puts "Bridging Header Found: #{bridging_header} in #{path}." if verbose bridging_headers << bridging_header end bridging_headers.uniq diff --git a/spec/fixtures/m/._MyProjectTests.m b/spec/fixtures/m/._MyProjectTests.m new file mode 100644 index 0000000..6c20169 Binary files /dev/null and b/spec/fixtures/m/._MyProjectTests.m differ diff --git a/spec/fixtures/m/unused_class.h b/spec/fixtures/m/unused_class.h index cbc323c..9d8bfcd 100644 --- a/spec/fixtures/m/unused_class.h +++ b/spec/fixtures/m/unused_class.h @@ -3,6 +3,6 @@ // FUI // -@interface UnusedClass +@interface UnusedClass\xAD @end