Skip to content

Instantly share code, notes, and snippets.

@byaruhaf
Created October 24, 2022 12:22
Show Gist options
  • Select an option

  • Save byaruhaf/f8d5c4f9f8ba6b90c14c35ad3ed0c876 to your computer and use it in GitHub Desktop.

Select an option

Save byaruhaf/f8d5c4f9f8ba6b90c14c35ad3ed0c876 to your computer and use it in GitHub Desktop.
Ruby script to find DeadCode
#!/usr/bin/ruby
puts "start dead code analysis"
result = `periphery scan`
result_stripped_of_absolute_path_prefix = result.gsub(Dir.pwd, '')
filtered_out_result = result_stripped_of_absolute_path_prefix.split("\n").filter { |line| /:\d+:\d+:/.match?(line) }
sorted_result = filtered_out_result.sort
result_with_removed_code_line_number = sorted_result.map {|l| l.sub(/:\d+:\d+:/, '') }
output = result_with_removed_code_line_number.join("\n") + "\n"
File.write('periphery_output', output)
puts "done with dead code analysis"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment