Skip to content

Commit

Permalink
Fixed rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhamo1107 committed Aug 17, 2024
1 parent 395ce43 commit f0e9a31
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ Style/StringLiterals:

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Lint/ScriptPermission:
Enabled: false
8 changes: 5 additions & 3 deletions bin/un_used_methods
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

#!/usr/bin/env ruby

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

UnUsedMethods::CLI.start(ARGV)
34 changes: 7 additions & 27 deletions lib/un_used_methods/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,25 @@ def find_in_directory(directory)
end

def extract_methods(file)
methods = []
content = File.read(file)
content.scan(/def (\w+)/).flatten.each do |method_name|
methods << method_name
end
methods
content.scan(/def (\w+)/).flatten
end

def method_used?(method)
# Perform a search across the entire app to see if the method is used
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_pattern = /#{method}/
files = Dir.glob("app/**/*.{rb}")

method_used
files.any? do |file|
content = File.read(file)
content.match?(method_pattern)
end
end

def report_un_used_methods(unused_methods)
if unused_methods.empty?
puts "No un used methods found!"
else
puts "Un used Methods found in your model, controller and helper directories:"
puts "Un used Methods found in your model, controller, and helper directories:"
unused_methods.each { |method| puts method }
end
end
Expand Down
2 changes: 1 addition & 1 deletion un_used_methods.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
end
end
spec.bindir = "exe"
spec.executables = ['un_used_methods']
spec.executables = ["un_used_methods"]
spec.require_paths = ["lib"]

# Add development dependencies
Expand Down

0 comments on commit f0e9a31

Please sign in to comment.