Skip to content

Commit

Permalink
Handled windows and linux in analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhamo1107 committed Aug 16, 2024
1 parent df4c5a3 commit 395ce43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/un_used_methods
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

require 'bundler/setup'
require 'un_used_methods'
require 'un_used_methods/analyzer'

UnUsedMethods::CLI.start(ARGV)
24 changes: 22 additions & 2 deletions lib/un_used_methods/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,28 @@ def extract_methods(file)

def method_used?(method)
# Perform a search across the entire app to see if the method is used
grep_result = `grep -r "#{method}" app/`
grep_result.split("\n").size > 1 # If found more than one occurrence (definition + usage)
def method_used?(method)
method_pattern = /#{method}/
files = Dir.glob('app/**/*.{rb}')
method_used = false

if RUBY_PLATFORM =~ /win32|win64|cygwin|mswin|mingw/
# Windows-specific logic
files.each do |file|
content = File.read(file)
if content =~ method_pattern
method_used = true
break
end
end
else
# Unix-like (Linux, macOS) specific logic using `grep`
grep_result = `grep -r "#{method}" app/`
method_used = grep_result.split("\n").size > 1
end

method_used
end
end

def report_un_used_methods(unused_methods)
Expand Down

0 comments on commit 395ce43

Please sign in to comment.