Run the following script in your rails console or irb. Also. you can create a file and paste it there, then run ruby your_file_name.rb
It will give you all files where is commented code.
require 'find'
directory = './' # Change this to your project directory
code_patterns = [
/^\s*#\s*\w+\s*=\s*/,
/^\s*#\s*\w+\s*\.\w+\s*/,
/^\s*#\s*def\s+\w+/,
/^\s*#\s*end\b/,
/^\s*#\s*if\b/,
/^\s*#\s*class\b/,
/^\s*#\s*module\b/,
/^\s*#\s*do\b/,
/^\s*#\s*{.*}/,
/^\s*#\s*begin\b/,
/^\s*#\s*rescue\b/,
]
def commented_code?(line, patterns)
patterns.any? { |pattern| line.match(pattern) }
end
files_with_commented_code = []
Find.find(directory) do |path|
next unless File.file?(path)
next unless path.end_with?('.rb') # Only consider Ruby files
File.foreach(path).with_index do |line, line_num|
if commented_code?(line, code_patterns)
files_with_commented_code << path unless files_with_commented_code.include?(path)
puts "File: #{path}, Line #{line_num + 1}: #{line.strip}"
end
end
end
if files_with_commented_code.empty?
puts "No files with commented-out code found."
else
puts "\nFiles with commented-out code:"
files_with_commented_code.each { |file| puts file }
end