Skip to content

Commit 95fec9f

Browse files
dblockCopilot
andcommitted
Fix delete command to also remove .mm implementation files
The delete command only looked for .m implementation files when deleting an unused header, missing .mm (Objective-C++) files in mixed projects. Also updated the prompt text from (.m) to (.m/.mm). Fixes #12. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c09c651 commit 95fec9f

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
### 0.5.1 (Next)
22

33
* [#45](https://github.com/dblock/fui/pull/45): Migrated from Travis CI to GitHub Actions with danger-pr-comment workflow - [@dblock](https://github.com/dblock).
4-
* [#37](https://github.com/dblock/fui/issues/37): Fixed `ArgumentError: invalid byte sequence in UTF-8` when processing files with non-UTF-8 encoding - [@dblock](https://github.com/dblock).
5-
* [#42](https://github.com/dblock/fui/issues/42): Fixed `NameError: undefined local variable or method 'project_path'` in verbose mode - [@dblock](https://github.com/dblock).
6-
* [#38](https://github.com/dblock/fui/issues/38): Added summary output to `find` command: prints `Found N unused header(s).` or `No unused imports found.` - [@dblock](https://github.com/dblock).
4+
* [#47](https://github.com/dblock/fui/pull/47): Fixed `ArgumentError: invalid byte sequence in UTF-8` when processing files with non-UTF-8 encoding - [@dblock](https://github.com/dblock).
5+
* [#48](https://github.com/dblock/fui/pull/48): Fixed `NameError: undefined local variable or method 'project_path'` in verbose mode - [@dblock](https://github.com/dblock).
6+
* [#49](https://github.com/dblock/fui/pull/49): Added summary output to `find` command: prints `Found N unused header(s).` or `No unused imports found.` - [@dblock](https://github.com/dblock).
7+
* [#50](https://github.com/dblock/fui/pull/50): Fixed `delete` command to also remove `.mm` (Objective-C++) implementation files - [@dblock](https://github.com/dblock).
78
* Your contribution here.
89

910
### 0.5.0 (2018/12/19)

bin/fui

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ command :delete do |c|
6363
end.each do |k, _v|
6464
relative_path = Pathname.new(k.path).relative_path_from(root).to_s
6565
if options[:prompt]
66-
print "Remove #{relative_path}(.m) [y/N] "
66+
print "Remove #{relative_path}(.m/.mm) [y/N] "
6767
response = STDIN.getc.upcase
6868
puts "#{response.chr}\r\n"
6969
next unless response.chr == 'Y'
@@ -74,16 +74,18 @@ command :delete do |c|
7474
puts "#{relative_path}#{options[:perform] ? '' : ' (simulation)'}\r\n"
7575
end
7676
File.delete(k.path) if options[:perform]
77-
impl_path = k.path.gsub(/\.h$/, '.m')
78-
next unless File.exist?(impl_path)
77+
['.m', '.mm'].each do |ext|
78+
impl_path = k.path.gsub(/\.h$/, ext)
79+
next unless File.exist?(impl_path)
7980

80-
relative_path = Pathname.new(impl_path).relative_path_from(root).to_s
81-
if global_options[:verbose]
82-
puts "Removing #{relative_path}#{options[:perform] ? '' : ' (simulation)'}\r\n"
83-
else
84-
puts "#{relative_path}#{options[:perform] ? '' : ' (simulation)'}\r\n"
81+
relative_path = Pathname.new(impl_path).relative_path_from(root).to_s
82+
if global_options[:verbose]
83+
puts "Removing #{relative_path}#{options[:perform] ? '' : ' (simulation)'}\r\n"
84+
else
85+
puts "#{relative_path}#{options[:perform] ? '' : ' (simulation)'}\r\n"
86+
end
87+
File.delete(impl_path) if options[:perform]
8588
end
86-
File.delete(impl_path) if options[:perform]
8789
end
8890
ensure
8991
system('stty -raw echo')

spec/fui/fui_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,25 @@
7070
end
7171
pending 'prompts for deletion'
7272
end
73+
describe '#delete with .mm files' do
74+
before :each do
75+
@mm_fixtures = File.expand_path(File.join(__FILE__, '../../fixtures/mm'))
76+
end
77+
it "doesn't delete .mm files by default" do
78+
output = `"#{@binary}" --verbose --path "#{@mm_fixtures}" delete --no-prompt`
79+
output = output.split("\r\n")
80+
expect(output).to include 'Removing unused_class.mm (simulation)'
81+
expect(File.exist?(File.join(@mm_fixtures, 'unused_class.mm'))).to be true
82+
end
83+
it 'deletes .mm files with --perform' do
84+
Dir.mktmpdir do |tmpdir|
85+
FileUtils.cp_r @mm_fixtures.to_s, tmpdir
86+
output = `"#{@binary}" --verbose --path "#{tmpdir}" delete --no-prompt --perform`
87+
output = output.split("\r\n")
88+
expect(output).to include 'Removing mm/unused_class.mm'
89+
expect(File.exist?(File.join(tmpdir, 'mm/unused_class.mm'))).to be false
90+
end
91+
end
92+
end
7393
end
7494
end

0 commit comments

Comments
 (0)