diff --git a/README.md b/README.md index 38c8d81..2e80895 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,23 @@ Starting searching globally it can take a while ``` ## Xcode integration -In order to integrate this to Xcode just add *Custom Build Phase/Run Script* -`~/Projects/swift-scripts/unused.rb xcode` +To integrate this into Xcode, simply add a "New Run Script Phase" and use the following code: +``` +file="unused.rb" +if [ -f "$file" ] +then +echo "$file found." +ruby unused.rb xcode +else +echo "unused.rb doesn't exist" +fi +``` +### Xcode ~/project/Build Phases: +Screenshot 2024-02-08 at 12 05 28 + +### Code Example: ![](https://user-images.githubusercontent.com/119268/32348473-88080ed2-c01c-11e7-9de6-762aeb195156.png) -![](https://user-images.githubusercontent.com/119268/32348476-8af3a700-c01c-11e7-893f-013851568882.png) + ## Known issues: - Fully text search (no fancy stuff) diff --git a/unused.rb b/unused.rb index 579f2c2..8cb998b 100755 --- a/unused.rb +++ b/unused.rb @@ -8,7 +8,8 @@ def initialize(file, line, at) @file = file @line = line @at = at + 1 - if match = line.match(/(func|let|var|class|enum|struct|protocol)\s+(\w+)/) + # typealias was added ⚠️ + if match = line.match(/(func|let|var|class|enum|struct|protocol|typealias)\s+(\w+)/) @type = match.captures[0] @name = match.captures[1] end @@ -117,7 +118,6 @@ def ignoring_regexps_from_command_line_args "Tests/" ] end - regexps end @@ -175,15 +175,15 @@ def find_usages_in_files(files, xibs, items_in) def grab_items(file) lines = File.readlines(file).map {|line| line.gsub(/^\s*\/\/.*/, "") } - items = lines.each_with_index.select { |line, i| line[/(func|let|var|class|enum|struct|protocol)\s+\w+/] }.map { |line, i| Item.new(file, line, i)} + # typealias was added ⚠️ + items = lines.each_with_index.select { |line, i| line[/(func|let|var|class|enum|struct|protocol|typealias)\s+\w+/] }.map { |line, i| Item.new(file, line, i)} end + # "CodingKeys" & "@main" & "Previews" for SwiftUI were added ⚠️ def filter_items(items) items.select { |f| - !f.name.start_with?("test") && !f.modifiers.include?("@IBAction") && !f.modifiers.include?("override") && !f.modifiers.include?("@objc") && !f.modifiers.include?("@IBInspectable") - } + !f.name.start_with?("test") && !f.modifiers.include?("@IBAction") && !f.modifiers.include?("override") && !f.modifiers.include?("@objc") && !f.modifiers.include?("@IBInspectable") && !f.modifiers.include?("@main") && !f.name.include?("CodingKeys") && !f.name.include?("Previews")} end - end class String @@ -212,5 +212,4 @@ def blink; "\e[5m#{self}\e[25m" end def reverse_color; "\e[7m#{self}\e[27m" end end - -Unused.new.find \ No newline at end of file +Unused.new.find